0
rock,paper and scissors game code
Hello, I face problem in coding of this game.
16 Respuestas
0
Do you have any code to show? You can attach a code using the plus sign.
That or if you can give a bit more detail?
0
Sorry I didn't see the Python tag, I'm more knowledgeable in c#, css, and Js but I hope you get some help..
0
I can share the code through email
0
I don’t know how to write here, but you can send for email and I will reply back with code
0
You can write your code at Playground here on Sololearn. Then we can just click and run.
0
#!/usr/bin/env python3
import random
"""This program plays a game of Rock, Paper, Scissors between two Players,
and reports both Player's scores each round."""
move = ['rock', 'paper', 'scissors']
"""The Player class is the parent class for all of the Players
in this game"""
class Player:
def move(self):
self.move = 0
def learn(self, my_move, their_move):
pass
class randomPlayer(Player):
"""docstring for ."""
def move(self):
p1 = random.choice(move)
return p1
class HumanPlayer(Player):
"""docstring for ."""
def move(self):
p2 = input('please select your choice')
if p2 == (move):
print ('please select your choice')
else:
print ('try a gain')
return p2
class reflectedPlayer(Player):
""docstring fo reflectedPlayer.""
def move(self):
class CyclePlayer(Player):
""docstring forCyclePlayer.""
def move(self):
if p2 == (move):
return rock
elif p2 == 'paper':
return Paper
else:
return scissors
class Game:
def __init__(self, p1, p2):
self.p1 = randomPlayer()
self.p2 = HumanPlayer()
def play_round(self):
move1 = self.p1.move()
move2 = self.p2.move()
print(f"Player 1: {move1} Player 2: {move2}")
self.p1.learn(move1, move2)
self.p2.learn(move2, move1)
def play_game(self):
print("Game start!")
for round in range(3):
print(f"Round {round}:")
self.play_round()
print("Game over!")
def beats(one, two):
if (one == 'rock' and two == 'scissors'):
return True
elif (one == 'scissors' and two == 'paper'):
return True
elif (one == 'paper' and two == 'rock'):
else:
return False
if __name__ == '__main__':
game = Game(Player(), Player())
game.play_game()
0
Actually, for cycle and reflected player the codes not complete.. I know the idea but I don’t know how to implement
0
I have a question, although I am not sure if it helps you, but:
Why all these classes? What are they actually doing that you couldn't do easier without them?
Python is not Java. When there's just a few basic operations of print, if and else, you can just write that (I guess you also don't have to do it like this in Java).
The easier you write, the easier it becomes to figure out what is going wrong.
0
I'm not sure if you know what I mean, so I'll add a possible start of your game without all these unnecessary classes.
import random
move = ['rock', 'paper', 'scissors'] print("Game start!\n")
for round in range(1, 3):
print(f'Round {round}: '
'please select your choice!\n')
move1 = input()
move2 = random.choice(move)
print(f'Player 1: {move1}\n'
f'Player 2: {move2}\n')
if ...
And there you start with your ifs and elses. What would you need functions, let alone classes for?
In my opinion you should generally choose a more complex structure only when the less complex structure can't do the job well.
A question you can ask yourself: 'Do I need this twice?'
It starts with values. If you need them only once, write print(2+2) and be done with it. If you need the values again in another place, well then and only then use x=2...
0
Do you execute your code once? Just write it down line by line. Do you want to run it more times or with branches? Now you can use basic logic with for, while, if and else.
Do you have to run areas of your code several times and from different places, and if you force it with normal logic, you get a logic monstrosity with eight indentation levels? Then now is the time to use functions.
Finally: Do you have chunks of data, that regularly interact with the same set of functions, and other chunks of data interacting with another set of functions and it's all a huge mess? Well NOW is the time to bind functions together with data inside a class.
Don't use a huge packet to send a love letter. Don't drive in a nail for a picture with a sledge hammer. Don't call the terminator to kill a mosquito.
0
See, this is a project and I need to make class and subclass ,
The idea is rock paper and scissors game. I need to make 4 classes
1. Random player both computer and me play randomly. It is correct in the code
2. Human player as in the code. It is correct in the code also.
3. Reflected player means if me play first time rock then computer will play either rock, paper or scissors. So computer in the second round will play what I played before”example:rock”
4. Cycle player, me play random but computer in sequence rock then paper then scissors
0
And at the end of the game, in each round should show the results and a rise the winner at the end
0
Hm. So your teacher told you to implement rock-paper-scissors with classes and subclasses?
0
Yub
0
Coze of that I am confused little bit
0
And rightfully so, I'd say: The game is far too simple to reasonably involve classes and even subclasses.
Take a look at my version down there to see what I mean.
https://code.sololearn.com/cq5P97pbm7Y4/?ref=app