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)