-->

Python Game - Dragon Cave Game

 The Dragon Cave Game 🐲

Python Game - Dragon Cave Game
Python Game - The Dragon Cave

This's a simple fun game for python beginners in coding. A very short game with a short introduction that goes like this:

You are in a land full of dragons. In front of you,

you see two caves. In one cave, the dragon is friendly,

and will share his treasure with you. The other dragon

is greedy and hungry, and will eat you on sight.

Which cave will you go into? (1 or 2 ?)

The trick here is that the result (consequences) of your choice may vary depending on your luck (a random result). The funny part is, you can choose the the same number twice, but you get different results.

And here's the code of the game:

import random
import time

def displayIntro():
    print("You are in a land full of dragons. In front of you,")
    print("you see two caves. In one cave, the dragon is friendly,")
    print("and will share his treasure with you. The other dragon")
    print("is greedy and hungry, and will eat you on sight.")
    print()

def chooseCave():
    cave = ""
    while cave != "1" and cave != "2":
        print("Which cave will you go into? (1 or 2 ?)")
        cave = input()

    return cave

def checkCave(chosenCave):
    print("You approach the cave ... ")
    time.sleep(2)
    print("It is dark and spooky ... ")
    time.sleep(2)
    print("A larg dragon jumps out in front of you! He opens his jaws and ... ")
    print()
    time.sleep(2)

    friendlyCave = random.randint(1 , 2)
    if chosenCave == str(friendlyCave):
        print("Give you his treasure!")
    else:
        print("Gobbles you down in one bite!")

playAgian = "yes"

while playAgian == "yes" or playAgian == "y":
    displayIntro()
    caveNumber = chooseCave()
    checkCave(caveNumber)
    print("Do you want to play again? (yes or no)" )
    playAgian = input()


This game has been coded by Al Sweigart, author of "Automate the Boring Stuff with Python"

Post a Comment

0 Comments