- 14 Tháng năm 2017
- 3,974
- 7,623
- 744
- 22
- Phú Yên
- Trường THPT Lương Văn Chánh
Chắc suất Đại học top - Giữ chỗ ngay!! ĐĂNG BÀI NGAY để cùng trao đổi với các thành viên siêu nhiệt tình & dễ thương trên diễn đàn.
Thật ra là Game "Tắt đèn chạy đua" Pascal mình thấy trên mạng rồi về làm thử
Mã:
Program Tat_Den;
Uses crt;
const
Soden = 7;
khch = 10;
Phimlen : array[1..Soden] of char = ('q','w','e','r','t','y','u');
Phimxuong: array[1..Soden] of char = ('a','s','d','f','g','h','j');
Min = 1;
Max = 24;
NguyHiem = 4;
Speed = 3000;
Var
Den, huong, mau: array[1..Soden] of integer;
phim: char;
Diem,DiemMax: integer;
f: text;
Procedure In_Gioi_Han;
var i,j: integer;
Begin
for i := khch to Soden*khch do
begin
TextColor(Red);
gotoxy(i, Min + 1);
Write(#196);
gotoxy(i, Max);
Write(#196);
TextColor(Green);
Gotoxy(i, 12);
Write('_');
end;
for i := 1 to SoDen do
begin
Textcolor(LightGray);
for j := Min + 2 To Max - 1 do
begin
Gotoxy(i * khch,j);
Write('.');
end;
end;
for i := 1 to SoDen do
begin
TextColor(Blue);
Gotoxy(i * khch,Min);
Write(PhimLen[i]);
Gotoxy(i * khch,Max + 1);
Write(Phimxuong[i]);
end;
End;
Procedure In_Den;
var i,j, c: integer;
Begin
In_Gioi_Han;
for i := 1 to Soden do
begin
if Den[i] > 0 then
j:= 12
else if Den[i] < 0 then j := 13;
c := j;
while j <> c - Den[i] do
begin
TextColor(mau[i]);
Gotoxy(i * khch,j);
Write(#219);
j := j - Den[i] div Abs(Den[i]);
end;
end;
End;
Procedure Dong_Dien;
var i : integer;
Begin
for i := 1 to Soden do
begin
Den[i] := Den[i] + huong[i];
end;
End;
Procedure Lay_Phim;
var i: integer;
Begin
Phim := #0;
if KeyPressed then Phim := Readkey;
for i := 1 to Soden do
begin
if Phim = Phimlen[i] then huong[i] := 1;
if Phim = Phimxuong[i] then huong[i] := -1;
end;
End;
Function EndGame: Boolean;
var i: integer;
Begin
EndGame := False;
for i := 1 to SoDen do
begin
if (Den[i] >= 12 - Min) or (Den[i] <= 12 - Max) then EndGame := True
else
if (Den[i] >= 12 - Min - NguyHiem) or
(Den[i] <= 12 + NguyHiem - Max) then mau[i] := LightRed
else mau[i] := Green;
end;
End;
Procedure Main;
var i,t: integer;
Begin
repeat
DiemMax := 0;
Assign(f,'DiemMax.txt');
reset(f);
Read(f,DiemMax);
Close(f);
clrscr;
TextColor(White);
Gotoxy(SoDen*khch + 3,7);
Write('Max: ',DiemMax);
diem := 0;
t := 0;
for i := 1 to Soden do begin Den[i] := 0;huong[i] := 1;end;
repeat
t := t+ 1;
Lay_Phim;
if t = Speed then
begin
Dong_Dien;
In_Den;
t := 0;
diem := diem + 1;
TextColor(White);
Gotoxy(khch*soDen + 3,5);
Write('Diem: ',diem);
end;
Until EndGame or (Phim = #27);
if Phim <> #27 then
begin
readln;
clrscr;
Write('Bam ESC de thoat, phim bat ki de choi lai!');
repeat Until Keypressed;
Phim := ReadKey;
end;
if Diem > DiemMax then
begin
ReWrite(f);
Write(f,Diem);
Close(f);
end;
Until Phim = #27;
End;
BEGIN
clrscr;
TextColor(White);
Write('Hay bam cac phim o tren va duoi cac den' +
' de dieu chinh dong dien qua den. ' +
'Khi dong dien cham cac vach do thi ban se thua!');
readln;
Main;
END.
Last edited: