#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import random
import sys


class player(object):
    def __init__(self):
        self.points = 50
        self.gameround = 0
        self.highnum = 100
        self.pointsperwin = 5
        self.intro()

    def intro(self):
        print("Welcome to a simple number game.\n")
        print("It's very simple, you guess a number between 1 and 100.")
        print("For each time you guess wrong, you lose one point.")
        print("Each time you guess right, you will get five points.\n")
        self.cycleintro()

    def cycleintro(self):
        if str(self.gameround).endswith(("0", "4", "5", "6", "7", "8",
                                         "9", "11", "12", "13")):
            if self.gameround != 0:
                gameround_ending = 'th'
        elif str(self.gameround).endswith('1'):
            gameround_ending = 'st'
        elif str(self.gameround).endswith('2'):
            gameround_ending = 'nd'
        elif str(self.gameround).endswith('3'):
            gameround_ending = 'rd'
        else:
            gameround_ending = ''
        if str(self.gameround) == '0':
            game_round_ending = ''
            print("Good Luck.")
            print("")
        else:
            print("You have tested your luck and came out on top " +
                  "for the {0}{1} time".format(self.gameround,
                                               gameround_ending))
            print("")                                   


        self.gameplay()


    def gameplay(self):
        picked_num = random.randint(1, self.highnum)
        try:
            number = int(input("Please choose a number between " + 
                               "1 and {0}: ".format(self.highnum)))
            if number == picked_num:
                print("")
                print("You guessed correctly! Woo!")
                print("")
                self.points = self.points + self.pointsperwin
                self.gameround = self.gameround + 1
                self.buyround()
            else:
                if self.points >= 1 :
                    self.points = self.points - 1
                    if number > picked_num:
                        print("Your number was too high. " +
                              "{0} attempts left.".format(self.points))
                    else:
                        print("Your number was too low. " +
                              "{0} attempts left.".format(self.points))
                elif self.points <= 0:
                    print('GAME OVER.')
                    sys.exit()
        except ValueError:
            print("BETWEEN 1 AND {0}.".format(self.highnum))

    def buyround(self):
        try:
            print("")
            print("")
            print("")
            print("")
            print("You have {0} points".format(self.points))
            print("Please use thise time to improve your luck")
            print("Each upgrade cost 100 points.")  
            print("1:  The highest the numbers can climb is 1 to {0}".format (self.highnum))
            print("pick this to lower that to {0}".format (self.highnum-1))
            print("")
            print("")
            print("2:  Want a bigger payout from each win?")
            print("choose this to get {0} each win.".format (self.pointsperwin)) 
            print("")
            print("")
            print("3 to exit and get to the next round:")
            print("")
            print("")
            print("")
            buymode = int(input("What is your choice?:"))

            if buymode == 1:
                self.points = self.points - 100
                silf.highnum = self.highnum - 1
                
            elif buymode == 2:
                self.pointsperwin = self.pointsperwin + 5
                self.points = self.points - 100 
                
            elif buymode == 3:
                self.gameround = self.gameround +1
                print ("Good Luck!!")
                self.cycleintro()

            else:
                print ("That is not 1, 2, or 3" +
                       "Try that again.")
                self.buyround()
        except ValueError:
            print("")
            print("Wait, what? That's not even a number.")
            self.buyround()

player()
