# Pascal Programming Help!!!!!!!!!!

January 30, 2010 at 10:09:11
Specs: Windows XP
 HiI'm doing my A Level Computing. We are doing a program on a battleship game.This is the program code below..program battleshipgame2;{\$APPTYPE CONSOLE}usesSysUtils;VarBattleship:Array[0..9,0..9] of Char;R,C:Integer;row,col:Integer; AllTargets---:Boolean;beginfor R:=0 to 9 dobeginfor C:=0 to 9do Battleship [R,C]:= 'M';end;Battleship [2,2]:='S';Battleship [5,5]:='S';Battleship [7,7]:='S';repeatfor R:=0 to 9 dobeginfor C:=0 to 9doif (Battleship [R,C]= 'U')then Writeln (Battleship[row,col]);end;Writeln ('Please enter a row number');Readln (row);Writeln ('Please enter a column number');Readln (col);if (Battleship [row,col])= 'S'then Writeln ('Target Hit')elsebegin;AllTargets---:=False;Writeln ('Miss, Try Again');end;Battleship [row,col]:= 'U';for R:=0 to 9 dobeginfor C:=0 to 9doifBattleship [2,2]='U'Battleship [5,5]='U'Battleship [7,7]='U';Battleship [R,C]='U'thenbegin;AllTargets---:=True;Writeln ('All Battleships Sunk.. Game Over..Congratulations.. You Win');end;end;until AllTargets---=True;Readlnend.I want help in the how the program ends. The program ends when all the battleships are sunk or when all the elements in the array have been used. Can you also please check if the whole program works. I also want the program to show the coordinates already used by the person before they enter the next numbers so that they dont enter the same numbers.Can u please help????? I am trying to this for weeks now. Can u please do it in a simple way as it is A-Level work.Thanks.

See More: Pascal Programming Help!!!!!!!!!!

#1
January 30, 2010 at 14:02:00
 i would recommend to start from scratch - with pseudocode or minimal rendition. (i use BASIC because that lang. is very simple and i've used it alot). I dispensed with the booleanin favor of simply counting hits, but every programmer has their own ways. Not sure if you're allowed to use GOTOsso i had to construct a funky do-loop to handle the INPUTsI used do-loops as opposed to for-next because imo they're better suited to the job. I coded an "escape" for the user to exit the game, which i'm suprised is not a requirement for the problem (exit/quit/end option should always be coded for, else user is forced to use a control-break or other means)'========== initializationsdim battleship(9,9) for i:=0 to 9for j:=0 to 9battleship(i,j):="M"next jnext ibattleship(2,2):="S"battleship(5,5):="S"battleship(7,7):="S"N:=0hits:=0max:=3print "enter negative number to quit"'======= begin main loopdo while N<100'------- display current board statusgosub board'-------- get input do input "row: ",R if R<0 then exit do input "col: ",C if C<0 then R:=-1 exit do end if if battleship(R,C)="U" then print R,C "already used, try another shot" end if end do'-------- analyze input and respond if R<0 then exit do N:=N+1 if battleship(R,C)="S" then print "nice shot" hits:=hits+1 end if battleship(R,C):="U" if hits>=max then exit do end ifend do'--------- end: show the resultsif hits>=max then print "you win!"if N=100 then print "took you long enough!"if hits"U" then x:=" "print x;next jprint ""next ireturn

Report •
Related Solutions