Saturday, January 29, 2011

Dragon Realm's 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!");
 print("Other one is greedy and Kill you!");
 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 large dragon jumps out in front of you and open the jaw...");
 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...!");

playAgain = "yes";

while playAgain == "yes" or playAgain == "y":
 displayIntro();
 caveNumber = chooseCave();
 checkCave(caveNumber);
 print("Do you want to play again? y/n");
 playAgain = input();
http://inventwithpython.com/chapter6.html

Guess The Number Simple Game in Python

I am learning python at this moment and created simple game. I saw some tutorial before and just coded this.

#!/usr/bin/env python3.1
#This is a guess the number game.
import random;

guessesToken = 0;

print("Hello! What is your name?");
myName = input();

number = random.randint(1, 20);

print("Well, Myfriend "+myName+" let's play a game");
print("Guess a number between 1 and 20");

while guessesToken < 6:
 guess = input();
 guess = int(guess);
 
 guessesToken = guessesToken + 1;
 
 if guess < number:
  print("Your guess is too low!");
 if guess > number:
  print("Your guess is too high!");
 if guess == number:
  break;
if guess == number:
 guessesToken = str(guessesToken);
 print("You guessed it within "+guessesToken+" times congratulations!");

if guess != number:
 print("You failed man!");