DEV Community

Cover image for Python Snake-water-gun Game....!
Bilal Aslam
Bilal Aslam

Posted on

Python Snake-water-gun Game....!

๐Ÿ๐Ÿ’ง๐Ÿ”ซ Building a Snake Water Gun Game in Python โ€” My First Console Game!

๐ŸŽฎ What Is Snake Water Gun?
Youโ€™ve heard of Rock Paper Scissors โ€” now meet its quirky cousin: Snake Water Gun! Itโ€™s a fun little game where:

  • ๐Ÿ Snake drinks water
  • ๐Ÿ’ง Water drowns gun
  • ๐Ÿ”ซ Gun shoots snake

Each player picks one of the three, and the winner is decided based on these rules.

๐Ÿง  How I Built It in Python
I wanted to create something simple, interactive, and beginner-friendly. Here's the core logic:

๐Ÿ“ฆ Step 1: Setup Choices

computer = random.choice([1, 0, -1])
youstr = input("Enter your choice : ")
youdict = {"s" : 1, "w" : -1, "g" : 0}
reversedict = {1 :"snake", 0 : "gun", -1 :"water"}
you = youdict[youstr]
Enter fullscreen mode Exit fullscreen mode
  • The computer randomly picks a move.
  • The player enters s, w, or g.
  • I use dictionaries to map choices to numbers and back.

โš”๏ธ Step 2: Decide the Winner

if computer == -1 and you == 1:
    print("Snake drinks water ๐Ÿ๐Ÿ’ง")
    print("You win....!")
Enter fullscreen mode Exit fullscreen mode

I wrote clear if-elif conditions for every possible matchup.
Emojis make the output more fun and readable!

๐Ÿš€ How to Play

Clone the repo:

bash
git clone https://github.com/bilal-dev-0x/Snake-water-gun-Game.git
Enter fullscreen mode Exit fullscreen mode

Run the game:

bash
python snake_water_gun.py
Enter fullscreen mode Exit fullscreen mode

Enter your move: s for snake, w for water, g for gun.

๐Ÿ’ก What I Learned

  1. How to use random.choice() for unpredictability.
  2. Mapping inputs with dictionaries for clean code.
  3. Writing readable and fun console output.

๐Ÿ”— Try It Yourself!
Check out the full code on GitHub:
https://github.com/bilal-dev-0x/Snake-water-gun-Game.git

Top comments (0)