This is a simple game of pong with made using pygame. You will need to make a picture of the pong for it to run properly. Simply make a cirlce in paint, 25x25. Just a note, the use of globals is a bad habit. With a little extra effort you can assign them to function arguments and return statements. Jan 22, 2018 We will be making a Pong game using Python, and the Tkinter module. Tkinter is nativity include in most Python code editors, and this code will run in with both Windows and Linux.
Active1 year, 4 months ago
$begingroup$I'm trying to code a machine learning version of pong in python. So far, all I have is the game without any AI.
I personally have very little experience with Python and coding in general, so any feedback would really help! If possible, I'd like to know what the common best practices are when working on a project like this and to what degree I am complying with those practices.
Anyway, here is the code:
![Python pygame pong Python pygame pong](/uploads/1/2/6/2/126236344/188335836.jpg)
7,97277 gold badges3939 silver badges9393 bronze badges
Pong Game Unblocked
TJenkinsTJenkins
$endgroup$1 Answer
$begingroup$First of all, welcome to CodeReview!
I'd like to know what the common best practices are when working on a project
- namingIt has been mentioned in the comments by @mast, naming is a very important part of coding. Would you still understand this code after a hiatus of a few months? I have a hard time understanding the code as is. I would have been able to give a better review if your code was more readable. Good code should be readable at first glance, the below variables have no meaning for me...
- Divide code into more functions/classes!You say you want to make it run by an AI... as is, your code would require a heck of a rewrite. But if you would have divided your code into more functions, the AI can reuse a lot of the functions you created for a single player game, and thus making your code easier to maintain, or add functionality.What functions/classes should a game of pong have?
- a Player (class) <-- This player class can be used by both Players.
- a Pong enviroment (class)
Using a structure like this will improve the code alot, and adding an AI (or other improvements will be easier after this) - Avoid working in the global namespaceThis point is interwoven with dividing the code into functions/classes, see this link as to WHY working in the global namespace is considered bad.
- Wrap up your code into a
if __name__ '__main__':
guard.This will make your code be runnable from the command line, while also be able to be imported into other scripts
Original Pong Game
Ludisposed9,36322 gold badges2727 silver badges7171 bronze badges
$endgroup$