Ping-Pong - Game Using C Programming Language



"Ping-Pong" is a graphic based multiplayer console game. Simply, it is a table tennis game. In this game, the main role to be played it to volley the pong (ball) so that it do not hit the vertical boundary. Failing to do so, score increases for opponent player. With the integration of a simple menu and options, it is an interactive game with simple graphics. The three levels are included, which are classified as easy, moderate and hard and can be chosen by the user manually. As the players continue on volleying the ball with the movable paddles, the speed gets on increasing. The speed of balls, for making players emphasized on the game, gets increased after the interval of every ten consecutive volleys by paddles. Once the ball hits the boundary, the speed of the balls is restored to normal. The player scoring 5 at first wins the game.  For representing the score scored, square bars are shown behind each paddle. The player scoring total score of five firstly wins the game. The guide has been added so that new players can learn about how to play.


How to download code?

  • Click here for source code.
  • New window will open where there is a source code of this project. Download all the files.
  • Remember that this project runs in Dev C++.


Demo of this game :

  

For more source code and tutorial, SUBSCRBE to my YouTube channel. 


Development platform

Computer programming language has been used to develop this project.

 

Compiler

Dev C++ has been used as compiler in this project whose version is 5.11.


Header files used

The header files used in this project are as follows :

  1. Conic
  2. Graphics
  3. Stdio.h


Library functions

The following library functions has been used :

  1. Under conio header file
    1. Clrscr
    2. Getch
  2. Under graphics header file
    1. Arc
    2. Bar
    3. Circle
    4. Closegraph
    5. Delay
    6. Exit
    7. Floodfill
    8. Getasynckeystate
    9. Getpixel
    10. Initwindow
    11. Line
    12. Outtextxy
    13. Rectangle
    14. System
    15. Setcolor
    16. Setfillstyle
    17. Setlinestyle
    18. Settextstyle
    19. System
  3. Under stdio header file
    1. Printf

 

Concepts used

Topics/ concepts of this language that you need to know for making this type of game :

  1. Array
  2. Function
  3. For looping statement
  4. If else conditional statement
  5. While looping statement
  6. Graphics 


Logic description

On the startup of the game, menu is shown which can be navigated using up and down arrow keys. 


Since this is a multiplayer game, two paddles are present, and for  their movement tab, left-control, up arrow and down arrow keys can be used. The paddles can be moved only in vertical direction. 


Talking about the direction of ball movement, here, includes four directions. Let us consider movement-1 : down-right, movement-2 : up-right, movement-3 : up-left and movement-4 : down-left. When ball gets hit on the paddles, if the ball is in movement-1, ball direction changes to movement-4, form movement-2 to movement-3, movement-3 to movement-2 and movement-4 to movement-1.


But this protocol do not get applied when ball collide on the top and bottom boundaries. Here, movement-1 changes to movement-2, movement-2 changes to movement-1, movement-3 changes to movement-4 and movement-4 changes to movement-3.


The score pattern is simple. Whenever the ball gets hit on the vertical boundaries score for opponent player gets increases. The player scoring total score of 5 at first wins the game.


In this project, different levels have not been included.


Lately, I realized that I have not included any medium to show the current score. 


Realizing all these, I have developed similar game using C++ platform, with features of multiple levels and score visualizations. Don't forget to check out that project.


No comments:

Post a Comment

Article Ad1