This Python online game tutorial will show you how to code a scaleable multiplayer game with python using sockets/networking and pygame. You will learn how to deploy your game so that people anywhere around the world can play against each other.
You will learn and understand the following after this tutorial:
• How a Client/Server System Works
• How to Develop Applications to an External Server
• How to Code a Client
• How to Code a Server
• Sending Encrypted Data Such as Objects Over a Port
• Connecting Multiple Clients to a Server
💻Code:
⭐️ Contents ⭐️
⌨️ (0:00:51) 1 – Creating a Client Using Sockets
⌨️ (0:16:55) 2 – Creating a Server
⌨️ (0:34:04) 3 – Sending & Receiving Information From Server
⌨️ (0:44:43) 4 – Connecting Multiple Clients
⌨️ (1:03:38) 5 – Sending Objects With Pickle!
⌨️ (1:14:52) 6 – Online Rock Paper Scissors
🔗 How to Install Pygame:
🔗 Pycharm Download:
🎥 Tutorial from Tech with Tim. Check out his YouTube channel:
—
Learn to code for free and get a developer job:
Read hundreds of articles on programming:
And subscribe for new videos on technology:
Samanvya Gautam
24.07.2022His computer is faster than my breathing ngl.
aaron
17.07.2022really helped me, thx bro
pzg2008
17.07.2022Why do you put 2 parantheses instead of 1 ?
iptsu yt
17.07.2022Thankyou for making this video!!!!!!!!!!!! this vid really helps me on my final project. I've learned so many things, you are my GOD now
bee rat
17.07.2022Hey I know this video is old, but at 1:23:18 where you use if statements to check for the winner for rock paper scissors, you could instead use a nested dictionary to improve the runtime. I substituted the use of the following one:
windict = {"R":{"S":0, "P":1, "R": -1}, "P":{"R":0, "S": 1, "P":-1}, "S":{"P":0, "R": 1, "S":-1}}
in this format, all I'd have to do is define the dictionary and then:
winner = windict[p1][p2]
@Tech With Tim
Mick Mickymick
17.07.2022This is not really a great tutorial. He basically just types everything out and keeps saying 'Don't worry, you'll understand it later', but he never actually explains anything later. Luckily most of the code is fairly self-explanatory.And some of that code is janky af. That line make_pos(read_pos) and then like a thousand brackets to convert a string to a tuple and back to a string.
Also nothing is commented so you have to do that all yourself but it also makes it impossible to come back to this code and re use it in future
On a more minor note, his names for variables are terrible 'p' and 'n' are basically textbook 'don't name your variables this' examples. Unfortunately this is the only tutorial like this I found so we have to make do.
K. Chris Caldwell
17.07.2022For those that may be wondering:
The needed dependencies are:
socket
pickle
_thread
pygame
K. Chris Caldwell
17.07.2022For those having trouble running the required multiple files – server, client1, and client2 – in Visual Studio Code (VSC), open subsequent instances of VSC for each client file to run and then open and run the one client file in each instance, while running the server file in the main instance. Cool is that edits in the client file in the main VSC instance will automatically show up in the other open two instances.
Lucas Premat
17.07.2022for me read and make pos didn't work in client file why is that i have checked my code a few times and it is the same code as in the video tim is showing
Krackhead Gamerz
17.07.2022GG to anyone who watched this whole vid
Gonzalo Escudero
17.07.2022This tutorial works for the "Secure real time multiplayer game" project on fcc curriculum?
GHΩƧƬ
15.07.2022Hey i have watching the 3 first part of the vidéo and i have a bad news :
This not working on Python 3.9.6
Just s.listen(2) not work correctly
Sorry
Sameera Sampath
15.07.2022s.listen(1) not work pl help
Tristen Fielding
15.07.2022Thanks for a great tutrorial on Socket programming in Python.
Here's another way to handle to rules to RPC. First define the the rules like so:
self.rules = {
"R": {"R": False, "P": False, "S": True},
"P": {"R": True, "P": False, "S": False},
"S": {"R": False, "P": True, "S": False}
}
# Note the rules only defines the winning combiniations.
Then the winner() method would be defined as:
def winner(self):
p1 = self.moves[0].upper()[0]
p2 = self.moves[1].upper()[0]
winner = -1
if self.rules[p1][p2]:
winner = 0 # player Id 0 won
elif self.rules[p2][p1]:
winner = 1 # player Id 1 won
return winner
enjoy!
jimm
15.07.2022i used 6969 for the port lol
ample man
15.07.2022I wish this still worked
unstopable
15.07.2022do minecraft
vincent cauchy
15.07.2022Thanks for this video. If I want to play on 2 different computers, do I have to copy the code to the 2 computers? also how to get it online. I apologize if my question sounds stupid, I have no knowledge of using python online. Thanks in advance.
MÂD ÀÁFÏ
15.07.2022mine problem is shown no module name py game what should i do
Anomonous ???
15.07.2022start thread basically screen.update() in turtle im assuming
DeeZy Games
15.07.2022if I could, I would give 10 hands up. That was very helpful <3
Martha Robins
12.07.2022I keep getting an error that says “OSError: [WinError 10022] An invalid argument was supplied” where I wrote “s.listen(2)”. Somebody please let me know what is going on.
kbrunot13
12.07.2022cool, but how i'm turn my socket in a real server?, exemplo: i need a socket for connect two peoples of != wi-fi, how i'm make this? i just can run in localhost
Srivatsan Suresh
12.07.2022Could someone tell how to make server be accessible across the internet. That is, I want to access the server running in one network from a completely different network. I tried all methods, such as using public IP, etc etc, but nothing seems to work…
نون الصالح
12.07.2022Game link?
Bgamer Bass
12.07.2022Just a small hint for everyone watching:
Don't lose time watching/trying to understand this video or code if you don't have GOOD basic understanding in python.
First learn the basics and object oriented programming, then come and watch this video
The Flusches
12.07.2022where is 'start_new_thread'?
luckyblo82 Channel
12.07.2022hey! I wanted to make a "The Price is Right" game where the opponent chooses a number and the other one has to guess it
depending of the number you pick it tells you "Higher" or "Lower"
could you help me please? thanks in advance! 😀
Tom Brandis
12.07.2022learning python whilst I am isolating with covid
Tom Brandis
12.07.2022I have seen a few videos about something called ursina for making 3d stuff – has anyone used it and how hard is it to use
bloxxer02
12.07.2022i wish you labeled the code before publishing theres a cool thing in coding called documenting your work for educational purposes
LagDaemon Programming
11.07.2022SOCK_STREAM means that the socket uses TCP/IP and holds Connections. SOCK_DGRAM is connectionless and uses the User Datagram Protocol (UDP).
Jean Zyx
11.07.2022amaizing tutorial gg
Petko Popov
11.07.2022deubg time to time pls!
Gabriel1443
11.07.2022this is super useful and fun thank you TIM!!
The Flusches
11.07.2022Never mind I found start_new_thread. Could you send a link to the files though? I am making a similar game but encountering lots of errors.
Emmess d
11.07.2022how can i play it with my friend now on two different computers?
Force
11.07.2022About 1:23:57
Hope u read it and say ur opinion about this method
There is an easier way
U just make a list:
Priority = ['R', 'P','S']
And then u can just say
If p1 == p2
Return -1
Elif Priority[Priority.index(p1)-1]==p2
Return 0
Else return 1
Pranav Nyavanandi
11.07.2022God.., does this guy know everything?😄
FantasticBeast
11.07.20221:23:15 I think this works too: implement moves as circular priority
Move=["R":0,"P":1,"S":2]
if(Move[p1]==Move[p2]):
TIE
elif((Move[p1]+1) mod 3==Move[p2]):
p2 winner
else:
p1 winner
aydin anginer
11.07.2022never use try: … except: pass, it's just bad, print error or something
조기영
11.07.2022when I execute client file at first video I get a error messge 'video system not initialized' at "keys= pygame.key.get_pressed()".
Is there any problem to execute the program? Why this happen?
Faisal
11.07.2022how do i play this with my friends
Aarthi Iyer
11.07.2022i'm getting the same error as at 41:10
s.listen(2)
OSError: [WinError 10022] An invalid argument was supplied
How do I resolve it?
Cole Payne-sexton
11.07.2022for linux
python3 –version
if it says python3 command not found then install python 3 with the following
sudo apt update && sudo apt upgrade -y && sudo apt install python3 -y && sudo apt install python3-pip -y
at the next prompt (assuming no errors) run the following
python3 -m pip install tk && sudo apt install tk and python3 -m pip install pygame
you vanced
11.07.2022But how can people access the game? They have to install it on their computer right? Cause pygame can't run on the browser
vafadie kongolo
11.07.2022Hi I am learn python for kids
Nils
11.07.2022Even if the Video is a bit older, can anyone help me? When I try to run the server, it throws an error and says that s.listen, an invalid argument is given, no matter how often I rewrite it or write 2 or nothing in the brackets…
Isak Kack
11.07.2022I got the error [WinError 10053] du you know hot to fix it
Anna Tsvetkova
11.07.2022You are just amazing!!! As well as your typing!!!!!