mirror of
https://github.com/metafy-social/python-scripts.git
synced 2024-11-27 22:11:10 +00:00
commit
081a7c7e60
13
scripts/Rock_Paper_Scissor/README.md
Normal file
13
scripts/Rock_Paper_Scissor/README.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Rock Paper Scissor Game
|
||||
This is a text-based game of Rock Paper Scissor made using Python where you play with a bot using CLI.
|
||||
|
||||
## How to install?
|
||||
1) Download the file rock_paper_scissor.py
|
||||
2) Open CMD (Command Prompt)
|
||||
3) Run python rock_paper_scissor.py
|
||||
4) Follow the instructions and enjoy!
|
||||
|
||||
## Requirements?
|
||||
None!
|
||||
|
||||
Hope you enjoy it! :heart:
|
75
scripts/Rock_Paper_Scissor/rock_paper_scissor.py
Normal file
75
scripts/Rock_Paper_Scissor/rock_paper_scissor.py
Normal file
|
@ -0,0 +1,75 @@
|
|||
import random
|
||||
|
||||
# Function to take input from the player
|
||||
def getPlayer():
|
||||
player = "empty"
|
||||
player = input("Please Enter You Choice From - Rock | Paper | Scissor = ")
|
||||
while not (player == "Rock" or player == "Paper" or player == "Scissor"):
|
||||
player = input("Please Enter You Choice From - Rock | Paper | Scissor = ")
|
||||
return player
|
||||
|
||||
# Function to generate input from the bot
|
||||
def getBot():
|
||||
lst = ["Rock", "Scissor", "Paper"]
|
||||
return random.choice(lst)
|
||||
|
||||
# Function to match the inputs
|
||||
def getWinner(player, bot):
|
||||
if player == "Rock" and bot == "Rock":
|
||||
return "Draw"
|
||||
elif player == "Rock" and bot == "Paper":
|
||||
return "Bot"
|
||||
elif player == "Rock" and bot == "Scissor":
|
||||
return "Player"
|
||||
elif player == "Paper" and bot == "Paper":
|
||||
return "Draw"
|
||||
elif player == "Paper" and bot == "Rock":
|
||||
return "Player"
|
||||
elif player == "Paper" and bot == "Scissor":
|
||||
return "Bot"
|
||||
elif player == "Scissor" and bot == "Scissor":
|
||||
return "Draw"
|
||||
elif player == "Scissor" and bot == "Paper":
|
||||
return "Player"
|
||||
elif player == "Scissor" and bot == "Rock":
|
||||
return "Bot"
|
||||
else:
|
||||
return "DRAW"
|
||||
|
||||
# Main Function
|
||||
def start():
|
||||
print("Welcome to the Game!\n")
|
||||
gameBegins()
|
||||
|
||||
# To begin game
|
||||
def gameBegins():
|
||||
# To end the game if user wants
|
||||
endTheGame = "n"
|
||||
# For storing score
|
||||
player_score = 0
|
||||
bot_score = 0
|
||||
|
||||
# Running the game till user wants
|
||||
while endTheGame.lower() != "y":
|
||||
player = getPlayer()
|
||||
bot = getBot()
|
||||
print("You Played -", player)
|
||||
print("Bot Played -", bot)
|
||||
winneris = getWinner(player=player, bot=bot)
|
||||
print("The Winner is - ", winneris)
|
||||
if winneris == "Player":
|
||||
player_score += 2
|
||||
elif winneris == "Bot":
|
||||
bot_score += 2
|
||||
else:
|
||||
player_score += 1
|
||||
bot_score += 1
|
||||
|
||||
print("-----Score Board-----")
|
||||
print("-----Player-----", player_score)
|
||||
print("-----Bot-----", bot_score)
|
||||
print(" ")
|
||||
endTheGame = input("You wish to end? Choose Y/N: ")
|
||||
print("\nThank you for Playing!")
|
||||
|
||||
start()
|
Loading…
Reference in New Issue
Block a user