On Jan 19, 7:51=A0am, Wolf Behrenhoff
<NoSpamPleaseButThisIsVal...@[EMAIL PROTECTED]
> wrote:
> israph...@[EMAIL PROTECTED]
schrieb:
>
> > 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.
>
> The user only needs to enter a column!
>
>
>
> > PROGRAM ConnectFour;
>
> > {$APPTYPE CONSOLE}
>
> > uses
> > =A0 SysUtils;
>
> > TYPE
> > =A0 Tboard =3D ARRAY[65..71,49..55] OF STRING;
>
> What is that?
>
> The board has 7 cols and 6 rows. So the easiest way is
> TBoard =3D Array[0..6, 0..5] of Whatever;
>
> Why an array of string? Better define a type of what can be at that
> position. For example
> type TField =3D (empty, red, yellow);
>
> There is no need to store something that you already know! You know that
> the file in the lower left corner is A1, so why store that?
>
> You should NOT define internal structures (like the TBoard) based on a
> representation the user sees. Rather define it so that they match the
> problem.
>
> And more, you should put functions/procedures and the internal board
> representation together in a class.
>
> What compiler are you using? (I'm asking because of the $APPTYPE)
>
> You could do (in Delphi, FPC)
> type TBoard =3D class
> =A0 private
> =A0 =A0 fBoard: Array...
>
> =A0 =A0 ...
> =A0 public
> =A0 =A0 procedure Draw;
> =A0 =A0 function getCell(x,y: Integer): TField;
> =A0 =A0 function canPut(ACol: Integer): Boolean;
> =A0 =A0 procedure Put(Acol: Integer);
> =A0 =A0 constructor Create(who: TWhoStarts);
> =A0 =A0 ...
> =A0 end
>
> Wolf
Thanks for the reply and the help.
I am using Borland Delphi 7
I am Not sure about classes. (Am new to programming)
I'm a little confused here with some things. I am new to this thank
for your patience.
> There is no need to store something that you already know! You know that
> the file in the lower left corner is A1, so why store that?
> You should NOT define internal structures (like the TBoard) based on a
> representation the user sees. Rather define it so that they match the
> problem.
=46rom this I am stuck as to how I can represent each square to the
user. Do you actually mean instead of having the cells showing 'A1'
just maybe something like this..
_ _ _
|_|_|_|
|_|_|_|
|_|_|_|
|_|_|_|
1 2 3
Displayed? (In order to obtain player input).
>The user only needs to enter a column!
Also by this image and your comment, this means I don't have to worry
about 'A1' really right? For users.


|