Пример #1
0
 def update_level(self):
     self.curr_level += 1
     if self.curr_level < len(self.levels):
         field = Field(os.path.join("levels", self.levels[self.curr_level]))
         self.game_instance = game_logic.Game(field,
                                              self.game_instance.score,
                                              self.game_instance.lives)
Пример #2
0
 def __init__(self, name="", passw=""):
     self.field = Field()
     self.name = name
     while self.name == "":
         self.name = input("Player, please type your name:")
     self.__passw = passw
     while self.__passw == "":
         self.__passw = input(self.name + ", now type your password:")
Пример #3
0
def play_game():
    field = Field(field_size)
    players = (PlayerRandom(0, field_size), PlayerRandom(1, field_size))

    game = Game(field, players, stdout=False)
    _, x, y = game.start()

    return x, y
Пример #4
0
    def test_field_pars_works_well(self):
        try:
            field = Field("tests\\test_board.txt")
        except Exception as e:
            field = Field("test_board.txt")

        self.assertEqual(field.cell(0, 0), game_states.MapCell.FOOD)
        self.assertEqual(field.cell(0, 1), game_states.MapCell.WALL)
        self.assertEqual(field.cell(1, 0), game_states.MapCell.PACMAN)
        self.assertEqual(field.cell(2, 0), game_states.MapCell.BLINKY)
        self.assertEqual(field.cell(1, 1), game_states.MapCell.INKY)
        self.assertEqual(field.cell(2, 1), game_states.MapCell.CLYDE)
        self.assertEqual(field.cell(3, 1), game_states.MapCell.PINKY)
Пример #5
0
def play_game():
    """
    ゲームを開始する。
    :param players: 使用したいプレイヤープログラムを格納する。
    :return:
    """
    field = Field(field_size)

    players = (PlayerRandom(0, field_size), PlayerRandom(1, field_size))

    game = Game(field, players)
    winner, _, _ = game.start()

    return winner
Пример #6
0
 def __init__(self):
     with open(os.path.join("levels", "description.txt")) as f:
         self.levels = f.read().split('\n')
     self.curr_level = 0
     field = Field(os.path.join("levels", self.levels[self.curr_level]))
     self.game_instance = game_logic.Game(field, 0)
Пример #7
0
class Board:
    f1 = Field("O")
    f2 = Field("O")
    f3 = Field("O")
    f4 = Field("O")
    f5 = Field("O")
    f6 = Field("O")
    f7 = Field("O")
    f8 = Field("O")
    f9 = Field("O")
    f10 = Field("O")
    f11 = Field("O")
    f12 = Field("O")
    f13 = Field("O")
    f14 = Field("O")
    f15 = Field("O")
    f16 = Field("O")
    f17 = Field("O")
    f18 = Field("O")
    f19 = Field("O")
    f20 = Field("O")
    f21 = Field("O")
    f22 = Field("O")
    f23 = Field("O")
    f24 = Field("O")

    def __init__(self):
        """Connects all of the fields."""
        self.f1.down = self.f8
        self.f1.right = self.f2
        self.f2.down = self.f10
        self.f2.left = self.f1
        self.f2.right = self.f3
        self.f3.down = self.f4
        self.f3.left = self.f2
        self.f4.up = self.f3
        self.f4.down = self.f5
        self.f4.left = self.f12
        self.f5.up = self.f4
        self.f5.left = self.f6
        self.f6.up = self.f14
        self.f6.left = self.f7
        self.f6.right = self.f5
        self.f7.up = self.f8
        self.f7.right = self.f6
        self.f8.up = self.f1
        self.f8.down = self.f7
        self.f8.right = self.f16
        self.f9.down = self.f16
        self.f9.right = self.f10
        self.f10.up = self.f2
        self.f10.down = self.f18
        self.f10.left = self.f9
        self.f10.right = self.f11
        self.f11.down = self.f12
        self.f11.left = self.f10
        self.f12.up = self.f11
        self.f12.down = self.f13
        self.f12.left = self.f20
        self.f12.right = self.f4
        self.f13.up = self.f12
        self.f13.left = self.f14
        self.f14.up = self.f22
        self.f14.down = self.f6
        self.f14.left = self.f15
        self.f14.right = self.f13
        self.f15.up = self.f16
        self.f15.right = self.f14
        self.f16.up = self.f9
        self.f16.down = self.f15
        self.f16.left = self.f8
        self.f16.right = self.f24
        self.f17.down = self.f24
        self.f17.right = self.f18
        self.f18.up = self.f10
        self.f18.left = self.f17
        self.f18.right = self.f19
        self.f19.down = self.f20
        self.f19.left = self.f18
        self.f20.up = self.f19
        self.f20.down = self.f21
        self.f20.right = self.f12
        self.f21.up = self.f20
        self.f21.left = self.f22
        self.f22.down = self.f14
        self.f22.left = self.f23
        self.f22.right = self.f21
        self.f23.up = self.f24
        self.f23.right = self.f22
        self.f24.up = self.f17
        self.f24.down = self.f23
        self.f24.left = self.f16

        self.dict = {
            "A1": self.f1,
            "A4": self.f2,
            "A7": self.f3,
            "B2": self.f9,
            "B4": self.f10,
            "B6": self.f11,
            "C3": self.f17,
            "C4": self.f18,
            "C5": self.f19,
            "D1": self.f8,
            "D2": self.f16,
            "D3": self.f24,
            "D5": self.f20,
            "D6": self.f12,
            "D7": self.f4,
            "E3": self.f23,
            "E4": self.f22,
            "E5": self.f21,
            "F2": self.f15,
            "F4": self.f14,
            "F6": self.f13,
            "G1": self.f7,
            "G4": self.f6,
            "G7": self.f5
        }

    def __str__(self):
        board = "  1  2  3  4  5  6  7\n" \
                "A {}━━━━━━━━{}━━━━━━━━{}\n" \
                "B ┃  {}━━━━━{}━━━━━{}  ┃\n" \
                "C ┃  ┃  {}━━{}━━{}  ┃  ┃\n" \
                "D {}━━{}━━{}     {}━━{}━━{}\n" \
                "E ┃  ┃  {}━━{}━━{}  ┃  ┃\n" \
                "F ┃  {}━━━━━{}━━━━━{}  ┃\n" \
                "G {}━━━━━━━━{}━━━━━━━━{}".format(self.dict["A1"].middle, self.dict["A4"].middle, self.dict["A7"].middle, self.dict["B2"].middle,
                                                  self.dict["B4"].middle, self.dict["B6"].middle, self.dict["C3"].middle, self.dict["C4"].middle,
                                                  self.dict["C5"].middle, self.dict["D1"].middle, self.dict["D2"].middle, self.dict["D3"].middle,
                                                  self.dict["D5"].middle, self.dict["D6"].middle, self.dict["D7"].middle, self.dict["E3"].middle,
                                                  self.dict["E4"].middle, self.dict["E5"].middle, self.dict["F2"].middle, self.dict["F4"].middle,
                                                  self.dict["F6"].middle, self.dict["G1"].middle, self.dict["G4"].middle, self.dict["G7"].middle)
        return board