示例#1
0
def main():

    menuSelection = 0

    menuSelection = mainMenu.display()
    while (menuSelection != '1' and menuSelection != "2"
           and menuSelection != "3"):
        print("Try again, enter 1, 2, or 3.")
        menuSelection = input("> ")

    if (menuSelection == "1"):
        newGame = gameState.gameState()
        roomParser.parseNewRoomData(newGame)
        gameObjects.createObjectList(newGame)
        passages.createPassages(newGame)
    elif (menuSelection == "2"):
        newGame = gameState.gameState()
        roomParser.parseNewRoomData(newGame)
        gameObjects.createObjectList(newGame)
        passages.createPassages(newGame)
        newGame.loadSavedGame()
    else:
        print("Goodbye")
        return 0

    #gameplay loop would start here
    newGame.printRoomDescription()

    #Call for testing
    #newGame.testSuite()

    while (newGame.gameOver() == 0):
        verb, noun = textParser.parse(newGame)
        newGame.modifyState(verb, noun)
示例#2
0
def getGametype():

    while 1:
        game_type = input("(N)ew game or (L)oad game > ")
        game_type = game_type.upper()

        if game_type == "QUIT" or game_type == "Q":
            exit()
        elif game_type == "N":
            gameName = input("Enter a new game name: ")
            myGameState = gameState.gameState()
            if len(gameName.replace(' ', '')) == 0:
                print("Please enter a game name!")
                continue
            if myGameState.newGame(gameName) == -1:
                print("A game with that name already exists!")
                print("Please try again.")
                continue
            else:
                return myGameState
        elif game_type == "L":
            gameName = input("Enter the saved game name to load: ")
            myGameState = gameState.gameState()
            if len(gameName.replace(' ', '')) == 0:
                print("Please enter a game name!")
                continue
            if myGameState.loadGame(gameName) == -1:
                print("No game with that name exists!")
                print("Please try again")
                continue
            else:
                return myGameState
        else:
            print("I don't understand that command.")
            print("Please try again!")
示例#3
0
文件: gameEngine.py 项目: kha4/TBA1
def main():

    #checking that the column size is big enough
    rows, columns = os.popen('stty size', 'r').read().split()
    if int(columns) < 172:
        print("Please increase your column size to at least 176")
        exit()
    menuSelection = 0
    # Main menu display is called
    menuSelection = mainMenu.display()
    # Validation for main menu input
    while (menuSelection != '1' and menuSelection != "2"
           and menuSelection != "3"):
        print("Try again, enter 1, 2, or 3.")
        menuSelection = input("> ")

    if (menuSelection == "1"):  # New game is started
        newGame = gameState.gameState()
        roomParser.parseNewRoomData(newGame)
        gameObjects.createObjectList(newGame)
        passages.createPassages(newGame)
    elif (menuSelection == "2"):  # Saved game is loaded
        newGame = gameState.gameState()
        roomParser.parseNewRoomData(newGame)
        gameObjects.createObjectList(newGame)
        passages.createPassages(newGame)
        newGame.loadSavedGame()
    else:
        print("Goodbye")
        return 0

    # Print starting room description
    newGame.printRoomDescription()

    #Call for testing
    #newGame.testSuite()

    verb = 'blank'  # verb intialized

    ##############################################################
    ## Gameplay loop begins here, winning state is checked for  ##
    ## time as well as if the player wants to quit.             ##
    ##############################################################
    while (newGame.gameOver() == 0 and verb != 'quit'):
        verb, noun = textParser.parse(newGame)
        if (verb == 'quit'):
            newGame.quitGame()
        else:
            newGame.modifyState(verb, noun)
示例#4
0
def makeStateFromCode(codeStr, width=7, height=6):
    codes = map(int, list(codeStr))
    state = gameState.gameState(width, height)

    for code in codes:
        state = state.getState(code)
    
    return state
示例#5
0
 def __init__(self, parent):
     QtGui.QFrame.__init__(self, parent)
     self.parent = parent
     self.var = parent.var
     self.mouse_x = -1
     self.mouse_y = -1
     self.x = -1
     self.y = -1
     self.pic = QtGui.QPixmap(os.getcwd() + "/pictures/flippyboard.png")
     self.pic = self.pic.scaled(self.var.boardWidth, self.var.boardHeight)
     self.mouseIn = False
     self.setFixedSize(self.var.boardWidth, self.var.boardHeight)
     self.state = gameState(self)
     self.pos_time = 0
     self.enemy_pic = QtGui.QPixmap(
         os.path.join(os.getcwd(), "pictures",
                      "mob.png")).scaled(self.var.blockSize,
                                         self.var.blockSize)
     self.road_pic = QtGui.QPixmap(
         os.path.join(os.getcwd(), "pictures",
                      "minrcraftdirt.png")).scaled(self.var.blockSize,
                                                   self.var.blockSize)
     self.tower1_pic = QtGui.QPixmap(
         os.path.join(os.getcwd(), "pictures",
                      "Bashnya1.png")).scaled(self.var.blockSize,
                                              self.var.blockSize)
     self.tower2_pic = QtGui.QPixmap(
         os.path.join(os.getcwd(), "pictures",
                      "Bashnya2.png")).scaled(self.var.blockSize,
                                              self.var.blockSize)
     self.tower3_pic = QtGui.QPixmap(
         os.path.join(os.getcwd(), "pictures",
                      "Bashnya3.png")).scaled(self.var.blockSize,
                                              self.var.blockSize)
     self.tower4_pic = QtGui.QPixmap(
         os.path.join(os.getcwd(), "pictures",
                      "Bashnya4.png")).scaled(self.var.blockSize,
                                              self.var.blockSize)
     self.tower_pic = {
         1: self.tower1_pic,
         2: self.tower2_pic,
         3: self.tower3_pic,
         4: self.tower4_pic
     }
     self.gameover_pic = QtGui.QPixmap(
         os.path.join(os.getcwd(), "pictures",
                      "gameover.png")).scaled(self.var.boardWidth,
                                              self.var.boardHeight)
     self.winner_pic = QtGui.QPixmap(
         os.path.join(os.getcwd(), "pictures",
                      "winner.png")).scaled(self.var.boardWidth,
                                            self.var.boardHeight)
示例#6
0
 def __init__(self, parent):
     QtGui.QFrame.__init__(self, parent)
     self.parent = parent
     self.var = parent.var
     self.mouse_x = -1
     self.mouse_y = -1
     self.x = -1
     self.y = -1
     self.pic = QtGui.QPixmap(os.getcwd() + "/pictures/flippyboard.png")
     self.pic = self.pic.scaled(self.var.boardWidth, self.var.boardHeight)
     self.mouseIn = False
     self.setFixedSize(self.var.boardWidth, self.var.boardHeight)
     self.state = gameState(self)
     self.pos_time = 0
     self.enemy_pic = QtGui.QPixmap(
         os.path.join(os.getcwd(), "pictures", "mob.png")).scaled(
         self.var.blockSize, self.var.blockSize)
     self.road_pic = QtGui.QPixmap(
         os.path.join(os.getcwd(),
                      "pictures", "minrcraftdirt.png")).scaled(
         self.var.blockSize, self.var.blockSize)
     self.tower1_pic = QtGui.QPixmap(os.path.join(
         os.getcwd(), "pictures", "Bashnya1.png")).scaled(
         self.var.blockSize, self.var.blockSize)
     self.tower2_pic = QtGui.QPixmap(
         os.path.join(os.getcwd(), "pictures", "Bashnya2.png")).scaled(
         self.var.blockSize, self.var.blockSize)
     self.tower3_pic = QtGui.QPixmap(
         os.path.join(os.getcwd(), "pictures", "Bashnya3.png")).scaled(
         self.var.blockSize, self.var.blockSize)
     self.tower4_pic = QtGui.QPixmap(
         os.path.join(os.getcwd(), "pictures", "Bashnya4.png")).scaled(
         self.var.blockSize, self.var.blockSize)
     self.tower_pic = {1: self.tower1_pic,
                       2: self.tower2_pic,
                       3: self.tower3_pic,
                       4: self.tower4_pic}
     self.gameover_pic = QtGui.QPixmap(
         os.path.join(os.getcwd(), "pictures", "gameover.png")).scaled(
         self.var.boardWidth, self.var.boardHeight)
     self.winner_pic = QtGui.QPixmap(
         os.path.join(os.getcwd(), "pictures", "winner.png")).scaled(
         self.var.boardWidth, self.var.boardHeight)
示例#7
0
 def setUp(self):
     with open(os.path.join(os.getcwd(), "maps", "default.py")) as f:
         self.road = json.load(f)
     self.state = gameState(road=self.road)
示例#8
0
def moveBy_s():
    mySpatial.rect = mySpatial.rect.move(10, 10)


def changeState():
    mygame.changeState('1')


def changeState2():
    mygame.changeState('2')


x = 20
y = 30

spatials = []
rect = pygame.Rect(x, y, 20, 20)
mySpatial = dynSpatial(rect, 2, BLUE)
mySpatial.addControl(repControl((200, 200), (140, 140), 70))
handler = keyDownHandler([(K_s, moveBy_s), (K_w, changeState),
                          (K_e, changeState2)
                          ])  #Setting keyhandlers in (key, action) pairs
spatials.append(mySpatial)
states = {
    '1': gameState(spatials, handler, WHITE),
    '2': gameState([], handler, BLUE)
}  #possible states
mygame = game(states, '1', 300, 300)
mygame.run()
示例#9
0
                    char.setTruth(False)
                    entering = False
                elif ans == "quit" or ans == "q":
                    return
                else:
                    print("Please enter [y] or [n].")
                    ans = str.lower(input("> "))

            game.addChar(char)  # update the gameState

    print("Thank you for playing!")

def addChars(obj, g):
    """Adds the characteristics defined in a gamestate g to an object, obj."""
    objs = []
    for i in dataBase:
        objs.append(i.get())
    dataBase[objs.index(obj)].addTag(g.getChars())
    saveData()

loadData()
saveData()

#Game initializations
oG = oG.oGuesser(dataBase)
cP = cP.cPicker(dataBase, charDict)
qB = qB.qBuilder()
game = Gs.gameState()

playGame()
示例#10
0
 def setUp(self):
     with open(os.path.join(os.getcwd(), "maps", "default.py")) as f:
         self.road = json.load(f)
     self.state = gameState(road=self.road)
示例#11
0
 def __init__(self,w=7,h=6):
   self.position = 0
   self.boardWidth = int(w)
   self.tree = dict()
   self.tree[0] = gameState.gameState(int(w),int(h))