#┌──────────────────────────────────────────────────────────────────────┐
#│                                                                      │
#│ mmmmm           m     mmmm    m                                 mmmm │
#│ #   "#  mmm   mm#mm  #"   " mm#mm   mmm    m mm   mmm          "   "#│
#│ #mmm#" #"  #    #    "#mmm    #    #" "#   #"  " #"  #           mmm"│
#│ #      #""""    #        "#   #    #   #   #     #""""             "#│
#│ #      "#mm"    "mm  "mmm#"   "mm  "#m#"   #     "#mm"         "mmm#"│
#│                                                                      │
#│                                                                      │
#└──────────────────────────────────────────────────────────────────────┘


import random
import sys
import os
from time import sleep
health = 20
import termcolor
from termcolor import colored
def getline(linetype):
    if linetype == "badpet":
        return random.choice([" is angry and growls.", " barks with anger.", " snaps at you.", " is not amused."])
    if linetype == "goodpet":
        return random.choice([" is happy.", "'s tail wags with joy.", " is haing fun."])

def getmail():
    # There was an online server for playing pettore over ssh
    # if you make one (i would use dgamelauch to do it) you can use this for in game mail delivery (Like NetHack on alt.org).
    if os.path.exists("/.petstoreserver"):
        try:
            # Get mail if on server
            user = sys.argv[1]
            my_file = open("/mail/" + user, 'r')
            for message in my_file.readlines():
                print(colored(message.rstrip(), 'white', 'on_red'))
            my_file.close()
            os.remove("/mail/" + user)
        except:
            pass
class dog:
    def __init__(self):
        names = ["Biscuit", "Snickers", "Astro", "Baron", "Sally", "Lady", "Peanut", "Pasha", "Annabelle"]
        self.name = random.choice(names)
        self.happy = random.randint(0, 10)
        self.hunger = random.randint(0, 10)
        self.temper = random.randint(-3, 3)
    def keepinrange(self):
        if self.happy > 10:
                self.happy = 10
        if self.happy < 0:
            self.happy = 0
    def pet(self, numberOfTimes):
        for i in range(numberOfTimes):
            self.happy = self.happy + (random.randint(-5, 5) - self.temper)
            if self.happy < 5 and self.happy < 1:
                print(self.name + getline("badpet"))
            if self.happy >= 5:
                print(self.name + getline('goodpet'))
            if self.happy == 0:
                healthloss = random.randint(0, 10)
                print(self.name + " is furious and bites your leg.  You lose " + str(healthloss) + " health points.")
                global health
                health = health - healthloss
            self.keepinrange()
            sleep(1)
    
    def walk(self):
        self.happy = self.happy + (random.randint(-5, 10) - self.temper)
        if self.happy < 5 and self.happy < 1:
            print(self.name + getline("badpet"))
        if self.happy >= 5:
            print(self.name + getline('goodpet'))
        if self.happy == 0:
            healthloss = random.randint(0, 10)
            print(self.name + " is furious and bites your leg.  You lose " + str(healthloss) + " health points.")
            global health
            health = health - healthloss
        self.keepinrange()
        sleep(1)
    
    def feed(self):
        self.hunger = 10
        self.happy = self.happy + (random.randint(0, 3) - self.temper)
        print(self.name + " devours the delicious food.")
        self.keepinrange()
        sleep(1)

MyDog = dog()
MyDog.color = input("What color dog would you like? ")
MyDog.breed = input(MyDog.color + "! A most exellent selection. What kind of dog are you looking for? ")
print(MyDog.breed + "! One of the finest breeds in our selection.  I have just the dog you want.")
sleep(2)
print("The shop owner goes through a door into another room, a few minutes later he returnes with a", MyDog.color, MyDog.breed, "named", MyDog.name)
sleep(3)
while True:
    getmail()
    print
    print(colored("[" + "Health:" + str(health) + "   Dog Hunger: " + str(MyDog.hunger) + "   Dog Happyness: " + str(MyDog.happy) + "   Dog Temper: " + str(MyDog.temper) + "]", 'blue', 'on_grey'))
    choice = input("""What do you want to do with your dog:
    1) Pet the dog
    2) Feed the dog
    3) Walk the dog
    Q) Leave the store
    """)
    if choice == "1":
        MyDog.pet(int(input("How many times? ")))
    if choice == "2":
        MyDog.feed()
    if choice == "3":
        MyDog.walk()
    if choice == "q":
        break
    if health <= 0:
        print("You have been killed by " + MyDog.name)
        sleep(3)
        break