Lesson 4

Ready-made game code

program pingpong;

uses GraphABC;

var

  game,pd,pu,ad,au,dx,dy:boolean;

  width,height,ypl,yan,wid,hei,spp,xb,yb,rb,speed,sc1,sc2:integer;

 

  procedure KeyDown(k:integer);

  begin

    if k=VK_S then pd:=True;

    if k=VK_W then pu:=True;

    if k=VK_Down then ad:=True;

    if k=VK_Up then au:=True;

  end;

  procedure KeyUp(k:integer);

  begin

    if k=VK_S then pd:=False;

    if k=VK_W then pu:=False;

    if k=VK_Down then ad:=False;

    if k=VK_Up then au:=False;

  end;

  begin

    //set

    game:=True;

    width:=1024;

    height:=768;

    lockDrawing();

    SetWindowSize(width,height);

    wid:=15;

    hei:=100;

    ypl:=(height-hei)div 2;

    yan:=(height-hei)div 2;

    spp:=20;

    xb:=width div 2;

    yb:=height div 2;

    rb:=20;

    speed:=10;

    while game do

    begin

      //logic

     

       if (dx and dy) then

       begin

         xb+=speed;

         yb+=speed;

       end

       else if (dx and not dy) then

       begin

         xb+=speed;

         yb-=speed;

       end

       else if (not dx and not dy) then

       begin

         xb-=speed;

         yb-=speed;

       end

       else if (not dx and dy) then

       begin

         xb-=speed;

         yb+=speed;

       end;

      

       if (pd and (ypl+hei<=height))then ypl+=spp;

       if (pu and (ypl>=0)) then ypl-=spp;

       if (ad and (yan+hei<=height)) then yan+=spp;

       if (au and (yan>=0)) then yan-=spp;

     

       if (xb-rb<=wid)then

       begin

         if(yb+rb>=ypl) and (yb-rb<=ypl+hei)then

           dx:=not dx

         else begin

           xb:=width div 2;

           yb:=height div 2;

           dx:=True;

           dy:=False;

           sc2+=1;

         end;

       end;

       if (xb+rb>=width-wid)then

       begin

         if (yb+rb>=yan) and (yb-rb<=yan+hei) then

           dx:=not dx

         else begin

           xb:=width div 2;

           yb:=height div 2;

           dx:=False;

           dy:=False;

           sc1:=1;

         end;

       end;

       if ((yb>=height-rb) or (yb<=rb)) then

         dy:=not dy;

      

       OnKeyDown:=KeyDown;

       OnKeyUp:=KeyUp;

       //draw

       window.clear();

       SetBrushColor(clBlue);

       FillRect(width div 2-5,0,width div 2+5,height);

     

       //player and anemy

       FillRect(0,ypl,wid,ypl+hei);

       FillRect(width-wid,yan,width,yan+hei);

       FillCircle(xb,yb,rb);

      

      

       //text

       SetFontSize(50);

       SetBrushColor(clRed);

       TextOut(width div 4,20,sc1);

       TextOut((width div 4)*3,20,sc2);

       redraw();

    end;

  end.

Presentation

After completing the project work in this lesson, ask the groups to present the design and results of the project to their classmates. Students can use the Pascal program, videos, interactive whiteboards, blogs and other multimedia. Various creative presentation methods can be used.

Conclusion

On this project, the students learned more information about the Pascal programming language. We created the game using the Pascal program.

Evaluation

PBL evaluation criteria:

Project based learning (project-based learning) is a learning method in which students acquire knowledge and skills by working on one project for 3 or 4 weeks to research and find an answer to a genuine, interesting and complex question, problem or challenge (follow the link PBL Rubrics on the headings).