Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/thetoriqul/rock-paper-scissors

This project provides a straightforward and engaging implementation of the classic rock paper scissors game.
https://github.com/thetoriqul/rock-paper-scissors

Last synced: 3 days ago
JSON representation

This project provides a straightforward and engaging implementation of the classic rock paper scissors game.

Awesome Lists containing this project

README

        

## Rock Paper Scissors Game: A Friendly Challenge

This Python code implements a simple rock paper scissors game against a computer opponent. It offers a fun and interactive way to test your luck and strategic thinking.

**Key Features:**

* **Playable against the computer:** Challenge the bot to a rock paper scissors duel.
* **Multiple rounds:** Keep playing as long as you want, racking up wins or losses.
* **Win/loss tracking:** Monitor your performance with separate counters for wins and losses.
* **Clear instructions:** The code provides user-friendly prompts and messages for easy interaction.
* **Randomized bot choices:** The bot makes its selections randomly, ensuring a fair and unpredictable game.
* **Informative feedback:** The code announces the winner of each round and keeps track of the overall score.
* **Graceful exit:** You can quit the game at any time by typing "Q".

**Overall:**

This project provides a straightforward and engaging implementation of the classic rock paper scissors game. It offers a good starting point for learning about game development in Python and can be easily extended with additional features, like difficulty levels or score tracking.

## Explanation of Rock Paper Scissors Game Codes:

**Imports:**

```python
import random
```

This line imports the `random` library, which allows us to generate random numbers for the bot's choices.

**Variables:**

```python
user_wins = 0
bot_wins = 0

options = ["rock", "paper", "scissors"]
```

These lines define variables:

* `user_wins`: Stores the number of times the user has won.
* `bot_wins`: Stores the number of times the bot has won.
* `options`: A list containing the possible choices for both the user and the bot.

**Main Loop:**

```python
while True:
# ... (user input, random choice, comparison, win/loss logic) ...
break
```

This `while True` loop ensures the game continues until the user decides to quit. Inside the loop:

1. **User Input:**
```python
user_input = input("Please type Rock/Paper/Scissors or Q to quit: ").lower()
```
This prompts the user for their choice and converts it to lowercase for easier comparison.
2. **Quit Check:**
```python
if user_input == "q":
break
```
This checks if the user entered "q", and if so, breaks the loop to end the game.
3. **Validation:**
```python
if user_input not in options:
continue
```
This checks if the user's input is valid (from the `options` list). If not, it skips to the next iteration of the loop without processing their choice.
4. **Bot Choice:**
```python
random_num = random.randint(0, 2)
bot_pick = options[random_num]
print("Bot picked", bot_pick + ".")
```
This generates a random number between 0 and 2, uses it to pick a corresponding option from the `options` list, and displays the bot's choice.
5. **Win/Loss Comparison:**
This section uses `if` statements to compare the user's choice with the bot's and update the score based on the winner:
```python
# (specific conditions for each winning possibility)
else:
print("You lost!")
bot_wins += 1
```
6. **Loop Termination:**
```python
break
```
This line breaks the loop once the user has played and the winner is determined.

**Final Score:**

```python
print("You won", user_wins, "times.")
print("The bot won", bot_wins, "times.")
print("See you again. Bye, Bye.")
```

These lines display the final score for both the user and the bot and a farewell message.