BASIC commenting help

admin

Administrator
Staff member
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.<br /><br />Here is what I finished:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->; the following lines ?Sets screen resolution, readies the backbuffer, readies the Random num generator and loads the pointer an image<br /><br />Graphics 800,600<br />SetBuffer BackBuffer()<br />SeedRnd MilliSecs()<br />pointer_img=LoadImage("1.bmp")<br /><br />; the following lines ?Sets up the arrays required to keep track of the cards and their current game statuses.<br /><br />Dim cards(52)<br />Dim face_up(52)<br />Dim card_imgs(52)<br />Dim on_table(52)<br />; the following lines ?call the init method (described later)<br /><br />cards_init()<br />; the following lines ?call the shuffle method in order to mix the cards up<br /><br />cards_shuffle()<br />; the following lines ?initializes last_n<br /><br />last_n=0<br />Repeat<br />; the following lines ?refreshes the screen, creates the pointer image at pointer location and places all the valid cards down.<br /><br />  Cls<br />  cards_display()<br />  DrawImage pointer_img,MouseX(),MouseY()<br />  Flip<br />; the following lines ?calls which_one method upon clicking<br /><br />  If MouseHit(1)<br />    n=cards_which_one()<br />; the following lines ?checks to see if the card still exists on the table, in order to 'flip it'<br /><br />    If n>0 Then<br />      face_up(n)=True<br />; the following lines ?calls display method<br /><br />      If last_n=0 Then<br />        last_n=n<br />      Else<br />        cards_display()<br />        Flip<br />        Delay 2000<br />        card=cards(n)<br />        last_card=cards(last_n)<br />        d=Abs(card-last_card)<br />; the following lines ?Basically checks to see if the two chosen cards are matching, and then proceeds to flip them down or remove them.<br /><br />        If d=13 Or d=26 Or d=39 Then<br />          on_table(n)=False<br />          on_table(last_n)=False<br />        Else<br />          face_up(n)=False<br />          face_up(last_n)=False<br />        End If<br />        last_n=0<br />      End If<br />    End If<br />  End If<br />; the following lines ?Game continues until Esc is pressed.<br /><br />Until KeyHit(1)<br />End<br /><br /><br />; the following lines ?This function begins caching the card images into the buffer for later use.<br /><br />Function cards_init()<br />  card_imgs(0)=LoadImage("back.bmp")<br />  For i=1 To 52<br />    cards(i)=i<br />    face_up(i)=False<br />    card_imgs(i)=LoadImage(i+".bmp")<br />    on_table(i)=True<br />  Next<br />End Function<br /><br />; the following lines ?This function shuffles the deck.<br /><br />Function cards_shuffle()<br />  For i=1 To 500<br />    r1=Rand(52)<br />    r2=Rand(52)<br />    t=cards(r1)<br />    cards(r1)=cards(r2)<br />    cards(r2)=t<br />  Next<br />End Function<br /><br />; the following lines ?draws the cards on to the screen.<br /><br />Function cards_display()<br />  n=1<br />  y=8<br />  For row=1 To 6<br />    x=68<br />    For col=1 To 9<br />      card=0<br />      If on_table(n) Then<br />        If face_up(n) Then card=cards(n)<br />        DrawBlock card_imgs(card),x,y<br />      End If<br />      x=x+74<br />      n=n+1<br />      If n=53 Then Exit<br />    Next<br />    y=y+98<br />  Next<br />End Function<br /><br />; the following lines ?This function checks to see if the card is face up or not<br /><br />Function cards_which_one()<br />  card=0<br />  n=1<br />  y=8<br />  For row=1 To 6<br />    x=68<br />    For col=1 To 9<br />      If mouse_in(x,y,x+74,y+98) Then If Not face_up(n) Then card=n<br />      x=x+74<br />      n=n+1<br />      If n=53 Then Exit<br />    Next<br />    y=y+98<br />  Next<br />  Return card<br />End Function<br /><br />; the following lines ?Enables the mouse pointer.<br /><br />Function mouse_in(x1,y1,x2,y2)<br />  x=MouseX(): y=MouseY()<br />  m=True<br />  If x<x1 Then m=False<br />  If x>x2 Then m=False<br />  If y<y1 Then m=False<br />  If y>y2 Then m=False<br />  Return m<br />End Function<!--c2--></div><!--ec2--><br /><br />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. <br /><br />Thanks a bunch.
</div>
 
Top