OutOfLuck
asked on
Memory Game
hi i know ive asked a lot of questions regarding this topic, but the other solutions havent worked regarding this topic. i basically need to make a memory game in delphi pascal, using a drawgrid and 20 bitmap images. i know that there is already a website out there that covers this topic but as it is for a school project i cannot use the exact same code. all the other codes that i have made eithr dont load the image into the drawgrid or have problem matching teh images. Please i am actually begging you to help me with this topic.
do you have to use a drawgrid ?
there are lots of other possible solutions ...
there are lots of other possible solutions ...
ASKER
well as im using images i thought a DrawGrid would be the most suitable option.
I sent you the memory game link in a previous question of yours.
However you must focus on the subject of programming and try to understand what is going on, and why everything exists where it is.
You have to make plan in your head about the code you will write. What parts is comprised of.
This site is about people who are stuck on something they do, and need a "push" by other people who might direct them to SOLVING their problem.
Please ask specific questions to problems you encounter. Don't just ask us to make your homework on your behalf. Its something I won't presonally do, and if I did I would charge for it.
However you must focus on the subject of programming and try to understand what is going on, and why everything exists where it is.
You have to make plan in your head about the code you will write. What parts is comprised of.
This site is about people who are stuck on something they do, and need a "push" by other people who might direct them to SOLVING their problem.
Please ask specific questions to problems you encounter. Don't just ask us to make your homework on your behalf. Its something I won't presonally do, and if I did I would charge for it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
frmRooms: TfrmRooms;
Images : array [0..19] of TImage;
fFirstCell, fSecondCell : boolean;
ShowPicture: Integer;
xArray: array[0..4, 0..3,1..4] of string;
ImagePaths : array [0..19] of string
=('bathroom.bmp', 'hallway.bmp' ,
'untitled3.bmp' , 'kitchen.bmp' , 'pantry.bmp' ,
'study room.bmp' , 'living room.bmp' , 'dining room.bmp' ,'toilet.bmp' ,
'House.bmp','Fbathroom.bmp
'Fpantry.bmp' ,'Fstudy.bmp' , 'Fliving room.bmp' , 'Fdining room.bmp' ,
'Ftoilet.bmp' ,'FHouse.bmp');
const
c_name = 1;
c_pic = 2;
c_type = 3;
c_status = 4;
procedure InitializeCellModes;
var
ARow, ACol: integer;
Begin
For ACol:= 0 to 4 do
For ARow:= 0 to 3 do
Begin;
xArray[ACol, ARow, c_type]:='NotVisible';
end;
end;
procedure RedrawCell;
var ACol, ARow: integer;
begin
frmRooms.DrawGrid1DrawCell
end;
procedure TfrmRooms.FormCreate(Sende
var
begin
ClickedRow := -1;
ClickedCol := -1;
DrawGrid1.Options := DrawGrid1.Options - [goRangeSelect,goRowSelect
fFirstCell:=True;
fSecondCell:=true;
InitializeCellModes;
ShowPicture := 0;
xArray[0, 0, c_name] := 'bedroom';
xArray[0, 0, c_pic] := 'Fbedroom.bmp';
xArray[0, 0, c_type] := '';
xArray[0, 0, c_status] := '';
xArray[0, 1, c_name] := 'bedroom';
xArray[0, 1, c_pic] := 'untitled3.bmp';
xArray[0, 1, c_type] := '';
xArray[0, 1, c_status] := '';
xArray[0, 2, c_name] := 'bathroom';
xArray[0, 2, c_pic] := 'Fbathroom.bmp';
xArray[0, 2, c_type] := '';
xArray[0, 2, c_status] := '';
xArray[0, 3, c_name] := 'bathroom';
xArray[0, 3, c_pic] := 'bathroom.bmp';
xArray[0, 3, c_type] := '';
xArray[0, 3, c_status] := '';
xArray[1, 0, c_name] := 'hallway';
xArray[1, 0, c_pic] := 'Fhallway.bmp';
xArray[1, 0, c_type] := '';
xArray[1, 0, c_status] := '';
xArray[1, 1, c_name] := 'hallway';
xArray[1, 1, c_pic] := 'hallway.bmp';
xArray[1, 1, c_type] := '';
xArray[1, 1, c_status] := '';
xArray[1, 2, c_name] := 'kitchen';
xArray[1, 2, c_pic] := 'Fkitchen.bmp';
xArray[1, 2, c_type] := '';
xArray[1, 2, c_status] := '';
xArray[1, 3, c_name] := 'kitchen';
xArray[1, 3, c_pic] := 'kitchen.bmp';
xArray[1, 3, c_type] := '';
xArray[1, 3, c_status] := '';
xArray[2, 0, c_name] := 'pantry';
xArray[2, 0, c_pic] := 'Fpantry.bmp';
xArray[2, 0, c_type] := '';
xArray[2, 0, c_status] := '';
xArray[2, 1, c_name] := 'pantry';
xArray[2, 1, c_pic] := 'pantry.bmp';
xArray[2, 1, c_type] := '';
xArray[2, 1, c_status] := '';
xArray[2, 2, c_name] := 'study room';
xArray[2, 2, c_pic] := 'Fstudy room.bmp';
xArray[2, 2, c_type] := '';
xArray[2, 2, c_status] := '';
xArray[2, 3, c_name] := 'study room';
xArray[2, 3, c_pic] := 'study room.bmp';
xArray[2, 3, c_type] := '';
xArray[2, 3, c_status] := '';
xArray[3, 0, c_name] := 'living room';
xArray[3, 0, c_pic] := 'Fbedroom.bmp';
xArray[3, 0, c_type] := '';
xArray[3, 0, c_status] := '';
xArray[3, 1, c_name] := 'bedroom';
xArray[3, 1, c_pic] := 'untitled3.bmp';
xArray[3, 1, c_type] := '';
xArray[3, 1, c_status] := '';
xArray[3, 2, c_name] := 'dining room';
xArray[3, 2, c_pic] := 'Fbedroom.bmp';
xArray[3, 2, c_type] := '';
xArray[3, 2, c_status] := '';
xArray[3, 3, c_name] := 'bedroom';
xArray[3, 3, c_pic] := 'untitled3.bmp';
xArray[3, 3, c_type] := '';
xArray[3, 3, c_status] := '';
xArray[4, 0, c_name] := 'toilet';
xArray[4, 0, c_pic] := 'Fbedroom.bmp';
xArray[4, 0, c_type] := '';
xArray[4, 0, c_status] := '';
xArray[4, 1, c_name] := 'bedroom';
xArray[4, 1, c_pic] := 'untitled3.bmp';
xArray[4, 1, c_type] := '';
xArray[4, 1, c_status] := '';
xArray[4, 2, c_name] := 'house';
xArray[4, 2, c_pic] := 'Fbedroom.bmp';
xArray[4, 2, c_type] := '';
xArray[4, 2, c_status] := '';
xArray[4, 3, c_name] := 'house';
xArray[4, 3, c_pic] := 'untitled3.bmp';
xArray[4, 3, c_type] := '';
xArray[4, 3, c_status] := '';
end;
procedure TfrmRooms.DrawGrid1SelectC
ARow: Integer; var CanSelect: Boolean);
var
NewRow, NewCol : integer;
begin
NewRow := DrawGrid1.Row;
NewCol := DrawGrid1.Col;
if ShowPicture = 0 then
begin
if ((ACol= ClickedCol) and (ARow=ClickedRow))then
xArray[ACol, ARow, c_type]:='Visible';
RedrawCell;
inc(ShowPicture);
fFirstCell:= False;
end
else if (ShowPicture = 1) and (fFirstCell = False) then
begin
if ((NewCol= ClickedCol) and (NewRow=ClickedRow))then
xArray[ACol, ARow, c_type]:='Visible';
RedrawCell;
fSecondCell:= False;
if (xArray[ARow, ACol, c_name] )= (xArray[NewCol, NewRow, c_name]) then
begin
Sleep(100);
xArray[ACol, ARow, c_type]:='Matched';
xArray[NewCol, NewRow, c_type]:='Matched';
RedrawCell;
ShowPicture := 0
end
else
inc(ShowPicture)
end
else begin
if (xArray[ARow, ACol, c_name] )<> (xArray[NewCol, NewRow, c_name]) then
begin
xArray[NewCol, NewRow, c_type]:='Visible';
RedrawCell;
end;
if fFirstCell=False then
begin
xArray[ACol, ARow, c_type]:='NotVisible';
RedrawCell;
end;
if fSecondCell= False then
begin
xArray[NewCol, NewRow, c_type]:='NotVisible';
RedrawCell;
end;
ShowPicture := 1
end
end;
procedure TfrmRooms.DrawGrid1DrawCel
ARow: Integer; Rect: TRect; State: TGridDrawState);
var
i,j : integer;
begin
DrawGrid1.Canvas.Brush.Col
DrawGrid1.Canvas.FillRect(
if (ACol =ClickedCol) and (ARow=ClickedRow) then
if xArray[i, j, c_type]='NotVisible'
then
begin
DrawGrid1.Canvas.Brush.Col
DrawGrid1.Canvas.FillRect(
end
else if xArray[i, j, c_type]='Matched'
then
begin
DrawGrid1.Canvas.Brush.Col
DrawGrid1.Canvas.FillRect(
end
else begin
DrawGrid1.Canvas.TextOut(R
end
end;