https://github.com/anurag1101/python_snake_water_gun
"A simple Python game implementing the classic Snake, Water, Gun game (similar to Rock-Paper-Scissors) with user vs computer gameplay."
https://github.com/anurag1101/python_snake_water_gun
python python-random python-random-function python3 snake-water-gun snake-water-gun-game
Last synced: about 1 year ago
JSON representation
"A simple Python game implementing the classic Snake, Water, Gun game (similar to Rock-Paper-Scissors) with user vs computer gameplay."
- Host: GitHub
- URL: https://github.com/anurag1101/python_snake_water_gun
- Owner: Anurag1101
- Created: 2024-09-30T15:25:07.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-02-27T11:23:13.000Z (about 1 year ago)
- Last Synced: 2025-02-27T15:47:15.260Z (about 1 year ago)
- Topics: python, python-random, python-random-function, python3, snake-water-gun, snake-water-gun-game
- Language: Python
- Homepage:
- Size: 82 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Snake Water Gun Game
This is a Python implementation of the classic `Snake, Water, Gun` game, similar to Rock-Paper-Scissors. The game is played between the user and the computer.
## Game Rules:
- **Snake** beats **Water**
- **Water** beats **Gun**
- **Gun** beats **Snake**
If both the player and the computer choose the same, it results in a draw.
## How to Play:
1. The player chooses either `snake`, `water`, or `gun`.
2. The computer randomly selects its choice.
3. The program compares both choices and determines the winner based on the rules.
## Code Overview:
The program uses Python's `random` module to make the computer's choice. The player's input is matched against predefined values for `snake`, `water`, or `gun`. After both choices are made, the game logic determines the winner or if it's a draw.
Here’s a simplified breakdown:
- **1 for Snake**, **-1 for Water**, and **0 for Gun**.
- The game compares the player's choice and the computer's choice to decide the outcome.
- If both choose the same, the game is a draw. Otherwise, the predefined logic determines the winner.
**Code Breakdown:**
**Choices:**
1 represents Snake.
-1 represents Water.
0 represents Gun.
**Game Logic:**
The player’s choice is converted into a corresponding numeric value using a dictionary (your_dict), and the computer’s choice is generated randomly.
The result is then computed by comparing the two choices:
If the player and the computer make the same choice, the game is a draw.
If the choices are different, a series of conditional statements determine the winner based on the game’s rules.
## How to Run the Code:
1. Clone the repository or download the code.
2. Ensure you have Python 3.x installed on your system.
3. Run the program from the terminal or command prompt:
```bash
python snake_water_gun.py
```
4. Follow the instructions to enter your choice and see the result.