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.
Program The_Tank_Game;
Uses Crt;
Type
Location = Record
x,y: Byte;
End;
Var
Tank,Enemy,Bullet,Arrow,Present: Location;
i,j,Spawm_Enemy,z,ExtraBullet: Byte;
KEY,m,w,SavedKey: Char;
Score,NumberOfBullet,Target: Integer;
Function CheckEnemy(x,y: Byte): Boolean;
Begin
If ((bullet.x = enemy.x+1) And (bullet.y = enemy.y)) Or ((bullet.x = enemy.x+3) And (bullet.y = enemy.y-1)) Or ((bullet.x = enemy.x+3) And (bullet.y = enemy.y+1)) Then CheckEnemy := True
Else CheckEnemy := False;
End;
Function CheckWin(Score,Target: Integer): Boolean;
Begin
If (Score=Target) Then ChecKWin := True
Else CheckWin := False;
End;
Function CheckLose(Score,Target,NumberOfBullet: Integer): Boolean;
Begin
If (Score<Target) And (NumberOfBullet=0) Then CheckLose := True
Else CheckLose := False;
End;
//==============================The Functions=========================
Procedure THE_UP_ARROW_ANIMATION;
Begin
GotoXY(48,15); Write(#32#32#32#32#32#32#32#32#32#32,
#32#32#32#32#32#32#32#32#32#32);
TextColor(LightGreen);
GotoXY(Arrow.x,Arrow.y);
Writeln(#32);
Arrow.y := Arrow.y - 2;
GotoXY(Arrow.x,Arrow.y);
Writeln(#16);
Arrow.y := 13;
TextColor(LightBlue);
GotoXY(51,13); Write('(Double ENTER Click)');
End;
Procedure THE_DOWN_ARROW_ANIMATION;
Begin
GotoXY(51,13); Write(#32#32#32#32#32#32#32#32#32#32,
#32#32#32#32#32#32#32#32#32#32);
TextColor(LightGreen);
GotoXY(Arrow.x,Arrow.y);
WriteLn(#32);
Arrow.y := Arrow.y + 2;
GotoXY(Arrow.x,Arrow.y);
Writeln(#16);
Arrow.y := 15;
TextColor(LightBlue);
GotoXY(48,15); Write('(Double ENTER Click)');
End;
//====================The Animation Of Arrow================
Procedure FITISSUE;
Begin
For i:=1 To 10 Do
Begin
TextColor(White);
GotoXY(i,2); WriteLn(#205);
GotoXY(i,28); WriteLn(#205);
End;
End;
//============================FIT THE ISSUE======================
Procedure INTERFACES;
Begin
Clrscr;
TextColor(LightBlue);
For j := 1 To 2 Do
For i := 1 To 13 Do
Begin
GotoXY(i+32,9+(j-1)*2);
WriteLn(#205);
End;
GotoXY(32,10); WriteLn(#186);
GotoXY(46,10); WriteLn(#186);
GotoXY(32,9); WriteLn(#201);
GotoXY(32,11); WriteLn(#200);
GotoXY(46,9); WriteLn(#187);
GotoXY(46,11); WriteLn(#188);
GotoXY(33,10);
TextColor(Yellow);
WriteLn('THE TANK GAME');
TextColor(LightGreen);
GotoXY(56,28);
WriteLn(#15#32#76#105#99#101#110#115#101,':',
#32#36#36#72#97#117#95#67#114#117#115#104#36#36); //License
TextColor(White);
For i := 1 To 78 Do
Begin
GotoXY(2+(i-1)*1,1); Write(#196);
GotoXY(2+(i-1)*1,29); Write(#196);
End;
GotoXY(1,1); Write(#218);
GotoXY(80,1); Write(#191);
GotoXY(1,29); Write(#192);
GotoXY(80,29); Write(#217);
For i := 1 To 27 Do
Begin
GotoXY(1,2+(i-1)*1); Write(#179);
GotoXY(80,2+(i-1)*1); Write(#179);
End;
TextColor(White);
GotoXY(33,13); WriteLn('Start the game');
GotoXY(33,15); WriteLn('Instruction');
TextColor(LightBlue);
GotoXY(51,13); WriteLn('(Double ENTER Click)');
TextColor(Green);
Arrow.x := 30;
Arrow.y := 13;
GotoXY(Arrow.x,Arrow.y); Write(#16);
Repeat
If KeyPressed Then
Case ReadKey Of
#72: If (Arrow.y <> 13) Then THE_UP_ARROW_ANIMATION;
#80: If (Arrow.y <> 15) Then THE_DOWN_ARROW_ANIMATION;
End;
Until Readkey = #13;
End;
Procedure INSTRUCTION;
Begin
For i := 1 To 80 Do
Begin
TextColor(White);
GotoXY(i,2);
Write(#196);
End;
TextColor(Yellow);
GotoXY(35,1); Writeln('INSTRUCTION');
TextColor(LightGreen);
GotoXY(1,1); Write('B: Back');
TextColor(White);
GotoXY(3,3);
WriteLn(#4#32,'Your assignment is that destroy the enemies with the specified bullets');
GotoXY(3,5);
WriteLn(#4#32,'If bullets run out and the enemies all aren`t destroyed, you`ll lose');
GotoXY(3,7);
WriteLn(#4#32,'If bullets don`t run out and the enemies all are destroyed, you`ll win');
GotoXY(3,9);
WriteLn(#4#32,'There is 6,67% for you to get an extra bullet when you destroy the enemies');
GotoXY(3,11);
WriteLn(#4#32,'Using the up arrow key',#32#24#32,'to control the tank going up');
GotoXY(3,13);
WriteLn(#4#32,'Using the down arrow key',#32#25#32,'to control the tank going up');
GotoXY(3,15);
WriteLn(#4#32,'Using SPACE key to shoot the enemies (Don`t press SPACE key fast)');
GotoXY(3,17);
WriteLn(#4#32,'Using ESC key to exit the game and return to Interface');
GotoXY(37,19);
TextColor(LightGreen);
WriteLn('GOOD LUCK!');
Repeat
Savedkey := ReadKey;
If (SavedKey <> 'b') Or (SavedKey <> 'B') Then
While KeyPressed Do ReadKey;
Until (SavedKey = 'b') Or (SavedKey = 'B');
If (SavedKey = 'b') Or (SavedKey = 'B') Then
Begin
ClrScr;
INTERFACES;
End;
End;
//========================The Interfaces==================
Procedure DRAW_ENEMY_1(x,y: Byte);
Begin
TextColor(LightGreen);
GotoXY(enemy.x+2,enemy.y+1); Write(#218#193#217);
GotoXY(enemy.x+2,enemy.y-1); Write(#192#194);
GotoXY(enemy.x+4,enemy.y); Write(#215);
GotoXY(enemy.x+4,enemy.y-1); Write(#191);
GotoXY(enemy.x+2,enemy.y); Write(#185);
TextColor(LightRed);
GotoXY(enemy.x,enemy.y); Write(#205#205);
TextColor(Yellow);
GotoXY(enemy.x+3,enemy.y); Write(#178);
End;
//================DRAW THE ENEMY V1================
Procedure DRAW_ENEMY_3(x,y: Byte);
Begin
TextColor(LightRed);
GotoXY(enemy.x+3,enemy.y); Write(#177#177);
TextColor(Yellow);
GotoXY(enemy.x+2,enemy.y-1); Write(#205#209);
GotoXY(enemy.x+2,enemy.y+1); Write(#205#207);
TextColor(LightBlue);
GotoXY(enemy.x,enemy.y); Write(#205#205#185);
TextColor(LightGreen);
GotoXY(enemy.x+5,enemy.y); Write(#228);
TextColor(White);
GotoXY(enemy.x+4,enemy.y-1); Write(#191);
GotoXY(enemy.x+4,enemy.y+1); Write(#217);
End;
//================DRAW THE ENEMY V3================
Procedure MOVE_ENEMY(x,y: Byte);
Begin
GotoXY(enemy.x,enemy.y);
Write(#32#32#32#32#32#32#32#32#32);
GotoXY(enemy.x,enemy.y-1);
Write(#32#32#32#32#32#32#32#32#32);
GotoXY(enemy.x,enemy.y+1);
Write(#32#32#32#32#32#32#32#32#32);
End;
//===============ERASE THE ENEMY BEFORE===============
Procedure MAP;
Begin
GotoXY(1,2);
TextColor(White);
For i:=1 To 80 Do Write(#205);
Delay(100);
GotoXY(1,28);
For i:=1 To 80 Do Write(#205);
GotoXY(29,1);
GotoXY(2,1); TextColor(LightGreen);
WriteLn('Esc: EXIT');
GotoXY(65,1); WriteLn('FULL ENERGY');
TextColor(White);
GotoXY(64,2); WriteLn(#207);
GotoXY(76,2); WriteLn(#207);
GotoXY(64,1); WriteLn(#179);
GotoXY(76,1); WriteLn(#179);
Randomize;
Target := Random(20);
If (Target<5) Then
Repeat
Target := Target + Random(12);
Until Target>7;
TextColor(LightGreen);
GotoXY(1,29); Write('TARGET:',#32,'0 /',Target);
NumberOfBullet := Target + Random(5);
GotoXY(25,29); TextColor(Yellow); Write(#175);
GotoXY(26,29); TextColor(LightBlue); Write(#32,':',#32,NumberOfBullet);
End;
//===============THE MAP===============
Procedure DRAW_TANK(x,y: Byte);
//Ve hình anh cua xe tâng
Begin
Textcolor(LightGreen);
Gotoxy(x,y); Writeln(#15#198#194#249,#32#32#32#32);
Gotoxy(x,y+1); Writeln(#15#179#178#216#205#205#205);
Gotoxy(x,y+2); Writeln(#15#198#193#249,#32#32#32#32);
End;
//===============DRAW THE TANK===============
Procedure MOVE_TANK(x,y: Byte);
//Xóa hoat anh cua xe tâng hiên tai
Begin
Gotoxy(x,y); Write(#32#32#32#32#32#32#32#32#32);
Gotoxy(x,y+1); Write(#32#32#32#32#32#32#32#32#32);
Gotoxy(x,y+2); Write(#32#32#32#32#32#32#32#32#32);
End;
//===============ERASE THE TANK BEFORE===============
Procedure THE_INTERACTION_OF_BULLET;
Begin
bullet.x := 9;
bullet.y := tank.y + 1;
NumberOfBullet := NumberOfBullet - 1;
TextColor(LightBlue);
GotoXY(29,29); Write(NumberOfBullet,#32);
If (NumberOfBullet = 0) Then
Begin
GotoXY(33,29);
TextColor(LightRed);
WriteLn('NO BULLETS');
End Else
Begin
GotoXY(33,29);
WriteLn(#32#32#32#32#32#32#32#32#32#32);
End;
Repeat
Gotoxy(bullet.x,bullet.y);
Textcolor(Yellow); Write(#175);
Delay(23); //Speed Of The Bullet
Gotoxy(bullet.x,bullet.y); Write(#32#32);
bullet.x := bullet.x + 1;
GotoXY(5,29);
TextColor(Yellow);
GotoXY(55,29); Write('..LOADING THE BULLET..');
TextColor(LightRed);
GotoXY(65,1); Write(#32,'NO ENEGRY',#32);
GotoXY(tank.x,tank.y); WriteLn(#15);
GotoXY(tank.x,tank.y+1); WriteLn(#15);
GotoXY(tank.x,tank.y+2); WriteLn(#15);
GotoXY(tank.x+5,tank.y+1); WriteLn(#205);
GotoXY(tank.x+6,tank.y+1); WriteLn(#205);
TextColor(Yellow);
GotoXY(tank.x+2,tank.y+1); WriteLn(#178);
TextColor(LightRed);
GotoXY(tank.x+3,tank.y); WriteLn(#249);
GotoXY(tank.x+3,tank.y+2); WriteLn(#249);
If (bullet.x=80) Or CheckEnemy(enemy.x,enemy.y)=True Then
Begin
GotoXY(55,29); WriteLn(#32#32#32#32#32#32#32#32#32#32#32,
#32#32#32#32#32#32#32#32#32#32#32#32);
TextColor(LightGreen);
GotoXY(65,1); WriteLn('FULL ENERGY');
GotoXY(tank.x,tank.y); WriteLn(#15);
GotoXY(tank.x,tank.y+1); WriteLn(#15);
GotoXY(tank.x,tank.y+2); WriteLn(#15);
GotoXY(tank.x+5,tank.y+1); WriteLn(#205);
GotoXY(tank.x+6,tank.y+1); WriteLn(#205);
GotoXY(tank.x+2,tank.y+1); WriteLn(#178);
GotoXY(tank.x+3,tank.y); WriteLn(#249);
GotoXY(tank.x+3,tank.y+2); WriteLn(#249);
End;
If (bullet.x=80) Then Break;
Until CheckEnemy(enemy.x,enemy.y)=True;
If (CheckEnemy(enemy.x,enemy.y))=True Then
Begin
Randomize;
ExtraBullet := Random(15);
If (ExtraBullet = 4) Then
Begin
NumberOfBullet := NumberOfBullet + 1;
TextColor(LightGreen);
GotoXY(32,29); WriteLn('+ 1');
Delay(50);
GotoXY(32,29); WriteLn(#32#32#32);
TextColor(LightBlue);
GotoXY(29,29); Write(NumberOfBullet,#32);
End;
End;
If CheckEnemy(enemy.x,enemy.y)=True Then //Check Location Of Enemy And Bullet
Begin
Randomize;
MOVE_ENEMY(enemy.x,enemy.y);
Spawm_Enemy := Random(2);
enemy.x := Random(80);
enemy.y := Random(26);
If (enemy.x>75) Then
Repeat
enemy.x := enemy.x + Random(3);
Until enemy.x<75;
If (enemy.x<30) Then
Repeat
enemy.x := enemy.x + Random(20);
Until enemy.x>30;
If (enemy.y<4) Then
Repeat
enemy.y := enemy.y + Random(8);
Until enemy.y>4;
Delay(300);
Case Spawm_Enemy Of
0: DRAW_ENEMY_1(enemy.x,enemy.y);
1: DRAW_ENEMY_3(enemy.x,enemy.y);
End;
Score := Score + 1;
GotoXY(9,29);
TextColor(LightGreen); Write(Score);
End;
End;
//===============THE ANIMATION FOR THE BULLET=============
Procedure DOWN;
Begin
MOVE_TANK(tank.x,tank.y-1);
tank.y := tank.y+1;
DRAW_TANK(tank.x,tank.y);
End;
//=================MOVE UP==================
Procedure UP;
Begin
MOVE_TANK(tank.x,tank.y+1);
tank.y := tank.y-1;
DRAW_TANK(tank.x,tank.y);
End;
//===============MOVE DOWN===============
{===========|==========|==========|======FOR THE TANK=======|===========|==========|========}
Procedure WIN; //For Win
Begin
ClrScr;
TextColor(LightGreen);
GotoXY(24,13); Write('YOU HAVE COMPLETED THE ASSIGNMENT!!');
TextColor(White);
GotoXY(36,15); Write('N: Next Assignment');
GotoXY(36,16); Write('Esc: Exit');
End;
//=================================================
Procedure LOSE; //For Lose
Begin
ClrScr;
TextColor(LightRed);
GotoXY(22,13); Write('YOU HAVE NOT COMPLETED THE ASSIGNMENT!!');
TextColor(White);
GotoXY(36,15); Write('R: Restar');
GotoXY(36,16); Write('Esc: Exit');
End;
//======================THE END OF GAME=================
Procedure PLAY;
Begin
ClrScr;
MAP;
DRAW_TANK(2,14);
tank.x := 2;
tank.y := 14;
Randomize;
enemy.x := Random(80);
enemy.y := Random(26);
Spawm_Enemy := Random(2);
If (enemy.x>75) Then
Repeat
enemy.x := enemy.x + Random(3);
Until enemy.x<75;
If (enemy.x<30) Then
Repeat
enemy.x := enemy.x + Random(20);
Until enemy.x>30;
If (enemy.y<4) Then
Repeat
enemy.y := enemy.y + Random(8);
Until enemy.y>4;
Delay(500);
TextColor(LightRed);
Case Spawm_Enemy Of //Spawm enemy
0: DRAW_ENEMY_1(enemy.x,enemy.y);
1: DRAW_ENEMY_3(enemy.x,enemy.y);
End;
Score := 0;
Repeat
If KeyPressed Then
Case ReadKey Of
#80: If (tank.y<25) Then DOWN; //If down arrow key is pressed
#72: If (tank.y>3) Then UP; //If up arrow key is pressed
#32: THE_INTERACTION_OF_BULLET; //If space key is pressed
#27: //If esc key is pressed
Begin
INTERFACES;
Repeat
Key := ReadKey;
If (Key = #13) And (Arrow.x = 30) And (Arrow.y = 15) Then
Begin
ClrScr;
INSTRUCTION;
End;
Until (Key = #13) And (Arrow.x = 30) And (Arrow.y = 13);
If (Key = #13) And (Arrow.x = 30) And (Arrow.y = 13) Then
Begin
ClrScr;
MAP;
End;
PLAY; //If esc key is pressed
End;
End;
FITISSUE;
Until (CheckWin(Score,Target)=True) Or (CheckLose(Score,Target,NumberOfBullet) = True);
If (CheckWin(Score,Target)=True) Then //If The Assignment Is Completed
Begin
MOVE_ENEMY(enemy.x,enemy.y);
WIN;
Repeat
If KeyPressed Then
Begin
m := ReadKey;
If (m=#78) Or (m=#110) Then
PLAY
Else if m = #27 Then
Begin
While KeyPressed Do ReadKey;
Halt;
End;
End;
Until False;
End;
//====================================================
If (CheckLose(Score,Target,NumberOfBullet)=True) Then //If The Assignment Is Not Completed
Begin
Delay(1000);
MOVE_ENEMY(enemy.x,enemy.y);
If (tank.y + 1 < enemy.y) Then
While (enemy.y > tank.y + 1) Do
Begin
MOVE_ENEMY(enemy.x,enemy.y);
enemy.y := enemy.y - 1;
Case Spawm_Enemy Of
0: DRAW_ENEMY_1(enemy.x,enemy.y);
1: DRAW_ENEMY_3(enemy.x,enemy.y);
End;
Delay(100);
End;
If (tank.y + 1 > enemy.y) Then
While (enemy.y < tank.y + 1) Do
Begin
MOVE_ENEMY(enemy.x,enemy.y);
enemy.y := enemy.y + 1;
Case Spawm_Enemy Of
0: DRAW_ENEMY_1(enemy.x,enemy.y);
1: DRAW_ENEMY_3(enemy.x,enemy.y);
End;
Delay(100);
End;
If (tank.y + 1 = enemy.y + 1) Then;
z:= enemy.x - 1;
Delay(1000);
TextColor(LightRed);
GotoXY(z,tank.y + 1); Write(#174);
Delay(30);
While (z > tank.x + 2) Do
Begin
Delay(30);
GotoXY(z,tank.y + 1); Write(#32);
z := z - 1;
GotoXY(z,tank.y + 1); Write(#174);
End;
LOSE;
Repeat
If KeyPressed Then
Begin
m := ReadKey;
If (m=#82) Or (m=#114) Then
PLAY
Else if m = #27 Then
Begin
While KeyPressed Do ReadKey;
Halt;
End;
End;
Until False;
End;
End;
//=============================FOR THE PLAYER TO PLAY THE GAME=========================
//===============================The Main Programme===========================
Begin
TextBackGround(Black);
Clrscr;
INTERFACES;
Repeat
Key := ReadKey;
If (Key = #13) And (Arrow.x = 30) And (Arrow.y = 15) Then
Begin
ClrScr;
INSTRUCTION;
End;
Until (Key = #13) And (Arrow.x = 30) And (Arrow.y = 13);
If (Key = #13) And (Arrow.x = 30) And (Arrow.y = 13) Then
Begin
ClrScr;
MAP;
End;
PLAY;
Repeat
If KeyPressed Then
Begin
w := ReadKey;
If (w=#82) Or (w=#114) Then
Begin
ClrScr;
MAP;
PLAY;
End
Else if (w = #27) Then
Begin
While KeyPressed Do ReadKey;
Halt;
End;
End;
Until False;
Readln;
End.
Uses Crt;
Type
Location = Record
x,y: Byte;
End;
Var
Tank,Enemy,Bullet,Arrow,Present: Location;
i,j,Spawm_Enemy,z,ExtraBullet: Byte;
KEY,m,w,SavedKey: Char;
Score,NumberOfBullet,Target: Integer;
Function CheckEnemy(x,y: Byte): Boolean;
Begin
If ((bullet.x = enemy.x+1) And (bullet.y = enemy.y)) Or ((bullet.x = enemy.x+3) And (bullet.y = enemy.y-1)) Or ((bullet.x = enemy.x+3) And (bullet.y = enemy.y+1)) Then CheckEnemy := True
Else CheckEnemy := False;
End;
Function CheckWin(Score,Target: Integer): Boolean;
Begin
If (Score=Target) Then ChecKWin := True
Else CheckWin := False;
End;
Function CheckLose(Score,Target,NumberOfBullet: Integer): Boolean;
Begin
If (Score<Target) And (NumberOfBullet=0) Then CheckLose := True
Else CheckLose := False;
End;
//==============================The Functions=========================
Procedure THE_UP_ARROW_ANIMATION;
Begin
GotoXY(48,15); Write(#32#32#32#32#32#32#32#32#32#32,
#32#32#32#32#32#32#32#32#32#32);
TextColor(LightGreen);
GotoXY(Arrow.x,Arrow.y);
Writeln(#32);
Arrow.y := Arrow.y - 2;
GotoXY(Arrow.x,Arrow.y);
Writeln(#16);
Arrow.y := 13;
TextColor(LightBlue);
GotoXY(51,13); Write('(Double ENTER Click)');
End;
Procedure THE_DOWN_ARROW_ANIMATION;
Begin
GotoXY(51,13); Write(#32#32#32#32#32#32#32#32#32#32,
#32#32#32#32#32#32#32#32#32#32);
TextColor(LightGreen);
GotoXY(Arrow.x,Arrow.y);
WriteLn(#32);
Arrow.y := Arrow.y + 2;
GotoXY(Arrow.x,Arrow.y);
Writeln(#16);
Arrow.y := 15;
TextColor(LightBlue);
GotoXY(48,15); Write('(Double ENTER Click)');
End;
//====================The Animation Of Arrow================
Procedure FITISSUE;
Begin
For i:=1 To 10 Do
Begin
TextColor(White);
GotoXY(i,2); WriteLn(#205);
GotoXY(i,28); WriteLn(#205);
End;
End;
//============================FIT THE ISSUE======================
Procedure INTERFACES;
Begin
Clrscr;
TextColor(LightBlue);
For j := 1 To 2 Do
For i := 1 To 13 Do
Begin
GotoXY(i+32,9+(j-1)*2);
WriteLn(#205);
End;
GotoXY(32,10); WriteLn(#186);
GotoXY(46,10); WriteLn(#186);
GotoXY(32,9); WriteLn(#201);
GotoXY(32,11); WriteLn(#200);
GotoXY(46,9); WriteLn(#187);
GotoXY(46,11); WriteLn(#188);
GotoXY(33,10);
TextColor(Yellow);
WriteLn('THE TANK GAME');
TextColor(LightGreen);
GotoXY(56,28);
WriteLn(#15#32#76#105#99#101#110#115#101,':',
#32#36#36#72#97#117#95#67#114#117#115#104#36#36); //License
TextColor(White);
For i := 1 To 78 Do
Begin
GotoXY(2+(i-1)*1,1); Write(#196);
GotoXY(2+(i-1)*1,29); Write(#196);
End;
GotoXY(1,1); Write(#218);
GotoXY(80,1); Write(#191);
GotoXY(1,29); Write(#192);
GotoXY(80,29); Write(#217);
For i := 1 To 27 Do
Begin
GotoXY(1,2+(i-1)*1); Write(#179);
GotoXY(80,2+(i-1)*1); Write(#179);
End;
TextColor(White);
GotoXY(33,13); WriteLn('Start the game');
GotoXY(33,15); WriteLn('Instruction');
TextColor(LightBlue);
GotoXY(51,13); WriteLn('(Double ENTER Click)');
TextColor(Green);
Arrow.x := 30;
Arrow.y := 13;
GotoXY(Arrow.x,Arrow.y); Write(#16);
Repeat
If KeyPressed Then
Case ReadKey Of
#72: If (Arrow.y <> 13) Then THE_UP_ARROW_ANIMATION;
#80: If (Arrow.y <> 15) Then THE_DOWN_ARROW_ANIMATION;
End;
Until Readkey = #13;
End;
Procedure INSTRUCTION;
Begin
For i := 1 To 80 Do
Begin
TextColor(White);
GotoXY(i,2);
Write(#196);
End;
TextColor(Yellow);
GotoXY(35,1); Writeln('INSTRUCTION');
TextColor(LightGreen);
GotoXY(1,1); Write('B: Back');
TextColor(White);
GotoXY(3,3);
WriteLn(#4#32,'Your assignment is that destroy the enemies with the specified bullets');
GotoXY(3,5);
WriteLn(#4#32,'If bullets run out and the enemies all aren`t destroyed, you`ll lose');
GotoXY(3,7);
WriteLn(#4#32,'If bullets don`t run out and the enemies all are destroyed, you`ll win');
GotoXY(3,9);
WriteLn(#4#32,'There is 6,67% for you to get an extra bullet when you destroy the enemies');
GotoXY(3,11);
WriteLn(#4#32,'Using the up arrow key',#32#24#32,'to control the tank going up');
GotoXY(3,13);
WriteLn(#4#32,'Using the down arrow key',#32#25#32,'to control the tank going up');
GotoXY(3,15);
WriteLn(#4#32,'Using SPACE key to shoot the enemies (Don`t press SPACE key fast)');
GotoXY(3,17);
WriteLn(#4#32,'Using ESC key to exit the game and return to Interface');
GotoXY(37,19);
TextColor(LightGreen);
WriteLn('GOOD LUCK!');
Repeat
Savedkey := ReadKey;
If (SavedKey <> 'b') Or (SavedKey <> 'B') Then
While KeyPressed Do ReadKey;
Until (SavedKey = 'b') Or (SavedKey = 'B');
If (SavedKey = 'b') Or (SavedKey = 'B') Then
Begin
ClrScr;
INTERFACES;
End;
End;
//========================The Interfaces==================
Procedure DRAW_ENEMY_1(x,y: Byte);
Begin
TextColor(LightGreen);
GotoXY(enemy.x+2,enemy.y+1); Write(#218#193#217);
GotoXY(enemy.x+2,enemy.y-1); Write(#192#194);
GotoXY(enemy.x+4,enemy.y); Write(#215);
GotoXY(enemy.x+4,enemy.y-1); Write(#191);
GotoXY(enemy.x+2,enemy.y); Write(#185);
TextColor(LightRed);
GotoXY(enemy.x,enemy.y); Write(#205#205);
TextColor(Yellow);
GotoXY(enemy.x+3,enemy.y); Write(#178);
End;
//================DRAW THE ENEMY V1================
Procedure DRAW_ENEMY_3(x,y: Byte);
Begin
TextColor(LightRed);
GotoXY(enemy.x+3,enemy.y); Write(#177#177);
TextColor(Yellow);
GotoXY(enemy.x+2,enemy.y-1); Write(#205#209);
GotoXY(enemy.x+2,enemy.y+1); Write(#205#207);
TextColor(LightBlue);
GotoXY(enemy.x,enemy.y); Write(#205#205#185);
TextColor(LightGreen);
GotoXY(enemy.x+5,enemy.y); Write(#228);
TextColor(White);
GotoXY(enemy.x+4,enemy.y-1); Write(#191);
GotoXY(enemy.x+4,enemy.y+1); Write(#217);
End;
//================DRAW THE ENEMY V3================
Procedure MOVE_ENEMY(x,y: Byte);
Begin
GotoXY(enemy.x,enemy.y);
Write(#32#32#32#32#32#32#32#32#32);
GotoXY(enemy.x,enemy.y-1);
Write(#32#32#32#32#32#32#32#32#32);
GotoXY(enemy.x,enemy.y+1);
Write(#32#32#32#32#32#32#32#32#32);
End;
//===============ERASE THE ENEMY BEFORE===============
Procedure MAP;
Begin
GotoXY(1,2);
TextColor(White);
For i:=1 To 80 Do Write(#205);
Delay(100);
GotoXY(1,28);
For i:=1 To 80 Do Write(#205);
GotoXY(29,1);
GotoXY(2,1); TextColor(LightGreen);
WriteLn('Esc: EXIT');
GotoXY(65,1); WriteLn('FULL ENERGY');
TextColor(White);
GotoXY(64,2); WriteLn(#207);
GotoXY(76,2); WriteLn(#207);
GotoXY(64,1); WriteLn(#179);
GotoXY(76,1); WriteLn(#179);
Randomize;
Target := Random(20);
If (Target<5) Then
Repeat
Target := Target + Random(12);
Until Target>7;
TextColor(LightGreen);
GotoXY(1,29); Write('TARGET:',#32,'0 /',Target);
NumberOfBullet := Target + Random(5);
GotoXY(25,29); TextColor(Yellow); Write(#175);
GotoXY(26,29); TextColor(LightBlue); Write(#32,':',#32,NumberOfBullet);
End;
//===============THE MAP===============
Procedure DRAW_TANK(x,y: Byte);
//Ve hình anh cua xe tâng
Begin
Textcolor(LightGreen);
Gotoxy(x,y); Writeln(#15#198#194#249,#32#32#32#32);
Gotoxy(x,y+1); Writeln(#15#179#178#216#205#205#205);
Gotoxy(x,y+2); Writeln(#15#198#193#249,#32#32#32#32);
End;
//===============DRAW THE TANK===============
Procedure MOVE_TANK(x,y: Byte);
//Xóa hoat anh cua xe tâng hiên tai
Begin
Gotoxy(x,y); Write(#32#32#32#32#32#32#32#32#32);
Gotoxy(x,y+1); Write(#32#32#32#32#32#32#32#32#32);
Gotoxy(x,y+2); Write(#32#32#32#32#32#32#32#32#32);
End;
//===============ERASE THE TANK BEFORE===============
Procedure THE_INTERACTION_OF_BULLET;
Begin
bullet.x := 9;
bullet.y := tank.y + 1;
NumberOfBullet := NumberOfBullet - 1;
TextColor(LightBlue);
GotoXY(29,29); Write(NumberOfBullet,#32);
If (NumberOfBullet = 0) Then
Begin
GotoXY(33,29);
TextColor(LightRed);
WriteLn('NO BULLETS');
End Else
Begin
GotoXY(33,29);
WriteLn(#32#32#32#32#32#32#32#32#32#32);
End;
Repeat
Gotoxy(bullet.x,bullet.y);
Textcolor(Yellow); Write(#175);
Delay(23); //Speed Of The Bullet
Gotoxy(bullet.x,bullet.y); Write(#32#32);
bullet.x := bullet.x + 1;
GotoXY(5,29);
TextColor(Yellow);
GotoXY(55,29); Write('..LOADING THE BULLET..');
TextColor(LightRed);
GotoXY(65,1); Write(#32,'NO ENEGRY',#32);
GotoXY(tank.x,tank.y); WriteLn(#15);
GotoXY(tank.x,tank.y+1); WriteLn(#15);
GotoXY(tank.x,tank.y+2); WriteLn(#15);
GotoXY(tank.x+5,tank.y+1); WriteLn(#205);
GotoXY(tank.x+6,tank.y+1); WriteLn(#205);
TextColor(Yellow);
GotoXY(tank.x+2,tank.y+1); WriteLn(#178);
TextColor(LightRed);
GotoXY(tank.x+3,tank.y); WriteLn(#249);
GotoXY(tank.x+3,tank.y+2); WriteLn(#249);
If (bullet.x=80) Or CheckEnemy(enemy.x,enemy.y)=True Then
Begin
GotoXY(55,29); WriteLn(#32#32#32#32#32#32#32#32#32#32#32,
#32#32#32#32#32#32#32#32#32#32#32#32);
TextColor(LightGreen);
GotoXY(65,1); WriteLn('FULL ENERGY');
GotoXY(tank.x,tank.y); WriteLn(#15);
GotoXY(tank.x,tank.y+1); WriteLn(#15);
GotoXY(tank.x,tank.y+2); WriteLn(#15);
GotoXY(tank.x+5,tank.y+1); WriteLn(#205);
GotoXY(tank.x+6,tank.y+1); WriteLn(#205);
GotoXY(tank.x+2,tank.y+1); WriteLn(#178);
GotoXY(tank.x+3,tank.y); WriteLn(#249);
GotoXY(tank.x+3,tank.y+2); WriteLn(#249);
End;
If (bullet.x=80) Then Break;
Until CheckEnemy(enemy.x,enemy.y)=True;
If (CheckEnemy(enemy.x,enemy.y))=True Then
Begin
Randomize;
ExtraBullet := Random(15);
If (ExtraBullet = 4) Then
Begin
NumberOfBullet := NumberOfBullet + 1;
TextColor(LightGreen);
GotoXY(32,29); WriteLn('+ 1');
Delay(50);
GotoXY(32,29); WriteLn(#32#32#32);
TextColor(LightBlue);
GotoXY(29,29); Write(NumberOfBullet,#32);
End;
End;
If CheckEnemy(enemy.x,enemy.y)=True Then //Check Location Of Enemy And Bullet
Begin
Randomize;
MOVE_ENEMY(enemy.x,enemy.y);
Spawm_Enemy := Random(2);
enemy.x := Random(80);
enemy.y := Random(26);
If (enemy.x>75) Then
Repeat
enemy.x := enemy.x + Random(3);
Until enemy.x<75;
If (enemy.x<30) Then
Repeat
enemy.x := enemy.x + Random(20);
Until enemy.x>30;
If (enemy.y<4) Then
Repeat
enemy.y := enemy.y + Random(8);
Until enemy.y>4;
Delay(300);
Case Spawm_Enemy Of
0: DRAW_ENEMY_1(enemy.x,enemy.y);
1: DRAW_ENEMY_3(enemy.x,enemy.y);
End;
Score := Score + 1;
GotoXY(9,29);
TextColor(LightGreen); Write(Score);
End;
End;
//===============THE ANIMATION FOR THE BULLET=============
Procedure DOWN;
Begin
MOVE_TANK(tank.x,tank.y-1);
tank.y := tank.y+1;
DRAW_TANK(tank.x,tank.y);
End;
//=================MOVE UP==================
Procedure UP;
Begin
MOVE_TANK(tank.x,tank.y+1);
tank.y := tank.y-1;
DRAW_TANK(tank.x,tank.y);
End;
//===============MOVE DOWN===============
{===========|==========|==========|======FOR THE TANK=======|===========|==========|========}
Procedure WIN; //For Win
Begin
ClrScr;
TextColor(LightGreen);
GotoXY(24,13); Write('YOU HAVE COMPLETED THE ASSIGNMENT!!');
TextColor(White);
GotoXY(36,15); Write('N: Next Assignment');
GotoXY(36,16); Write('Esc: Exit');
End;
//=================================================
Procedure LOSE; //For Lose
Begin
ClrScr;
TextColor(LightRed);
GotoXY(22,13); Write('YOU HAVE NOT COMPLETED THE ASSIGNMENT!!');
TextColor(White);
GotoXY(36,15); Write('R: Restar');
GotoXY(36,16); Write('Esc: Exit');
End;
//======================THE END OF GAME=================
Procedure PLAY;
Begin
ClrScr;
MAP;
DRAW_TANK(2,14);
tank.x := 2;
tank.y := 14;
Randomize;
enemy.x := Random(80);
enemy.y := Random(26);
Spawm_Enemy := Random(2);
If (enemy.x>75) Then
Repeat
enemy.x := enemy.x + Random(3);
Until enemy.x<75;
If (enemy.x<30) Then
Repeat
enemy.x := enemy.x + Random(20);
Until enemy.x>30;
If (enemy.y<4) Then
Repeat
enemy.y := enemy.y + Random(8);
Until enemy.y>4;
Delay(500);
TextColor(LightRed);
Case Spawm_Enemy Of //Spawm enemy
0: DRAW_ENEMY_1(enemy.x,enemy.y);
1: DRAW_ENEMY_3(enemy.x,enemy.y);
End;
Score := 0;
Repeat
If KeyPressed Then
Case ReadKey Of
#80: If (tank.y<25) Then DOWN; //If down arrow key is pressed
#72: If (tank.y>3) Then UP; //If up arrow key is pressed
#32: THE_INTERACTION_OF_BULLET; //If space key is pressed
#27: //If esc key is pressed
Begin
INTERFACES;
Repeat
Key := ReadKey;
If (Key = #13) And (Arrow.x = 30) And (Arrow.y = 15) Then
Begin
ClrScr;
INSTRUCTION;
End;
Until (Key = #13) And (Arrow.x = 30) And (Arrow.y = 13);
If (Key = #13) And (Arrow.x = 30) And (Arrow.y = 13) Then
Begin
ClrScr;
MAP;
End;
PLAY; //If esc key is pressed
End;
End;
FITISSUE;
Until (CheckWin(Score,Target)=True) Or (CheckLose(Score,Target,NumberOfBullet) = True);
If (CheckWin(Score,Target)=True) Then //If The Assignment Is Completed
Begin
MOVE_ENEMY(enemy.x,enemy.y);
WIN;
Repeat
If KeyPressed Then
Begin
m := ReadKey;
If (m=#78) Or (m=#110) Then
PLAY
Else if m = #27 Then
Begin
While KeyPressed Do ReadKey;
Halt;
End;
End;
Until False;
End;
//====================================================
If (CheckLose(Score,Target,NumberOfBullet)=True) Then //If The Assignment Is Not Completed
Begin
Delay(1000);
MOVE_ENEMY(enemy.x,enemy.y);
If (tank.y + 1 < enemy.y) Then
While (enemy.y > tank.y + 1) Do
Begin
MOVE_ENEMY(enemy.x,enemy.y);
enemy.y := enemy.y - 1;
Case Spawm_Enemy Of
0: DRAW_ENEMY_1(enemy.x,enemy.y);
1: DRAW_ENEMY_3(enemy.x,enemy.y);
End;
Delay(100);
End;
If (tank.y + 1 > enemy.y) Then
While (enemy.y < tank.y + 1) Do
Begin
MOVE_ENEMY(enemy.x,enemy.y);
enemy.y := enemy.y + 1;
Case Spawm_Enemy Of
0: DRAW_ENEMY_1(enemy.x,enemy.y);
1: DRAW_ENEMY_3(enemy.x,enemy.y);
End;
Delay(100);
End;
If (tank.y + 1 = enemy.y + 1) Then;
z:= enemy.x - 1;
Delay(1000);
TextColor(LightRed);
GotoXY(z,tank.y + 1); Write(#174);
Delay(30);
While (z > tank.x + 2) Do
Begin
Delay(30);
GotoXY(z,tank.y + 1); Write(#32);
z := z - 1;
GotoXY(z,tank.y + 1); Write(#174);
End;
LOSE;
Repeat
If KeyPressed Then
Begin
m := ReadKey;
If (m=#82) Or (m=#114) Then
PLAY
Else if m = #27 Then
Begin
While KeyPressed Do ReadKey;
Halt;
End;
End;
Until False;
End;
End;
//=============================FOR THE PLAYER TO PLAY THE GAME=========================
//===============================The Main Programme===========================
Begin
TextBackGround(Black);
Clrscr;
INTERFACES;
Repeat
Key := ReadKey;
If (Key = #13) And (Arrow.x = 30) And (Arrow.y = 15) Then
Begin
ClrScr;
INSTRUCTION;
End;
Until (Key = #13) And (Arrow.x = 30) And (Arrow.y = 13);
If (Key = #13) And (Arrow.x = 30) And (Arrow.y = 13) Then
Begin
ClrScr;
MAP;
End;
PLAY;
Repeat
If KeyPressed Then
Begin
w := ReadKey;
If (w=#82) Or (w=#114) Then
Begin
ClrScr;
MAP;
PLAY;
End
Else if (w = #27) Then
Begin
While KeyPressed Do ReadKey;
Halt;
End;
End;
Until False;
Readln;
End.