Example #1
0
    def save(self):
        if not self._controller.canSave():
            Tkinter.Tk().wm_withdraw()
            tkMessageBox.showinfo("Save", "Can't save right now. Someone's turn is in progress!")
            return
        array = self._sb.getBoard().getRawBoard()
        first_player = self._sb.getPlayerColors()
        second_player = self._controller.getSecondPlayer()
        turn = self._controller.getActivePlayer()
        turn_number = self._controller.getTurnNumber()
        timer = self._sb.getTimer()
        time = timer.getTime()

        SaveFile.saveFile(array, first_player, second_player, turn, turn_number, time)

        Tkinter.Tk().wm_withdraw()
        tkMessageBox.showinfo("Save", "Save completed successfully.")
Example #2
0
def GameMain():
    
    Rc.Recover()
    while True:
    
        Mn.printMenu()

        choice=input('输入您的选择: ')
        if choice == '3':
            AM.AboutMe()
        if choice == '2':
            SU.SignUp()
        if choice == '1':
            SI.SignIn()
        if choice == '0':
            SF.SaveFile()
Example #3
0
    def load(self):
        try:
            positions, first_player, second_player, playerTurn, turn_number, time = SaveFile.loadFile()
            self._sb.getBoard().setPositions(positions)
            self.newState(STATE_PLAY)
            self._sb.setPlayerColors(first_player)
            self._controller.setSecondPlayer(second_player)
            self._controller.setActivePlayer(playerTurn)
            self._controller.setTurnNumber(turn_number)
            timer = Timer.Timer()
            timer.setTime(time * 1000)
            self._sb.setTimer(timer)
            self._controller.setTimer(timer)
            Tkinter.Tk().wm_withdraw()
            tkMessageBox.showinfo("Load", "Load completed successfully.")

        except BoardException as e:
            Tkinter.Tk().wm_withdraw()
            tkMessageBox.showinfo("Load Error", e)
Example #4
0
    def SaveList(self, destroy=True):
        """
        Sauvegarder le fichier de vocabulaire modifié.
        :return: None
        """

        if len(self.mot) > 2:
            self.sauvegarder = SaveFile.SaveFile()
            self.filepath = self.sauvegarder.getFileName()
            self.activateWindow()
            continuer = True
        else:
            msg = QtWidgets.QMessageBox()
            msg.setWindowTitle("ERREUR")
            msg.setText(
                "Impossible d'enregistrer le fichier: Il n'y a pas assez de mots dans la liste!"
            )
            msg.exec()
            continuer = False
            self.filepath = None

        if self.filepath != None and continuer:
            self.filepath = self.filepath.split(".")
            self.filepath = self.filepath[0]
            file = open(self.filepath + ".vocab", "w+")

            for mot, trad in zip(self.mot, self.trad):
                file.write(mot + "|" + trad + "\n")

            file.close()

            if destroy: self.destroy()
        elif self.filepath == None and continuer:
            msg = QtWidgets.QMessageBox()
            msg.setWindowTitle("ERREUR")
            msg.setText("Impossible d'enregistrer le fichier!")
            msg.exec()
Example #5
0
def gameMenu(user_name, user_password):
    firstGamingGuide(user_name, user_password)
    print('您的基本信息:')
    Ps.persons[SI.users[user_name][2]].printPerson()
    while True:
        print('''
        1 查看关卡
        2 选择关卡
        3 查看背包
        4 穿戴物品
        5 查看人物属性及装备
        0 保存并退出
        ''')
        choice = input('请输入您的选择:')
        if choice == '1':
            GL.printGames()
        if choice == '2':
            pass
        if choice == '3':
            n = 0
            for num in Ps.persons[SI.users[user_name][2]].person_bag:
                print('背包序号:', n)
                Ep.equipments[num].printEquipment()
                n = n + 1
        if choice == '4':
            num = input('请输入您要装备的物品的背包序号或back返回:')
            if num == 'back':
                continue
            elif num not in Ps.persons[SI.users[user_name][2]].person_bag:
                print('没有此装备!')
                continue
            else:
                Ps.persons[SI.users[user_name][2]].updatEquipment(num)
        if choice == '5':
            Ps.persons[SI.users[user_name][2]].printPerson()
        if choice == '0':
            SF.SaveFile()
Example #6
0
def walk_with_exam():
    proc = ProcessHtml.ProcessHtml()
    save_html = SaveFile.SaveHtml()
    exam_html = GlobalVal.spider.get_my_exam(GlobalVal.check_exam_val)
    exam_html_proced = proc.proc_exam(exam_html)
    save_html.save_as_exam(exam_html_proced)
Example #7
0
def walk_with_timetable():
    proc = ProcessHtml.ProcessHtml()
    save_html = SaveFile.SaveHtml()
    timetable_html = GlobalVal.spider.get_my_timetable(GlobalVal.check_timetable_val)
    timetable_html_proced = proc.proc_timetable(timetable_html)
    save_html.save_as_timetable(timetable_html_proced)
Example #8
0
def walk_with_score():
    proc = ProcessHtml.ProcessHtml()
    save_html = SaveFile.SaveHtml()
    score_html = GlobalVal.spider.get_my_score(GlobalVal.check_myscore_val)
    score_html_proced = proc.proc_score(score_html)
    save_html.save_as_score(score_html_proced)
Example #9
0
parser.add_argument(
    '--river-heights',
    help=
    'The background will be colored according to the height of the local river node',
    dest='showRiverHeights',
    action='store_true')
parser.add_argument('-o',
                    '--output-image',
                    help='The image to write',
                    dest='outputFile',
                    metavar='output.png',
                    required=True)
args = parser.parse_args()

resolution, edgeLength, shore, hydrology, cells, Ts = SaveFile.readDataModel(
    args.inputFile  # read the data model
)

imgOutline = cv.imread(args.inputDomain)

# boundaries of the debug image
lowerX = float(args.lowerX) if args.lowerX else 0
lowerY = float(args.lowerY) if args.lowerY else 0
upperX = float(args.upperX) if args.upperX else shore.realShape[0]
upperY = float(args.upperY) if args.upperY else shore.realShape[1]

plt.figure(figsize=(20, 20))  # set the resolution of the debug image

# Generate a background image for context
if not args.showVoronoiCells and not args.showRiverHeights:
    # just show the shoreline
Example #10
0
    help=
    'An experimental method of conserving memory when rendering large terrains',
    dest='extremeMemory',
    action='store_true',
    required=False)
args = parser.parse_args()

inputFile = args.inputFile
outputDir = args.outputDir + '/'
outputResolution = int(args.outputResolution)  # in pixels
numProcs = int(args.num_procs)
latitude = float(args.latitude)
longitude = float(args.longitude)

## Read the data
resolution, edgeLength, shore, hydrology, cells, Ts = SaveFile.readDataModel(
    inputFile)

radius = edgeLength / 3
rwidth = edgeLength / 2

# oceanFloor is calculated ensure that all land appears as green in the output
# image. It should be about 25% of the way up the color ramp
maxq = max([q.elevation for q in cells.allQs() if q is not None])
oceanFloor = 0 - 0.25 * maxq / 0.75

outputShape = (outputResolution, outputResolution
               )  # shape of the output matrix
outputType = np.single  # dtype of the output matrix

# Create an array that is all water by default
imgInit = np.full(outputShape, oceanFloor, dtype=outputType)
Example #11
0
def GameState(screen):
    exit = False
    quit = False
    # remain in the loop until the player exits the game state, either by
    # quiting the game or returning to the menu.
    while not exit:
        moveFlag = False

        # handle player input
        for event in pygame.event.get():
            # quit the game if they press the x button on the window
            if event.type == pygame.QUIT:
                exit = True
                quit = True
                break

            else:
                if event.type == pygame.KEYDOWN:
                    # enter the pause screen if they press escapse
                    if event.key == pygame.K_ESCAPE:
                        pauseFlag = PauseScreen.pauseSequence()
                        # save the game then resume playing if that is what
                        # the player choses
                        if pauseFlag == 2:
                            SaveFile.saveFile(gameStateVariables.enemyWaves, gameStateVariables.enemy_bullet_list, gameStateVariables.player_bullet_list, gameStateVariables.player, shared.score)
                        # return true to leave the game state and return to the
                        # menu if that is what the player choses
                        elif pauseFlag == 3:
                            return True

                # handle player movement
                moveFlag = PlayerMovement.Move(event, gameStateVariables.player)
                gameStateVariables.player.update()  # update player position

        # this is needed to make the player move smoothely
        if not moveFlag:
            gameStateVariables.player.update()

        # Spawn an enemy wave after an enemyWaveDelay, with a max of 4 waves on
        # screen at once
        if (pygame.time.get_ticks() - gameStateVariables.prevEnemySpawnTime) >= shared.enemyWaveDelay and (len(gameStateVariables.enemyWaves) < 4):
            gameStateVariables.prevEnemySpawnTime = pygame.time.get_ticks()
            gameStateVariables.enemyWaves.append(EnemyCreation.EnemyWave())
            if len(gameStateVariables.enemyWaves) > 1:
                if gameStateVariables.enemyWaves[-2].currentY < -shared.enemyBuffer:
                    gameStateVariables.enemyWaves[-1].currentY = gameStateVariables.enemyWaves[-2].currentY
            gameStateVariables.enemyWaves[-1].CreateEnemyWave()

        # update and move all enemy waves
        if (pygame.time.get_ticks() - gameStateVariables.prevEnemyMoveTime >= shared.enemyMoveDelay):
            gameStateVariables.prevEnemyMoveTime = pygame.time.get_ticks()
            toRemove = []
            # iterate through all enemywaves and update their positions
            for i in range(len(gameStateVariables.enemyWaves)):
                gameStateVariables.enemyWaves[i].move(shared.enemyStep)
                # remove enemies if they move off screen
                if gameStateVariables.enemyWaves[i].currentY > shared.height :
                    for j in gameStateVariables.enemyWaves[i].activeIndecies:
                        shared.enemy_list.remove(gameStateVariables.enemyWaves[i].IndexEnemyWave(j))
                        shared.score -= int(gameStateVariables.enemyWaves[i].Etype*100*gameStateVariables.enemyWaves[i].Size*shared.difficulty)
                    toRemove.append(gameStateVariables.enemyWaves[i])
            for e in toRemove:
                gameStateVariables.enemyWaves.remove(e)

        # fire a player bullet after a set delay
        if pygame.time.get_ticks() - gameStateVariables.prevPlayerFireTime >= shared.playerFireDelay:
            gameStateVariables.prevPlayerFireTime = pygame.time.get_ticks()
            gameStateVariables.player_bullet_list.add(Bullets.Bullet("p1", gameStateVariables.player))

        # fire enemy bullet(s) after a set delay
        if pygame.time.get_ticks() - gameStateVariables.prevEnemyFireTime >= shared.enemyFireDelay:
            gameStateVariables.prevEnemyFireTime = pygame.time.get_ticks()
            # chose a random wave from which to fire bullets
            randomIndex = random.randint(0, len(gameStateVariables.enemyWaves) - 1)
            # set the number of bullets to fire according to the enemy type and
            # the difficluty of the game
            bulletNum = 1
            if gameStateVariables.enemyWaves[randomIndex].Etype == 2:
                bulletNum = int(3*shared.difficulty)
            elif gameStateVariables.enemyWaves[randomIndex].Etype == 3:
                bulletNum = int(6*shared.difficulty)
            # fire bulletNum bullets from each active enemy in the wave at a
            # random angle
            prevAngle = 0
            for j in range(bulletNum):
                for i in gameStateVariables.enemyWaves[randomIndex].activeIndecies:
                    randomAngle = random.randint(-20, 20)
                    if i == 0:
                        if prevAngle - 2 < randomAngle and randomAngle < prevAngle + 2:
                            randomAngle += random.randint(-5, 5)
                    prevAngle = randomAngle
                    gameStateVariables.enemy_bullet_list.add(Bullets.Bullet("e1", gameStateVariables.enemyWaves[randomIndex].IndexEnemyWave(i), randomAngle))

        screen.fill(shared.BLACK) # draw background
        shared.enemy_list.draw(screen) # draw enemyWaves
        gameStateVariables.player_list.draw(screen) # draw player
        # draw bullets
        gameStateVariables.player_bullet_list.draw(screen)
        gameStateVariables.enemy_bullet_list.draw(screen)

        bToRemove = []
        # check for collision between player and enemy bullets, damage the
        # player if necessary and destroy the bullet
        collision = pygame.sprite.spritecollideany(gameStateVariables.player, gameStateVariables.enemy_bullet_list, pygame.sprite.collide_mask)
        if collision is not None:
            flag = gameStateVariables.player.changeHealth(-1, screen, gameStateVariables.player_list)
            if flag:
                exit = True
            collision.setActive(False)

        # iterate through enemy bullets. move them and remove the bullets if
        # there was a collisions
        for b in gameStateVariables.enemy_bullet_list:
            if not b.getActive():
                bToRemove.append(b)
            else:
                b.update()
        for b in bToRemove:
            gameStateVariables.enemy_bullet_list.remove(b)

        # iterate through player bullets, move them and check for collisions
        bToRemove = []
        for b in gameStateVariables.player_bullet_list:
            # iterate through all enemy waves to check for collisions
            for EWave in gameStateVariables.enemyWaves:
                collisionFlag = False
                # if bullet is in range of wave in the y direction
                if b.rect.y <= EWave.getCurrentY() + shared.enemyImgHeight and EWave.getCurrentY() <= b.rect.y:
                    # iterate through all active enemies in the wave
                    for i in EWave.activeIndecies:
                        currEnemy = EWave.IndexEnemyWave(i)
                        # if bullet is in range of enemy, damage the enemy and
                        # set the bullet as no longer active
                        if b.rect.x <= currEnemy.rect.right and currEnemy.rect.left <= b.rect.x:
                            b.setActive(False)
                            EWave.impactEnemyAtX(i, 1)
                            collisionFlag = True
                            break
                # if there has been a collision, check the size of the wave
                # and remove the wave if all enemies have been destroyed
                if collisionFlag:
                    if EWave.getSize() <= 0:
                        gameStateVariables.enemyWaves.remove(EWave)
                        break
            # remove bullets that have collided with enemies, and update the
            # position of the remaining bullets
            if not b.getActive():
                bToRemove.append(b)
            else:
                b.update()
        for b in bToRemove:
            gameStateVariables.player_bullet_list.remove(b)

        # check for collision between the player character and all enemies
        for e in gameStateVariables.enemyWaves:
            playerDeath = False
            # only run further checks if the player's y coordinates are in
            # range of the enemy wave
            if e.getCurrentY() <= gameStateVariables.player.rect.bottom and e.getCurrentY() + e.height >= gameStateVariables.player.rect.top:
                for i in e.activeIndecies:
                    currEnemy = e.IndexEnemyWave(i)
                    # if player is in range of individual enemy, then damage
                    # the player and exit the game state if the player dies
                    if gameStateVariables.player.rect.x <= currEnemy.rect.right and currEnemy.rect.left <= gameStateVariables.player.rect.right:
                        playerDeath = gameStateVariables.player.changeHealth(-1, screen, gameStateVariables.player_list)
                        if playerDeath:
                            exit = True
                        e.impactEnemyAtX(i, 1)
                        break
            if e.getSize() <= 0:
                gameStateVariables.enemyWaves.remove(e)
                break

        pygame.display.flip()  # required to show changes to screen
        shared.clock.tick(shared.fps) # limit fps of game to shared.fps
    # if the player exited the game, quit pygame and sys
    if quit:
        pygame.quit()
        sys.exit()
    return False # show that the player is not returning to the menu
Example #12
0
    elif i == 4:
        city_code = raw_input("Enter the city code.")

        valid = QueryData.getroute(city_code)

        if valid == False:
            print "No such code."

    elif i == 5:
        EditRoute.editnetwork()

    elif i == 6:
        EditRoute.addnetwork()

    elif i == 7:
        SaveFile.saveFile()

    elif i == 8:
        RouteInfo.routeinfo()

    elif i == 9:
        MapParser.newMapParser()

    elif i == 10:
        RouteInfo.shortestroute()

    elif i == 0:
        print "See ya!"
        break

    else:
        gameStateVariables.playerBullets = []
        gameStateVariables.enemyBullets = []
        gameStateVariables.enemyWaves = []
        shared.enemy_list = pygame.sprite.Group()
        gameStateVariables.player_bullet_list = pygame.sprite.Group()
        gameStateVariables.enemy_bullet_list = pygame.sprite.Group()
        shared.score = 0

        gameStateVariables.prevEnemySpawnTime = pygame.time.get_ticks(
        ) - shared.enemyWaveDelay
        gameStateVariables.prevPlayerFireTime = gameStateVariables.prevEnemyMoveTime = gameStateVariables.prevEnemyFireTime = pygame.time.get_ticks(
        )

        shared.playerName = ''
        save = SaveFile.loadFile()
        if save:
            gameStateVariables.enemyWaves, gameStateVariables.enemyBullets, gameStateVariables.playerBullets, gameStateVariables.player, shared.score = save
            for b in gameStateVariables.enemyBullets:
                gameStateVariables.enemy_bullet_list.add(b)
            for b in gameStateVariables.playerBullets:
                gameStateVariables.player_bullet_list.add(b)

            gameStateVariables.prevEnemySpawnTime = pygame.time.get_ticks()
            gameStateVariables.player_list.empty()
            gameStateVariables.player_list.add(gameStateVariables.player)

        # restart if no save file is detected
        else:
            Restart = True
        load = False
Example #14
0
    def start(self):
        MapParser.MapParser()
        s = "Type the number for corresponding options:\n" \
            "1. Get all the cities from CSAir\n" \
            "2. Get a specific information about one city\n" \
            "3. Get all kinds of stats\n" \
            "4. Get a specific route\n" \
            "5. Edit the current city's information\n" \
            "6. Add/Remove cities and routes\n" \
            "7. Save the changed list to JSON File\n" \
            "8. Calculuate the total flight\n" \
            "9. Update CSAir with new Champaign hub town\n" \
            "10. Calculate the shortest route between to cities.\n" \
            "0. Exit the program"

        while True:

            print s

            i = raw_input("Enter the number.")
            i = int(i)
            if i == 1:
                cityList = QueryData.citylist()
                print "Here are the lists!"
                for city in cityList:
                    print city

            elif i == 2:
                city_name = raw_input("Enter the city name.")

                valid = QueryData.getcitydata(city_name)

                if valid == False :
                    print "No such city."

            elif i == 3:
                QueryData.getstat()

            elif i == 4:
                city_code = raw_input("Enter the city code.")

                valid = QueryData.getroute(city_code)

                if valid == False :
                    print "No such code."

            elif i == 5:
                EditRoute.editnetwork()

            elif i == 6:
                EditRoute.addnetwork()

            elif i == 7:
                SaveFile.saveFile()

            elif i == 8:
                RouteInfo.routeinfo()

            elif i == 9:
                MapParser.newMapParser()

            elif i == 10:
                self.routeInfo.shortestroute()

            elif i == 0:
                print "See ya!"
                break

            else:
                print "Invalid Number!"
Example #15
0
    def start(self):
        MapParser.MapParser()
        s = "Type the number for corresponding options:\n" \
            "1. Get all the cities from CSAir\n" \
            "2. Get a specific information about one city\n" \
            "3. Get all kinds of stats\n" \
            "4. Get a specific route\n" \
            "5. Edit the current city's information\n" \
            "6. Add/Remove cities and routes\n" \
            "7. Save the changed list to JSON File\n" \
            "8. Calculuate the total flight\n" \
            "9. Update CSAir with new Champaign hub town\n" \
            "10. Calculate the shortest route between to cities.\n" \
            "0. Exit the program"

        while True:

            print s

            i = raw_input("Enter the number.")
            i = int(i)
            if i == 1:
                cityList = QueryData.citylist()
                print "Here are the lists!"
                for city in cityList:
                    print city

            elif i == 2:
                city_name = raw_input("Enter the city name.")

                valid = QueryData.getcitydata(city_name)

                if valid == False:
                    print "No such city."

            elif i == 3:
                QueryData.getstat()

            elif i == 4:
                city_code = raw_input("Enter the city code.")

                valid = QueryData.getroute(city_code)

                if valid == False:
                    print "No such code."

            elif i == 5:
                EditRoute.editnetwork()

            elif i == 6:
                EditRoute.addnetwork()

            elif i == 7:
                SaveFile.saveFile()

            elif i == 8:
                RouteInfo.routeinfo()

            elif i == 9:
                MapParser.newMapParser()

            elif i == 10:
                self.routeInfo.shortestroute()

            elif i == 0:
                print "See ya!"
                break

            else:
                print "Invalid Number!"
Example #16
0
    elif i == 4:
        city_code = raw_input("Enter the city code.")

        valid = QueryData.getroute(city_code)

        if valid == False :
            print "No such code."

    elif i == 5:
        EditRoute.editnetwork()

    elif i == 6:
        EditRoute.addnetwork()

    elif i == 7:
        SaveFile.saveFile()

    elif i == 8:
        RouteInfo.routeinfo()

    elif i == 9:
        MapParser.newMapParser()

    elif i == 10:
        RouteInfo.shortestroute()

    elif i == 0:
        print "See ya!"
        break

    else: