@AshaRajagopal/

MinorMagnificentDifference

Python

No description

fork
loading
Files
  • main.py
main.py
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
"""
Asha Rajagopal
Tamagotchi game
22 march 2019
"""
class Pet:
  
  def __init__(self, name, hunger, boredom):
    self._name = name
    self._hunger = hunger
    self._boredom = boredom
    self._hunger = randrange(self.hunger_threshold())
    self._boredom = randrange(self.boredom_threshold())
    self._sounds = self._sounds[:]

  def clock_tick(self):
        self.boredom += 1
        self.hunger += 1

  def mood(self):
        if self.hunger <= self.hunger_threshold and self.boredom <= self.boredom_threshold:
            return "happy"
        elif self.hunger > self.hunger_threshold:
            return "hungry"
        else:
            return "bored"
  def __str__(self):
        state = "     I'm " + self.name + ". "
        state += " I feel " + self.mood() + ". "
        # state += "Hunger {} Boredom {} Words {}".format(self.hunger, self.boredom, self.sounds)
        return state

  def hi(self):
      print(self.sounds[randrange(len(self.sounds))])
      self.reduce_boredom()

  def teach(self, word):
      self.sounds.append(word)
      self.reduce_boredom()

  def feed(self):
      self.reduce_hunger()

  def reduce_hunger(self):
      self.hunger = max(0, self.hunger - self.hunger_decrement)

  def reduce_boredom(self):
      self.boredom = max(0, self.boredom - self.boredom_decrement)

  

def main():
  hunger_start = 4
  boredom_start = 6
  boredom_trhreshold = 10
  hunger_threshold = 5
  sounds = ["Mrrp"]

  import random
  p1  = Pet("Fido", hunger_start,boredom_start)
  print(p1)
  for i in range(10):
    p1.clock_tick()
    print(p1)
  p1.feed()
  p1.hi()
  p1.teach("Boo")
  for i in range(10):
    p1.hi()
  print(p1)
 


main()