Buat Game pake pascal

Program Game;
Uses crt;
Var field : array [1..80,1..25] of boolean;

procedure init_field;
var i : longint;
begin
clrscr; fillchar(field,sizeof(field),0);
for i := 3 to 22 do
begin
gotoxy(20,i); write(#186); field[20,i] := true;
gotoxy(36,i); write(#186); field[36,i] := true;
gotoxy(60,i); write(#186); field[60,i] := true;
gotoxy(76,i); write(#186); field[76,i] := true;
end;
for i := 1 to 15 do
begin
gotoxy(20+i,23); write(#205);
field[19+i,23] := true;
gotoxy(60+i,23); write(#205);
field[59+i,23] := true;
end;
gotoxy(20,23); write(#200);
gotoxy(60,23); write(#200);
gotoxy(36,23); write(#188);
gotoxy(76,23); write(#188);
gotoxy(6,4); write('Next:');
gotoxy(46,4); write('Next:');
end;

type _points = array [1..4] of record
x, y : longint;
end;
type
...
tetris = record
points : _points;
cshape,nshape,xmodel,xtetris,ymodel,ytetris: longint;
end;
var
...
tetris1, tetris2, ttetris : tetris;

Const template : array [1..8] of _points =
(((x:1; y:1),(x:1; y:2),(x:2; y:1),(x:2; y:2)),
((x:2; y:1),(x:1; y:1),(x:3; y:1),(x:4; y:1)),
((x:1; y:2),(x:1; y:1),(x:1; y:3),(x:2; y:3)),
((x:2; y:2),(x:2; y:1),(x:2; y:3),(x:1; y:3)),
((x:1; y:2),(x:1; y:1),(x:2; y:2),(x:2; y:3)),
((x:1; y:2),(x:2; y:1),(x:2; y:2),(x:1; y:3)),
((x:1; y:2),(x:1; y:1),(x:1; y:3),(x:2; y:2)),
((x:1; y:2),(x:2; y:1),(x:2; y:2),(x:2; y:3)));

procedure init_tetris(var objek : tetris; id : longint);
begin
objek.nshape := random(8) + 1;
if id = 1 then
begin
objek.xmodel := 7; objek.xtetris := 26;
end else begin
objek.xmodel := 47; objek.xtetris := 66;
end;
objek.ymodel := 5; objek.ytetris := 2;
dropnew(objek);
end;

Procedure drawtetris(objek : tetris; mode : Boolean);
Var I : longint;
C : char;
Begin
If mode then c := #178 else c := ‘ ‘;
For I := 1 to 4 do
Begin
Gotoxy(objek.tpoints[i].x, objek.tpoints[i].y);
Write(c);
Field[objek.tpoints[i].x,objek.tpoints[i].y]:=mode;
End;
Gotoxy(1,1);
End;

procedure dropnew(var objek : tetris);
var i : longint;
begin
if objek.cshape <> 0 then
begin
for i := 1 to 4 do
begin
ttetris.points[i].x:=template[objek.nshape,i].x+objek.xmodel;
ttetris.points[i].y:=template[objek.nshape,i].y+objek.ymodel;
end;
drawtetris(ttetris,false);
end;
objek.cshape := objek.nshape;
objek.nshape := random(8) + 1;
for i := 1 to 4 do
begin
objek.points[i].x:=template[objek.cshape,i].x+objek.xtetris;
objek.points[i].y:=template[objek.cshape,i].y+objek.ytetris;
ttetris.points[i].x:=template[objek.nshape,i].x+objek.xmodel;
ttetris.points[i].y:=template[objek.nshape,i].y+objek.ymodel;
if field[objek.points[i].x,objek.points[i].y] then
begin
gameover := true;
break;
end;
end;
drawtetris(objek,true);
drawtetris(ttetris,true);
end;

begin
randomize;
while not quit do
begin
init_field;
init_tetris(tetris1,1);
init_tetris(tetris2,2);
gameover := false;
while not gameover do
begin
slide(tetris1);
slide(tetris2);
userinput;
end;
gotoxy(1,25); write('Play Again[Y/N]? ');
repeat
answer := upcase(readkey);
until answer in ['Y','N',#27];
if (answer = 'N') or (answer = #27) then break;
end;
end.


email : dzulfadhli@hotmail.com

HP : +6285260255535

0 Comments:

Post a Comment