Example #1
0
def main_automated(moves=[]):
    text = checking_file("maps\map_good.txt")
    new_game = Map(text)
    new_map = new_game.mapping()
    move = Moves(new_map)
    if new_map is not False:
        current_room = new_map[0].name
        for move_to in moves:
            print("You are in room: " + current_room)
            if new_game.mapping() is not False:
                print("Possible moves: " +
                      str(move.possible_moves_in_room(current_room).keys()))
                print("For exit press 'x'")
                next_move = move_to
                print("Your choice: " + move_to)
                if next_move.strip() == 'x':
                    break
                if next_move in new_game.moves.keys():
                    current_room = move.move(next_move, current_room)
                else:
                    print("Wrong letter, you did not move")
                time.sleep(1)
            else:
                print("Error in map - check the map")
                return False
Example #2
0
 def __init__(self, screen):
     self.players = default_players()
     self.map = Map.new()
     self.map.cells = []
     self.screen = screen
     self.buttons = [Button("Menu", (window_width - 60, 0, 60, 30))]
     self.messagebox = []
     self.adjustrect = []
     self.textbox = []
     self.box = []
     self.map_buttons = []
Example #3
0
def main(argv):
	if len(argv) != 2:
		print 'USAGE:'
		print argv[0],'level'
		exit()

	m = Map.load(argv[1])
	while not m.done:
		m.show()
		c = raw_input('>')
		print 'res:', m.execute(c)
	m.show()
Example #4
0
def main_bad_map():

    text = checking_file("maps\map_wrong_direction.txt")
    new_game = Map(text)
    new_map = new_game.mapping()
    move = Moves(new_map)
    if new_map is not False:
        current_room = new_map[0].name
        while True:
            print("You are in room: " + current_room)
            if new_game.mapping() is not False:
                print("Possible moves: " +
                      str(move.possible_moves_in_room(current_room).keys()))
                print("For exit press 'x'")
                next_move = input("your choice: ")
                if next_move.strip() == 'x':
                    break
                if next_move in new_game.moves.keys():
                    current_room = move.move(next_move, current_room)
                else:
                    print("Wrong letter, you did not move")
            else:
                print("Error in map - check the map")
                return False
Example #5
0
    def __init__(self, maps, key_handler):
        self.score = 0
        self.target = type('', (), dict(x=600, y=20))
        self.player = None
        self.draw = False
        self.start_position = dict(x=190, y=550, rotation=-30)
        maps = maps or []
        self.key_handler = key_handler
        self.maps = [Map(map) for map in maps]
        if len(maps) == 2:
            self.gates = Gate(maps[0], maps[1])

        # neat
        self.population = Population(
            target=self.target,
            player=lambda: Player(rotation=0, x=20, y=20),
            maps=self.maps,
            count=1000,
        )
Example #6
0
 def load(self, map_name):
     self.map = Map.load(map_name)
     player_list = maps.player_list()
     self.map.init_players(player_list)
Example #7
0
def play():
    """Initiate a game, using the command line arguments as configuration."""
    arguments = docopt(__doc__)

    if arguments['list_rules']:
        # list all possible game rules
        names = [
            name.replace('.py', '') for name in listdir('rules')
            if '__init__' not in name and '.pyc' not in name
        ]
        print('\n'.join(names))
    elif arguments['list_maps']:
        # list all possible maps
        print('\n'.join(listdir('maps')))
    else:
        # start a game
        # parse arguments
        rules_name = arguments['RULES']
        initial_zombies = int(arguments['-z'])
        minimum_zombies = int(arguments['-n'])
        docker_isolator = arguments['-i']
        debug = arguments['-d']
        isolator_port = int(arguments['-p'])
        use_basic_icons = arguments['-b']
        max_frames = int(arguments['-f'])
        use_arduino = arguments['-a']
        arduino_device = arguments['-v']
        arduino_bauds = int(arguments['-u'])

        player_names = []
        for player_part in arguments['PLAYERS'].split(','):
            if ':' in player_part:
                player_name, count = player_part.split(':')
                count = int(count)
            else:
                player_name = player_part
                count = 1
            player_names.extend([
                player_name,
            ] * count)

        size = arguments['-s']
        if size:
            size = tuple(map(int, size.split('x')))

        map_name = arguments['-m']
        if map_name:
            map_file = path.join('maps', map_name)
            map_ = Map.from_file(map_file)

            if size:
                if size[0] < map_.size[0] or size[1] < map_.size[1]:
                    message = "Map (%s) doesn't fit in specified size (%s) " \
                              "(leave it empty to use best fit)"
                    raise Exception(message % (str(map_.size), str(size)))
                else:
                    map_.size = size
        else:
            if not size:
                size = 30, 10

            map_ = Map(size, [])

        # create and start game
        g = Game(rules_name=rules_name,
                 player_names=player_names,
                 map_=map_,
                 initial_zombies=initial_zombies,
                 minimum_zombies=minimum_zombies,
                 docker_isolator=docker_isolator,
                 isolator_port=isolator_port,
                 debug=debug,
                 use_basic_icons=use_basic_icons,
                 use_arduino=use_arduino,
                 arduino_device=arduino_device,
                 arduino_bauds=arduino_bauds)
        g.play(max_frames)
    def __setMap(self):

        self.map = Map.Map(self.ctl, self.MAX_HEIGHT_COUNT)
Example #9
0
        for e in event.get():
            if e.type == QUIT or (e.type == KEYDOWN and e.key == K_ESCAPE):
                MAIN_LOOP = False
                HOME_LOOP = False
                GAME_LOOP = False
                display.flip()

            if e.type == KEYDOWN and e.key == K_RETURN:
                window.blit(transform.scale(BACKGROUND, SCREEN_SIZE), (0, 0))
                window.blit(transform.scale(WELCOME, SCREEN_SIZE), (0, 0))
                display.flip()

                HOME_LOOP = False
                GAME_LOOP = True
                window.blit(transform.scale(BACKGROUND, SCREEN_SIZE), (0, 0))
                labyrinth = Map(FILE)
                labyrinth.generate()
                labyrinth.display(window)
                display.flip()
                Macgyver = Player(labyrinth)
                display.flip()
                while GAME_LOOP:
                    time.Clock().tick(30)
                    for e in event.get():
                        if e.type == QUIT:
                            MAIN_LOOP = False
                            GAME_LOOP = False
                        if e.type == KEYDOWN:
                            if e.key == K_RIGHT:
                                Macgyver.move('right')
                            if e.key == K_LEFT:
Example #10
0
def play():
    """Initiate a game, using the command line arguments as configuration."""
    arguments = docopt(__doc__)

    if arguments['list_rules']:
        # list all possible game rules
        names = [name.replace('.py', '')
                 for name in listdir('rules')
                 if '__init__' not in name and '.pyc' not in name]
        print('\n'.join(names))
    elif arguments['list_maps']:
        # list all possible maps
        print('\n'.join(listdir('maps')))
    else:
        # start a game
        # parse arguments
        rules_name = arguments['RULES']
        initial_zombies = int(arguments['-z'])
        minimum_zombies = int(arguments['-n'])
        docker_isolator = arguments['-i']
        debug = arguments['-d']
        isolator_port = int(arguments['-p'])
        use_basic_icons = arguments['-b']
        max_frames = int(arguments['-f'])
        use_arduino = arguments['-a']
        arduino_device = arguments['-v']
        arduino_bauds = int(arguments['-u'])

        player_names = []
        for player_part in arguments['PLAYERS'].split(','):
            if ':' in player_part:
                player_name, count = player_part.split(':')
                count = int(count)
            else:
                player_name = player_part
                count = 1
            player_names.extend([player_name, ] * count)

        size = arguments['-s']
        if size:
            size = tuple(map(int, size.split('x')))

        map_name = arguments['-m']
        if map_name:
            map_file = path.join('maps', map_name)
            map_ = Map.from_file(map_file)

            if size:
                if size[0] < map_.size[0] or size[1] < map_.size[1]:
                    message = "Map (%s) doesn't fit in specified size (%s) " \
                              "(leave it empty to use best fit)"
                    raise Exception(message % (str(map_.size), str(size)))
                else:
                    map_.size = size
        else:
            if not size:
                size = 30, 10

            map_ = Map(size, [])

        # create and start game
        g = Game(rules_name=rules_name,
                 player_names=player_names,
                 map_=map_,
                 initial_zombies=initial_zombies,
                 minimum_zombies=minimum_zombies,
                 docker_isolator=docker_isolator,
                 isolator_port=isolator_port,
                 debug=debug,
                 use_basic_icons=use_basic_icons,
                 use_arduino=use_arduino,
                 arduino_device=arduino_device,
                 arduino_bauds=arduino_bauds)
        g.play(max_frames)
Example #11
0
    def handle_msg_all(self, msg):
        if msg['msg_type_id'] == 1 and msg['content']['type'] == 0:
            if re.search(r"restart",msg['content']['data'])!=None:
                self.m=Map()
                self.robot_switch=True
                self.send_msg_by_uid(u"游戏重新启动!",self.group_id)
                
        if not self.robot_switch: # and msg['msg_type_id'] != 1
            return
        if msg['msg_type_id'] == 3 and msg['content']['type'] == 0:  # group text message
            if 'detail' in msg['content']:

                src_id=msg['content']['user']['id']
                self.group_id=msg['user']['id']
                if msg['content']['type'] == 0:  # text message
                    mm=msg['content']['desc']
                    result_join=re.match(self.pattern_join,mm)
                    if result_join!=None:
                        src_name=result_join.group(2)
                        if src_id in self.m.players:
                            self.send_msg_by_uid("@"+src_name+'\n'+"已经加入!",self.group_id)
                        else:
                            if src_name in self.m.names:
                                self.send_msg_by_uid("@"+src_name+'\n'+"名字已存在!",self.group_id)
                                return
                            p = Player(src_id,src_name)                 
                            self.m.addplayer(p)
                            self.send_msg_by_uid("@"+src_name+'\n'+"加入成功!",self.group_id)
                    #else:
                        #self.send_msg_by_uid("sorry,错误的名字格式不利于游戏平衡\n正确格式:1至4个英文字母",self.group_id)
       
                            
        elif msg['msg_type_id'] == 4 and msg['content']['type'] == 0:
            src_id=msg['user']['id']
            mm=msg['content']['data']
            result_atk=re.match(self.pattern_atk,mm)
            result_skl=re.match(self.pattern_skl,mm)
            result_mov=re.match(self.pattern_mov,mm)
            
            if mm == 's':
                if src_id in self.m.players:
                    self.send_msg_by_uid(self.m.getplayerinfo(src_id), src_id)
                        
            elif result_mov!=None:
                if src_id in self.m.players:
                    self.send_msg_by_uid(self.m.moveplayer(src_id,mm), src_id)
                        
            elif result_atk!=None:
                pid=self.get_id(result_atk.group(2))
                if pid==None or src_id==pid:
                    self.send_msg_by_uid("无效攻击!",src_id)
                    return
                msga=self.m.attackplayer(src_id,pid)
                self.send_msg_by_uid(msga[0],src_id)
                self.send_msg_by_uid(msga[1],pid)
                self.send_msg_by_uid(msga[2],self.group_id)
                            
            elif result_skl!=None:
                pid=self.get_id(result_skl.group(2))
                if pid!=None:
                    pid=pid[1:]
                if src_id in self.m.players==False:
                    return
                msgk=self.m.castskill(src_id,pid)
                self.send_msg_by_uid(msgk[0],src_id)
                if msgk[1]!=():
                    for victim in msgk[1][1]:
                        self.send_msg_by_uid(msgk[1][0],victim)
                self.send_msg_by_uid(msgk[2],self.group_id)
                            
            if self.m.event_death!=[]:
                for event in self.m.event_death:
                    if event[0].character!=0:
                        self.send_msg_by_uid(u"竞争就是这么残酷,杀手永远无情,唯有活到最后,才是真的王者!\n\n"+event[0].name+u'被'+event[1].name+event[2],self.group_id)
                        self.send_msg_by_uid(u"很遗憾!你出局了!凶手:"+event[1].name,event[0].id)
                    
                self.m.event_death=[]
                if len(self.m.players)<=1:
                    for winner in self.m.players.values():
                        self.send_msg_by_uid(u"Winner Winner, Chicken Dinner!\n恭喜"+winner.name+u'!'+'\n\n等待造物主xzq授权重新开始游戏...',self.group_id)
                    self.robot_switch = False
Example #12
0
 def __init__(self):
     WXBot.__init__(self)
     self.m=Map()
     self.group_id=''
     self.robot_switch = True
Example #13
0
 def createEmptyMap(self):
     emptyMap = Map(self.scene, self, editor=True)
     emptyMap.addTile("NONE", [0, 0], 0)
     emptyMap.addTile("NONE", [1, 0], 1)
     emptyMap.addTile("NONE", [2, 0], 2)
     emptyMap.addTile("NONE", [0, 1], 3)
     emptyMap.addTile("NONE", [1, 1], 4)
     emptyMap.addTile("NONE", [2, 1], 5)
     emptyMap.addTile("NONE", [3, 1], 6)
     emptyMap.addTile("NONE", [-1, 2], 7)
     emptyMap.addTile("NONE", [0, 2], 8)
     emptyMap.addTile("NONE", [1, 2], 9)
     emptyMap.addTile("NONE", [2, 2], 10)
     emptyMap.addTile("NONE", [3, 2], 11)
     emptyMap.addTile("NONE", [0, 3], 12)
     emptyMap.addTile("NONE", [1, 3], 13)
     emptyMap.addTile("NONE", [2, 3], 14)
     emptyMap.addTile("NONE", [3, 3], 15)
     emptyMap.addTile("NONE", [0, 4], 16)
     emptyMap.addTile("NONE", [1, 4], 17)
     emptyMap.addTile("NONE", [2, 4], 18)
     emptyMap.setTileNumbers(arg=[-1] * 19)
     return emptyMap