Ejemplo n.º 1
0
    def play(self, gameText):
        global playing
        playing = 1

        self.gameNum = -1  #self.gameTexts.index(gameText)
        self.gameAlreadyInFile = True
        gameVars = self.setGameVars(gameText)
        global distribution
        distribution = getDist()
        #distribution = gameVars[10]#.split(",")
        self.distribution = distribution
        #print(self.distribution)
        #print(distribution)
        func.popup(
            func.root, "Pass Device", "Pass Device to %s\n\n" %
            [gameVars[0], gameVars[2]][gameVars[9] - 1], 500, 500)
        super(SavedGame, self).__init__(gameVars[0], gameVars[2], gameVars[4],
                                        gameVars[5])
        self.gameWindow.destroy()
        self.startGame(gameVars[7], gameVars[8])
        self.player1.board, self.player2.board = gameVars[6], gameVars[6]
        self.player1.score, self.player2.score = int(gameVars[1]), int(
            gameVars[3])
        #self.player1.rack, self.player2.rack = gameVars[7], gameVars[8]
        self.playerGoing = gameVars[9]
        self.main()
        playing = 0
Ejemplo n.º 2
0
 def main(self):
     #self.startGame()
     if self.mode2.lower() == "n":
         if self.player1.de:
             while len(self.player1.distribution) > 0 or (len(
                     self.player1.rack) > 0 and len(self.player2.rack) > 0):
                 self.doTurn()
                 #self.updateScores()
         else:
             while len(func.distribution) > 0 or (len(
                     self.player1.rack) > 0 and len(self.player2.rack) > 0):
                 self.doTurn()
                 #self.updateScores()
     else:
         while self.player1.score < 75 and self.player2.score < 75:
             self.doTurn()
             #self.updateScores()
     if self.player1.score > self.player2.score:
         func.popup(func.root, "Player 1 Won", "Player 1 Won",
                    self.player1.screenHeight, self.player1.screenWidth)
     else:
         func.popup(func.root, "Player 2 Won", "Player 2 Won",
                    self.player1.screenHeight, self.player1.screenWidth)
     self.player1.root.destroy()
     self.player2.root.destroy()
     self.mainRoot.destroy()
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
def check(string, validInputs, popupHeader, popupText):
    if string in validInputs:
        return True
    else:
        func.popup(root, popupHeader, popupText, root.winfo_screenheight(),
                   root.winfo_screenwidth())
        return False
Ejemplo n.º 5
0
    def movableCheck(self, boardToCheck):
        for movable in self.movables:
            movable.words = []
            movable.wordIndexes = {}
        words = self.getBoardWords(boardToCheck)
        if isinstance(words, dict):
            for (word, attributes) in words.items():
                for attribute in attributes:
                    for movable in self.movables:
                        if movable.row != "NA":
                            movable.attributes = self.getAttributes(
                                "%s,%s" % (movable.column, movable.row),
                                self.board)
                            if str(movable.attributes) == str(attribute):
                                movable.wordIndexes[word] = attributes.index(
                                    movable.attributes)
                                movable.words.append(word)

            sharedWords = []
            for movable in self.movables:
                if movable.row != "NA":
                    notWord = 0
                    for word in movable.words:
                        sharedWords.append(word)
                    if notWord >= len(movable.words):
                        #popup(self.root, 'a', 'a', 50, 50)
                        pass

            sharedWord = self.getMode(sharedWords)
            movablesInWord = 0
            for movable in self.movables:
                if sharedWord[0] in movable.words:
                    movablesInWord += 1
                #print(sharedWord, movable.words)
            otherwords = []
            for movable in self.movables:
                for word in movable.words:
                    if word != sharedWord[0]:
                        otherwords.append(word)
                #print(otherwords, movable.words, sharedWord[0])

            for word in otherwords:
                if otherwords.count(word) > 1:
                    func.popup(self.root, "Same Word", "All movables must be in the same word\n\n\n", \
                          500, 500)

                    return False
            if movablesInWord < sharedWord[1][0]:
                func.popup(self.root, "Same Word", "All movables must be in the same word\n\n\n", \
                      500, 500)

                return False

            self.movables[-1].sharedWord = sharedWord
            return True
        else:
            return False
Ejemplo n.º 6
0
def playSavedGame(file="savedGame.txt"):

    if len(open(file).read()) > 0:
        playing = 1
        global scrabble
        scrabble = SavedGame(func.root)
        playing = 0
    else:
        func.popup(func.root, "No saved games", "No saved games\n\n\n",
                   root.winfo_screenheight(), root.winfo_screenwidth())
Ejemplo n.º 7
0
    def setBoard(self):
        word = ""
        specialScores = {}
        for movable in self.movables:
            if not (movable.row == "NA"):
                word += movable.origText
                movable.row = int(movable.row)
                movable.column = int(movable.column)
                if self.board[movable.row][movable.column][0] != " " and \
                    self.board[movable.row][movable.column] != "*": #If it was ontop of a letter

                    #The extra scores
                    if self.board[movable.row][
                            movable.column] in self.scoreList:

                        #Check for each of the types
                        if self.board[movable.row][movable.column] == "DLS":
                            self.addKey(specialScores, "DLS", movable.text)

                        elif self.board[movable.row][movable.column] == "TLS":
                            self.addKey(specialScores, "TLS", movable.text)

                        elif self.board[movable.row][movable.column] == "DWS":
                            self.addKey(
                                specialScores, "DWS", ""
                            )  #Don't need to show a letter because it just doubles the score

                        else:
                            self.addKey(specialScores, "TWS", "")

                        self.board[movable.row][movable.column] = movable.text

                    else:
                        func.popup(self.root, "Letters Cannot Overlap", "Letters Cannot Overlap\n\n\n", \
                              self.screenHeight, self.screenWidth)
                        self.resetBoard()
                        self.enterButton.place(x=self.x + 150, y=self.y + 100)
                        return False
                else:
                    if self.board[movable.row][movable.column][0] == "*":
                        self.addKey(specialScores, "DWS", "")
                    self.board[movable.row][
                        movable.column] = movable.text  #Place the letter

        return word, specialScores
Ejemplo n.º 8
0
def checkData():

    if check(mode1Var.get(), ['n', 'h', 'N', 'H', 'normal', 'hardcore'],
             "Invalid Mode 1", "Invalid Mode 1"):
        if check(mode2Var.get(), ['n', 's', 'N', 'S', 'normal', 'short'],
                 "Invalid Mode 2", "Invalid Mode 2"):
            playing = 1
            enterWindow.destroy()
            func.popup(func.root, "Pass Device", "Pass Device to %s\n\n" % name1Var.get(), \
                  500, 500)
            global scrabble
            if name2Var.get() == "CPU":
                scrabble = games.GameWithCPU(name1Var.get(), mode1Var.get(),
                                             mode2Var.get())
            else:
                scrabble = games.Game(name1Var.get(), name2Var.get(),
                                      mode1Var.get(), mode2Var.get())
            scrabble.startGame()
            scrabble.main()
            playing = 0
Ejemplo n.º 9
0
    def getNewWord(self):
        for movable in self.movables:
            movable.snapToGrid()
            movable.frame.update()

        self.hideButtons()
        #self.scoreAnimation(50, 245, 245, 500, 0, 50, 100) #Testing
        if self.board[8][8] == "*":
            isFirstTurn = True
        else:
            isFirstTurn = False
        places = []
        self.rows = []
        self.columns = []
        specialScores = {}
        for movable in self.movables:
            movable.row = movable.hoveringOver.split(",")[0]
            movable.column = movable.hoveringOver.split(",")[1]
            if movable.row != "NA":
                self.rows.append(movable.row)
                self.columns.append(movable.column)

        if self.rows:
            wordAndScores = self.setBoard()
            if wordAndScores is False:
                self.resetBoard()
                self.placeButtons()
                return False
            else:
                word = wordAndScores[0]
                specialScores = wordAndScores[1]
                if self.movableCheck(self.board):
                    boardCheck = self.checkWholeBoard(self.board, isFirstTurn)
                    if boardCheck[0]:
                        for scoreType in specialScores.keys():
                            if scoreType == "DWS" or scoreType == "TWS":
                                specialScores[scoreType] = self.movables[
                                    -1].sharedWord
                        self.newGetScore(specialScores)
                        if len(word) == 7:
                            func.popup(self.root, "Bingo!!!", "Bingo!!!\n\n\nYou used all your tiles!\n\n\n+50 points!", \
                                  self.screenHeight, self.screenWidth)
                            #self.score += 50
                            self.scoreAnimation(50, self.scoreX, self.scoreY)
                            self.score += 50

                        for movable in self.movables:
                            movable.frame.place_forget()
                        for letter in word:
                            self.rack.remove(letter)
                        #self.drawTiles()
                        #self.movables[-1].boardFrame.destroy()
                        self.endTurn()
                    else:
                        if boardCheck[1] == "Invalid Word":
                            text = "Invalid Words: \n\n"
                            for invalidWord in boardCheck[2]:
                                text += invalidWord
                                text += "\n"

                            self.resetBoard()
                            if self.mode1 == "h" or self.mode1 == "H":
                                #while func.popupClosed == 0: pass
                                text += "\n\n\nPass Device to " + self.otherName
                                func.popup(self.root, "Invalid Word", text,
                                           500, 500)
                                self.endTurn()

                            else:
                                func.popup(self.root, "Invalid Word", text,
                                           500, 500)
                        else:
                            func.popup(self.root, boardCheck[1], boardCheck[1],
                                       500, 500)
                        self.placeButtons()
                        #self.resetBoard()
                        return False
                else:
                    self.resetBoard()
                    self.placeButtons()
                    return False
        else:
            func.popup(self.root, "No tiles played", "No tiles played\n\n\n",
                       500, 500)
            self.placeButtons()
Ejemplo n.º 10
0
def mode2questions():
    text = """Normal: play until bag and one of the player's racks are empty
    Short: play until one person reaches 75 points.\n\n\n
    Note: normal play can take at least an hour, but short play is very fast."""
    func.popup(func.root, "Mode 2 Description", text,
               func.root.winfo_screenheight(), func.root.winfo_screenwidth())
Ejemplo n.º 11
0
def mode1questions():
    text = """Normal: wrong word --> continue
    Hardcore: wrong word --> lose turn."""
    func.popup(func.root, "Mode 1 Description", text,
               func.root.winfo_screenheight(), func.root.winfo_screenwidth())