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.
- Snake beats Water
- Water beats Gun
- Gun beats Snake
If both the player and the computer choose the same, it results in a draw.
- The player chooses either
snake
,water
, orgun
. - The computer randomly selects its choice.
- The program compares both choices and determines the winner based on the rules.
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.
-
Clone the repository or download the code.
-
Ensure you have Python 3.x installed on your system.
-
Run the program from the terminal or command prompt:
python snake_water_gun.py
-
Follow the instructions to enter your choice and see the result.