Skip to content

citymonkeymao/Tamagotchi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

8236106 · Oct 9, 2017

History

25 Commits
Oct 9, 2017
Oct 9, 2017
Oct 8, 2017
Oct 9, 2017
Oct 9, 2017
Oct 8, 2017

Repository files navigation

prerequisite

  • Ubuntu 16.04
  • python 2.7
  • pip install -r requirements.txt

Play

Change directory to game, run python game.py, you will enter an IPython interactive interface. screen shot

Basic pet

The basic pet has only one metric, hunger. By feeding it, the hunger metric will increase. This pet will not die even if the hunger became negative.

  • create a basic pet: in IPython interface, enter:

    pokemon = BasicPet()

    a basic pet called pokemon is created.

  • to start playing the game, type in:

    start_play(pokemon)

By this time, a figure generated by Matplotlib will come to your screen, the big blue bar indicate the hunger metric, the lower the bar, the hungery your pet. As a known issue, start_play can only invoke once before you restart the game.

  • feeding will increase the hunger value

    pokemon.feed()

Basic pet is the only type supported in the 1st release which contains only 4 files. metric.py defines the update strategies of metrics which were used to represent status of pet such as hunger, happiness and health, and gives an interface to increase the value. pet.py is the class file for BasicPet. These two files were not modified in later versions, new types of pet and metric come to the game by adding new files. game.py is the program's entrance. thread_utils.py were renamed as decorators.py, the @sync decorator defined in this file makes a function thread safe as the main program often involves two threads, one thread read user input, another update and show the status. This version is a minimal workable product.

Mortal creature

Just like basic pet, mortal creature has only one metric and one action. However, if the hunger metric goes blow zero, this animal is going to die. Trying to feed or update a dead pet will incur PetDeadException.

  • create and start play,

    mortal = MortalCreature()

    start_play(mortal)

If no more command following, the pet will die when it's hunger goes to zero.

  • By feeding it, the creature could stay alive.

    mortal.feed()

  • Feeding the dead could result in an exception wait for few seconds until the pet die............. mortal.feed()

2 files were added at this stage, death_metric.py defines the behavior of a metric that can cause death. mortal_creature.py defines a pet that will raise exception when dead. The @death_check decorator is used to check if this pet is alive.

Koala

A koala typically sleeps 18 hours a day, during the sleep hours, it does not eat anything. Thus, a koala can only be feed from 00:00AM to 06:00AM

  • create a koala and start play:

    k = Koala()

    start_play(k)

  • try to feed koala in sleeping time:

    when the daytime bar is larger than 6 and the legend shows it's sleeping.....

    k.feed()

the hunger will not increase if you feed it at this time, but feeding in awake state will.

  • When you put a koala to bed, it will sleep despite of the time, this operation is only allowed when the pet is awake.

    k.to_bed()

  • to make it awake again, manually take it out of bed is necessary. off_bed can be called when the animal is sleeping.

    k.off_bed()

multi-metric pet

This new version simply added two metrics to koala: happiness and health. Happiness will increase if you play with it, health will increase when you clean it. If health goes 0, the pet dies.

  • create and start play:

    m = MultiMetricPet()

    start_play(b)

  • clean and play:

    m.clean()

    m.play()

Aging pet

Another factor of the Tamagotchi is that an animal has its own life cycle. An aging pet has two stages in its life, before its 20s, we call it young. 20 to 40s is called old. Finally, this creature will die on 40. The age metric increases every 2 seconds.

  • create and play

    a = AgingPet()

    start_play(a)

  • feed, clean, play, to bed and off bed

    a.feed()

    a.clean()

    a.play()

    a.to_bed()

    a.off_bed()

Known issues

  • Not able to invoke start_play twice, a possible reason is that matplotlib is not thread safe. A walk through is to restart game each time. One way to solve this problem is use another UI library.
  • The figure window pauses for few seconds after input a command. The reason is unknown.

About

Simple python implementation of Tamagotchi

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages