예제 #1
0
    def _checkObjects(self, game: Game, player: IPlayer) -> ActionResult:
        cell = game.labyrinth.getCell(player.x, player.y)
        object = game.labyrinth.getObject(cell)

        if object:
            result = object.activate(player, game)

            if isinstance(object, Treasure):
                return ActionResult.success("step executed, treasure")
            if isinstance(object, Wormhole):
                return ActionResult.success("step executed, wormhole")
            if isinstance(object, River):
                return ActionResult.success("step executed, river (" + str(result) + ")")

        return ActionResult.success("step executed")
예제 #2
0
    def do(self,
           params: List[str],
           game: Game,
           player: IPlayer = None) -> ActionResult:
        if not game.is_started:
            raise InvalidAction("game didn't start yet")

        cell = game.labyrinth.getCell(player.x, player.y)
        object = game.labyrinth.getObject(cell)

        if object and isinstance(object, River):
            result = object.activate(player, game)
            return ActionResult.success("step executed, river (" +
                                        str(result) + ")")

        return ActionResult.success("step skipped")
예제 #3
0
    def do(self,
           params: List[str],
           game: Game,
           player: IPlayer = None) -> ActionResult:
        if not game.is_started:
            raise InvalidAction("game didn't start yet")

        players_cells = {}
        for player in game.players:
            if player.x not in players_cells:
                players_cells[player.x] = {}
            if player.y not in players_cells[player.x]:
                players_cells[player.x][player.y] = player.getName(short=True)

        s = "\n"
        for row in game.labyrinth.cells:
            for cell in row:
                s += '*  ' if cell.canGo(DIRECTION_TOP) else '*--'
            s += "*\n"
            for cell in row:
                s += ' ' if cell.canGo(DIRECTION_LEFT) else '|'

                if cell.x in players_cells and cell.y in players_cells[cell.x]:
                    s += players_cells[cell.x][cell.y]
                else:
                    obj = game.labyrinth.getObject(cell)
                    s += obj.id if obj else "  "

            s += " \n" if cell.canGo(DIRECTION_RIGHT) else "|\n"

        for cell in game.labyrinth.cells[-1]:
            s += '*  ' if cell.canGo(DIRECTION_BOTTOM) else '*--'
        s += "*\n"

        return ActionResult.success(s)
예제 #4
0
    def _checkPlayers(self, game: Game, player: IPlayer) -> ActionResult:
        for other_player in game.players:
            if other_player == player:
                continue
            if other_player.x != player.x or other_player.y != player.y:
                continue

            player.interact(other_player, game)
            other_player.interactBack(player, game)

        return ActionResult.success("step executed")
예제 #5
0
    def do(self, params: List[str], game: Game, player: IPlayer = None) -> ActionResult:
        if len(params) < 1:
            raise InvalidActionParams("filename should be given")

        filename = params[0]

        if (not path.exists(filename)) or (not path.isfile(filename)):
            raise InvalidActionParams("file must be exist")

        try:
            game.load(filename)
        except Exception:
            raise InvalidActionParams("file mast be in the correct format")

        return ActionResult.success("game loaded, let's continue", step_completed=False)
예제 #6
0
    def do(self,
           params: List[str],
           game: Game,
           player: IPlayer = None) -> ActionResult:
        if not game.is_started:
            raise InvalidAction("game didn't start yet")

        if len(params) < 1:
            raise InvalidActionParams("filename should be given")

        filename = params[0]

        try:
            game.save(filename)
        except Exception:
            raise Exception("unexpected error while saving")

        return ActionResult.success("game saved", step_completed=False)
예제 #7
0
    def do(self, params: List[str], game: Game, player: IPlayer = None) -> ActionResult:
        if len(params) < 1:
            raise InvalidActionParams("labyrinth size should be given")
        
        size = int(params[0])

        if (size < 4) or (size > 10):
            raise InvalidActionParams("labyrinth size should be beetween 4 and 10")

        labyrinth_factory = LabyrinthFactory(size=size)
        players_factory = PlayersFactory(
            players_count=1,
            bears_count=1,
            labyrinth_size=size
        )

        game.start(labyrinth_factory, players_factory)

        return ActionResult.success("game created, let's start")
예제 #8
0
    def go(self, player: IPlayer, direction: str) -> ActionResult:
        if self.directions[direction] == SIDE_TYPE_WALL:
            return ActionResult.fail("step impossible, wall")
        if self.directions[direction] == SIDE_TYPE_MONOLITH:
            return ActionResult.fail("step impossible, monolith")

        if (self.directions[direction] == SIDE_TYPE_EXIT):
            if player.canFinish():
                return ActionResult.finish()
            return ActionResult.fail("exit impossible, treasure not found")

        if direction == DIRECTION_LEFT:
            player.x -= 1
        elif direction == DIRECTION_RIGHT:
            player.x += 1
        elif direction == DIRECTION_TOP:
            player.y -= 1
        elif direction == DIRECTION_BOTTOM:
            player.y += 1

        return ActionResult.success("step executed")