Tin học CÓ GÌ SAI SÓT TRONG ĐÂY MÀ MÌNH SỬA KHÔNG ĐƯỢC VẬY Ạ!

HauBright

Học sinh mới
20 Tháng tư 2023
72
36
11
15
Bến Tre
[TẶNG BẠN] TRỌN BỘ Bí kíp học tốt 08 môn
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 Tank;
Uses crt;
Const
BULLET_SPEED = 3;
Type
TCoordinate = Record
x : Integer;
y : Integer;
End;
Var
tank_x, tank_y : Integer;
bullet_x, bullet_y : Integer;
ch : Char;
Procedure draw_tank(x,y : Integer);
Begin
textcolor(green);
Gotoxy(x,y);
Writeln(' __,__,');
Gotoxy(x,y+1);
Writeln(' | || |]');
Gotoxy(x,y+2);
Writeln('_ _ _|oo||oo|_ _ _');
Gotoxy(x,y+3);
Writeln('|_|_|__|__|__|_|_|');
textcolor(white);
End;
Procedure draw_bullet(x,y : Integer);
Begin
Gotoxy(x,y);
Writeln('*');
End;
Procedure update_bullet(Var bullet_coord : TCoordinate);
Begin
bullet_coord.y := bullet_coord.y - BULLET_SPEED;
End;
Function is_bullet_hit_target(bullet_coord, target_coord : TCoordinate) : Boolean;
Begin
If (bullet_coord.x = target_coord.x) And (bullet_coord.y = target_coord.y) Then
is_bullet_hit_target := True
Else
is_bullet_hit_target := False;
End;
Begin
Clrscr;
tank_x := 40;
tank_y := 12;
bullet_x := -1;
bullet_y := -1;
Repeat
// vẽ xe tăng và đạn
draw_tank(tank_x,tank_y);
If (bullet_x <> -1) And (bullet_y <> -1) Then
draw_bullet(bullet_x,bullet_y);
// đọc phím bấm từ bàn phím và điều khiển xe tăng hoặc bắn đạn
ch := Readkey;
Case ch Of
#72: tank_y := tank_y - 1;
// di chuyển lên trên
#80: tank_y := tank_y + 1;
// di chuyển xuống dưới
#75: tank_x := tank_x - 1;
// di chuyển sang trái
#77: tank_x := tank_x + 1;
// di chuyển sang phải
' ':
Begin
// bắn đạn
bullet_x := tank_x + 4;
bullet_y := tank_y - 1;
End;
End;
// cập nhật vị trí của đạn
If (bullet_x <> -1) And (bullet_y <> -1) Then
Begin
update_bullet(TCoordinate(bullet_x,bullet_y));
If bullet_y < 2 Then // nếu đạn bay ra khỏi màn hình thì xoá đạn
Begin
bullet_x := -1;
bullet_y := -1;
End;
End;
// kiểm tra xem đạn có va chạm với mục tiêu không
If (bullet_x <> -1) And (bullet_y <> -1) And (is_bullet_hit_target(TCoordinate(bullet_x,bullet_y
), TCoordinate(50,5))) Then
Begin
bullet_x := -1;
bullet_y := -1;
Gotoxy(50,5);
Writeln('X');
End;
Clrscr;
Until ch = #27;
// thoát ra khi nhấn phím Esc
End.
 
Top Bottom