You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.4 KiB

Unit GameUnit;
Interface
Uses
dataUnit;
Procedure playLevel(var theGS: dataUnit.GameState);
Implementation
Uses
crt,
Math,
heroEnemy,
toolsProc,
moversProc;
Procedure writeMap(Var theGS: dataUnit.GameState);
Var
col: integer;
row: integer;
Begin
clrscr;
For row := 1 To theGS.mapHeight Do
Begin
For col := 1 To theGS.mapWidth Do
Write(theGS.map[row, col]);
writeln;
End;
End;
Procedure playLevel(var theGS: dataUnit.GameState);
Var
move: boolean;
Begin
randomize;
(* Game loop *)
Repeat
writeMap(theGS);
gotoxy(1, theGS.mapHeight + 1);
writeLn(theGS.ID,' Hint:', theGS.clue);
gotoxy(theGS.manCol, theGS.manRow);
(* Player turn *)
Repeat
move := True;
Case readKey Of
'i': moveMan(theGS, -1, 0);
'j': moveMan(theGS, 0, -1);
'k': moveMan(theGS, 1, 0);
'l': moveMan(theGS, 0, 1);
' ': ;
'q': theGS.goal := -1;
Else
move := False;
End;
Until move;
(* Update map *)
doMagnet(theGS);
moveMovers(theGS);
moveEnemies(theGS);
Until theGS.goal <=0;
(* Win/Lose state *)
writeMap(theGS);
gotoxy(theGS.mapWidth Div 2 - 4, theGS.mapHeight Div 2);
If theGS.goal = 0 Then
Begin
Write('You Win!');
End
Else
Write('You Lose!');
gotoxy(1, theGS.mapHeight + 2);
writeLn('Press ENTER to continue.');
readLn;
End;
End.