diff --git a/Rock paper scissors Game Version 1.3 Stable.py b/Rock paper scissors Game Version 1.3 Stable.py new file mode 100644 index 0000000..87117a0 --- /dev/null +++ b/Rock paper scissors Game Version 1.3 Stable.py @@ -0,0 +1,73 @@ +import random + +"""A simple Rock-Paper-Scissors game.""" + +# Game data +choices = ("r", "p", "s") +emojis = {"r": "🌋", "p": "📜", "s": "✂️"} +aliases = { + 'r': 'r', + 'rock': 'r', + 'p': 'p', + 'paper': 'p', + 's': 's', + 'scissors': 's' +} +winning_rules = {('r', 's'), ('s', 'p'), ('p', 'r')} + +# Main game loop +def get_user_choice_on_playing(): + while True: + mode = input("Do you want to play rock paper and scissors game (y/n): ").lower().strip() + + if mode in ('n', 'no'): + print("Goodbye!") + return False + elif mode not in ("yes", "y"): + print("Please enter yes or no.") + continue + else: + return True + + # Inner game loop +def get_user_choice(): + while True: + user_input = input("Rock, Paper or Scissors (r/p/s): ").lower().strip() + user_choice = aliases.get(user_input) + if user_choice not in choices: + print("Invalid choice!.") + continue + else: + return user_choice + +def display_choices(user_choice, computer_choice): + print(f"You chose {emojis[user_choice]} and the computer chose {emojis[computer_choice]}") + +def determine_the_winner(user_choice, computer_choice): + if user_choice == computer_choice: + print("It's a tie!") + else: + result = (user_choice, computer_choice) + if result in winning_rules: + print("You win!") + else: + print("You lose!") + +def play_game(): + while True: + if get_user_choice_on_playing(): + user_choice = get_user_choice() + computer_choice = random.choice(choices) + display_choices(user_choice, computer_choice) + determine_the_winner(user_choice, computer_choice) + + + # Ask if the user wants to play again + should_continue = input("Do you want to play again (y/n): ").lower().strip() + if should_continue in ('n', 'no'): + print("Goodbye!") + break # Exit the loop if the user doesn't want to play again + else: + break # Exit the loop if the user doesn't want to play initially +play_game() + diff --git a/Rock, paper and scissors.py b/Rock, paper and scissors.py new file mode 100644 index 0000000..21ae130 --- /dev/null +++ b/Rock, paper and scissors.py @@ -0,0 +1,3 @@ +user_choice = input("Rock, Paper and scissors (r/p/s): ") +if user_choice not in choices: + print("Invalid Choice ") \ No newline at end of file diff --git a/Rock, paper, scissors.py b/Rock, paper, scissors.py new file mode 100644 index 0000000..77897ad --- /dev/null +++ b/Rock, paper, scissors.py @@ -0,0 +1,53 @@ +import random + +"""A simple Rock-Paper-Scissors game.""" + +choices = ("r", "p", "s",) +emojis = {"r" : "🌋", "p" : "📜", "s" : "✂️"} +normalised_choices = { + 'r': 'r', + "rock": "r", + 'paper': "p", + "p": "p", + "scissors": "s", + "s": "s" +} +winning_rules = {('r', 's'), ('s', 'p'), ('p', 'r')} + +while True: + mode = input("Do you want to play rock paper and scissors game (y/n): ").lower().strip() + + if mode in ('n', 'no'): + print("Goodbye!") + break + if mode not in ("yes", "y"): + print("Enter yes or no, Please") + continue + while True: + + user_choice = input("Rock, Paper and Scissors (r/p/s): ").lower().strip() + if user_choice not in choices: + user_choice = (normalised_choices[user_choice]) + + break + else: + print("Invalid Choice, please pick one of: r, p, s") + + computer_choice = random.choice(choices) + print(f"You choose {emojis[user_choice]} and computer choose {emojis[computer_choice]}") + + if user_choice == computer_choice: + print("So it's a tie") + else: + result = (user_choice, computer_choice) + if result in winning_rules: + print("You win") + else: + print("You lost") + print("More innovation coming soon") + + + + + + \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..d21430d --- /dev/null +++ b/main.py @@ -0,0 +1,13 @@ +from rock import get_user_choice, get_user_choice_on_playing, determine_the_winner, generate_computer_choice +while True: + if get_user_choice_on_playing(): + user_choice = get_user_choice() + computer_choice = generate_computer_choice() + determine_the_winner(user_choice, computer_choice) + + should_continue = input("Do you want to play again (y/n): ").lower().strip() + if should_continue in ('n', 'no'): + print("Goodbye!") + break + else: + break \ No newline at end of file diff --git a/rock.py b/rock.py new file mode 100644 index 0000000..87117a0 --- /dev/null +++ b/rock.py @@ -0,0 +1,73 @@ +import random + +"""A simple Rock-Paper-Scissors game.""" + +# Game data +choices = ("r", "p", "s") +emojis = {"r": "🌋", "p": "📜", "s": "✂️"} +aliases = { + 'r': 'r', + 'rock': 'r', + 'p': 'p', + 'paper': 'p', + 's': 's', + 'scissors': 's' +} +winning_rules = {('r', 's'), ('s', 'p'), ('p', 'r')} + +# Main game loop +def get_user_choice_on_playing(): + while True: + mode = input("Do you want to play rock paper and scissors game (y/n): ").lower().strip() + + if mode in ('n', 'no'): + print("Goodbye!") + return False + elif mode not in ("yes", "y"): + print("Please enter yes or no.") + continue + else: + return True + + # Inner game loop +def get_user_choice(): + while True: + user_input = input("Rock, Paper or Scissors (r/p/s): ").lower().strip() + user_choice = aliases.get(user_input) + if user_choice not in choices: + print("Invalid choice!.") + continue + else: + return user_choice + +def display_choices(user_choice, computer_choice): + print(f"You chose {emojis[user_choice]} and the computer chose {emojis[computer_choice]}") + +def determine_the_winner(user_choice, computer_choice): + if user_choice == computer_choice: + print("It's a tie!") + else: + result = (user_choice, computer_choice) + if result in winning_rules: + print("You win!") + else: + print("You lose!") + +def play_game(): + while True: + if get_user_choice_on_playing(): + user_choice = get_user_choice() + computer_choice = random.choice(choices) + display_choices(user_choice, computer_choice) + determine_the_winner(user_choice, computer_choice) + + + # Ask if the user wants to play again + should_continue = input("Do you want to play again (y/n): ").lower().strip() + if should_continue in ('n', 'no'): + print("Goodbye!") + break # Exit the loop if the user doesn't want to play again + else: + break # Exit the loop if the user doesn't want to play initially +play_game() + diff --git a/rock_paper.py b/rock_paper.py new file mode 100644 index 0000000..f88d208 --- /dev/null +++ b/rock_paper.py @@ -0,0 +1,16 @@ +import random + +# Store game data +emojis = {"r": "🌋", "p": "📜", "s": "✂️"} +choices = ("r", "p", "s") +results = { + ("r", "s"): "You win! Rock crushes Scissors!", + ("s", "p"): "You win! Scissors cut Paper!", + ("p", "r"): "You win! Paper covers Rock!", + ("s", "r"): "You lose! Rock crushes Scissors!", + ("p", "s"): "You lose! Scissors cut Paper!", + ("r", "p"): "You lose! Paper covers Rock!" +} + +while True: + user_choice = input("Do you want to play (y/n): ").lower().strip() diff --git a/rock_paper_scissors.py b/rock_paper_scissors.py new file mode 100644 index 0000000..0bb5b07 --- /dev/null +++ b/rock_paper_scissors.py @@ -0,0 +1,43 @@ +# Store all data needed for the game +import random + +emojis = { + "r" : "🌋", "p" : "📜", "s" : "✂️" +} +choices = ("r", "p", "s") +results = { + ("r", "s"): "You win! Rock crushes Scissors!", + ("s", "p"): "You win! Scissors cut Paper!", + ("p", "r"): "You win! Paper covers Rock!", + ("s", "r"): "You lose! Rock crushes Scissors!", + ("p", "s"): "You lose! Scissors cut Paper!", + ("r", "p"): "You lose! Paper covers Rock!" +} + +# Ask users if they want to play +while True: + user_choice = input("Do you want to play (y/n): ").lower().strip() +if user_choice in ("n" or "no"): +print("Goodbye 👋👋👋😘😘") +break +while True: + +elif user_choice in ("y" or "yes"): +user_move = input("Rock, Paper, Scissors(r, p, s): ").lower().strip() +if user_move not in choices: +print("Invalid choice, press r for rock, p for paper, s for scissors") +else : +print("Please, Type only yes or no") +computer_move = random.choice(choices) +if user_move == computer_move: +print("It a Tie") +print(results[(user_move, computer_move)]) +# Validate answers for errors(non words and number) + +# Generate computer answers + +# print result + +# print the winner or loser + +# Allow user to terminate the program \ No newline at end of file