import random
import turtle
import time
bonus = 0
def main():
global writeT
writeT = turtle.Turtle()
global rchance
rchance = 0
Day = 0
global Steve
#0 name 1:days 2money 3health 4stress 5food
Steve = ["", 0, 200, 100, 0, 10]
DisplayTextOn("Welcome to Life Simulation!", 1)
DisplayTextOn("In this game, you will face many events \nthat you will have to go through.", 3)
DisplayTextOn("Your goal is to get thousand within one month.\nIf you get debt more than $1000, you lose.", 3)
DisplayTextOn("Also if your health is 0, you lose.\nStress level affects income level", 3)
DisplayTextOn("If your stress level is too high,\nHealth level will drop quickly.", 3)
DisplayTextOn("Good Luck!", 2)
turtle.bye()
Steve[0] = raw_input("Type your character's name :")
for days in range(30):
print "\nDay", days, "\n"
foodadjust(-2)
action()
stressadjust(5)
if Steve[4] > 50:
HPbonus(-10)
if days%7 == 0:
weeklypayment()
if days%30 == 0:
moneyinterest()
checkStatue()
if LostorNo() == True:
DisplayTextOn("Your health dropped to 0,\nor your debt is more than 1 grand.\nYou lost.", 2)
turtle.bye()
exit()
if WinorNo() == True:
DisplayTextOn("You succesfully collect 1 grand. Congrats!", 2)
turtle.bye()
exit()
Steve[1] += 1
def DisplayTextOn(text, t):
writeT.write(text, align='Center', font=('Calibri', 25, 'bold'))
time.sleep(t)
writeT.clear()
def RepeatText(text, inter, rept):
for repeating in range(rept):
writeT.write(text, align='Center', font=('Calibri', 25, 'bold'))
time.sleep(inter)
writeT.clear()
time.sleep(inter)
turtle.bye()
def moneyinterest():
Steve[2] += Steve[2]*0.005
def weeklypayment():
weekpay = 500 - 500*Steve[4]/100 + 50*bonus
print "You got weekly payment of $"+str(weekpay)
Steve[2] += weekpay
def action():
actnum = raw_input("Which action do you want to take?(1:eat, 2:work, 3:sleep, 4:go outside, 5:check statue)\nType num : ")
if actnum == "5":
checkStatue()
action()
elif actnum == "4":
outside()
elif actnum =="3":
sleep()
elif actnum =="2":
work()
elif actnum == "1":
eat()
elif actnum == "D":
developercommand()
else:
print "Invalid. Type again."
action()
def developercommand():
Steve[2] = float(input("Adjust money :"))
Steve[3] = float(input("Adjust health :"))
Steve[4] = float(input("Adjust stress :"))
Steve[5] = float(input("Adjust food :"))
action()
def work():
RepeatText("Working...", 1, 4)
print "You worked your second job."
print "You got paid $100."
foodadjust(-2)
Steve[2] += 100
def foodadjust(a):
Steve[5] += a
if Steve[5] < 0:
print "Your food is not enough"
print "Your health level decreased."
Steve[5] = 0
HPbonus(-10)
def stressadjust(a):
Steve[4] += a
if Steve[4] >= 100:
Steve[4] = 100
elif Steve[4] < 0:
Steve[4] = 0
def sleep():
RepeatText("Sleeping...", 1, 4)
print "You slept for the whole day. Your stress level reduced."
stressadjust(-15)
def eat():
RepeatText("Eating...", 1, 3)
print "You ate too much. Your stress level, food reduced. Health slightly decreased."
HPbonus(-2)
stressadjust(-25)
foodadjust(-4)
def lottery():
rchance = random.randrange(0, 50)
typeof = raw_input("What type of lottery do you want to buy? \n1:$5 lottery, $1000 if win\n2:$50 lottery, $10000 if win\n3:$500 lottery, $100000 if win :")
if typeof == "1":
Steve[2] -= 5
if rchance == 0:
print "You won! $100 into your bank account."
Steve[2] += 100
else:
print "You lost."
elif typeof == "2":
Steve[2] -= 50
if rchance == 0:
print "You won! $1000 into your bank account."
Steve[2] += 1000
else:
print "You lost."
elif typeof == "3":
Steve[2] -= 500
if rchance == 0:
print "You won! $10000 into your bank account."
Steve[2] += 10000
else:
print "You lost."
else:
print "Invalid. Type again."
lottery()
def buyfood():
amountfood = int(input("How much food do you want to buy? $10 each. : "))
print "It costed", str(amountfood*10) + "$"
Steve[2] -= amountfood*10
foodadjust(amountfood)
def gym():
RepeatText("Working out...", 1, 3)
print "You worked out in GYM. It costed $5."
print "Health level increased. Stress decreased."
Steve[2] -= 5
stressadjust(-20)
HPbonus(20)
#WHEN CHOSE TO GO OUTSIDE. 2 OPTIONS ARE THERE : EVENTS OR NORMAL OUTSIDE
def outside():
rchance = random.randrange(0, 4)
if rchance !=0:
print "You went outside."
normaloutside()
else:
events()
def normaloutside():
actnum = raw_input("Which action do you want to take?(1:walk, 2:run, 3:buy food, 4:buy lottery, 5:go to gym)\nType num : ")
if actnum == "1":
RepeatText("Walking...", 1, 3)
DisplayTextOn("You walked down the street.\nYou feel healthy.", 2)
print "You walked down the street. You feel healthy."
HPbonus(10)
elif actnum == "2":
print "You ran. You feel refreshed."
HPbonus(15)
stressadjust(-10)
foodadjust(-2)
elif actnum == "3":
buyfood()
elif actnum == "4":
lottery()
elif actnum == "5":
gym()
else:
print "Invalid. Type again."
normaloutside()
#EVENT SIDE*********************************************************************************************************************************************
def events():
rchance = random.randrange(1, 101)
if rchance <= 20:
hitcar()
elif rchance > 20 and rchance <= 40:
betterjob()
elif rchance > 40 and rchance <= 60:
thief()
elif rchance > 60 and rchance <= 80:
helppoor()
elif rchance > 80 and rchance <= 100:
gothitbycar()
def thief():
print "You encountered thieves. They threaten you to give them money."
Response = raw_input("Fight Back or Give them money?(yes or no) :").lower()
if Response == "yes":
if Steve[3] > 80:
print "You fought back. You successfully took them down."
print "Your health level decreased. Your stress greatly decreased."
stressadjust(-50)
HPbonus(-20)
else:
print "They took you down. They stole every money you have."
print "Your health level greatly decreased. Your stress greatly increased."
HPbonus(-40)
stressadjust(40)
if Steve[2] > 0:
Steve[2] = 0
else:
print "You gave them $200."
print "Your stress level increased."
stressadjust(10)
Steve[2] -= 200
def hitcar():
print "You just hit a car. But the owner of the car didn't see."
Response = raw_input("Run or Stay?(yes or no):").lower()
if Response == "yes":
print "You got arrested. You were able to get out by paying $1000 and $500 for automobile."
print "Your stress level increased."
Steve[4] += 20
Steve[2] -= 1500
else:
print "You paid $500 for the owner. Your stress level increased."
Steve[2] -= 500
Steve[4] += 5
def betterjob():
print "You got a chance to learn a better skill."
print "The education costs $200."
Response = raw_input("Pay or No?(yes or no):").lower()
if Response =="yes":
global bonus
print "You paid $200, and now you get bonus $50."
bonus += 1
Steve[2] -= 200
else:
print "Nothing happened."
def helppoor():
print "You saw a person begging for $20."
Response = raw_input("Give or No?(yes or no):").lower()
if Response == "yes":
DisplayTextOn("You gave him $20.\nYour stress level decreased.", 2)
print "You gave him $20."
print "Your stress level decreased."
stressadjust(-40)
Steve[2] -= 20
else:
DisplayTextOn("You ignored him.\nNothing happend.", 3)
print "You ignored him."
print "Nothing happened."
def gothitbycar():
DisplayTextOn("You got hit by a car.\nHe ran away.\nThe treatment costed $1000.\nYour stress increased.\nYour health is reset to 80.", 3)
print "You got hit by a car."
print "He ran away. The treatment costed $1000."
print "Your stress increased. Your health is reset to 80."
stressadjust(20)
Steve[2] -= 1000
Steve[3] = 80
#END OF EVENT***************************************************************3*********************************************************************************
def LostorNo():
if Steve[2] <= -1000:
return True
elif Steve[3] <= 0:
return True
def WinorNo():
if Steve[2] > 10000:
return True
def HPbonus(a):
Steve[3] += a
if Steve[3] > 100:
Steve[3] = 100
def checkStatue():
print "Health :", Steve[3],
print "Stress :", Steve[4],
print "Money : $"+str(Steve[2]),
print "Food :", Steve[5]
main()
I'm making a game as the final project for my programming class, but I'm getting error(It says invalid command .bunch of numbers) in RepeatText() function part. The feature that I'm trying to make is to make turtle blinking text. For example, If I put "Working..." for the first parameter, 1 for second parameter and 3 for third parameter, it blinks 3 times with interval of 1 second. When I put the exact same code in other program, It worked fine. Does anyone know why I'm getting this error?
I'm using python 2 for the function because my class uses python 2.
I tried making the feature as its own, and It worked totally fine. Here's the program :
import turtle
import time
def RepeatText(text, inter, rept):
for i in range(rept):
writeT.write(text, align='Center', font=('Calibri', 25, 'bold'))
time.sleep(inter)
writeT.clear()
time.sleep(inter)
turtle.bye()
def main():
global writeT
writeT = turtle.Turtle()
excess()
def excess():
RepeatText("Blinking", 0.5, 3)
main()