def load_in_to_class(self): ''' DataFrame: ''' self.dataSource = [] connection = dataSource.Database().get_connection() cursor = connection.cursor(dictionary=True) try: cursor.execute('SELECT * FROM players;') data = cursor.fetchall() for result in data: try: # the attributes are the inGame order stats = [result['vitality'], result['wisdom'], result['strength'], result['intelligence'], result['chance'], result['agility']] if result['color1'] == -1: color1 = 'ffffffff' else: color1 = hex(result['color1']).replace("0x","") if result['color2'] == -1: color2 = 'ffffffff' else: color2 = hex(result['color2']).replace("0x","") if result['color3'] == -1: color3 = 'ffffffff' else: color3 = hex(result['color3']).replace("0x","") player = Player(result['id'], result['name'], result['account'], result['group'], result['sexe'], result['class'], color1, color2, color3, result['kamas'], result['spellboost'], result['capital'], result['energy'], result['level'], result['xp'], result['size'], result['gfx'], result['alignement'], result['honor'], result['deshonor'], result['alvl'], stats, result['seeFriend'], result['seeAlign'], result['seeSeller'], result['channel'], result['map'], result['cell'], result['pdvper'], result['spells'], result['objets'], result['storeObjets'], result['savepos'], result['zaaps'], result['jobs'], result['mountxpgive'], result['title'], result['wife'], result['morphMode'], result['emotes'], result['prison'], result['server'], result['logged'], result['allTitle'], result['parcho'], result['timeDeblo'], result['noall'],) self.dataSource.append(player) except: self.log.warning('player_data.py - player:{} can\'t be loaded'.format(result['id'])) return self.dataSource except Exception as Error: self.log.warning('player_data.py - Can\'t load table player') self.log.warning(str(Error)) finally: cursor.close() connection.close()
def __init__(self, name, addr, port): pygame.init() self.requests = Requests(addr, port) self.window = Window(name) self.keyboard = {} self.maze = [[]] self.player = Player(name) self.otherPlayers = [] self.treasurePos = None self.winner = "" self.soundShot = pygame.mixer.Sound(Constants.SOUND_SHOT) self.running = True
def test_gm(player): if 0: from client.player import Player player = Player() print player.game_master.reward(42) print player.game_master.add_item(38, 1, can_trade=1) print player.game_master.use_item_ex(38) player.game_master.status_inc('bfBestCount') print player.game_master.status_get('bfBestCount') player.game_master.status_inc('bfBestCount', -1) print player.game_master.status_get('bfBestCount') print player.game_master.status_set('bfBestCount', 1, 1) player.game_master.attr_set('test_json', dict(a=1, b=2, c=[1, 2, 3])) print player.game_master.attr_get('test_json')
def merge_fate_test(player, type): """ 命格合成测试 type=0 背包内的合并 type=1 都在身上的合并 type=2 将身上的命格放到背包某命格合并 type=3 将背包里的某命格放到身上某命格合并 """ if 0: from client.player import Player player = Player() #清理数据 player.game_master.clear_player() player.game_master.add_role(3) roles = player.role.role_roles() tRole = roles[0] print "tRole = ", tRole tIlsit = player.bag.bag_get_ilist() if not tIlsit['fate']: player.game_master.add_fate(ADD_FATEID_HP) player.game_master.add_fate(ADD_FATEID_STK) #player.game_master.add_fate(ADD_FATEID_DEF) tIlsit = player.bag.bag_get_ilist() tFates = tIlsit['fate'] print "bag merge_fate : [%s, %s]" % (tFates[0], tFates[1]) if type == 1: #都在身上的合并 player.role.role_wear_fate(tFates[0]['id'], tRole['id'], 1) player.role.role_wear_fate(tFates[1]['id'], tRole['id'], 2) elif type == 2: # 将身上的命格放到背包某命格合并 player.role.role_wear_fate(tFates[0]['id'], tRole['id'], 1) elif type == 3: #将背包里的某命格放到身上某命格合并 player.role.role_wear_fate(tFates[1]['id'], tRole['id'], 1) if type: re = player.role.role_merge_fate(tFates[0]['id'], tFates[1]['id'], tRole['id']) else: re = player.role.role_merge_fate(tFates[0]['id'], tFates[1]['id']) #显示结果 print "re = ", re tIlsit = player.bag.bag_get_ilist() print 'res-fate = ', tIlsit['fate'] roles = player.role.role_roles() tRole = roles[0] print "res-tRole = ", tRole
def fete_test(player, type): """ 祭天测试 """ if 0: from client.player import Player player = Player() #进入祭天 rs = player.role.role_enter_enterFete() print "role_enter_enterFete = %s", rs #进行祭天 # for i in xrange(50): # rs = player.role.role_fete(type) # if rs.has_key('item'): # print 'item-count-', rs['item'][0]['count'] # else: # print 'item--NO--', rs['frid'] rs = player.role.role_fete(type) print "role_fete = %s", rs
def equip_move_test(player): """ 装备等级转移测试 """ if 0: from client.player import Player player = Player() tRole = _handle_data(player) tIlsit = player.bag.bag_get_ilist() for tEq in tIlsit['equip']: if tEq['eid'] == EQUIP_QUALITY_SMALL_EID: tWearEqId = tEq['id'] player.role.role_wear_eq(tWearEqId, tRole['id']) else: tBagEqId = tEq['id'] print "change (%s, %s)" % (tWearEqId, tBagEqId) player.bag.bag_eq_move(tRole['id'], tWearEqId, tBagEqId) tIlsit = player.bag.bag_get_ilist() print "tIlsit.equip = ", tIlsit['equip'] roles = player.role.role_roles() for role in roles: if role['id'] == tRole['id']: print "tRole =", role break
def hit_fate_test(player, type, isBatch=0): """ 猎命测试 type:1 普通猎命 type:2 元宝猎命 """ if 0: from client.player import Player player = Player() #print 'play_data = %s, %s, %s ', player.info['coin1'], player.info['coin2'], player.info['coin3'] #进入猎命 rs = player.role.role_enter_hitFate() #print "role_enter_hitFate = %s", rs #进行猎命 if not isBatch: #非批量猎命 for i in xrange(1): rs = player.role.role_hitFate(type) print 'rs--type', rs['wait'][0]['items'] else: #批量猎命 rs = player.role.role_hitFate(type, isBatch)
def update(self): """ This function is ran every frame """ new = get_keyboard_state() if new != self.keyboard_state: self.keyboard_state = new self.nursery.start_soon(self.pdata.stream.write, { "type": "keyboard", "state": self.keyboard_state }) # see if there any fresh updates from the server try: update = self.update_getch.receive_nowait() except trio.WouldBlock: # no updates available, "guess" what should be happening for player in self.players.values(): player.update() return if update['type'] != 'update': log.warning(f"Recieved invalid update: {update}") return # update state from server self.lps= update['lps'] for username in update['gone_players']: del self.players[username] log.info(f"Remove player {username}") for username, state in update['players'].items(): self.players[username].update_state(state['pos']) for username, state in update['new_players'].items(): self.players[username] = Player(username, state['pos'], state['color'], self.pdata.fonts) log.info(f"Add new player {self.players[username]}")
def redraw_other_players(self, other_players_points: List[Point]): for player_point in other_players_points: Player(self.canvas, 'red', player_point)
from client import constants from client.cursor import Cursor from client.enemy import Enemy from client.event_dispatcher import game_dispatcher as dispatcher from client.events import events as Events from client.player import Player from client.vector import Vector pygame.init() run = True win = pygame.display.set_mode( (constants.screen_width, constants.screen_height)) pygame.display.set_caption("Super Game") player = Player() enemy = Enemy(300, 300) cursor = Cursor() clock = pygame.time.Clock() pygame.mouse.set_visible(False) def update_player_velocity(keys): vector = Vector() if keys[pygame.K_a]: vector.x = -0.5 if keys[pygame.K_d]: vector.x = 0.5 if keys[pygame.K_w]: vector.y = -0.5
def setUp(self): self.player = Player('Kieran')
class TestPlayer(unittest.TestCase): def setUp(self): self.player = Player('Kieran') @patch('requests.get') def test_make_request_to_server__get(self, mock_get): make_request_to_server('some/endpoint') mock_get.assert_called() @patch('requests.post') def test_make_request_to_server__post(self, mock_post): make_request_to_server('some/endpoint', method='POST', body={'body': 'hello'}) mock_post.assert_called() @patch('builtins.print') @patch('client.player.make_request_to_server') def test_establish_connection(self, mock_make_request, _): mock_response = Mock(status_code=200) mock_response.json.return_value = { 'game_id': '123', 'player': { 'player_id': '456', 'disc': 'X' } } mock_make_request.return_value = mock_response self.assertTrue(self.player.establish_connection()) self.assertEqual(self.player.disc, 'X') self.assertEqual(self.player.game_id, '123') self.assertEqual(self.player.player_id, '456') @patch('builtins.print') @patch('time.sleep') @patch('client.player.make_request_to_server', side_effect=Exception) def test_establish_connection__cannot_connect(self, *_): self.assertRaises(Exception, self.player.establish_connection) @patch('client.player.make_request_to_server') def test_drop_disc__no_winner_after_drop(self, mock_make_request): mock_response = Mock(status_code=200) mock_response.json.return_value = { 'game_id': '123', 'winner': None, 'state': 'PLAYING' } mock_make_request.return_value = mock_response self.player.drop_disc(5) self.assertIsNone(self.player.winner) self.assertEqual(self.player.game_state, 'PLAYING') @patch('client.player.make_request_to_server') def test_drop_disc__winner_after_drop(self, mock_make_request): mock_response = Mock(status_code=200) mock_response.json.return_value = { 'game_id': '123', 'winner': '456', 'state': 'WINNER' } mock_make_request.return_value = mock_response self.player.player_id = '456' self.player.drop_disc(5) self.assertEqual(self.player.winner, '456') self.assertEqual(self.player.game_state, 'WINNER') @patch('client.player.make_request_to_server') def test_drop_disc__invalid_column(self, mock_make_request): mock_response = Mock(status_code=400) mock_response.json.return_value = {'message': 'Invalid column: 5'} mock_make_request.return_value = mock_response with self.assertRaises(Exception) as e: self.player.drop_disc(5) self.assertEqual('Invalid column: 5', str(e.exception)) @patch('builtins.print') @patch('client.player.make_request_to_server') def test_poll_until_other_player_connected__other_player_joined( self, mock_make_request, _): mock_response = Mock(status_code=200) mock_response.json.return_value = {'opponent': True} mock_make_request.return_value = mock_response self.assertTrue(self.player.poll_until_other_player_connected()) @patch('time.sleep') @patch('builtins.print') @patch('client.player.make_request_to_server') def test_poll_until_other_player_connected(self, *_): with self.assertRaises(Exception) as e: self.player.poll_until_other_player_connected() self.assertEqual( 'No opponent joined within the timeout of 60 seconds.', str(e.exception)) @patch('builtins.print') @patch('time.time', side_effect=[0, 1]) @patch('client.player.Player.get_game_status', return_value={ 'state': 'PLAYING', 'winner': None, 'player_turn': '123' }) def test_poll_until_turn__players_turn(self, *_): self.player.player_id = '123' self.assertTrue(self.player.poll_until_turn()) @patch('builtins.print') @patch('time.time', side_effect=[0, 1]) @patch('client.player.Player.get_game_status', return_value={ 'state': 'WINNER', 'winner': '123', 'player_turn': '123' }) def test_poll_until_turn__winner_found(self, *_): self.assertFalse(self.player.poll_until_turn()) self.assertEqual(self.player.game_state, 'WINNER') @patch('time.sleep') @patch('time.time', side_effect=[0, 1, 100]) @patch('client.player.Player.get_game_status', return_value={ 'state': 'PLAYING', 'winner': None, 'player_turn': '456' }) @patch('builtins.print') def test_poll_until_turn__opponent_disconnected(self, mock_print, *_): self.player.player_id = '123' self.assertFalse(self.player.poll_until_turn()) mock_print.assert_called_with( 'Opponent took to long to respond. You are the winner.') self.assertEqual(self.player.player_id, self.player.winner) @patch( 'client.player.Player.get_game_status', return_value={ 'game_board': " ['_' '_' '_' '_' '_' '_' '_' '_' '_']\n ['_' '_' '_' '_' '_' '_' '_' '_' '_']\n ['_' '_' '_' '_' '_' '_' '_' '_' '_']\n ['_' '_' '_' '_' '_' '_' '_' '_' '_']\n ['_' '_' '_' '_' '_' '_' '_' '_' '_']\n ['_' '_' '_' '_' '_' '_' '_' '_' '_']\n\n 1 2 3 4 5 6 7 8 9 " }) @patch('builtins.print') def test_display_board(self, mock_print, _): self.player.display_board() mock_print.assert_called_with( " ['_' '_' '_' '_' '_' '_' '_' '_' '_']\n ['_' '_' '_' '_' '_' '_' '_' '_' '_']\n ['_' '_' '_' '_' '_' '_' '_' '_' '_']\n ['_' '_' '_' '_' '_' '_' '_' '_' '_']\n ['_' '_' '_' '_' '_' '_' '_' '_' '_']\n ['_' '_' '_' '_' '_' '_' '_' '_' '_']\n\n 1 2 3 4 5 6 7 8 9 \n" ) @patch('builtins.print') @patch('builtins.input', side_effect=list(range(1, 9))) def test_select_column__valid_inputs(self, *_): for i in range(1, 9): self.assertEqual(select_column(), i - 1) @patch('builtins.input', side_effect=['100', '6']) @patch('builtins.print') def test_select_column__invalid_column_number(self, mock_print, _): self.assertEqual(select_column(), 5) mock_print.assert_called_with('Invalid range: 100 not in range (1-9)') @patch('builtins.input', side_effect=['Not a number', '6']) @patch('builtins.print') def test_select_column__invalid_input_string(self, mock_print, _): self.assertEqual(select_column(), 5) mock_print.assert_called_with('Please enter an integer') @patch('client.player.Player.establish_connection') @patch('client.player.Player.poll_until_other_player_connected', side_effect=Exception( 'No opponent joined within the timeout of 60 seconds.')) @patch('builtins.input', return_value='Kieran') def test_start_game__opponent_did_not_join(self, *_): with self.assertRaises(Exception) as e: start_game() self.assertEqual( 'No opponent joined within the timeout of 60 seconds.', str(e.exception)) @patch('client.player.select_column') @patch('builtins.input', return_value='Kieran') @patch('client.player.Player.establish_connection') @patch('client.player.Player.poll_until_other_player_connected') @patch('client.player.Player.display_board') @patch('client.player.Player.drop_disc') @patch('client.player.Player.poll_until_turn') @patch('client.player.create_player') @patch('builtins.print') def test_start_game__player_win(self, mock_print, mock_player, *_): self.player.game_state = 'WINNER' self.player.winner = self.player.player_id mock_player.return_value = self.player start_game() mock_print.assert_called_with('You won. Congratulations!!!') @patch('builtins.input', return_value='Kieran') def test_create_player(self, _): player = create_player() self.assertEqual(player.player_name, 'Kieran') @patch('client.player.select_column') @patch('builtins.input', return_value='Kieran') @patch('client.player.Player.establish_connection') @patch('client.player.Player.poll_until_other_player_connected') @patch('client.player.Player.display_board') @patch('client.player.Player.drop_disc') @patch('client.player.Player.poll_until_turn') @patch('client.player.create_player') @patch('builtins.print') def test_start_game__player_lost(self, mock_print, mock_player, *_): self.player.game_state = 'WINNER' self.player.winner = '123' mock_player.return_value = self.player start_game() mock_print.assert_called_with('You lost.')
def create_player(self, accId, name, pClass, sex, color1, color2, color3): __playerID = 0 for player in self.playersData: if player.get_id() > __playerID: __playerID = player.get_id() __playerID = __playerID + 1 __startMapCellList = self.constant.get_start_map_incarnam(pClass) player = Player( __playerID, name, accId, -1, # id, name, account, group, sex, pClass, color1, color2, color3, # sexe, pClass, color1-3, 0, 1, '', 10000, 1, # kamas, spellboost, capital, energy, level, #0, 100, pClass * 10 + sex, # xp, size, gfx, 0, 100, (pClass * 10 + sex), # xp, size, gfx, 0, 0, 0, 0, # alignement, honor, deshonor, alvl, [0, 0, 0, 0, 0, 0], 1, 0, # stats(list), seeFriend, seeAlign, 0, '*#$p^', __startMapCellList[0], # seeSeller, channel, map, __startMapCellList[1], 100, # cell, pdvper, '141;', # spells <-- TODO placeholder '', '', # objets, storeObjets, str(__startMapCellList[0]) + ':' + str(__startMapCellList[1]), # savepos '', '', 0, # zaaps, jobs, mountxpgive, 0, 0, '0;0', # title, wife, morphMode, '', 0, 1, # emotes, prison, server, <-- TODO placeholder True, '', # logged allTitle '118,0;119,0;123,0;124,0;125,0;126,0', 0, 0, ) # parcho, timeDeblo, noall del __startMapCellList self.playersData.append(player)
def __init__(self, player): self.player = player if 0: from client.player import Player self.player = Player()