1. Trang chủ
  2. » Giáo Dục - Đào Tạo

Mô phỏng trò chơi bóng bàn

10 171 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 10
Dung lượng 18,5 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

TRƯỜNG CAO ĐẲNG CÔNG NGHỆ HÀ NỘIKHOA CÔNG NGHỆ THÔNG TIN LỚP CNTT3 – K6 BÀI TẬP LỚN Kỹ Thuật Đồ Họa Pascal Đề tài: Mô phỏng trò chơi bóng bàn Nhóm: 1.. Writeln''; Readln; init_variables

Trang 1

TRƯỜNG CAO ĐẲNG CÔNG NGHỆ HÀ NỘI

KHOA CÔNG NGHỆ THÔNG TIN

LỚP CNTT3 – K6

BÀI TẬP LỚN

Kỹ Thuật Đồ Họa Pascal

Đề tài: Mô phỏng trò chơi bóng bàn

Nhóm:

1. Phạm Đức Tiến

2. Triệu Bảo Trung

3. Đỗ Viết Hoàng

Trang 2

CODE CHƯƠNG TRÌNH

Program PascalPong;

Uses Crt, graph;

{ global variables }

Var

physics_counter : byte;

raq_y, cpu_raq_y : integer;

ball_x, ball_y : integer;

ball_x_dir, ball_y_dir : integer;

score, score_cpu : integer;

exit : boolean;

//reset variables

Procedure reset_variables;

Begin

physics_counter := 0;

raq_y := 8;

cpu_raq_y := 8;

ball_x := 28;

ball_y := 8;

Trang 3

if Random(1) = 1 then ball_x_dir := 2

else ball_x_dir := -2;

if Random(1) = 1 then ball_y_dir := Random(2) + 1 else ball_y_dir := -(Random(2) + 1);

End;

//init variables

Procedure init_variables;

Begin

Randomize; { set random seed }

score := 0;

score_cpu := 0;

reset_variables;

End;

//handle screen

Procedure handle_screen;

Begin

TextBackground(black);

ClrScr;

Trang 4

TextBackground(white);

GotoXY(ball_x,ball_y); Write(' ');

TextBackground(white);

GotoXY(1,raq_y);

Writeln(' ');

Writeln(' ');

Writeln(' ');

Write(' ');

GotoXY(61,cpu_raq_y); Write(' ');

GotoXY(61,cpu_raq_y + 1); Write(' ');

GotoXY(61,cpu_raq_y + 2); Write(' ');

GotoXY(61,cpu_raq_y + 3); Write(' ');

TextBackground(black);

Trang 5

GotoXY(20,25);

Write('Player: ', score);

GotoXY(40,25);

Write('CPU: ', score_cpu);

GotoXY(1,26);

End;

// handle input

Procedure handle_input;

Var

key : char;

Begin

if KeyPressed then

begin

key := ReadKey;

case key of

'q' : exit := true;

'w' : if (raq_y > 1) then raq_y := raq_y - 1; 's' : if (raq_y < 17) then raq_y := raq_y + 1; end;

end;

Trang 6

//handle physics

Procedure handle_physics;

Begin

physics_counter := physics_counter + 1;

if physics_counter = 10 then

begin

physics_counter := 0;

//AI

if (cpu_raq_y > ball_y - 1) and (cpu_raq_y > 1) then

cpu_raq_y := cpu_raq_y - 1

else if (cpu_raq_y < ball_y - 1) and (cpu_raq_y < 17) then

cpu_raq_y := cpu_raq_y + 1;

//move ball

ball_x := ball_x + ball_x_dir;

ball_y := ball_y + ball_y_dir;

//check y

if (ball_y > 19) or (ball_y < 2) then ball_y_dir := ball_y_dir * -1;

Trang 7

//check x

if ball_x < 3 then //Nguoi choi

begin

if (ball_y >= raq_y) and (ball_y <= raq_y + 4) then

ball_x_dir := ball_x_dir * -1

else //cpu score + 1

begin

score_cpu := score_cpu + 1;

reset_variables;

end;

end

else if ball_x > 58 then //cpu

begin

if (ball_y >= cpu_raq_y) and (ball_y <= cpu_raq_y + 4) then ball_x_dir := ball_x_dir * -1

else //score + 1

begin

score := score + 1;

reset_variables;

end;

end;

//set correct position for ball

Trang 8

if ball_x < 1 then ball_x := 1;

if ball_y < 1 then ball_y := 1;

end;

End;

//MAIN

BEGIN

ClrScr;

Writeln('');

Writeln(' + -+'); Writeln(' | PASCAL PONG v0.1 |'); Writeln(' + -+'); Writeln(' by Antonio Ni¤o D¡az'); Writeln('');

Writeln('');

Writeln(' Controls');

Writeln(' -');

Writeln(' W/S : Up/Down');

Writeln(' Q : Quit game');

Writeln('');

Writeln('');

Writeln(' Press ENTER to start'); Writeln('');

Trang 9

Writeln('');

Readln;

init_variables; exit := false; Repeat

handle_input; handle_physics; handle_screen; Delay(20); Until exit;

END

Ngày đăng: 22/11/2017, 21:30

TỪ KHÓA LIÊN QUAN

w