def main():
    file_path = os.path.dirname(os.path.realpath(__file__))
    os.chdir(file_path)
    count = 0

    for file in glob.glob("input*.txt"):
        file = file_path+"/"+file
        count = count + 1
        input_type = input("How you want to play all the levels. Press '1' for Automatic and '2' for Manual ?")
        if len(input_type) == 1 and ord(input_type) == 49:
            Auto(file, count)
        elif len(input_type) == 1 and ord(input_type) == 50:
            game(file)
        else:
            print("Illegal Value")
def test1():

    Piece_A = queen("white")
    Piece_A.setPosition("b2")

    Piece_B = king("black")
    Piece_B.setPosition("e5")

    Piece_C = king("white")
    Piece_C.setPosition("b4")

    Piece_D = pawn("black")
    Piece_D.setPosition("c3")

    myGame = game()
    myGame.pieces = [Piece_A, Piece_B, Piece_C, Piece_D]

    print("probando movimiento de las piezas")
    print(
        movementRules(p_piece=Piece_A,
                      p_enviroment=myGame.pieces,
                      p_futurePosition="e5"))

    print("probando la amenaza al rey")
    print(check(myGame.pieces[0], myGame.pieces))
    def test_computer_opponent_outcomes_randomly_distributed(self):
        outcomes = [0, 0, 0]  # player_win, player_lose, draw

        # play 10000 games and check there is an approximately equal distribution of outcomes
        games = 10000
        for play in range(games):
            result = game(self.paper)
            if "Allen beat computer" in result:
                outcomes[0] += 1
            elif "computer beat Allen" in result:
                outcomes[1] += 1
            else:
                outcomes[2] += 1

        proportions = [outcome / games for outcome in outcomes]

        for proportion in proportions:
            self.assertAlmostEqual(0.3, proportion, 1)
def graphic1():

    Piece_A = queen("balck")
    Piece_A.setPosition("b2")

    Piece_B = king("black")
    Piece_B.setPosition("e5")

    Piece_C = king("white")
    Piece_C.setPosition("b4")

    Piece_D = pawn("black")
    Piece_D.setPosition("c3")

    myGame = game()
    myGame.pieces = [Piece_A, Piece_B, Piece_C, Piece_D]

    return Graphicall_environment(myGame.pieces)["draw"]
示例#5
0
    def test_creation_of_game_3_2_1(s):
        game(
            s.db,
            s.mocked_input([{
                "text": '/n',
                "wait": .3
            }, {
                "text": 'function ciao() { return "Ciao" }',
                "wait": .2
            }]))

        game(
            s.db,
            s.mocked_input([{
                "text": '/n',
                "wait": .2
            }, {
                "text": 'function ciao() { return "Ciao" }',
                "wait": .15
            }]))

        game(
            s.db,
            s.mocked_input([{
                "text": '/n',
                "wait": .1
            }, {
                "text": 'function ciao() { return "Ciao" }',
                "wait": .1
            }]))

        pos1 = s.db.getResultPosition(1, s.testId)
        pos2 = s.db.getResultPosition(2, s.testId)
        pos3 = s.db.getResultPosition(3, s.testId)

        s.assertEqual(pos1, 3)
        s.assertEqual(pos2, 2)
        s.assertEqual(pos3, 1)
示例#6
0
 def test_rock_beats_scissors_player2(self):
     self.assertEqual("rock beats scissors", game(self.player2,
                                                  self.player1))
示例#7
0
 def test_paper_beats_rock_player1(self):
     self.assertEqual("paper beats rock", game(self.player3, self.player1))
示例#8
0
 def test_player_has_correct_gesture(self):
     self.assertEqual("play by the rules, a-hole",
                      game(self.player1, self.player4))
示例#9
0
 def test_game_is_draw(self):
     self.assertEqual("draw", game(self.player1, self.player5))
示例#10
0
    def launch(self):
        Globals.player = Pacman()
        # create game and level objects and load first level
        Globals.thisGame = game()
        Globals.thisLevel = Level()
        Globals.thisLevel.LoadLevel(Globals.thisGame.GetLevelNum())
        pygame.mixer.music.set_volume(1)
        pygame.mixer.music.play(-1)

        self.ghostDieAnim = {}
        for i in range(1, 11, 1):
            self.ghostDieAnim[i] = pygame.image.load("res/sprite/exp" +
                                                     str(i) +
                                                     ".png").convert_alpha()

        # self.window = pygame.display.set_mode( Globals.thisGame.screenSize, SWSURFACE  )
        # self.window = pygame.display.set_mode( (1200,825), 0 ,0 )
        self.window.set_alpha(None)

        while True:

            # --------- Background
            # --------------------------------------------------------------

            if Globals.thisGame.mode == 1:
                back_x = 0
                back_y = 0
                if (Globals.thisLevel.levelSize -
                        Globals.thisGame.screenPixelPos[0]
                    ) < Globals.thisLevel.levelOffset:
                    back_x = -Globals.thisLevel.levelOffset
                else:
                    back_x = -Globals.thisGame.screenPixelPos[0]
                if (Globals.thisLevel.levelHeight -
                        Globals.thisGame.screenPixelPos[1]
                    ) < Globals.thisLevel.heightOffset:
                    back_y = -Globals.thisLevel.heightOffset
                else:
                    back_y = -Globals.thisGame.screenPixelPos[1]

                draw(Globals.img_Background, (back_x, back_y))
                # normal gameplay mode
                self.CheckInputs()
                if not self.dialog:
                    Globals.player.Move()
                    for item in Globals.thisLevel.items:
                        if Globals.thisLevel.CheckIfHit(
                            (Globals.player.x, Globals.player.y),
                            (item[0], item[2]), (25, 21)):
                            Globals.thisLevel.items.remove(item)
                            Globals.thisGame.AddToScore(1)
                            Globals.snd_item.play()
                            self.checkCompletion()
                            break
                    for item in Globals.thisLevel.powerups:
                        if Globals.thisLevel.CheckIfHit(
                            (Globals.player.x, Globals.player.y),
                            (item[0], item[2]), (50, 41)) and not item[4] == 0:
                            item[4] = 0
                            mytimer = Timer(10.0, self.turnNormal)
                            mytimer.start()
                            self.PUtimer = 1
                            self.turnVulnerable()
                            break
                    for k, item in Globals.ghosts.items():
                        if Globals.thisLevel.CheckIfHit(
                            (Globals.player.x, Globals.player.y),
                            (item.x, item.y), (50, 90)):
                            if Globals.player.state == 2:
                                Globals.questionId = item.id
                                self.dialog = 1
                                pygame.mixer.music.load(
                                    'res/sounds/Musica/preguntas.ogg')
                                pygame.mixer.music.play(-1)
                                Globals.player.velX = 0
                                Globals.player.velY = 0
                            elif Globals.player.state == 1:
                                Globals.thisGame.AddToScore(-15)
                                if Globals.thisGame.score < 0:
                                    self.gameOver()
                                else:
                                    Globals.thisLevel.Restart()
                                    self.tryAgain = 1
                    Globals.player.Draw()
                    for k, item in Globals.ghosts.items():
                        item.Move()
                    if self.PUtimer > 0:
                        self.PUtimer += 1
                        if (self.PUtimer == 450):
                            self.restorePowerups()
                    if self.ghostDying:
                        draw(self.ghostDieAnim[self.ghostDieFrame],
                             (self.dyingPos[0] -
                              Globals.thisGame.screenPixelPos[0],
                              self.dyingPos[1] -
                              Globals.thisGame.screenPixelPos[1]))
                        self.ghostAnimTimer += 1
                        if self.ghostAnimTimer == 4:
                            self.ghostDieFrame += 1
                            self.ghostAnimTimer = 1
                        if self.ghostDieFrame == 11:
                            self.ghostDieFrame = 1
                            self.ghostDying = 0

            elif Globals.thisGame.mode == 3:
                self.CheckInputs()
                # self.checkPersistence()
                # Globals.thisGame.StartNewGame()
                Globals.thisGame.modeTimer += 1
                if Globals.thisGame.modeTimer == 1:
                    pass
                    # self.checkPersistence()
                elif Globals.thisGame.modeTimer == 30:
                    Globals.img_Background = pygame.image.load(
                        "res/backgrounds/Splash_2.png")
                elif Globals.thisGame.modeTimer == 60:
                    Globals.img_Background = pygame.image.load(
                        "res/backgrounds/Splash_3.png")
                elif Globals.thisGame.modeTimer == 90:
                    Globals.img_Background = pygame.image.load(
                        "res/backgrounds/Splash_4.png")
                elif Globals.thisGame.modeTimer == 120:
                    Globals.img_Background = pygame.image.load(
                        "res/backgrounds/Splash_5.png")
                elif Globals.thisGame.modeTimer >= 150:
                    # if self.persistenceChecked:
                    # self.showScreen(self.screenToGo)
                    # Globals.thisGame.StartNewGame(1)
                    Globals.thisGame.SetMode(9)
                draw(Globals.img_Background, (0, 0))

            elif Globals.thisGame.mode == 4:
                if self.timeOver:
                    draw(self.timeOverImg, (229, 264))
                Globals.thisGame.modeTimer += 1
                if Globals.thisGame.modeTimer == 150:
                    Globals.thisGame.changeToLevel(1)

            elif Globals.thisGame.mode == 6:
                # Globals.thisGame.SetMode(7)
                self.showEmotionTrivia()

            elif Globals.thisGame.mode == 7:
                Globals.thisGame.modeTimer += 1
                draw(self.winImg, (111, 25))
                if Globals.thisGame.modeTimer == 100:
                    self.goNextLevel()

            elif Globals.thisGame.mode == 8:
                # blank screen before changing levels
                Globals.thisGame.modeTimer += 1
                if Globals.thisGame.modeTimer == 10:
                    self.goNextLevel()
                    # Globals.thisGame.SetNextLevel()
            elif Globals.thisGame.mode == 9:
                if Globals.thisGame.modeTimer == 0:
                    back = pygame.image.load(
                        "res/backgrounds/tutorial.png").convert()
                    Globals.thisGame.modeTimer += 1
                draw(back, (0, 0))
                for event in pygame.event.get():
                    if event.type == QUIT:
                        Globals.thisGame.SetMode(10)
                    elif event.type == pygame.KEYDOWN:
                        if event.key == pygame.K_KP1 or event.key == pygame.K_RETURN:
                            Globals.thisGame.SetMode(2)
            elif Globals.thisGame.mode == 2:
                if Globals.thisGame.modeTimer == 0:
                    back = pygame.image.load(
                        "res/backgrounds/select_gender.png").convert()
                    gm1 = pygame.image.load(
                        "res/sprite/select_gender_m1.png").convert_alpha()
                    gm2 = pygame.image.load(
                        "res/sprite/select_gender_m2.png").convert_alpha()
                    gw1 = pygame.image.load(
                        "res/sprite/select_gender_w1.png").convert_alpha()
                    gw2 = pygame.image.load(
                        "res/sprite/select_gender_w2.png").convert_alpha()
                    Globals.thisGame.modeTimer += 1
                draw(back, (0, 0))
                if Globals.selectedCharacter == 'm':
                    draw(gm1, (204, 88))
                    draw(gw2, (561, 88))
                else:
                    draw(gm2, (204, 88))
                    draw(gw1, (561, 88))
                drawScaled(self.inst1, (268, 80), (280, 745))
                drawScaled(self.inst2, (268, 80), (610, 745))

                for event in pygame.event.get():
                    if event.type == QUIT:
                        Globals.thisGame.SetMode(10)
                    elif event.type == pygame.KEYDOWN:
                        if event.key == pygame.K_KP6 or event.key == pygame.K_RIGHT:
                            Globals.selectedCharacter = 'w'
                        elif event.key == pygame.K_KP4 or event.key == pygame.K_LEFT:
                            Globals.selectedCharacter = 'm'
                        elif event.key == pygame.K_KP1 or event.key == pygame.K_RETURN:
                            Globals.player = Pacman()
                            Globals.thisGame.modeTimer = 0
                            Globals.thisGame.StartNewGame(1)

            elif Globals.thisGame.mode == 10:
                for event in pygame.event.get():
                    if event.type == QUIT:
                        pass
                if Globals.thisGame.modeTimer == 0:
                    Globals.img_Background = pygame.image.load(
                        "res/backgrounds/Splash_final.png")
                    draw(Globals.img_Background, (0, 0))
                    # self.savePersistence()
                if Globals.thisGame.modeTimer == 150:
                    sys.exit(0)

            elif Globals.thisGame.mode == 11:
                Globals.thisGame.SetMode(9)

            if not Globals.thisGame.mode == 8:
                # Globals.thisLevel.DrawMap()
                if Globals.thisGame.mode == 1:
                    Globals.thisGame.SmartMoveScreen()
                    Globals.thisLevel.drawItems()
                    self.drawPowerups()
                    for k, item in Globals.ghosts.items():
                        item.Draw()

                    if self.dialog:
                        self.showDialog()
                    if self.tryAgain:
                        draw(self.tryAgainImg, (229, 250))
                        self.tryAgainTimer += 1
                        if self.tryAgainTimer == 60:
                            self.tryAgain = 0
                            self.tryAgainTimer = 0

                    # indicadores de items, siempre deben ir de ultimo
                    draw(self.fondoItem, (0, 0))
                    draw(self.starIcon, (5, 10))
                    self.__collectedItemsIndicator.setText(
                        'x ' + str(Globals.thisGame.score))
                    self.__collectedItemsIndicator.doPaint()
                    draw(self.clockBack, (495, 0))
                    draw(self.clockImg, (500, 3))
                    self.__timeRemainingIndicator.setText(
                        self.getRemainingTime())
                    self.__timeRemainingIndicator.doPaint()
                    Globals.thisGame.timer += 1
                    if Globals.thisGame.timer == 17550:
                        pygame.mixer.music.load("res/sounds/FX/reloj.ogg")
                        pygame.mixer.music.play(-1)
                    if Globals.thisGame.timer == 18000:
                        pygame.mixer.music.stop()
                        self.gameOver()
            pygame.display.update()
            self.clock.tick(30)
示例#11
0
 def test_input_1_is_invalid(self):
     self.assertEqual("please enter valid player", game(self.player1, 2))
 def test_player_has_correct_gesture(self):
     self.assertEqual(
         "Invalid gesture: Valid gestures are - rock, paper, scissors.",
         game(self.rock, self.cheat))
    def test_single_player_input_activates_computer(self):
        outcome_as_list = "draw"
        while "draw" in outcome_as_list:
            outcome_as_list = (game(self.rock)).split()

        self.assertTrue("computer" in outcome_as_list)
 def test_scissors_beats_paper_player2_win(self):
     self.assertEqual("Edward beat Allen (scissors beats paper)",
                      game(self.paper, self.scissors))
示例#15
0
from src.game import game_world as game
from os import chdir as cd

if __name__ == '__main__':
    cd("src")  # gamb mode-on
    game()
 def test_paper_beats_rock_player2_win(self):
     self.assertEqual("Allen beat Dwayne (paper beats rock)",
                      game(self.rock, self.paper))
 def test_rock_beats_scissors_player2_win(self):
     self.assertEqual("Dwayne beat Edward (rock beats scissors)",
                      game(self.scissors, self.rock))
 def test_game_is_draw(self):
     self.assertEqual("draw: Dwayne and Dwayne both chose rock",
                      game(self.rock, self.rock))
示例#19
0
 def test_scissors_beats_paper_player1(self):
     self.assertEqual("scissors beats paper",
                      game(self.player3, self.player2))
 def test_input_is_valid(self):
     self.assertEqual("Invalid input: Please enter valid player",
                      game(1, 2))
 def test_one_input_is_invalid(self):
     self.assertEqual("Invalid input: Please enter valid player",
                      game(self.rock, 2))
     self.assertEqual("Invalid input: Please enter valid player",
                      game("string", self.paper))
 def test_not_enough_inputs(self):
     self.assertEqual("not enough players added to the game", game())