def PlayerShow(self, players): ''' List out all the players that are currently connected ''' numPlay = len(players) leftPlay = desktop.math.ceil(numPlay / 2) rightPlay = desktop.math.floor(numPlay / 2) center = int(super().getScreenH() / 2) offset = int(super().getScreenH() / 10) textColour = "white" self.window.reset() self.setup() #left player list if (leftPlay % 2) == 1: for i in range(leftPlay): label = desktop.Label(super().framelist[1], text=players[2 * i], font=self.window.deffont, bg=super().framelist[1]['bg'], fg=textColour) label.place(anchor="w", y=center - ((((leftPlay - 1) / 2) - i + 1) * offset), x=super().getScreenW() / 64) else: for i in range(leftPlay): label = desktop.Label(super().framelist[1], text=players[2 * i], font=self.window.deffont, bg=super().framelist[1]['bg'], fg=textColour) label.place(anchor="w", y=center - (leftPlay / 2 + .5 - i) * offset, x=super().getScreenW() / 64) #right player list if (rightPlay % 2) == 1: for i in range(rightPlay): label = desktop.Label(super().framelist[2], text=players[2 * i + 1], font=self.window.deffont, bg=super().framelist[2]['bg'], fg=textColour) label.place(anchor="w", y=center - ((((rightPlay - 1) / 2) - i + 1) * offset), x=super().getScreenW() / 64) else: for i in range(rightPlay): label = desktop.Label(super().framelist[2], text=players[2 * i + 1], font=self.window.deffont, bg=super().framelist[2]['bg'], fg=textColour) label.place(anchor="w", y=center - (rightPlay / 2 + .5 - i) * offset, x=super().getScreenW() / 64)
def display(self, players, timer, currentP, nextP, max): ''' Displays the players, their current score, the current holds of the potato and the next player to go ''' numPlay = len(players) leftPlay = desktop.math.ceil(numPlay / 2) rightPlay = desktop.math.floor(numPlay / 2) center = int(super().getScreenH() / 2) offset = int(super().getScreenH() / 10) textColour = "white" for i, player in enumerate(players): playerScore = players[player].get("score") xPos = super().getScreenW() / 32 yPos = 0 yPosS = super().getScreenW() / 40 fontSize = super().setFontSize(int((super().getScreenH()) / 40)) curFrame = super().framelist[2] explosion = False if timer <= 0: result = "palm_explosion_Desktop.png" explosion = True else: result = "palm_potato_Desktop.png" explosion = False resImg = super().imageCreation(result, super().getScreenH() / 12, super().getScreenW() / 12) if i < leftPlay: curFrame = super().framelist[1] if leftPlay % 2 == 1: yPos = center - ((((leftPlay - 1) / 2) - i + 1) * offset) else: yPos = center - (leftPlay / 2 + .5 - i) * offset else: if rightPlay % 2 == 1: yPos = center - ((((rightPlay - 1) / 2) - (i - leftPlay) + 1) * offset) else: yPos = center - (rightPlay / 2 + .5 - (i - leftPlay)) * offset label1 = desktop.Label(curFrame, text = player, font = fontSize, bg = super().backgroundC, fg = textColour) label1.place(anchor = "nw", x = xPos, y = yPos) label2 = desktop.Label(curFrame, text = "Score: " + str (playerScore), font = fontSize, bg = super().backgroundC, fg = textColour) label2.place (anchor = "nw", x = xPos, y = yPos + yPosS) if currentP == player: label5 = desktop.Label(curFrame, image = resImg, bg = super().backgroundC) label5.image = resImg label5.place(anchor = "nw", y = yPos, x = super().getScreenW() / 4) label3 = desktop.Label(super().framelist[0], text = "First to " + str(max) + " points wins!", font = super().setFontSize(int((super().getScreenH() / 30))), bg = super().backgroundC, fg = textColour) label3.place(anchor = "s", x = super().getScreenW() / 2, y = super().getScreenH() / 20) label4 = desktop.Label(super().framelist[0], text = "Next player: " + nextP, font = super().setFontSize(int((super().getScreenH() / 30))), bg = super().backgroundC, fg = textColour) label4.place(anchor = "n", x = super().getScreenW() / 2, y = super().getScreenH() / 20) if explosion: desktop.time.sleep(3)
def setup(self): def get_ip_address(): ''' Obtains the IP address for all platforms, so players know where to connect and for the generation of the QR code ''' s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("8.8.8.8", 80)) return s.getsockname()[0] super().setup() super().framelist[1] = desktop.Frame( height=(super().getScreenH() / 10) * 8, width=super().getScreenW() / 3, bg=super().backgroundC) super().framelist[1].pack_propagate(False) super().framelist[1].place(x=0, y=super().getScreenH() / 10) super().framelist[2] = desktop.Frame( height=(super().getScreenH() / 10) * 8, width=super().getScreenW() / 3, bg=super().backgroundC) super().framelist[2].pack_propagate(False) super().framelist[2].place(x=(super().getScreenW() / 3) * 2, y=super().getScreenH() / 10) super().framelist[3] = desktop.Frame( height=(super().getScreenH() / 10) * 8, width=(super().getScreenW() / 3), bg=super().backgroundC) super().framelist[3].pack_propagate(False) super().framelist[3].place(x=(super().getScreenW() / 3), y=super().getScreenH() / 10) IP = get_ip_address() label1 = desktop.Label( super().framelist[0], text="Go to http://" + str(IP) + ":5000 or scan the below code to enter the lobby", bg=super().framelist[0]['bg'], fg="white", font=self.window.deffont) label1.place(x=super().getScreenW() / 2, y=super().getScreenH() / 20, anchor='center') img = qrcode.make("http://" + str(IP) + ":5000") resImg = desktop.ImageTk.PhotoImage(img) label2 = desktop.Label(super().framelist[3], image=resImg) label2.image = resImg # needed so images aren't garbage collected, thus not showing up label2.place(anchor='center', x=super().getScreenW() / 6, y=super().getScreenH() * 2 / 5)
def __init__(self, ui, instructions): ''' Will show the insturctions for the game the players are about to play ''' self.window = ui super().setWindow(ui.win) super().setscreen(ui.screenW, ui.screenH) super().reset() windowFrame = desktop.Frame(height=super().getScreenH(), width=super().getScreenW(), bg=self.backgroundC) windowFrame.pack_propagate(False) windowFrame.place(x=0, y=0) super().addFrame(windowFrame) instr = desktop.Label(windowFrame, text=instructions, font=super().setFontSize(super().getScreenH() / 30), bg=super().backgroundC, fg='white', justify='left', wraplength=super().getScreenW()) instr.place(anchor='center', x=super().getScreenW() / 2, y=super().getScreenH() / 2)
def updateCard(self, card, position, highlighted): ''' Displays the cards for the board ''' if highlighted: # i.e. cursor is on that card cardFrame = desktop.Frame(super().framelist[1], height=super().getScreenH() / 5 - 20, width=super().getScreenW() / 10 - 20, bg=super().backgroundC, highlightthickness=10) cardImage = super().imageCreation(self.getCardImgName(card), super().getScreenH() / 5 - 45, super().getScreenW() / 10 - 45, "/match/cards") cardFrame.pack_propagate(False) cardFrame.grid(row=position[0], column=position[1], padx=10, pady=10) label2 = desktop.Label(cardFrame, image=cardImage, bg=super().backgroundC) label2.img = cardImage label2.place(x=0, y=0) else: cardFrame = desktop.Frame(super().framelist[1], height=super().getScreenH() / 5 - 20, width=super().getScreenW() / 10 - 20, bg=super().backgroundC) cardImage = super().imageCreation(self.getCardImgName(card), super().getScreenH() / 5 - 20, super().getScreenW() / 10 - 20, "/match/cards") cardFrame.pack_propagate(False) cardFrame.grid(row=position[0], column=position[1], padx=10, pady=10) label = desktop.Label(cardFrame, image=cardImage, bg=super().backgroundC) label.img = cardImage label.place(x=0, y=0)
def displaySimon(self, seq, timer, maxTimer): ''' Setup for Simon ''' if timer == maxTimer: label = desktop.Label(super().framelist[0], text="Watch the sequence", font=super().setFontSize( super().getScreenH() / 20), bg=super().backgroundC, fg="white") label.place(anchor="s", x=super().getScreenW() / 2, y=super().getScreenH() / 10) self.window.win.update() desktop.time.sleep(1.5) for i in seq: super().framelist[3]['bg'] = i.lower() self.timerLabel['bg'] = i.lower() desktop.time.sleep(1.25) self.window.win.update() super().framelist[3]['bg'] = super().framelist[2]['bg'] self.timerLabel['bg'] = super().framelist[2]['bg'] desktop.time.sleep(.5) self.window.win.update() label = desktop.Label(super().framelist[0], text="Replicate the sequence", font=super().setFontSize(super().getScreenH() / 20), bg=super().backgroundC, fg="white") label.place(anchor="s", x=super().getScreenW() / 2, y=super().getScreenH() / 10) self.displayTimer(timer) self.window.win.update()
def setup(self): ''' Slight modification to the initial display setup ''' super().setup() self.timerLabel = desktop.Label(super().framelist[3], text="", fg='white', bg=super().backgroundC, font=super().setFontSize( super().getScreenH() / 10)) self.timerLabel.place(anchor="center", x=super().getScreenW() / 4, y=super().getScreenH() * 2 / 5)
def displayTimer(self, timer): ''' Displays the timer as it ticks ''' timerHeader = desktop.Label(super().framelist[3], text="Time Remaining: ", fg='white', bg=super().backgroundC, font=super().setFontSize( super().getScreenH() / 30)) timerHeader.place(anchor="s", x=super().getScreenW() / 4, y=super().getScreenH() * 1 / 5) self.timerLabel.configure(text=str(timer))
def displayQM(self, formula, timer): ''' Setup for QuickMaff ''' label = desktop.Label(super().framelist[0], text="Solve: " + str(formula), bg=super().backgroundC, fg='white', font=super().setFontSize(super().getScreenH() / 20)) label.place(anchor="s", x=super().getScreenW() / 2, y=super().getScreenH() / 10) self.displayTimer(timer) self.window.win.update()
def displayTap(self, goal, timer): ''' Setup for Tap ''' label = desktop.Label( super().framelist[0], text="Tap the screen exactly " + str(goal) + " times", font=super().setFontSize(super().getScreenH() / 20), bg=super().backgroundC, fg="white") label.place(anchor="s", x=super().getScreenW() / 2, y=super().getScreenH() / 10) self.displayTimer(timer) self.window.win.update()
def setup(self, timer): ''' Slight modification of the default setup ''' super().setup() self.timerLabel = desktop.Label(super().framelist[0], text="Time Remaining: " + str(timer), font=super().setFontSize( int((super().getScreenH() / 30))), bg=super().backgroundC, fg='white') self.timerLabel.place(anchor="n", x=super().getScreenW() / 2, y=super().getScreenH() / 20)
def __init__(self, ui, obj): ''' Default setup, completed on first call ''' self.window = ui super().setWindow(self.window.win) super().setscreen(self.window.screenW, self.window.screenH) super().reset() super().setup() self.topFrameLabel = desktop.Label(super().framelist[0], text='init', font=self.window.deffont, bg=super().framelist[2]['bg'], fg="white") self.topFrameLabel.place(anchor="center", y=super().getScreenH() / 20, x=super().getScreenW() / 2) self.timer(obj.get('timer'), obj.get('players')) self.display(obj.get('players'), obj.get('timer'))
def display(self, boardState, nextP, cursor, timer): ''' Shows all the cards, the timer, the current player and the next player ''' for i in range(self.rows): for j in range(self.columns): if cursor == [i, j]: self.updateCard(boardState[i, j], [i, j], True) else: self.updateCard(boardState[i, j], [i, j], False) self.displayTimer(timer, nextP[0]) self.nextLabel = desktop.Label(super().framelist[2], text="Next Player: " + nextP[1], bg=super().backgroundC, font=super().setFontSize( int((super().getScreenH() / 30))), fg='white') self.nextLabel.place(anchor="center", x=super().getScreenW() / 2, y=super().getScreenH() / 20)
def __init__(self, ui, obj, columns, rows): ''' The inital setup for this game ''' super().setWindow(ui.win) super().setscreen(ui.screenW, ui.screenH) super().reset() self.setup() self.topFrameLabel = desktop.Label( super().framelist[0], text="init", bg=super().backgroundC, font=super().setFontSize(int((super().getScreenH() / 30))), fg='white') self.topFrameLabel.place(anchor="center", x=super().getScreenW() / 2, y=super().getScreenH() / 20) self.columns = columns self.rows = rows self.display(obj.get('gameBoard'), obj.get('next'), obj.get('cursor'), obj.get('timer'))
def display(self, players, valid, game, timer, formula, maxTimer): ''' Places the players and their HP as well as any other features needed for each of the subgames ''' numPlay = len(players) leftPlay = desktop.math.ceil(numPlay / 2) rightPlay = desktop.math.floor(numPlay / 2) center = int(super().getScreenH() / 2) offset = int(super().getScreenH() / 8) textColour = "white" doubleFont = self.window.setFontSize(int(super().getScreenH() / 50)) for i, player in enumerate(players): lives = self.heartDisplay(players[player].get("hp")) curFrame = super().framelist[2] xPosPH = super().getScreenW() / 128 xPosA = super().getScreenW() / 4.1 yPosP = 0 yPosHA = super().getScreenH() / 30 if i < leftPlay: curFrame = super().framelist[1] if (leftPlay / 2) % 2 == 1: yPosP = center - ((((leftPlay - 1) / 2) - i + 1) * offset) else: yPosP = center - (leftPlay / 2 + .5 - i) * offset else: if (rightPlay % 2) == 1: yPosP = center - ((((rightPlay - 1) / 2) - (i - leftPlay) + 1) * offset) else: yPosP = center - (rightPlay / 2 + .5 - (i - leftPlay)) * offset label1 = desktop.Label(curFrame, text=player, font=doubleFont, bg=curFrame['bg'], fg=textColour) label1.place(anchor="nw", y=yPosP, x=xPosPH) label2 = desktop.Label(curFrame, text="HP: ", image=lives, font=doubleFont, bg=curFrame['bg'], fg=textColour) label2.image = lives label2.place(anchor="nw", y=yPosP + yPosHA, x=xPosPH) if not (players[player].get('old_correct')): imgLast = "xMark.png" else: imgLast = "Checkmark.png" prevAct = super().imageCreation(imgLast, super().getScreenH() / 10, super().getScreenW() / 11, "/multigame") label3 = desktop.Label(curFrame, text="Prev: ", image=prevAct, font=doubleFont, bg=curFrame['bg'], fg=textColour) label3.image = prevAct label3.place(anchor="e", y=yPosP + yPosHA, x=xPosA) if game == "Simon": self.displaySimon(valid, timer, maxTimer) elif game == "QuickMaff": self.displayQM(formula, timer) else: self.displayTap(valid, timer)
def eventlog(self, players): ''' Prints out a log of all the actions taken in the previous round so players know what is actually happening ''' playerActed = [ ] # used to ensure there is no double counting of actions act = 0 result = 0 posCounter = 0 ELFont = super().setFontSize(int(super().getScreenH() / 50)) textColour = "white" for player in players: if players[player].get( 'hp') != "dead": # i.e. if the players are alive curPlayerAction = players[player].get('defend') if not ( curPlayerAction == "none" or curPlayerAction == "all" or (player in playerActed) ): # i.e. if the players actually attacked and haven't already been shown oppAct = players[curPlayerAction].get('defend') playerActed.append(player) if oppAct == 'all': # attack into a block playerActed.append(curPlayerAction) act = "Attack.png" result = "Defend.png" elif oppAct == 'none' or oppAct != player: # attack into a player attacking a different player act = "Attack.png" result = "Heart.png" else: # players attacking one another playerActed.append(curPlayerAction) act = "CAttack.png" result = "none" posY = super().getScreenH() * (1 / 10 + 1 / 10 * posCounter) label1 = desktop.Label(super().framelist[3], text=player, font=ELFont, bg=super().framelist[3]['bg'], fg=textColour) label1.place(anchor="nw", y=posY, x=1 / 40 * super().getScreenW() / 2) actImg = super().imageCreation( act, int(super().getScreenH() / 20), int(super().getScreenW() / 30)) label2 = desktop.Label(super().framelist[3], image=actImg, bg=super().framelist[3]['bg']) label2.image = actImg label2.place(anchor="nw", y=posY, x=17 / 40 * super().getScreenW() / 2) label3 = desktop.Label(super().framelist[3], text=curPlayerAction, font=ELFont, bg=super().framelist[3]['bg'], fg=textColour) label3.place(anchor="ne", y=posY, x=35.5 / 40 * super().getScreenW() / 2) if result != 'none': # shows the result of the attackers attack (i.e. took HP or was blocked) resImg = super().imageCreation( result, int(super().getScreenH() / 20), int(super().getScreenW() / 30)) label4 = desktop.Label(super().framelist[3], image=resImg, bg=super().framelist[3]['bg']) label4.image = resImg label4.place(anchor="nw", y=posY, x=36.5 / 40 * super().getScreenW() / 2) posCounter += 1 self.window.win.update() desktop.time.sleep( 2) # done so eventlog appears one entry at a time else: # if the player is dead, we dont need to deal with them playerActed.append(player) for player in players: # this is done so that attacks show first, then defends that blocked nothing and reloads act = "" if not (player in playerActed): playerAct = players[player].get('defend') if playerAct == "none": act = "Reload.png" else: act = "Defend.png" posY = (1 / 10 + 1 / 10 * posCounter) * super().getScreenH() label1 = desktop.Label(super().framelist[3], text=player, font=ELFont, bg=super().framelist[3]['bg'], fg=textColour) label1.place(anchor="nw", y=posY, x=1 / 40 * super().getScreenW() / 2) actImg = super().imageCreation(act, super().getScreenH() / 20, super().getScreenW() / 30) label2 = desktop.Label(super().framelist[3], image=actImg, bg=super().framelist[3]['bg']) label2.image = actImg label2.place(anchor="nw", y=posY, x=17 / 40 * super().getScreenW() / 2) posCounter += 1 self.window.win.update() desktop.time.sleep(1) self.window.win.update() desktop.time.sleep(1)
def display(self, players, timer, fragment): ''' Displays all the players, their current score and the image they need a fragment from ''' numPlay = len(players) leftPlay = desktop.math.ceil(numPlay / 2) rightPlay = desktop.math.floor(numPlay / 2) center = int(super().getScreenH() / 2) offset = int(super().getScreenH() / 10) textColour = "white" for i, player in enumerate(players): playerScore = players[player].get("score") xPos = super().getScreenW() / 32 yPos = 0 yPosS = super().getScreenW() / 40 fontSize = super().setFontSize(int((super().getScreenH()) / 40)) curFrame = super().framelist[2] if i < leftPlay: curFrame = super().framelist[1] if leftPlay % 2 == 1: yPos = center - ((((leftPlay - 1) / 2) - i + 1) * offset) else: yPos = center - (leftPlay / 2 + .5 - i) * offset else: if rightPlay % 2 == 1: yPos = center - ((((rightPlay - 1) / 2) - (i - leftPlay) + 1) * offset) else: yPos = center - (rightPlay / 2 + .5 - (i - leftPlay)) * offset label1 = desktop.Label(curFrame, text=player, font=fontSize, bg=super().backgroundC, fg=textColour) label1.place(anchor="nw", x=xPos, y=yPos) label2 = desktop.Label(curFrame, text="Score: " + str(playerScore), font=fontSize, bg=super().backgroundC, fg=textColour) label2.place(anchor="nw", x=xPos, y=yPos + yPosS) label3 = desktop.Label(super().framelist[0], text="Find the fragment that matches the image", font=super().setFontSize( int((super().getScreenH() / 30))), bg=super().backgroundC, fg=textColour) label3.place(anchor="s", x=super().getScreenW() / 2, y=super().getScreenH() / 20) fragmentImg = super().imageCreation(fragment, super().getScreenW() / 2.5, super().getScreenW() / 2.5, "/fragments") label5 = desktop.Label(super().framelist[3], image=fragmentImg, bg=super().backgroundC) label5.img = fragmentImg label5.place(anchor="center", y=super().getScreenH() * (2 / 5), x=super().getScreenW() / 4)
def display(self, players, timer): ''' Prints out all the players, their current HP and their previous action ''' numPlay = len(players) leftPlay = desktop.math.ceil(numPlay / 2) rightPlay = desktop.math.floor(numPlay / 2) center = int(super().getScreenH() / 2) offset = int(super().getScreenH() / 8) textColour = "white" doubleFont = super().setFontSize(int(super().getScreenH() / 50)) for i, player in enumerate(players): lives = self.heartDisplay(players[player].get("hp")) prevAct = self.actions(players[player].get("defend")) curFrame = super().framelist[2] xPosPH = super().getScreenW() / 128 xPosA = super().getScreenW() / 4.1 yPosP = 0 yPosHA = super().getScreenH() / 30 if i < leftPlay: curFrame = super().framelist[1] if (leftPlay / 2) % 2 == 1: yPosP = center - ((((leftPlay - 1) / 2) - i + 1) * offset) else: yPosP = center - (leftPlay / 2 + .5 - i) * offset else: if (rightPlay % 2) == 1: yPosP = center - ((((rightPlay - 1) / 2) - (i - leftPlay) + 1) * offset) else: yPosP = center - (rightPlay / 2 + .5 - (i - leftPlay)) * offset label = desktop.Label(curFrame, text=player, font=doubleFont, bg=curFrame['bg'], fg=textColour) label.place(anchor="nw", y=yPosP, x=xPosPH) label2 = desktop.Label(curFrame, text="HP: ", image=lives, font=doubleFont, bg=curFrame['bg'], fg=textColour) label2.image = lives label2.place(anchor="nw", y=yPosP + yPosHA, x=xPosPH) label3 = desktop.Label(curFrame, text="Act: ", image=prevAct, font=doubleFont, bg=curFrame['bg'], fg=textColour) label3.image = prevAct label3.place(anchor="e", y=yPosP + yPosHA, x=xPosA)