Skip to content

Instantly share code, notes, and snippets.

@WillGriff64
Created December 30, 2023 02:23
Show Gist options
  • Save WillGriff64/0a9c32e69be4d2723b4dc7ba2eaff948 to your computer and use it in GitHub Desktop.
Save WillGriff64/0a9c32e69be4d2723b4dc7ba2eaff948 to your computer and use it in GitHub Desktop.
from tkinter import *
import threading
#Window Setup
root = Tk()
root.title("Horse")
root.resizable(False, False)
root.configure(background='lightblue')
#Variables
horseCount = 0
hayCount = 0
stableCount = 0
trackCount = 0
looptime = 1
looptimeCost = 1
horseAmount = 1
hayAmount = 1
stableAmount = 1
trackAmount = 1
#Adding Functions
def AddHorse():
global horseCount
horseCount+=horseAmount
HorseCounter.delete(0.0, END)
HorseCounter.insert(0.0, horseCount)
def AddHay():
global hayCount
global horseCount
if horseCount >= 20*hayAmount:
hayCount +=hayAmount
horseCount -= 20*hayAmount
HayCounter.delete(0.0, END)
HayCounter.insert(0.0, hayCount)
HorseCounter.delete(0.0, END)
HorseCounter.insert(0.0, horseCount)
def AddStable():
global stableCount
global hayCount
if hayCount >= 20*stableAmount:
stableCount +=stableAmount
hayCount -= 20*stableAmount
StableCounter.delete(0.0, END)
StableCounter.insert(0.0, stableCount)
HayCounter.delete(0.0, END)
HayCounter.insert(0.0, hayCount)
def AddTrack():
global trackCount
global stableCount
if stableCount >= 20*trackAmount:
trackCount +=trackAmount
stableCount -= 20*trackAmount
StableCounter.delete(0.0, END)
StableCounter.insert(0.0, stableCount)
TrackCounter.delete(0.0, END)
TrackCounter.insert(0.0, trackCount)
def UpgradeLT():
global looptime ,looptimeCost, horseCount, hayCount, stableCount, trackCount
if trackCount >= looptimeCost and stableCount >= looptimeCost and hayCount >= looptimeCost and horseCount >= looptimeCost:
trackCount -= looptimeCost
stableCount -= looptimeCost
hayCount -= looptimeCost
horseCount -= looptimeCost
looptime /= 2
looptimeCost *= 10
Button(root, text="Speed upgrade is "+str(looptimeCost)+" of every object", width=112, height=1, bd=10, background="LightGreen", command=UpgradeLT).grid(row=4,column=0,columnspan=4)
def UpgradeHorse():
global horseAmount
global horseCount
if horseCount >= (10**horseAmount)*10:
horseCount -= (10**horseAmount)*10
horseAmount += 1
Button(root, text="Upgrade Horse :"+str(10**horseAmount)+"0", width=25, height=1, bd=10, background="LightCoral", command=UpgradeHorse).grid(row=5,column=0)
def UpgradeHay():
global hayAmount
global hayCount
if hayCount >= (10**hayAmount)*10:
hayCount -= (10**hayAmount)*10
hayAmount += 1
Button(root, text="Upgrade Hay :"+str(10**hayAmount)+"0", width=25, height=1, bd=10, background="Khaki", command=UpgradeHay).grid(row=5,column=1)
def UpgradeStable():
global stableAmount
global stableCount
if stableCount >= (10**stableAmount):
stableCount -= (10**stableAmount)
stableAmount += 1
Button(root, text="Upgrade Stables :"+str(10**stableAmount), width=25, height=1, bd=10, background="PowderBlue", command=UpgradeStable).grid(row=5,column=2)
def UpgradeTrack():
global trackAmount
global trackCount
if trackCount >= (10**trackAmount):
trackCount -= (10**trackAmount)
trackAmount += 1
Button(root, text="Upgrade Race Track :"+str(10**stableAmount), width=25, height=1, bd=10, background="Plum", command=UpgradeTrack).grid(row=5,column=3)
#Creating Buttons and counters
#Horse
HorseCounter = Text(root, width=22, height=1, bd=10, background="steelblue")
HorseCounter.grid(row=1,column=0)
Button(root, text="Horse", width=25, height=1, bd=10, command=AddHorse).grid(row=2,column=0)
#Hay
HayCounter = Text(root, width=22, height=1, bd=10, background="steelblue")
HayCounter.grid(row=1,column=1)
Button(root, text="Hay", width=25, height=1, bd=10, command=AddHay).grid(row=2,column=1)
#Stable
StableCounter = Text(root, width=22, height=1, bd=10, background="steelblue")
StableCounter.grid(row=1,column=2)
Button(root, text="Stable", width=25, height=1, bd=10, command=AddStable).grid(row=2,column=2)
#Race Track
TrackCounter = Text(root, width=22, height=1, bd=10, background="steelblue")
TrackCounter.grid(row=1,column=3)
Button(root, text="Race Track", width=25, height=1, bd=10, command=AddTrack).grid(row=2,column=3)
#Information text
InfoText = Label(root, text = "Every object costs 20 of the previous (Horses are free)\n Every second, every object generates one of its previous", anchor="center" ,width=50, height=1, bd=10, background="Lightblue", font=("Helvetica", 11))
InfoText.grid(row=0,column=0,columnspan=4)
#Upgrade Title
InfoText = Label(root, text = "Upgrades", anchor="center" ,width=56, height=1, bd=10, background="steelblue", font=("Helvetica", 18))
InfoText.grid(row=3,column=0,columnspan=4)
#Upgrade Title
InfoText = Label(root, text = " ", anchor="center" ,width=112, height=1, bd=10, background="steelblue", font=("Helvetica", 9))
InfoText.grid(row=6,column=0,columnspan=4)
#Running functions to set up upgrades
UpgradeLT()
UpgradeHorse()
UpgradeHay()
UpgradeStable()
UpgradeTrack()
#Automatic adding function
def AutoAdd():
threading.Timer(looptime, AutoAdd).start()
global horseCount
global hayCount
global stableCount
#Adding the variables
stableCount += trackCount
hayCount += stableCount
horseCount += hayCount
#Adding method that still accounts for cost
#addTest = stableCount
#while addTest > 0:
# if horseCount >= 20:
# hayCount +=1
# horseCount -= 20
# addTest -= 1
#Diplaying the variables
HayCounter.delete(0.0, END)
HayCounter.insert(0.0, hayCount)
HorseCounter.delete(0.0, END)
HorseCounter.insert(0.0, horseCount)
StableCounter.delete(0.0, END)
StableCounter.insert(0.0, stableCount)
TrackCounter.delete(0.0, END)
TrackCounter.insert(0.0, trackCount)
AutoAdd()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment