Interessant war für mich dabei die Zufallsfunktion und die Zeit.
Da ich die 'Konventionen' noch nicht verinnerlicht haben kann, hoffe ich besonders hier auf konstruktive Kritik/ Tips.
Danke für Aufmerksamkeit!
Code: Alles auswählen
# Python Version: 3.2
# Simulation des Schere-Stein-Papier Spiels
# Bei 100000 Runden Vorgabe braucht mein
# PC fast zwei Sekunden! Lahme Kiste.
import random
from tkinter import *
f1= Tk()
f1.geometry('140x160')
f1.config(bg='white')
f1.title('w3h1ssp')
def spiel():
aplay=0 #Player A Punkte
bplay=0 #Player B Punkte
playp=0 # Patt
playz=0 # Rundenzähler
zw = 0
while zw < 100000: # Runden-Vorgabe
a = random.randint(1,3)
b = random.randint(1,3)
# 1= Stein, 2= Papier, 3=Schere
if a == b:
playp = playp + 1
else:
if a > b:
z = a - b
if z == 1:
aplay =aplay + 1
else:
bplay = bplay + 1
else:
z = b - a
if z == 1:
bplay = bplay + 1
else:
aplay = aplay +1
playz = playz +1
zw = zw+1
print('Player A: ', aplay)
print('Player B: ', bplay)
print('Patt', playp)
print('Runden', playz)
atex.delete(0, END)
atex.insert(INSERT, aplay)
btex.delete(0, END)
btex.insert(INSERT, bplay)
ptex.delete(0, END)
ptex.insert(INSERT, playp)
ztex.delete(0, END)
ztex.insert(INSERT, playz)
atex=Entry()
atex.place(relx=0.05, rely=0.05, relwidth=0.90)
atex.config( font =("Arial", 14))
atex.insert(INSERT, 'Player A')
btex=Entry()
btex.place(relx=0.05, rely=0.20, relwidth=0.90)
btex.config(font =("Arial", 14))
btex.insert(INSERT, 'Player B')
ptex=Entry()
ptex.place(relx=0.05, rely=0.40, relwidth=0.90)
ptex.config(font =("Arial", 12 ))
ptex.insert(INSERT, 'Patt')
ztex=Entry()
ztex.place(relx=0.05, rely=0.55, relwidth=0.90)
ztex.config(font =("Arial", 12))
ztex.insert(INSERT, 'Runden')
strt=Button(command=spiel, text='Start')
strt.config(bg='white', fg='red', font =('Arial', 14))
strt.place(relx=0.05, rely=0.72, relwidth=0.90)
f1 = mainloop()