Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,164 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,886 people online right now. Registration is fast and FREE... Join Now!




BASIC commenting help

 
Reply to this topicStart new topic

BASIC commenting help, A lil help identifying...

Revitalized
7 Dec, 2007 - 01:25 AM
Post #1

New D.I.C Head
*

Joined: 11 Sep, 2007
Posts: 17


My Contributions
So this is for BASIC programming, and our assignment was to comment each part of the program and describe what that segment does. The program is for the game Concentration. (A bunch of flipped down cards with the objective to match two of the same) I've finished the assignment, but I'm not sure if it's completely right as I did have a couple areas where I was feeling vague.

Here is what I finished:
CODE
; the following lines … Sets screen resolution, readies the backbuffer, readies the Random num generator and loads the pointer an image

Graphics 800,600
SetBuffer BackBuffer()
SeedRnd MilliSecs()
pointer_img=LoadImage("1.bmp")

; the following lines … Sets up the arrays required to keep track of the cards and their current game statuses.

Dim cards(52)
Dim face_up(52)
Dim card_imgs(52)
Dim on_table(52)
; the following lines … call the init method (described later)

cards_init()
; the following lines … call the shuffle method in order to mix the cards up

cards_shuffle()
; the following lines … initializes last_n

last_n=0
Repeat
; the following lines … refreshes the screen, creates the pointer image at pointer location and places all the valid cards down.

  Cls
  cards_display()
  DrawImage pointer_img,MouseX(),MouseY()
  Flip
; the following lines … calls which_one method upon clicking

  If MouseHit(1)
    n=cards_which_one()
; the following lines … checks to see if the card still exists on the table, in order to 'flip it'

    If n>0 Then
      face_up(n)=True
; the following lines … calls display method

      If last_n=0 Then
        last_n=n
      Else
        cards_display()
        Flip
        Delay 2000
        card=cards(n)
        last_card=cards(last_n)
        d=Abs(card-last_card)
; the following lines … Basically checks to see if the two chosen cards are matching, and then proceeds to flip them down or remove them.

        If d=13 Or d=26 Or d=39 Then
          on_table(n)=False
          on_table(last_n)=False
        Else
          face_up(n)=False
          face_up(last_n)=False
        End If
        last_n=0
      End If
    End If
  End If
; the following lines … Game continues until Esc is pressed.

Until KeyHit(1)
End


; the following lines … This function begins caching the card images into the buffer for later use.

Function cards_init()
  card_imgs(0)=LoadImage("back.bmp")
  For i=1 To 52
    cards(i)=i
    face_up(i)=False
    card_imgs(i)=LoadImage(i+".bmp")
    on_table(i)=True
  Next
End Function

; the following lines … This function shuffles the deck.

Function cards_shuffle()
  For i=1 To 500
    r1=Rand(52)
    r2=Rand(52)
    t=cards(r1)
    cards(r1)=cards(r2)
    cards(r2)=t
  Next
End Function

; the following lines … draws the cards on to the screen.

Function cards_display()
  n=1
  y=8
  For row=1 To 6
    x=68
    For col=1 To 9
      card=0
      If on_table(n) Then
        If face_up(n) Then card=cards(n)
        DrawBlock card_imgs(card),x,y
      End If
      x=x+74
      n=n+1
      If n=53 Then Exit
    Next
    y=y+98
  Next
End Function

; the following lines … This function checks to see if the card is face up or not

Function cards_which_one()
  card=0
  n=1
  y=8
  For row=1 To 6
    x=68
    For col=1 To 9
      If mouse_in(x,y,x+74,y+98) Then If Not face_up(n) Then card=n
      x=x+74
      n=n+1
      If n=53 Then Exit
    Next
    y=y+98
  Next
  Return card
End Function

; the following lines … Enables the mouse pointer.

Function mouse_in(x1,y1,x2,y2)
  x=MouseX(): y=MouseY()
  m=True
  If x<x1 Then m=False
  If x>x2 Then m=False
  If y<y1 Then m=False
  If y>y2 Then m=False
  Return m
End Function


A tad long, but basically I was wondering if anyone could tell me if my comments for each section is correct, and if anything is wrong or can be tweaked.

Thanks a bunch.
User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: BASIC Commenting Help
7 Dec, 2007 - 07:53 PM
Post #2

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 3,984



Thanked: 16 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
first of all you don't need to have the "the following lines … " on every comment, if there is a newline a comment then code, it is assumed to be a comment on the code below the comment.

You should add some comments in the loops, There are many loops and if statements, you should at least a little information as to what case they are handling.
User is offlineProfile CardPM
+Quote Post

Revitalized
RE: BASIC Commenting Help
7 Dec, 2007 - 09:12 PM
Post #3

New D.I.C Head
*

Joined: 11 Sep, 2007
Posts: 17


My Contributions
Oh of course, "the following lines" were placed there by my teacher. Those were the spots we were suppose to fill in and identify.

Not really any need to go into great detail, so I kept it simple.
User is offlineProfile CardPM
+Quote Post

chili5
RE: BASIC Commenting Help
2 Jan, 2008 - 05:08 PM
Post #4

D.I.C Addict
****

Joined: 28 Dec, 2007
Posts: 700



Thanked: 4 times
My Contributions
When I was using Just Basic I always commented my code using

CODE

'close window
end


In Just Basic, you can use ' or the word "rem" to put comments in your code.

I hope that helps I don't know about other forms of the basic language.

This post has been edited by chili5: 2 Jan, 2008 - 05:08 PM
User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: BASIC Commenting Help
2 Jan, 2008 - 06:06 PM
Post #5

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 3,984



Thanked: 16 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
there are many different variations, and comments are really a compiler specific thing, whether it is standardized or not becomes another issue.

Whenever I've done Basic I too used ' as a comment, the semi-colon ; should be a concatenation operator similar to the & in this language.
User is offlineProfile CardPM
+Quote Post

lime_rising
RE: BASIC Commenting Help
5 Jan, 2008 - 03:41 PM
Post #6

New D.I.C Head
*

Joined: 5 Jan, 2008
Posts: 11


My Contributions
Looks good... I've always been told to tell what variables the functions input/output, but I program in True Basic so that might not be applicable.

I get what you said about feeling vague, I feel like that all the time when I'm commenting. I hate commenting my programs, it's just so mind-numbingly boring. sleep.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 12:03AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month