uses crt;
type CharDirection = (Up, Down, Left, Right, None);
var GoalX : Integer ;
GoalY : Integer ;
CharX : Integer ;
CharY : Integer ;
Stage : String ;
Key : Char ;
Direction : CharDirection;
procedure SetGoal;
begin
Randomize;
GoalX:=Random(80)+1;
Randomize;
GoalY:=Random(24)+2;
end;
procedure InfStage;
begin
GotoXY(1,1);
write(Stage,' ');
end;
procedure CheckWin;
begin
if (CharX = GoalX) and (CharY = GoalY) and (Key = #13) then
begin
clrscr;
write('You won!');
end;
end;
procedure CheckChar;
begin
if not CharX in [1..WindMaxX] then
begin
if CharX < 1 then CharX := 1
else if CharX > WindMaxX then CharX := WindMaxX;
if Direction in [Left, Right] then
Direction := None;
end;
if not CharY in [2..WindMaxY] then
begin
if CharY <= 2 then CharY := 2
else if CharY > WindMaxY then CharY := WindMaxY;
if Direction in [Up, Down] then
Direction := None;
end;
InfStage;
end;
procedure CheckCoord;
begin
if (CharX in [1..WindMaxX]) and (CharY in [2..WindMaxY]) then Stage := 'Freezing! D:';
if (CharX in [GoalX-12..GoalX+12]) and (CharY in [GoalY-12..GoalY-12]) then Stage := 'So Cold :<';
if (CharX in [GoalX-8..GoalX+8]) and (CharY in [GoalY-8..GoalY+8]) then Stage := 'Cool :o';
if (CharX in [GoalX-5..GoalX+5]) and (CharY in [GoalY-5..GoalY+5]) then Stage := 'Warm :)';
if (CharX in [GoalX-3..GoalX+3]) and (CharY in [GoalY-3..GoalY+3]) then Stage := 'Hot hot :D';
if (CharX in [GoalX-1..GoalX+1]) and (CharY in [GoalY-1..GoalY+1]) then Stage := 'Warm >:D';
InfStage;
end;
procedure WriteO;
begin
CheckChar;
CheckCoord;
write(' ');
gotoxy(CharX,CharY);
write('o');
gotoxy(CharX,CharY);
InfStage;
end;
procedure UpdatePosition;
begin
case Direction of
Up: Dec(CharY);
Down: Inc(CharY);
Left: Dec(CharX);
Right: Inc(CharX);
end;
end;
procedure SetDirection(NewDirection: CharDirection);
begin
if Direction <> NewDirection then
Direction := NewDirection;
end;
begin
ClrScr;
CharX:=Random(80)+1;
CharY:=Random(24)+2;
WriteO;
Direction := None;
SetGoal;
repeat
CheckChar;
CheckCoord;
key:=readkey;
case key of
#72,'W','w': Direction(Up);
#75,'A','a': Direction(Left) ;
#80,'S','s': Direction(Down) ;
#77,'D','d': Direction(Right);
else Direction := None;
end;
UpdatePosition;
InfStage;
CheckWin;
until key = #27;
end.