def getBoard(self): """Main graphics point of the program; shows the board.""" self.extraList = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", \ "TWS", "DWS", "TLS", "DLS", \ "A ", "B ", "C ", "D ", "E ", "F ", "G ", "H ", "I ", "J ", "K ", "L ", "M ", "N ", "O ", \ "*", " "] colors = {"TWS":"red", "DWS":"pink", "TLS":"light green", "DLS":"light blue", "*":"pink"} self.boardFrame = func.Frame(self.root, bd=1, relief=func.SUNKEN) self.boardFrame.place(x=50, y=50, width=497, height = 497) labels = list() squares = list() for i in range(16): for j in range(16): label = self.board[j][i] if label in self.extraList: entry = func.Frame(self.boardFrame, bd=1, relief=func.RAISED) entry.place(x=(i*31), y=(j*31), width=31, height=31) labels.append(func.Label(entry, text = label, height = 31, width = 31)) if label in colors.keys(): labels[-1].config(bg=colors[label]) labels[-1].pack() else: if mpl_in == 0: frame = func.Frame(self.boardFrame, bd=1, relief=func.RAISED) frame.place(x=(i*31), y=(j*31), width=31, height=31) entry = func.Frame(self.boardFrame, bd=1, relief=func.SUNKEN) entry.place(x=(i*31) + 3, y=(j*31) + 3, width=25, height=25) squares.append(func.Label(entry, bd = 1, text=label+self.getSubscript(self.scores[label.lower()]), height=25, width=25, relief=func.RAISED)) squares[-1].pack(fill=func.X, padx=1, pady=1) entry.lift() else: #frame = func.Frame(self.boardFrame, bd=1, relief=func.RAISED) #frame.place(x=(i*31), y=(j*31), width=31, height=31) #entry = func.Frame(self.boardFrame, bd=1, relief=func.SUNKEN) #entry.place(x=(i*31) + 3, y=(j*31) + 3, width=25, height=25) hf = Subscript(self.boardFrame, label, i*31, j*31, board=True) #squares.append(hf.label) #squares[-1].pack(fill=func.X, padx=1, pady=1) print(hf.letter) self.helpLabel = func.Label(self.root, text = "Note: For best tile placement, \naim for below and to the right of the square.", ) self.helpLabel.place(x=50, y=10, height=35, width=497)
def getExchangeRack(self): self.exchangeRack = func.Frame(self.root, bd=1, relief=func.RAISED) self.exchangeRack.place(x=self.exchangeRackX, y=self.exchangeRackY, width=self.exchangeRackWidth, height = self.exchangeRackHeight) labels = [] for i in range(7): labels.append(func.Label(self.exchangeRack, relief=func.SUNKEN)) labels[-1].place(x=i*30+self.exchangeRackX, y=self.exchangeRackY, height=30, width=30)
def scoreAnimation(self, scoreLabel, startX, startY): frame = func.Frame(self.root, relief=func.RAISED) frame.place(x=startX, y=startY, height=25, width=25) label = func.Label(frame, text="+" + str(scoreLabel), bd=1, relief=func.RAISED, height=25, width=25) label.pack() frame.lift() fontsize = 12 for i in range(1, 15, 1): self.player1ScoreLabel.config(height=round(i / 10), width=round(15 * (i / 10)), font=("Courier", fontsize + (round( (i / 10) * 3)))) self.player1ScoreLabel.place_configure(x=self.scoreX - round( (i / 10) * 25), y=self.scoreY - round( (i / 10) * 25)) self.player1ScoreLabel.lift() self.player1ScoreLabel.update() for scoreChange in range(scoreLabel): self.player1ScoreLabel.config( text="%s's Score: %d" % (self.name, self.score + scoreChange + 1)) self.player1ScoreLabel.update() func.sleep(0.05) frame.destroy() label.destroy()
def exchange(self): self.root.update_idletasks() self.exchangeWindow = func.Toplevel(self.root, height=self.screenHeight/2, \ width = self.screenWidth/2-200) self.exchangeWindow.wm_title("Exchange") label = func.Label( self.exchangeWindow, text="Drag the letters you wish to exchange to the rack.", relief=func.RAISED) label.place(x=90, y=30, height=50, width=320) self.exchangeLetters = [] for letterCount in range(len(self.rack)): self.exchangeLetters.append( tiles.MovingExchangeLetter(self.exchangeWindow, self.rack[letterCount], letterCount * 30 + 150, 300, self.exchangeWindow)) for i in self.exchangeLetters: i.els = self.exchangeLetters i.weed_els() self.exchangeLetters[-1].getExchangeRack() button = func.Button(self.exchangeWindow, text="Back", command=self.exchangeWindow.destroy) button.place(x=250, y=175) exchangeButton = func.Button(self.exchangeWindow, text="Enter", command=self.getNewTiles) exchangeButton.place(x=175, y=175)
def checkDictWord(self): q=self.e.get() if self.checkWord(q): if self.dwlgen == 1: self.dwl["text"] = "%s is a word." % q self.dwl["foreground"] = "green" else: self.dwl = func.Label(self.dict_window, text="%s is a word." % q, foreground="green") self.dwlgen = 1 else: if self.dwlgen == 1: self.dwl["text"] = "%s is not a word." % q self.dwl["foreground"] = "red" else: self.dwl = func.Label(self.dict_window, text="%s is not a word." % q, foreground="red") self.dwlgen = 1 self.dwl.pack()
def getScoreBoard(self, otherName, otherScore): self.player1ScoreLabel = func.Label(self.root, text="%s's Score: %d" % (self.name, self.score), height=1, width=15, relief=func.SUNKEN, justify=func.LEFT, anchor=func.W) self.player2ScoreLabel = func.Label(self.root, text="%s's Score: %d" % (otherName, otherScore), height=1, width=15, relief=func.SUNKEN, justify=func.LEFT, anchor=func.W) if self.de: self.tilesLabel = func.Label(self.root, text="%d tiles left" % len(self.distribution), height=1, width=15, relief=func.SUNKEN) else: self.tilesLabel = func.Label(self.root, text="%d tiles left" % len(func.distribution), height=1, width=15, relief=func.SUNKEN) if self.playerNum == 1: self.player1ScoreLabel.place(x=500, y=550) self.player2ScoreLabel.place(x=500, y=570) self.scoreX, self.scoreY = 500, 550 else: self.player1ScoreLabel.place(x=500, y=550) self.player2ScoreLabel.place(x=500, y=570) self.scoreX, self.scoreY = 500, 570 self.tilesLabel.place(x=500, y=590)
def make_dict(self): self.dict_window = func.Toplevel(self.root, height=500, width=500) self.dict_window.title("Dictionary") l = func.Label(self.dict_window, height=2, width=50, text="Type a word below to check if it's actually a word.") # self.sv = func.StringVar() # self.sv.set("Word") self.e = func.Entry(self.dict_window)#, textvariable=self.sv) self.e.delete(0, func.END) self.e.insert(0, "word") # e.place(height=2, width=50) be = func.Button(self.dict_window, text="Enter", command=self.checkDictWord) bb = func.Button(self.dict_window, text="Back", command=self.dict_window.destroy) self.dwlgen = 0 for i in [l, self.e, bb, be]: i.pack()
def __init__(self, root, file="savedGame.txt"): self.root = func.Toplevel(root) self.root.withdraw() self.gameWindow = func.Toplevel(self.root, height=root.winfo_screenheight(), width=root.winfo_screenwidth()) self.gameWindow.resizable(0, 0) self.gameWindow.wm_title("Saved Games") gameTexts = open(file).read() gameTexts = gameTexts.split("New Game\n") newGameTexts = [] for i in gameTexts: newGameTexts.append(i.strip()) #print(gameTexts) self.gameTexts = newGameTexts gameLabels = [] gameButtons = [] deleteButtons = [] column = 0 for gameText in gameTexts: if gameText: fullText = self.setGameVars(gameText) if fullText != "nogame": text = """%s's score: %s %s's score: %s Mode 1: %s Mode 2: %s""" % (fullText[0], fullText[1], fullText[2], fullText[3], fullText[4], fullText[5]) gameLabel = func.Label( self.gameWindow, text=text, height=4, width=20, relief=func.RAISED) #Definetly changeable gameLabels.append(gameLabel) gameLabels[-1].place(x=0, y=column * 100) gameButton = func.Button(self.gameWindow, text="Play!", height=1, width=5, \ command=lambda game=gameText: self.play(game)) gameButtons.append(gameButton) gameButtons[-1].place(x=350, y=(gameTexts.index(gameText) * 100)) column += 1
def instructions(): """Needs to be updated""" text = """Instructions for Scrabble: You get a rack of 7 tiles to start the game. You must play words with these 7 tiles so that each word formed vertically and horizontally is a word. \tNote: Whenever you play a word, make sure that it touches at least \tone other letter on the board (not diagonally.) \tThe first move must touch the star in the middle of the board. To play a tile, click and drag the tile to the board. \tNote: When you play a tile, make sure that it snaps into a space. \tIf it doesn't, then it didn't place and you have to do it again. "?" tiles are blank tiles. They can be played as any letter. If you can't find any words to make, you can exchange. Exchanging You get a certain amount of points based on the letters you played. Special Score Tiles: \tTWS (triple word score): Multiplies your score for that turn by 3. \tDWS (double word score): Multiplies your score for that turn by 2. \tTLS (triple letter score): Multiplies your score for that letter by 3. \tDLS (double letter score): Multiplies your score for that letter by 2. Once you play a word, you draw tiles until you have seven again. The game ends when there are no tiles left in the bag. Modes: Normal: wrong word -> continue Hardcore: wrong word -> lose turn Normal: play until no tiles in bag Short: play to 75 points""" instructionsWindow = func.Toplevel(root, height=root.winfo_screenheight(), width=root.winfo_screenwidth()) instructionsWindow.title("Instructions") instructionsLabel = func.Label(instructionsWindow, text=text, justify=LEFT) instructionsLabel.place(x=300, y=10, height=750, width=500) closeButton = func.Button(instructionsLabel, text="Close", command=instructionsWindow.destroy) closeButton.place(x=225, y=600)
def chooseBlank(self): self.blankWindow.deiconify() chooseLabel = func.Label(self.blankWindow, text = "Choose the tile you want your blank to be.") chooseLabel.place(x = 400, y = 200, width = 300, height = 100) self.choiceWindow = func.Frame(self.blankWindow) self.choiceWindow.place(x=400, y=400, width=500, height = 500) buttons = [] row = 1 column = 1 for letter in func.ascii_uppercase: button = func.Button(self.choiceWindow, text = letter, command = lambda letter=letter: self.setBlank(letter), \ height = 1, width = 1) buttons.append(button) buttons[-1].place(x = row * 30, y = column * 30) column += 1 if column % 6 == 0: column = 1 row += 1
def setup(): func.setup() func.root.config(bg=func.generateRandomColor()) welcomeLabel = func.Label(func.root, text="Welcome to Scrabble in Python!") instructionsButton = func.Button(func.root, text="Instructions", command=instructions) playButton = func.Button(func.root, text="Play", command=play) playSavedButton = func.Button(func.root, text="Play Saved Game", command=games.playSavedGame) exitButton = func.Button(func.root, text="Exit", command=exitGame) welcomeLabel.place(x=40, y=0) #instructionsButton.place(x = 90, y = 50) playButton.place(x=110, y=100) #playSavedButton.place(x = 76, y = 150) exitButton.place(x=112, y=200)
def getFrame(self, size): """Gets a frame of size {size} (normally 31) with text {self.text + subscirpt of score}""" #self.frame.pack() if mpl_in == 1: #self.frame.config(bd=0) overarch = Subscript(self.rackFrame, self.text, self.x, self.y) self.label = overarch.label self.frame = overarch.frame #print(self.x, self.y) #self.label.place_configure(x=self.x, y=self.y) self.label.bind('<ButtonPress-1>', self.startMoveWindow) self.label.bind('<B1-Motion>', self.MoveWindow) self.label.bind('<ButtonRelease-1>', self.checkForReturn) self.frame.bind('<ButtonPress-1>', self.startMoveWindow) self.frame.bind('<B1-Motion>', self.MoveWindow) self.frame.bind('ButtonRelease-1>', self.checkForReturn) else: self.frame = func.Frame(self.rackFrame, bd=1, relief=func.SUNKEN) self.frame.place(x=self.x, y=self.y, width=size, height=size) self.label = func.Label(self.frame, bd=1, relief=func.RAISED, \ text=self.text+self.getSubscript(self.scores[self.text.lower()]), #Puts the points for the letter on the label\ height=size, width=size, bg="yellow") self.label.pack(fill=func.X, padx=1, pady=1) self.label.bind('<ButtonPress-1>', self.startMoveWindow) self.label.bind('<B1-Motion>', self.MoveWindow) self.label.bind('<ButtonRelease-1>', self.checkForReturn) self.frame.bind('<ButtonPress-1>', self.startMoveWindow) self.frame.bind('<B1-Motion>', self.MoveWindow) self.frame.bind('ButtonRelease-1>', self.checkForReturn) self.frame.lift()
player_missiles_storage.append(PlayerMissile("circle", "white", x, -225)) for player_missile in player_missiles_storage: player_missiles.append(player_missile) for i in range(30): enemy_missiles_storage.append(EnemyMissile("circle", "red", random.randint(-450, 450), random.randint(400, 800))) for enemy_missile in enemy_missiles_storage: if len(enemy_missiles) < game.level: enemy_missile.set_target(random.choice(cities + silos)) enemy_missiles.append(enemy_missile) # Create Labels status_label = functions.Label("Missile Command \nLevel: {} \nScore: {} \nCities: {} \nSilos: {} \nPlayer Missiles: {} \nEnemy Missiles: {}", "white", -390, 160) # Create Buttons # Set Keyboard Bindings while True: # Call the game tick method game.tick() # Check to see if the player missile collides with the enemy missiles for player_missile in player_missiles: for enemy_missile in enemy_missiles: # Check if the player missile is exploding if player_missile.state == "explode": radius = (player_missile.size * 20) / 2
def play(): global enterWindow, name1Var, name2Var, mode1Var, mode2Var, playing playing = 1 enterWindow = func.Toplevel(func.root, height = func.root.winfo_screenheight(),\ width = func.root.winfo_screenwidth()) enterWindow.wm_title("Enter Names and Modes") label1 = func.Label(enterWindow, text="Enter name 1:") label1.place(x=50, y=50, height=20, width=95) name1Var = func.StringVar() name1Var.set("Joe") name1 = func.Entry(enterWindow, textvariable=name1Var) name1.place(x=150, y=50, height=20, width=100) label2 = func.Label(enterWindow, text="Enter name 2:") label2.place(x=50, y=175, height=20, width=95) name2Var = func.StringVar() name2Var.set("CPU") name2 = func.Entry(enterWindow, textvariable=name2Var) name2.place(x=150, y=175, height=20, width=100) cpuRemindLabel = func.Label(enterWindow, text="""Note: If name 2 is CPU, the computer will play for that player.""") cpuRemindLabel.place(x=50, y=215, height=30, width=250) mode1Label = func.Label(enterWindow, text="Enter mode 1 (normal or hardcore):") mode1Label.place(x=50, y=295, height=20, width=210) mode1Var = func.StringVar() mode1Var.set("normal") mode1 = func.Entry(enterWindow, textvariable=mode1Var) mode1.place(x=270, y=295, height=20, width=100) mode1Questions = func.Button(enterWindow, text="?", command=mode1questions) mode1Questions.place(x=370, y=280, height=50, width=50) mode1Switch = func.Button(enterWindow, text="Switch", command=mode1VarSwitch) mode1Switch.place(x=430, y=280, height=50, width=75) mode2Label = func.Label(enterWindow, text="Enter mode 2 (normal or short):") mode2Label.place(x=50, y=465, height=20, width=200) mode2Var = func.StringVar() mode2Var.set("normal") mode2 = func.Entry(enterWindow, textvariable=mode2Var) mode2.place(x=270, y=465, height=20, width=100) mode2Questions = func.Button(enterWindow, text="?", command=mode2questions) mode2Questions.place(x=370, y=450, height=50, width=50) mode2Switch = func.Button(enterWindow, text="Switch", command=mode2VarSwitch) mode2Switch.place(x=430, y=450, height=50, width=75) enterButton = func.Button(enterWindow, text="Enter data", command=checkData) enterButton.place(x=100, y=500)