Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Last Revision: 5/2/2018 - 18:56
- Current Version: RPS V2.0 Release
- '''
- #Just paste this into a .py and have the most fun you will ever have with a random number generator
- #All this now comes with a very shitty GUI :D
- #manual imports
- from tkinter import *
- import random
- import datetime
- def setRock():
- playerSelection.set("Rock")
- rps(1)
- winrateSet()
- def setPaper():
- playerSelection.set("Paper")
- rps(2)
- winrateSet()
- def setScissors():
- playerSelection.set("Scissors")
- rps(3)
- winrateSet()
- def winrateSet():
- wins = gamesWonCounterCount.get()
- losses = gamesLostCounterCount.get()
- ties = gamesTiedCounterCount.get()
- winrateCalc = wins/(losses + ties + wins)
- winrateCalc = round(winrateCalc, 2)
- winrate.set(winrateCalc)
- def saveRes():
- currenttime = datetime.datetime.now()
- currenttime = 'Time of round: ' + str(currenttime) + '\n \n'
- wins = gamesWonCounterCount.get()
- losses = gamesLostCounterCount.get()
- ties = gamesTiedCounterCount.get()
- winrategotten = winrate.get()
- winrateString = "Win Rate: " + str(winrategotten) + '\n \n'
- winString = "Wins: " + str(wins) + '\n \n'
- tieString = "Ties: " + str(ties) + '\n \n'
- lossString = "Losses: " + str(losses) + '\n \n'
- file = open("RPS Game Results.txt", "a+")
- file.write('--------=Results=--------- \n')
- file.write(currenttime)
- file.write(winString)
- file.write(tieString)
- file.write(lossString)
- file.write(winrateString)
- file.writelines("\n \n \n")
- if winrategotten < 0.50:
- file.write('Well that was a bad round, wasnt it? \n \n \n')
- else:
- pass
- file.close()
- #play AI generator
- def rps(userPlay):
- roll = random.randint(1, 3)
- #Roll Values: 1-Rock, 2-Paper, 3-Scissors
- if roll == 1:
- if userPlay == 1:
- tempIntVar = gamesTiedCounterCount.get()
- return gamesTiedCounterCount.set(tempIntVar + 1), aiSelection.set("Rock"), gameResult.set("Tie")
- elif userPlay == 2:
- tempIntVar = gamesLostCounterCount.get()
- return gamesLostCounterCount.set(tempIntVar + 1), aiSelection.set("Rock"), gameResult.set("You've lost!")
- elif userPlay == 3:
- tempIntVar = gamesWonCounterCount.get()
- return gamesWonCounterCount.set(tempIntVar + 1), aiSelection.set("Rock"), gameResult.set("You've won!")
- else:
- print("That wasn't one of the choices! Try again!")
- elif roll == 2:
- if userPlay == 1:
- tempIntVar = gamesWonCounterCount.get()
- return gamesWonCounterCount.set(tempIntVar + 1), aiSelection.set("Scissors"), gameResult.set("You've won!")
- elif userPlay == 2:
- tempIntVar = gamesTiedCounterCount.get()
- return gamesTiedCounterCount.set(tempIntVar + 1), aiSelection.set("Scissors"), gameResult.set("Tie")
- elif userPlay == 3:
- tempIntVar = gamesLostCounterCount.get()
- return gamesLostCounterCount.set(tempIntVar + 1), aiSelection.set("Scissors"), gameResult.set("You've lost!")
- else:
- print("That wasn't one of the choices! Try again!")
- elif roll == 3:
- if userPlay == 1:
- tempIntVar = gamesLostCounterCount.get()
- return gamesLostCounterCount.set(tempIntVar + 1), aiSelection.set("Paper"), gameResult.set("You've lost!")
- elif userPlay == 2:
- tempIntVar = gamesWonCounterCount.get()
- return gamesWonCounterCount.set(tempIntVar + 1), aiSelection.set("Paper"), gameResult.set("You've won!")
- elif userPlay == 3:
- tempIntVar = gamesTiedCounterCount.get()
- return gamesTiedCounterCount.set(tempIntVar + 1), aiSelection.set("Paper"), gameResult.set("Tie")
- else:
- print("That wasn't one of the choices! Try again!")
- else:
- print('Something went wrong!')
- print('rollGenerator error: Random rumber generator returned a number that was out of range.')
- #GUI segment
- mainwindow = Tk()
- font = ("verdana", 24)
- mainwindow.minsize(750, 320)
- mainwindow.geometry("750x320")
- gamesWonCounterCount = IntVar()
- gamesWonCounterCount.set(0)
- gamesTiedCounterCount = IntVar()
- gamesTiedCounterCount.set(0)
- gamesLostCounterCount = IntVar()
- gamesLostCounterCount.set(0)
- playerSelection = StringVar()
- aiSelection = StringVar()
- gameResult = StringVar()
- winrate = DoubleVar()
- winrate.set(0)
- #row 1
- pSel = Label(mainwindow, text="You've selected:", font=font)
- pSel.grid(row=1, column=1)
- aSel = Label(mainwindow, text="The AI selected:", font=font)
- aSel.grid(row=1, column=3)
- #row 2
- plselection = Label(mainwindow, textvariable=playerSelection, font=font)
- plselection.grid(row=2, column=1)
- gameResultLabel = Label(mainwindow, textvariable=gameResult,bg="blue", fg="red", font=font)
- gameResultLabel.grid(row=1, column=2)
- aiSelectionLabel = Label(mainwindow, textvariable=aiSelection, font=font)
- aiSelectionLabel.grid(row=2, column=3)
- #row 3
- winLabel = Label(mainwindow, text="Wins", bg="Green", font=font)
- winLabel.grid(row=3, column=1)
- lossLabel = Label(mainwindow, text="Losses", bg="Red", font=font)
- lossLabel.grid(row=3, column=3)
- tieLabel = Label(mainwindow, text="Ties", bg="Yellow", font=font)
- tieLabel.grid(row=3, column=2)
- #row 4
- gamesWonCounter = Label(mainwindow, textvariable=gamesWonCounterCount, bg="Green", font=font,)
- gamesWonCounter.grid(row=4, column=1)
- gamesPlayedCounter = Label(mainwindow,textvariable=gamesTiedCounterCount, bg="Yellow", font=font,)
- gamesPlayedCounter.grid(row=4, column=2)
- gamesLostCounter = Label(mainwindow, textvariable=gamesLostCounterCount, bg="Red", font=font)
- gamesLostCounter.grid(row=4,column=3)
- #row 5
- rockButton = Button(mainwindow, text="Rock", font=font, command=setRock)
- rockButton.grid(row=5, column=1)
- paperButton = Button(mainwindow, text="Paper", font=font, command=setPaper)
- paperButton.grid(row=5, column=2)
- scissorButton = Button(mainwindow, text="Scissors", font=font, command=setScissors)
- scissorButton.grid(row=5, column=3)
- #row 6
- winrateLabel = Label(mainwindow, text="Current winrate", font=font)
- winrateLabel.grid(row=6, column=1)
- winrateLabelMath = Label(mainwindow, textvariable=winrate, font=font)
- winrateLabelMath.grid(row=6, column=2)
- saveResButton = Button(mainwindow, text="Save results", command=saveRes)
- saveResButton.grid(row=6, column=3)
- mainwindow.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement