Snake Water Gun Game in Python is a simple game that can be played. The rules say that each player must use one hand to make one of three shapes at an agreed-upon time.
The person who plays the strongest “object” is the winner of the game.
Also read: How To Make Tic Tac Toe In Python
Snake Water Gun Game Project Software Information
Project Name: | Snake Water Gun Game in Python |
Abstract: | Snake Water Gun Game in Python is a hand game where the player picks one of three shapes at random: snake, water, or gun. |
Language Used: | Python Programming Language |
Python Version: | 2.x or 3.x |
Database: | None |
Type: | Console Based |
Developer: | Angel Jude Suarez |
About Snake Water Gun Game Project
Snake Water Gun is a well-known two-player game that many people like to play. It’s a hand game where the player picks one of three shapes at random: snake, water, or gun.
Here, we’re going to use Python to make this game work.
This Python project is to make a single-player game that is played against the computer.
How To Play Snake Water Gun Game?
This is the same as “rock, paper, scissors.” Both players should keep their movements at the same time. The snake drinks the water, and the gun kills the snake, but the gun doesn’t do anything to the water.
Instructions:
Your task for today is to make your first Python game, “Snake Water Gun.”
Most of you must already know about the game. Still, I will give you a brief description.
This is a two-player game where each person chooses one object. As we know, there are three things: a snake, water, and a gun.
Rules of the Game:
Following are the rules of Snake Water Gun Games.
- Snake vs. Water: Snake drinks water, so it wins.
- Water vs Gun: The gun will sink in water, so it’s a point for water.
- Snake vs. Gun: The gun will win because it will kill the snake.
- If both players choose the same object, the game will end in a tie.
How To Make a Snake Water Gun Game in Python with Source Code
Before you start creating a Snake Water Gun Game in Python, make sure that you have already Pycharm IDE and Installed Python on your Computer.
Steps on how To Make a Snake Water Gun Game in Python:
Time needed: 5 minutes
How To Make a Snake Water Gun Game in Python with Source Code
- Step 1: Open PyCharm IDE and Create New Project
First, Open PyCharm IDE, Select Create New Project, and Name it.
- Step 2: Create Python File
Next, just right-click your Project Folder, Select New, and Select Python File.
- Step 3: Python File Name
Next, after creating a Python File you are required to name the file.
- Step 4: Actual Code
Finally, just copy the complete source code given below and paste it into your Python File.
Code Explanations
Here are the step-by-step explanations in each line of code on how to create a Snake Water Gun Game.
1. Import Libraries
Explanation:
The line of code given below explained that we want to import “random” as the game Libraries.
Code:
# Import random library
import random
2. Number of Rounds
Explanation:
The line of code given below explained that we want to input the number of rounds in playing the game.
Code:
# Input no. of rounds
n = int(input('Enter number of rounds: '))
3. Game Options
Explanation:
In the line of code given below explained that we want to select what option we want is either Snake (s), Water (w) or Gun (s).
Code:
# List containing Snake(s), Water(w), Gun(g)
options = ['s', 'w', 'g']
4. Declaring Variables
Explanation:
The line of code given below explained for declaring Variables and their Value.
Code:
#Declaring Variables
# Round numbers
rounds = 1
# Count of computer wins
comp_win = 0
# Count of player wins
user_win = 0
5. Conditions Based On The Selected Game Option
Explanation:
The line of code given below explained the step-by-step condition based on the selected option given by the system.
Code:
while rounds <= n:
# Display round
print(f"Round :{rounds}\nSnake - 's'\nWater - 'w'\nGun - 'g'")
# Exception handling
try:
player = input("Choose your option: ")
except EOFError as e:
print(e)
# Control of bad inputs
if player != 's' and player != 'w' and player != 'g':
print("Invalid input, try again\n")
continue
# random.choice() will randomly choose
# item from list- options
computer = random.choice(options)
# Conditions based on the game rule
if computer == 's':
if player == 'w':
comp_win += 1
elif player == 'g':
user_win += 1
elif computer == 'w':
if player == 'g':
comp_win += 1
elif player == 's':
user_win += 1
elif computer == 'g':
if player == 's':
comp_win += 1
elif player == 'w':
user_win += 1
6. Announced Winner Based on Every Selected Options
Explanation:
The line of code given below explained for announcing the winner based on every selected option given by the system.
Code:
# Announce winner of every round
if user_win > comp_win:
print(f"You Won round {rounds}\n")
elif comp_win > user_win:
print(f"Computer Won round {rounds}\n")
else:
print("Draw!!\n")
rounds += 1
7. Final Winner Based on The Number of Won’s
Explanation:
In the line of code given below is the final process of the system to declare who wins based on the number of won.
Code:
# Final winner based on the number of wons
if user_win > comp_win:
print("Congratulations!! You Won")
elif comp_win > user_win:
print("You lose!!")
else:
print("Match Draw!!")
In Summary
Hooray! we have completed the step-by-step process on How To Make a Snake Water Gun Game in Python with Source Code and explanations are given. I hope you learned a lot in developing a simple game for Snake Water Gun Game Project.