Created
December 29, 2013 19:00
-
-
Save imfromsweden/8173594 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tkinter import * | |
import tkinter | |
import time | |
import json | |
class Tamaguchi(object): | |
def __init__(self,size=1): | |
self.size=size | |
def increasesize(self): | |
self.size+=1 | |
GoodBadChange.config(text="Bra jobbat! Du ökade i storlek!") | |
def decreasesize(self): | |
self.size-=1 | |
GoodBadChange.config(text="Dåligt jobbat! Du minskade i storlek!") | |
def halfsize(self): | |
self.size=self.size/2 | |
GoodBadChange.config(text="Riktigt dåligt jobbat! Du halverades i storlek!") | |
def samesize(self): | |
GoodBadChange.config(text="Inte så effektivt! Ingenting hände!") | |
def HämtaLista(sökväg): | |
namn=[] | |
tmp=[] | |
for i, line in enumerate(open(sökväg)): | |
if i % 4 == 0 and tmp !=[]: | |
namn.append(tmp) | |
tmp = [] | |
if len(line.strip())>3: | |
tmp.append(line.strip()) | |
if (len(namn))>1: | |
return namn | |
else: | |
namn=[] | |
lista=[] | |
global lista | |
a = open(sökväg,'r') | |
b = [line.strip() for line in a.readlines()] | |
namn = b | |
lista=namn | |
return lista | |
class Application(Frame): | |
def __init__(self,master): | |
super(Application,self).__init__(master) | |
self.grid() | |
if svar == "nej" and delta > 72: | |
self.label1 = tkinter.Label(self,text = "Tyvärr så har det gått 3 dagar sen du lekte med mig. Jag är rosenrasande.\n",font=('Helvetica', 12)) | |
self.label1.grid() | |
tamaguchin.size-=20 | |
elif svar == "nej" and delta > 48: | |
self.label2 = tkinter.Label(self,text = "Tyvärr så har det gått 2 dagar sen du lekte med mig. Jag är förbannad.\n",font=('Helvetica', 12)) | |
self.label2.grid() | |
tamaguchin.size-=10 | |
elif svar == "nej" and delta > 24: | |
self.label3 = tkinter.Label(self,text = "Tyvärr så har det gått en hel dag sen du lekte med mig. Jag är sur nu.\n",font=('Helvetica', 12)) | |
self.label3.grid() | |
tamaguchin.size-=5 | |
self.btn0 = tkinter.Button(self, text = "Fortsätt med tidigare sparning", command = lambda:self.continue1('ja')) | |
self.btn0.grid() | |
self.btn10 = tkinter.Button(self,text = "Starta ny omgång", command = lambda:self.continue1('nej')) | |
self.btn10.grid() | |
def continue1(self,value1): | |
if value1 == "ja": | |
self.btn0.destroy() | |
self.btn10.destroy() | |
if svar == "nej" and delta > 72: | |
self.label1.destroy() | |
elif svar == "nej" and delta > 48: | |
self.label2.destroy() | |
elif svar == "nej" and delta > 24: | |
self.label3.destroy() | |
self.create_widgets() | |
elif value1 == "nej": | |
lista=['sova','sova','sova'] | |
tamaguchin.size=1 | |
if delta > 72: | |
self.label1.destroy() | |
elif delta > 48: | |
self.label2.destroy() | |
elif delta > 24: | |
self.label3.destroy() | |
self.btn0.destroy() | |
self.btn10.destroy() | |
self.create_widgets() | |
global lista | |
updateDisplay() | |
def create_widgets(self): | |
self.btn1 = tkinter.Button(self, width=20, height=6, text = "plugga", command = lambda:self.update_text('plugga')) | |
self.btn1.grid(row=2,column=2) | |
self.btn2 = tkinter.Button(self, width=20, height=6, text = "festa", command = lambda:self.update_text('festa')) | |
self.btn2.grid(row=3,column=2) | |
self.btn3 = tkinter.Button(self, width=20, height=6, text = "tenta", command = lambda:self.update_text('tenta')) | |
self.btn3.grid(row=3,column=3) | |
self.btn4 = tkinter.Button(self, width=20, height=6, text = "sova", command = lambda:self.update_text('sova')) | |
self.btn4.grid(row=2,column=3) | |
self.btn5 = tkinter.Button(self, width=20, height=6, text = "exit", command = self.exit) | |
self.btn5.grid(row=5,column=4) | |
def update_text(self,value): | |
lista.append(value) | |
lista.remove(lista[0]) | |
if lista in PositivLista: | |
tamaguchin.increasesize() | |
elif lista in NegativLista: | |
tamaguchin.decreasesize() | |
elif lista in HalveringsLista: | |
tamaguchin.halfsize() | |
else: | |
tamaguchin.samesize() | |
updateDisplay() | |
return lista | |
def exit(self): | |
print('du har valt att avsluta programmet') | |
root.destroy() | |
def updateDisplay(): | |
if tamaguchin.size >= 8: | |
Picture.config(image=mostHappy) | |
elif tamaguchin.size >= 5: | |
Picture.config(image=MOREHAPPY) | |
elif tamaguchin.size >= 2: | |
Picture.config(image=happy) | |
elif tamaguchin.size <= -8: | |
Picture.config(image=mostUnhappy) | |
elif tamaguchin.size <= -6: | |
Picture.config(image=evenmoreunhappy) | |
elif tamaguchin.size <= -4: | |
Picture.config(image=moreUnhappy) | |
elif tamaguchin.size <= -2: | |
Picture.config(image=unhappy) | |
else: | |
Picture.config(image=normal) | |
ScoreBoard.config(text="Poäng: " + str(tamaguchin.size)) | |
LatestAction.config(text="Din tamaguchi valde att: " + lista[2]+'\nDess tre senaste händelser är därmed: '+lista[0]+"-"+lista[1]+"-"+lista[2]+"\n") | |
def getLists(): | |
PositivLista = HämtaLista('PositivLista.txt') | |
global PositivLista | |
NegativLista = HämtaLista('NegativLista.txt') | |
global NegativLista | |
HalveringsLista = HämtaLista('HalveringsLista.txt') | |
global HalveringsLista | |
lista = HämtaLista('lista.txt') | |
global lista | |
def getPhotos(): | |
normal = tkinter.PhotoImage(file="normal.gif") | |
global normal | |
happy = tkinter.PhotoImage(file="happy.gif") | |
global happy | |
MOREHAPPY= tkinter.PhotoImage(file="MOREHAPPY.gif") | |
global MOREHAPPY | |
mostHappy = tkinter.PhotoImage(file="mostHappy.gif") | |
global mostHappy | |
unhappy = tkinter.PhotoImage(file="unhappy.gif") | |
global unhappy | |
moreUnhappy = tkinter.PhotoImage(file="moreUnhappy.gif") | |
global moreUnhappy | |
evenmoreunhappy = tkinter.PhotoImage(file="evenmoreunhappy.gif") | |
global evenmoreunhappy | |
mostUnhappy = tkinter.PhotoImage(file="mostUnhappy.gif") | |
global mostUnhappy | |
def lastGame(): | |
with open("Tamaguchis.txt","r") as file: | |
dictionary = json.loads(file.read()) | |
lista = dictionary["order"] | |
global lista | |
tamaguchin.size=dictionary["size"] | |
from datetime import datetime | |
date_format = "%m/%d/%y %H:%M:%S" | |
då=(dictionary["date"]) | |
then = datetime.strptime(str(då), date_format) | |
now = datetime.now() | |
delta = then - now | |
delta = (delta.total_seconds()/3600) | |
global delta | |
file.close() | |
def main(): | |
root = tkinter.Tk() | |
global root | |
root.title("Tamaguchi-spelet") | |
root.geometry("900x900") | |
getLists() | |
getPhotos() | |
"""lastGame()""" | |
Picture = tkinter.Label(root, image=normal) | |
Picture.pack() | |
global Picture | |
ScoreBoard = tkinter.Label(root, text="Poäng " + str(tamaguchin.size), font=('Helvetica', 15)) | |
ScoreBoard.pack() | |
global ScoreBoard | |
GoodBadChange = tkinter.Label(root, text="", font=('Helvetica', 12)) | |
GoodBadChange.pack() | |
global GoodBadChange | |
LatestAction = tkinter.Label(root, text="", font=('Helvetica', 12)) | |
LatestAction.pack() | |
global LatestAction | |
app = Application(root) | |
app.pack() | |
updateDisplay() | |
LatestAction.config(text="Hej och välkommen till tamaguchi-spelet!\nTamaguchins börjar dagen med storleken "+str(tamaguchin.size)+"!\nTamaguchin börjar dagen med "+lista[0]+"-"+lista[1]+"-"+lista[2]+"\n") | |
root.mainloop() | |
tamaguchin = Tamaguchi() | |
list2 = [] | |
svar = input('vill ni skapa ny omgång?') | |
if svar == "ja": | |
tamaguchi_list=[] | |
Antal=int(input("Number of tamaguchis in your farm: ")) | |
for i in range(Antal): | |
tamaguchin = Tamaguchi() | |
tamaguchi_list.append(tamaguchin) | |
print(len(tamaguchi_list)) | |
AnotherList = [] | |
for tamaguchis in tamaguchi_list: | |
main() | |
AnotherList.append(tamaguchin.size) | |
AnotherList.append(lista) | |
with open("Tamaguchis.txt","r+") as file: | |
date = time.strftime("%c") | |
dictionary = {"size":tamaguchin.size,"date":date,"order":lista} | |
file.write(json.dumps(dictionary)) | |
file.close() | |
print(list2) | |
print('TESTAR') | |
if svar == "nej": | |
tamaguchin = Tamaguchi() | |
lastGame() | |
print(tamaguchin.size) | |
print(lista) | |
main() | |
with open("Tamaguchis.txt","w") as file: | |
date = time.strftime("%c") | |
dictionary = {"size":tamaguchin.size,"date":date,"order":lista} | |
file.write(json.dumps(dictionary)) | |
file.close() | |
print(svar) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment