Python Online Game Tutorial #6 - Online Rock Paper Scissors p.1

preview_player
Показать описание
In this python online game tutorial I show how to create an online rock paper scissors game using python sockets, networking and pygame.

◾◾◾◾◾
💻 Enroll in The Fundamentals of Programming w/ Python

◾◾◾◾◾◾

⚡ Please leave a LIKE and SUBSCRIBE for more content! ⚡

Tags:
- Tech With Tim
- Online Game Tutorial Python
- Python Tutorials
- Sockets Python
Рекомендации по теме
Комментарии
Автор

8:49 you can use a dictionary mapping, e.g.:

key = p1 + p2
keymap = {'PP': -1, 'PR' : 0, 'PS': 1, 'RR' : -1, 'RS': 0, 'RP': 1, 'SS': -1, 'SP': 0, 'SR': 1}
result = keymap[key]


Great channel!

therealatrifix
Автор

8:50 I made reduces if statements

if p1 == p2:
winner = -1
elif p1+p2 in ('PR', 'RS', 'SP'):
winner = 0
else:
winner = 1

samuelpospisil
Автор

9:03 Yes, there is a WAY easier way man !


I wrote that in PHP but still, using modulo you don't have to write any of the if statements.


<?php


$hands = ['R' => 1, 'P' => 2, 'S' => 3];
$outcomes = [0 => "Draw", 1 => "P1 WIN", 2 => "P2 WIN"];


$p1Hand = 'P';
$p2Hand = 'R';


- $hands[$p2Hand] + 3) % 3]); // P1 WIN

zHqqrdz
Автор

Tim: I didn't post for 3 days
Me: Really!!! You make every day a Post! That's awesome!!

mathcat
Автор

8:49 you can decide that:

rock = 1
paper = 2
scissors = 3

and then do:

def func(n1, n2):
if n1 == n2:
return "tie"
winner = "1" if n1 == n2 + 1 or n1 == n2 -2 else "2"
return f"player {winner} won!

WaldoTheWombat
Автор

After breaking my head for more than one hour, I thought that both rock-paper-scissors and the modulo operator have a circular nature, so I decided to utilize that: def winner(self):
if moves[0] == moves[1]:
self.ties += 1
return -1
options = ["R", "S", "P"]
winner = ((options[moves[0]] - options[moves[1]]) % 2)
self.wins[winner] += 1
return winner

nick_fous
Автор

8:50 with years of hindsight, match/case will do this far more efficiently in both code and typing

RileyMeta
Автор

Love your content you really helped me keep going👏👏👏

billmaniatis
Автор

if you're having problems with s.listen(), you can change the last dygit of the port number. It works for me

MarianaPereira-izee
Автор

Hi Tim, I have been following your tutorials and I like them so much. Recently, I created a python-selenium bot and my friends want to use it. I want to share it with them in a way they cannot decompile the executable file and without sharing my codes. I tried following your "Python Online Game Tutorials" but it did not work. Any ideas how I can approach this? Thanks

catsliving
Автор

if p0 == p1:
return -1

if (p0, p1) in [(ROCK, SICC), (PAPER, ROCK), (SICC, PAPER)]:
return 0
return 1

i think this is the most elegant way

Xmanpl
Автор

I don't really understood why u stop to use pickle to transfer data. Don't should it be more efficient? I mean.. pickle is made for this, no?

gabrielmarcondes
Автор

i can't seem to choose on the 2nd player. the first player works just fine

Vincent
Автор

What would be some key differences between this and trying to make rock paper scissors in a discord python bot?

musicstar
Автор

how to determine the port and the server? can i know?.. is it random?

rinsarata
Автор

im trying to create a spades card game online - i have the game done but not sure how to use this video to send the game to both players etc. any help would be great or links ...

donlanky
Автор

9:04 you may have taken them in dictionary and it would have 3 cases instead of 9

raseshshetty
Автор

Nobody: Hey guys and welcome back to another ... :D

yigitgumus
Автор

What about the S.listen? Why can't people ask you about that, you need to smoke weed and chill or have fun or something bruh, I've never seen someone with no personality before, not trying to be mean just smile dude lol

TanzanihT