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 NO_NAME;
Uses Crt;
Const HeightJumping = 6;
Type
Position = Record
x,y: Integer;
JumpingStatus: Boolean;
End;
Var
Character: Position;
Height: Integer;
Gravity: Integer;
Procedure MapForGame;
Var
i,j : Byte;
Begin
For j := 21 To 29 Do
For i := 1 To 80 Do
Begin
TextColor(White);
GotoXY(i,1);
Write(Chr(178));
Gotoxy(i,j);
Write(Chr(178));
End;
End;
Procedure DrawCharacter(x,y: Integer);
Begin
Gotoxy(Character.x,Character.y);
Write(Chr(219));
End;
Procedure ClearCharacter(x,y: Integer);
Begin
Gotoxy(Character.x,Character.y);
Write(Chr(32));
End;
Procedure IsJumping;
Begin
ClearCharacter(Character.x,Character.y);
Character.y := Character.y - 1;
DrawCharacter(Character.x,Character.y);
End;
Procedure IsFalling;
Begin
ClearCharacter(Character.x,Character.y);
Character.y := Character.y + 1;
DrawCharacter(Character.x,Character.y);
End;
Procedure Jumping;
Begin
If (Not Character.JumpingStatus) Then
Begin
Character.JumpingStatus := True;
End;
Repeat
IsJumping;
Height := Height - 1;
Delay(Gravity);
Gravity := Gravity + 5;
Until Height = 0;
Delay(30);
Repeat
IsFalling;
Height := Height + 1;
Delay(Gravity);
Gravity := Gravity - 5;
Until Height = HeightJumping;
If (Height = HeightJumping) Then
Character.JumpingStatus := False;
End;
Procedure MoveRight;
Begin
// If right arrow key pressed
ClearCharacter(Character.x,Character.y);
Character.x := Character.x + 1;
DrawCharacter(Character.x,Character.y);
Delay(40);
End;
Procedure MoveLeft;
Begin
ClearCharacter(Character.x,Character.y);
Character.x := Character.x - 1;
DrawCharacter(Character.x,Character.y);
Delay(35);
End;
//====================The Main Program===================
Begin
TextBackGround(Black);
Clrscr;
MapForGame;
Gravity := 50;
Height := 6;
Character.x := 40;
Character.y := 20;
DrawCharacter(Character.x,Character.y);
Character.JumpingStatus := False;
While True Do
Begin
If (Not Character.JumpingStatus) Then
Begin
If Keypressed Then
Case Readkey Of
Chr(72): Jumping;
// If up arrow key Pressed
Chr(77): If (Character.x < 80) Then MoveRight;
// If right arrow key pressed
Chr(75): If (Character.x > 1) Then MoveLeft;
// If left arrow key pressed
End;
End;
End;
End.
Uses Crt;
Const HeightJumping = 6;
Type
Position = Record
x,y: Integer;
JumpingStatus: Boolean;
End;
Var
Character: Position;
Height: Integer;
Gravity: Integer;
Procedure MapForGame;
Var
i,j : Byte;
Begin
For j := 21 To 29 Do
For i := 1 To 80 Do
Begin
TextColor(White);
GotoXY(i,1);
Write(Chr(178));
Gotoxy(i,j);
Write(Chr(178));
End;
End;
Procedure DrawCharacter(x,y: Integer);
Begin
Gotoxy(Character.x,Character.y);
Write(Chr(219));
End;
Procedure ClearCharacter(x,y: Integer);
Begin
Gotoxy(Character.x,Character.y);
Write(Chr(32));
End;
Procedure IsJumping;
Begin
ClearCharacter(Character.x,Character.y);
Character.y := Character.y - 1;
DrawCharacter(Character.x,Character.y);
End;
Procedure IsFalling;
Begin
ClearCharacter(Character.x,Character.y);
Character.y := Character.y + 1;
DrawCharacter(Character.x,Character.y);
End;
Procedure Jumping;
Begin
If (Not Character.JumpingStatus) Then
Begin
Character.JumpingStatus := True;
End;
Repeat
IsJumping;
Height := Height - 1;
Delay(Gravity);
Gravity := Gravity + 5;
Until Height = 0;
Delay(30);
Repeat
IsFalling;
Height := Height + 1;
Delay(Gravity);
Gravity := Gravity - 5;
Until Height = HeightJumping;
If (Height = HeightJumping) Then
Character.JumpingStatus := False;
End;
Procedure MoveRight;
Begin
// If right arrow key pressed
ClearCharacter(Character.x,Character.y);
Character.x := Character.x + 1;
DrawCharacter(Character.x,Character.y);
Delay(40);
End;
Procedure MoveLeft;
Begin
ClearCharacter(Character.x,Character.y);
Character.x := Character.x - 1;
DrawCharacter(Character.x,Character.y);
Delay(35);
End;
//====================The Main Program===================
Begin
TextBackGround(Black);
Clrscr;
MapForGame;
Gravity := 50;
Height := 6;
Character.x := 40;
Character.y := 20;
DrawCharacter(Character.x,Character.y);
Character.JumpingStatus := False;
While True Do
Begin
If (Not Character.JumpingStatus) Then
Begin
If Keypressed Then
Case Readkey Of
Chr(72): Jumping;
// If up arrow key Pressed
Chr(77): If (Character.x < 80) Then MoveRight;
// If right arrow key pressed
Chr(75): If (Character.x > 1) Then MoveLeft;
// If left arrow key pressed
End;
End;
End;
End.