-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvirtual_pet.py
More file actions
93 lines (74 loc) · 2.16 KB
/
virtual_pet.py
File metadata and controls
93 lines (74 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import random
import sys
import time
COLORS = ['purple', 'red', 'blue', 'orange']
class Animal(object):
start = time.time()
now = time.time()
health = 10
experience = 0
happy = 10
attack = 0
sound = "gurbl"
def minute(self):
self.health -= 1
self.happy -= 1
self.attack += 1
self.experience += 1
if self.will_attack():
print "You're pet has mauled you!"
print "Game Over"
sys.exit()
def speak(self):
return self.sound().upper()
def will_attack(self):
roll = random.randint(1, self.attack)
if self.type == 'snake' or self.type == 'aligator':
roll += 2
elif self.type == 'bear':
roll += 1
return roll > 5
def get_pet(self):
pet_choice = raw_input("Choose baby pet ([S]nake, [A]ligator, [B]ear): ").lower()
print pet_choice
if pet_choice in 'sab':
if pet_choice == 's':
return 'snake'
elif pet_choice == 'a':
return 'aligator'
else:
return 'bear'
else:
self.get_pet()
def __init__(self):
self.name = raw_input("Name: ")
self.color = random.choice(COLORS)
self.type = self.get_pet()
class Snake(Animal):
attack = 1
sound = "hisssss"
class Bear(Animal):
attack = 2
sound = "growl"
class Aligator(Animal):
attack = 3
sound = "snap"
def menu():
choice = raw_input("Choose action ([F]eed, [P]lay, [W]alk or [I]gnore): ").lower()
if choice in "fpwi":
pass
else:
return self.menu()
def main():
new_pet = Animal()
while new_pet.health > 0:
new_pet.now = time.time()
if new_pet.now - new_pet.start >= 10.0:
new_pet.minute()
print "\n" * 20
print "{} is still {}. It's health is {}, experience is {}, happiness is {} and attack is {}.".format(new_pet.name, new_pet.color, new_pet.health, new_pet.experience, new_pet.happy, new_pet.attack)
new_pet.start = time.time()
else:
menu()
if __name__ == '__main__':
main()