Example #1
0
    def exec(self, context: GameContext):
        room = context.get_current_room()

        if self.name in room._exits:
            context.current_room = room._exits['zapad']
            context.get_current_room().show()
            context.history.append(self.name)
        else:
            print('Tam sa nedá ísť.')
Example #2
0
    def exec(self, context:GameContext):
        """
        Enter the room on east from current room.
        If there is no exit to the east, then no change. The new room will be returned from the function.
        :param world: the world the player is in
        :param current_room: the name of current room player is in
        :return: the name of new room on the east
        """
        room = context.get_current_room()

        if self.name in room._exits:
            context.current_room = room._exits['vychod']
            context.get_current_room().show()
            context.history.append(self.name)
        else:
            print('Tam sa nedá ísť.')
Example #3
0
 def exec(self, context: GameContext):
     try:
         item = context.backpack.remove_item(self.params)
         room = context.get_current_room()
         room['items'].append(item)
         print(f'{item.name} si vyložil z batohu.')
         context.history.append(f'{self.name} {self.params}')
     except ItemNotFoundException:
         print('Taký predmet u seba nemáš.')
Example #4
0
    def exec(self, context: GameContext):
        room = context.get_current_room()
        items = room['items'] + context.backpack

        for item in items:
            if item.name == self.params:
                if not isinstance(item, UsableMixin):
                    print('Tento predmet sa nedá použiť')
                    return

                context.history.append(f'{self.name} {item.name}')
                item.use(context)

        print('Taký predmet tu nikde nevidím.')
Example #5
0
    def exec(self, context: GameContext):
        room = context.get_current_room()
        for item in room['items']:
            if item.name == self.params:
                if not isinstance(item, MovableMixin):
                    print('Tento predmet sa nedá vziať.')
                elif len(context.backpack) >= 1:
                    print('Batoh je plný.')
                else:
                    context.backpack.add_item(item)
                    room['items'].remove(item)
                    print(f'{item.name} si vložil do batohu.')
                    context.history.append('f{self.name} {item.name}')

                break  # return
        else:
            print('Taký predmet tu nikde nevidím.')
Example #6
0
    def exec(self, context: GameContext):
        name = self.params

        # search in backpack
        if name in context.backpack:
            print(context.backpack[name].description)
            return

        room = context.get_current_room()
        items = room['items']

        for item in items:
            if item.name == self.params:
                print(item.description)
                return

        print('Taký predmet tu nikde nevidím.')
Example #7
0
def fresh_gc_ef(n_players=random.randint(4, 8)):
    players = [player.Player("CPU_{}".format(
        i), 'unused', 'unused', True) for i in range(1, n_players + 1)]
    ef = elements.ElementFactory()

    gc = GameContext(
        players=players,
        characters=ef.CHARACTERS,
        black_cards=ef.BLACK_DECK,
        white_cards=ef.WHITE_DECK,
        green_cards=ef.GREEN_DECK,
        areas=ef.AREAS,
        ask_h=lambda x, y, z: {'value': random.choice(y['options'])},
        tell_h=lambda x, y, *z: 0,
        show_h=lambda x, *y: 0,
        update_h=lambda: 0
    )
    return (gc, ef)
Example #8
0
def main():
    # inicializacia hry
    context = GameContext()
    context.init_game()
    context.backpack = Backpack(2)
    context.backpack.add_item(Whip())
    context.world = world

    commands = [
        About(),
        LookAround(),
        Inventory(),
        Quit(),
        North(),
        South(),
        East(),
        West(),
        Down(),
        # Up(),
        UseItem(),
        DropItem(),
        TakeItem(),
        ExamineItem(),
        Save()
    ]

    commands.append(Commands(commands))
    commands.append(Help(commands))

    parser = Parser(commands)

    print("Indiana Jones")
    context.get_current_room().show()

    while context.state == 'playing':
        line = input('> ')

        try:
            command = parser.parse(line)
            command.exec(context)
        except UnknownCommandException:
            print('Taký príkaz nepoznám.')
Example #9
0
 def exec(self, context: GameContext):
     print('ta diky ze si si zahral tuto mocnu hru, lebo je fakt mocna.')
     context.state = 'quit'
Example #10
0
def on_start(json):

    # Get room and players in it
    R.connection_lock.acquire()
    room_id = get_room_id(rooms, request.sid)
    if not room_id:
        R.connection_lock.release()
        return

    people_in_room = rooms[room_id]['connections']
    names_and_sids = [(people_in_room[x], x) for x in people_in_room.keys()]

    # Check for false start
    n_players = max(min(int(json['n_players']), 8), 4)
    if len(names_and_sids) > n_players:
        R.connection_lock.release()
        packet = {'field': n_players, 'actual': len(names_and_sids)}
        socketio.emit('false_start', packet, room=request.sid)
        return

    # Initialize human and AI players
    rgb = ['rgb(245,245,245)', 'rgb(100,100,100)', 'rgb(79,182,78)',
           'rgb(62,99,171)', 'rgb(197,97,163)', 'rgb(219,62,62)',
           'rgb(249,234,48)', 'rgb(239,136,43)']
    human_players = [Player(n[0], n[1], rgb.pop(0), False)
                     for n in names_and_sids]
    ai_players = [Player("CPU_{}".format(i), str(i), rgb.pop(0), True)
                  for i in range(1, n_players - len(human_players) + 1)]
    players = human_players + ai_players

    # Initialize game context with players and emission functions
    ef = ElementFactory()
    gc = GameContext(
        players=players,
        characters=ef.CHARACTERS,
        black_cards=ef.BLACK_DECK,
        white_cards=ef.WHITE_DECK,
        hermit_cards=ef.HERMIT_DECK,
        areas=ef.AREAS,
        ask_h=lambda x, y, z: socket_ask(x, y, z, room_id),
        tell_h=None,
        show_h=None,
        update_h=None
    )
    gc.tell_h = lambda x, y, *z: socket_tell(x, y, gc, room_id, z)
    gc.show_h = lambda x, *y: socket_show(x, gc, room_id, y)
    gc.update_h = lambda: socket_update(gc.dump()[0], room_id)

    # Assign game to room
    if rooms[room_id]['status'] == 'GAME':
        R.connection_lock.release()
        return
    rooms[room_id]['gc'] = gc
    rooms[room_id]['status'] = 'GAME'

    R.connection_lock.release()

    # Send public and private game states to frontend
    gc.tell_h("Loading game...", [])
    public_state, private_state = gc.dump()
    for priv in private_state:
        data = {
            'public': public_state,
            'private': priv
        }
        socketio.emit('game_start', data, room=priv['socket_id'])
    socketio.sleep(1)
    gc.tell_h("Started a game with players {}".format(
        ", ".join(['{}'] * len(players))), [p.user_id for p in players])

    # Initiate gameplay loop
    gc.play()
Example #11
0
 def exec(self, context: GameContext):
     context.get_current_room().show()