Hi all.
I have been writing a connect four game.
So far I have defined the board using a 2D Array.
Because I have no graphical programming experience, this is being done
in the console application.
My board is displayed and in each cell appears notation which
represents that cell. The user chooses for e.g. 'A1'. So the counter
appears in this cell. That's how I want it to go, I've tried
implementing it using a search algorithm, but something is up and I'm
sturuggling with this, help would be very appreciated, many thanks.
PROGRAM ConnectFour;
{$APPTYPE CONSOLE}
uses
SysUtils;
TYPE
Tboard = ARRAY[65..71,49..55] OF STRING;
{*************************************************
**********************
Creates the Connect four board
**************************************************
**********************}
PROCEDURE makeBoard(VAR board : Tboard);
VAR
x, y : integer;
m, n : STRING;
BEGIN
FOR x:= 65 TO 71 DO
BEGIN
m := chr(x);
FOR y := 49 TO 55 DO
BEGIN
n := chr(y);
board[X,Y] := m + n;
END;
END;
END;
{*************************************************
***********************
Accesses the board and displays it.
**************************************************
***********************}
PROCEDURE displayBoard(board : Tboard);
VAR
X, Y : INTEGER;
BEGIN
writeln('
----------------------------------------------------------------');
FOR x:= 65 TO 71 DO
BEGIN
FOR y := 49 TO 55 DO
BEGIN
write(' |');
write(' ',board[X,Y]);
END;
write(' |');
writeln;
writeln(' ==================================================
==============');
END;
END;
PROCEDURE placeCounter(cell : STRING; var board : Tboard);
VAR
x, y : integer;
BEGIN
FOR x:= 65 TO 71 DO
FOR y:= 49 TO 55 DO
IF (board[x,y] = 'A1') THEN
board[x,y] := '#'
END;
PROCEDURE chooseCell(board : Tboard);
VAR
cell : STRING;
BEGIN
writeln;
writeln('Choose a cell you would like to drop a counter in.(e.g.
''B3'') : ');
readln(cell);
END;
{*************************************************
****************
Puts all of the procedures uses in the game together, The loop
controll will also be administered in here(overall game control).
**************************************************
*****************}
PROCEDURE newGame();
VAR
board : Tboard;
won : boolean;
BEGIN
won := false;
makeboard(board);
repeat
displayboard(board);
chooseCell(board);
until (won = true);
END;
PLEASE NOTE HERE : I have attempted to replace 'A1' string with '#' to
represent the cell. Ultimately this is not how the program will work,
but at the moment my primary concern is getting this search and
replace procedure working.


|