Exemple #1
0
 def doTurn(self):
     if self.playerGoing == 1:
         self.root1 = func.Toplevel(self.mainRoot)
         self.player1.reRoot(self.root1)
         self.player1.startTurn(self.player2.name, self.player2.score)
         self.player2.board = self.player1.board
         self.playerGoing = 2
         func.popup(self.mainRoot, "Pass Device",
                    "Pass Device to %s\n\n" % self.player2.name, 500, 500)
     else:
         if self.player2.name == "CPU":
             self.playerGoing = 1
             self.player2._run()
             self.player2.turnrotation = 0
             self.player1.board = self.player2.board
         else:
             self.root2 = func.Toplevel(self.mainRoot)
             self.player2.reRoot(self.root2)
             self.player2.startTurn(self.player1.name, self.player1.score)
             self.player1.board = self.player2.board
             self.playerGoing = 1
             func.popup(self.mainRoot, "Pass Device",
                        "Pass Device to %s\n\n" % self.player1.name, 500,
                        500)
     if self.gameAlreadyInFile is False:
         writeGameToFile(self,
                         gameNum=self.gameNum,
                         gameAlreadyInFile=False)
         self.gameAlreadyInFile = True
     else:
         writeGameToFile(self, gameNum=self.gameNum, gameAlreadyInFile=True)
Exemple #2
0
    def __init__(self, name1, name2, mode1, mode2):
        self.mainRoot = func.Tk()
        self.root = func.Toplevel(self.mainRoot)
        self.root2 = func.Toplevel(self.mainRoot)
        self.mainRoot.withdraw()

        self.name1 = name1
        self.name2 = name2
        self.mode1 = mode1[0]
        self.mode2 = mode2[0]

        self.gameNum = len(open("savedGame.txt").read().split("New Game"))
        print(self.gameNum)
        self.gameAlreadyInFile = False
Exemple #3
0
    def __init__(self, root, text, x, y, frame):
        self.board = Board()
        self.scoreList = ['TWS', 'DWS', 'TLS', 'DLS']
        self.scores = {"a": 1, "c": 3, "b": 3, "e": 1, "d": 2, "g": 2,
       "f": 4, "i": 1, "h": 4, "k": 5, "j": 8, "m": 3,
       "l": 1, "o": 1, "n": 1, "q": 10, "p": 3, "s": 1,
       "r": 1, "u": 1, "t": 1, "w": 4, "v": 4, "y": 4,
       "x": 8, "z": 10, "?" : 0}
        
        self. root = root
        self.rackFrame = frame
        self.x = x
        self.y = y

        self.origX = x
        self.origY = y

        self.text = text
        self.origText = text
        if text == "?": #Blank tile
            self.blankChosen = 0
            self.blankWindow = func.Toplevel(self.root)
            self.blankWindow.geometry("%dx%d%+d%+d" % (self.root.winfo_screenwidth(), self.root.winfo_screenheight(), 0, 0))
            self.blankWindow.resizable(0, 0)
            self.blankWindow.withdraw()
            self.blankWindow.title("Choose Blank")
                      
        self.getFrame(31) #Same size as spaces on board
        
        self.hoveringOver = "%s,%s" % ("NA", "NA") #Not hovering over anything = "NA", you see this a lot
        self.getPositions() #So it knows where the board spaces are so it can go to them in snapToGrid()
Exemple #4
0
    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)
Exemple #5
0
    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
Exemple #6
0
    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()
Exemple #7
0
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)
Exemple #8
0
    def doTurn(self):
        if self.playerGoing == 1:
            self.root1 = func.Toplevel(self.mainRoot)
            self.player1.reRoot(self.root1)
            self.player1.startTurn(self.player2.name, self.player2.score)
            self.player2.board = cpu.Board(self.player1.board)
            self.playerGoing = 2
            #func.popup(self.mainRoot, "Pass Device", "Pass Device to %s\n\n" % self.player2.name, 500, 500)
        else:
            self.playerGoing = 1
            self.player2._run()
            self.player2.turnrotation = 0
            self.player1.board = self.player2.board.board
##        if self.gameAlreadyInFile is False:
##            writeGameToFile(self, gameNum = self.gameNum, gameAlreadyInFile = False)
##            self.gameAlreadyInFile = True
##        else:
##            writeGameToFile(self, gameNum = self.gameNum, gameAlreadyInFile = True)
        print(len(func.distribution))
Exemple #9
0
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)