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ơ trò chơi bóng bàn Nhóm: Phạm Đức Tiến Triệu Bảo Trung Đỗ Viết Hồng 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; if Random(1) = then ball_x_dir := else ball_x_dir := -2; if Random(1) = then ball_y_dir := Random(2) + 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; 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); 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; End; //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 - 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; //check x if ball_x < then //Nguoi choi begin if (ball_y >= raq_y) and (ball_y 58 then //cpu begin if (ball_y >= cpu_raq_y) and (ball_y