Created
October 5, 2016 02:40
-
-
Save P1n3appl3/198efc7b3ca15d450160a224d0193cae to your computer and use it in GitHub Desktop.
CS homework pokemon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import msvcrt | |
import os | |
import colorama | |
colorama.init() | |
WHITE = "\033[1;37m" | |
RED = "\033[0;31m" | |
class Pokemon: | |
def __init__(self): | |
self.health = 100 | |
self.hunger = 50 | |
self.wins = 0 | |
self.losses = 0 | |
self.sleep = 0 | |
def __str__(self): | |
return ((WHITE if self.health > 10 else RED) + "Hp: " + str(self.health) + (WHITE if self.hunger > 20 else RED) + "\nHunger: " + str(self.hunger) + (WHITE if self.sleep < 5 else RED) + "\nTiredness: " + str(self.sleep) + WHITE) | |
def battle(self): | |
if random.random() < .5: | |
self.wins += 1 | |
self.health += 10 | |
self.hunger -= 10 | |
print "you won the fight!" | |
else: | |
self.losses += 1 | |
self.health -= 10 | |
self.hunger -= 10 | |
self.sleep += 1 | |
print "you lost the fight!" | |
def rest(self): | |
self.sleep = 0 | |
self.health += 10 | |
self.hunger += 10 | |
print "zzzzzzzzzzzz" | |
def eat(self): | |
if random.random() < .5: | |
self.hunger += 15 | |
print "you ate rations" | |
else: | |
if random.random() < .5: | |
self.health += 10 | |
self.hunger += 10 | |
print "you ate yummy food" | |
else: | |
self.health -= 10 | |
print "you ate rotten food" | |
gameOver = False | |
pikachu = Pokemon() | |
choice = "" | |
while(not gameOver): | |
print pikachu | |
print "Do you want to: [E]at, [S]leep, or [F]ight" | |
choice = msvcrt.getch() | |
os.system("cls") | |
if choice in "eE": | |
pikachu.eat() | |
elif choice in "sS": | |
pikachu.rest() | |
else: | |
pikachu.battle() | |
pikachu.health = min(pikachu.health, 100) | |
if pikachu.sleep >= 5: | |
pikachu.health -= 10 | |
pikachu.sleep += 1 | |
if pikachu.wins == 10: | |
print "YOU WIN (10 fights won)" | |
gameOver = True | |
elif pikachu.losses == 10: | |
print "YOU DIE (10 fights lost)" | |
gameOver = True | |
elif pikachu.hunger <= 0 or pikachu.hunger >= 100: | |
print "YOU DIE (hunger)" | |
gameOver = True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment