Пример #1
0
    def up_date_game(self):
        '''
            セットされた情報をもとにゲームの情報を更新する
        '''
        if (self.client_to_server_data_ == None):
            print("クライアント側からの情報がセットされていません。")
            return
        if (self.is_init_game_ == False):
            #完成まではランダムに決めない
            #self.maze_ = MAZE_LIST[random.randint(0,2)]
            self.maze_ = MAZE_LIST[1]
            print("迷路を決定しました。")
            self.create_player_info()
            print("ゲームの情報を生成しました。")
            self.is_init_game_ = True
        else:
            self.up_date_all_object_info()

        self.turn_ += 1
        self.game_info_ = GameInfo()
        self.game_info_.set_maze(self.maze_)
        self.game_info_.set_turn(self.turn_)
        self.game_info_.set_player_info_list(
            self.player_info_manager_.get_all_object_info())
        self.game_info_.set_bullet_info_list(
            self.bullet_info_manager_.get_all_object_info())
        self.game_info_.set_item_info_list(
            self.item_info_manager_.get_all_object_info())
        print("ゲームの情報を更新しました。")
        return
Пример #2
0
class GameState:
    'This container Class stores information about a quizduell game state'
    def __init__(self, dicVal):
        
        # these must be included
        self.your_question_types        = dicVal['your_question_types']
        self.elapsed_min                = dicVal['elapsed_min']
        self.cat_choices                = dicVal['cat_choices']
        self.opponent_answers           = dicVal['opponent_answers']
        self.messages                   = dicVal['messages']
        self.your_answers               = dicVal['your_answers']
        self.state                      = dicVal['state']
        self.mode                       = dicVal['mode']
        self.is_image_question_disabled = dicVal['is_image_question_disabled']
        self.your_turn                  = dicVal['your_turn']
        self.game_id                    = dicVal['game_id']
        self.opponent_question_types    = dicVal['opponent_question_types']
        self.opponent_name              = dicVal['opponent']['name']
        self.opponent_uid               = dicVal['opponent']['user_id']
        
        # this value is lazily being fetched just in time for performance reasons
        self.game_info = GameInfo(self.game_id)
        
        # optional dicVal
        if 'rating_bonus' in dicVal:
            self.rating_bonus = dicVal['rating_bonus']
            
    def getPlayerScore(self):
        counter = 0
        for answer in self.your_answers:
            if answer == 0:
                counter += 1

        return counter
    
    def getOpponentScore(self):
        counter = 0
        for answer in self.opponent_answers:
            if answer == 0:
                counter += 1

        return counter

    def printDetails(self):
        print "Dumping GameState to Console:"
        print "your_question_types       : " + str(self.your_question_types)
        print "elapsed_min               : " + str(self.elapsed_min)
        print "cat_choices               : " + str(self.cat_choices)
        print "opponent_answers          : " + str(self.opponent_answers)
        print "messages                  : " + str(self.messages)
        print "your_asnwers              : " + str(self.your_answers)
        print "state                     : " + str(self.state)
        print "mode                      : " + str(self.mode)
        print "is_image_question_disabled: " + str(self.is_image_question_disabled)
        print "your_turn                 : " + str(self.your_turn)
        print "game_id                   : " + str(self.game_id)
        print "opponent_question_types   : " + str(self.opponent_question_types)
        print "opponent_name             : " + str(self.opponent_name)
        self.game_info.printDetails()
Пример #3
0
 def __init__(self):
     #オブジェクトのidを管理する
     self.id_list_ = []
     #ipが同じ可能性があるのでリストに格納する--->いるか?
     self.ip_name_list_ = []
     self.is_init_game_ = False
     self.maze_ = None
     self.turn_ = 0
     self.player_info_manager_ = PlayerInfoManager()
     self.bullet_info_manager_ = BulletInfoManager()
     self.item_info_manager_ = ItemInfoManager()
     self.game_info_ = GameInfo(
     )  #------------------------------------------------->こいつの管理がメイン
     self.server_to_client_data_ = None
     self.client_to_server_data_ = None
     print("GameInfoManagerオブジェクトを生成しました。")
Пример #4
0
    def fill_db(self):
        '''
        Fill the DB with all our games, using data from gameinfo.
        '''
        conn = sqlite3.connect(DB_PATH)
        cur = conn.cursor()

        print("Getting titles and IDs from BGG API to fetch info...")
        all_games_dict = bggapi_get.get_game_dict()  # ids and titles
        data_to_fill = []

        print("Collecting all games data from bgg-json.azurewebsites.net...")
        for game_id in all_games_dict.keys(
        ):  #collect all data from all games to feed it to db, key=name
            one_game_dict = GameInfo().get_game_info(game_id)
            if one_game_dict:
                data_to_fill.append(self.get_tuple(one_game_dict))

        print("Filling database...")
        stmt = '''
        INSERT OR REPLACE INTO Games (title, id, player_num_min, player_num_max,
        playing_minutes, coco, mechanics, url)
        VALUES (?, ?, ?, ?, ?, ?, ?, ?)
        '''
        cur.executemany(stmt, data_to_fill)  #fill in all games

        conn.commit()
        cur.close()
        print("Done! Total: " + str(len(data_to_fill)) + " games")
Пример #5
0
 def __init__(self):
     self.id_list = []
     #ipが同じ可能性があるのでリストに格納する
     self.ip_name_list = []
     #self.maze_object_ = Maze()---------------------------------->必要なし
     self.player_info_maneger_ = PlayerInfoManager()
     self.bullet_info_maneger_ = BulletInfoManager()
     self.item_info_manager_ = ItemInfoManager()
     self.game_info_ = GameInfo()
     self.client_to_server_packet_ = ClientToServerPacket()
     self.server_to_client_packet_ = ServerToClientPacket()
     self.maze_server_socket = MazeServerSocket()
     print("ゲーム開始準備 開始")
Пример #6
0
def enter():
    global cookie, stage, pet, game_timer, gameinfo, hp_time
    game_timer = get_time()
    hp_time = get_time()
    cookie = Cookie()
    gameinfo = GameInfo()
    stage = Stage()
    pet = Pet()
    game_world.objects = [[], [], [], []]
    game_world.add_object(stage, 0)
    game_world.add_object(cookie, 1)
    game_world.add_object(pet, 2)
    game_world.add_object(gameinfo, 3)
Пример #7
0
    def fill_in_missing(self):
        '''
        An alternative to fill_db().
        Retrieve from BGG only the games missing in the db.
        This reduces the load on the BGG and BGG-JSON servers.
        '''
        current_collection = self.titles_in_collection()
        conn = sqlite3.connect(DB_PATH)
        cur = conn.cursor()

        print("Getting titles and IDs from BGG API to fetch info...")
        all_games_dict = bggapi_get.get_game_dict()  # ids and titles
        data_to_fill = []

        print(
            "Collecting missing/new games data from bgg-json.azurewebsites.net..."
        )
        for game_id in all_games_dict.keys(
        ):  #collect all data from all games to feed it to db, key=name
            if all_games_dict[
                    game_id] not in current_collection:  # remove the games already in collection
                one_game_dict = GameInfo().get_game_info(game_id)
                if one_game_dict:
                    data_to_fill.append(self.get_tuple(one_game_dict))

        print("Filling database...")
        stmt = '''
        INSERT OR REPLACE INTO Games (title, id, player_num_min, player_num_max,
        playing_minutes, coco, mechanics, url)
        VALUES (?, ?, ?, ?, ?, ?, ?, ?)
        '''
        cur.executemany(stmt, data_to_fill)  #fill in all games

        conn.commit()
        cur.close()
        print("Done! Total: " + str(len(data_to_fill)) +
              " new games retrieved")
Пример #8
0
 def __init__(self, dicVal):
     
     # these must be included
     self.your_question_types        = dicVal['your_question_types']
     self.elapsed_min                = dicVal['elapsed_min']
     self.cat_choices                = dicVal['cat_choices']
     self.opponent_answers           = dicVal['opponent_answers']
     self.messages                   = dicVal['messages']
     self.your_answers               = dicVal['your_answers']
     self.state                      = dicVal['state']
     self.mode                       = dicVal['mode']
     self.is_image_question_disabled = dicVal['is_image_question_disabled']
     self.your_turn                  = dicVal['your_turn']
     self.game_id                    = dicVal['game_id']
     self.opponent_question_types    = dicVal['opponent_question_types']
     self.opponent_name              = dicVal['opponent']['name']
     self.opponent_uid               = dicVal['opponent']['user_id']
     
     # this value is lazily being fetched just in time for performance reasons
     self.game_info = GameInfo(self.game_id)
     
     # optional dicVal
     if 'rating_bonus' in dicVal:
         self.rating_bonus = dicVal['rating_bonus']
Пример #9
0
import sys
from gameinfo import GameInfo
from connhandle import buildConnection, sendMsgToServer, listenServerInfo
from util import writeLog, fileClean, setFileName

if __name__ == '__main__':
    uip = sys.argv[1]
    uport = int(sys.argv[2])
    myip = sys.argv[3]
    myport = int(sys.argv[4])
    myid = sys.argv[5]
    myname = 'kobe'

    print '\ngameserver ip: ', uip
    print 'gameserver port: ', uport
    print 'my ip: ', myip
    print 'my port: ', myport
    print 'my id:', myid
    print 'my name: ', myname
    setFileName(myid)
    fileClean()

    gameinfo = GameInfo()
    gameinfo.myid = myid
    skt = buildConnection(myip, myport, uip, uport)
    # 发送注册信息
    regmsg = 'reg: %s %s\n' % (myid, myname)
    regSend = 'Send message: %s' % regmsg
    writeLog(regSend)
    sendMsgToServer(skt, regmsg)
    listenServerInfo(skt, gameinfo)
class GameScraper:
    def __init__(self, url):
        self.url = url
        self._bs = None
        self._info = GameInfo()

    def _get_html(self, path=""):
        html = requests.get(self.url.strip() + path)
        bs = BeautifulSoup(html.text, "html.parser")
        return bs

    def scrape(self) -> GameInfo:
        self._scrape_detail_page()
        self._scrape_line_up_page()
        return self._info

    def _scrape_detail_page(self):
        self._bs = self._get_html()
        self._add_team_names()
        self._add_goals()
        self._add_stats()
        self._add_result_infos()
        self._add_game_info()

    def _scrape_line_up_page(self):
        self._bs = self._get_html("aufstellung")
        self._add_home_coach()
        self._add_away_coach()
        self._add_line_up("heim")
        self._add_line_up("gast")

    def _add_away_coach(self):
        try:
            away_coach = self._get_coach_block("gast").get_text()
            self._info.away_team_add_info("coach", away_coach)
        except AttributeError:
            pass

    def _add_home_coach(self):
        try:
            home_coach = self._get_coach_block("heim").get_text()
            self._info.home_team_add_info("coach", home_coach)
        except AttributeError:
            pass

    def _get_coach_block(self, which="gast"):
        return self._bs.find_all("div", {"class": f"{which}-content"})[2].find(
            "a", {"class": "text lineup"})

    def _add_line_up(self, which="gast"):
        player_blocks = self._get_player_blocks(which)
        players_names = self._convert_player_blocks_to_player_names(
            player_blocks)
        if which == "heim":
            self._info.home_team_add_info("lineup", players_names)
        elif which == "gast":
            self._info.away_team_add_info("lineup", players_names)

    def _get_player_blocks(self, which):
        lineup = self._bs.find("div", {"class": f"{which}-content"})
        try:
            names = lineup.find("div", {
                "class": "box-taktik"
            }).findAll("a", {"class": "name"})
        except AttributeError:
            names = lineup.findAll("a", {"class": "text lineup"})
        return names

    def _convert_player_blocks_to_player_names(self, player_blocks):
        player_links = list(map(_get_link, player_blocks))
        players = list(map(_get_name, player_links))
        return players

    def _add_team_names(self):
        away_name, home_name = self._extract_team_names()
        self._info.home_team_add_info("name", home_name)
        self._info.away_team_add_info("name", away_name)

    def _extract_team_names(self):
        names = self._bs.findAll("span", {"class": "verein-name"})
        home_name = names[0].get_text()
        away_name = names[2].get_text()
        return away_name, home_name

    def _add_goals(self):
        away_goals, home_goals = self._extract_team_goals()
        self._info.home_team_add_info("goals", int(home_goals))
        self._info.away_team_add_info("goals", int(away_goals))

    def _extract_team_goals(self):
        goals = self._bs.find("div", {"class": "box-spiel-ergebnis"})
        home_goals, away_goals = goals.get_text().split(":")
        return away_goals, home_goals

    def _add_stats(self):
        stats = self._bs.find("div", {
            "class": "box bs hide-empty"
        }).findAll("div", {"class": "col-md-6"})
        for stat in stats:
            for stat_child in stat.children:
                self._add_stat(stat_child)

    def _add_stat(self, stat):
        desc = self._extract_desc(stat)
        if desc:
            stats = stat.find_all("span")
            if len(stats) == 2:
                home_stat, away_stat = stats
                home_stat = _save_cast_to_float(home_stat.get_text())
                away_stat = _save_cast_to_float(away_stat.get_text())
                self._info.home_team_add_info(desc, home_stat)
                self._info.away_team_add_info(desc, away_stat)

    def _extract_desc(self, stat):
        desc = stat.find("div", {"class": "text-center"})
        if desc == "Tore":
            return None
        if desc:
            desc = desc.get_text()
            desc = _desc_german_to_english(desc)
            return desc
        return None

    def _add_result_infos(self):
        result_infos = list(
            self._bs.find("div", {
                "class": "ergebnis-info"
            }).children)[1]
        self._add_season_time(result_infos)
        self._add_date_playday(result_infos)

    def _add_date_playday(self, result_infos):
        result_infos = result_infos.get_text()
        league = self._extract_league(result_infos)
        result_infos = result_infos[result_infos.find("-") + 1:]
        gameday = result_infos[:result_infos.find(".")].strip()
        result_infos = result_infos[result_infos.find("-") + 1:]
        if "-" in result_infos:
            result_infos = result_infos[:result_infos.find("-")]
        date = result_infos[result_infos.find(",") + 1:].strip()
        self._info.game_info_add("league", league)
        self._info.game_info_add("date", date)
        self._info.game_info_add("gameday", gameday)

    def _extract_league(self, result_infos):
        league = result_infos[:result_infos.find("-")]
        league = league.split()[:-1]
        league = " ".join(league)
        return league

    def _add_season_time(self, result_infos):
        season, time = self._extract_season_time(result_infos)
        self._info.game_info_add("time", time)
        self._info.game_info_add("season", season)

    def _extract_season_time(self, result_infos):
        season_time = result_infos.findAll("span", {"class": "hidden-mini"})
        time = None
        if _is_time_included(season_time):
            season, time = season_time
            season = season.get_text()
            time = self._clean_time(time)
        else:
            season = season_time[0].get_text()
        return season, time

    def _clean_time(self, time):
        time = time.get_text().strip()
        time = time.replace("Uhr", "").strip()
        return time

    def _add_game_info(self):
        referee, location, stadium, visitors = self._extract_referee_location_stadium_visitors(
        )
        self._info.game_info_add("referee", referee)
        self._info.game_info_add("location", location)
        self._info.game_info_add("stadium", stadium)
        self._info.game_info_add("visitors", visitors)

    def _extract_referee_location_stadium_visitors(self):
        game_infos = self._bs.find(
            "div", {"class": "box bs green-top box-spielinfos"})
        if game_infos:
            referee, location, stadium, visitors = [
                i.get_text()
                for i in game_infos.findAll("b", {"class": "pull-right"})
            ]
            return referee, location, stadium, visitors.replace(".", "")
        return None, None, None, None
Пример #11
0
class GameInfoManager(object):
    """
    ゲーム全体の情報を管理するクラス
    """
    def __init__(self):
        #オブジェクトのidを管理する
        self.id_list_ = []
        #ipが同じ可能性があるのでリストに格納する--->いるか?
        self.ip_name_list_ = []
        self.is_init_game_ = False
        self.maze_ = None
        self.turn_ = 0
        self.player_info_manager_ = PlayerInfoManager()
        self.bullet_info_manager_ = BulletInfoManager()
        self.item_info_manager_ = ItemInfoManager()
        self.game_info_ = GameInfo(
        )  #------------------------------------------------->こいつの管理がメイン
        self.server_to_client_data_ = None
        self.client_to_server_data_ = None
        print("GameInfoManagerオブジェクトを生成しました。")

    def set_maze(self, maze):
        self.maze_ = maze

    def set_turn(self, turn):
        self.turn_ = turn

    def set_player_info_manager(self, player_info_manager):
        self.player_info_maneger_ = player_info_manager

    def set_bullet_info_manager(self, bullet_info_manager):
        self.bullet_info_maneger_ = bullet_info_manager

    def set_item_info_manager(self, item_info_manager):
        self.item_info_manager_ = item_info_manager

    def set_game_info(self, game_info):
        '''
            これを使うことはない
        '''
        pass

    def set_server_to_client_data(self, server_to_client_data):
        '''
            これを使うことはない
        '''
        self.server_to_client_data_ = server_to_client_data

    def set_client_to_server_data(self, client_to_server_data):
        print("GIMが新しいプレイヤーの情報を受け取りました。")
        self.client_to_server_data_ = client_to_server_data

    def get_maze(self):
        return self.maze_

    def get_turn(self):
        return self.turn_

    def get_player_info_manager(self):
        return self.player_info_maneger_

    def get_bullet_info_manager(self):
        return self.bullet_info_maneger_

    def get_item_info_manager(self):
        return self.item_info_manager_

    def get_game_info(self):
        '''
            これも使いたくない が 使い
        '''
        print("新しいGameInfoオブジェクトをMazeserverクラスに渡します。")
        return self.game_info_

    def get_server_to_client_data(self):
        '''
            これ使わないかも
        '''
        return self.server_to_client_data_

    def get_client_to_server_data(self):
        return self.client_to_server_data_

    def create_player_info(self):
        '''
            ゲーム開始準備中にプレイヤーから受け取ったipと名前の辞書を受け取り、idと初期座標を設定して
            プレイヤー情報を生成する。
        '''

        print("プレイヤー情報生成開始")
        name_list = []
        color_list = []
        maze_edge = []
        posi_list = []

        #迷路の端の座標を設定
        x_min = 0
        y_min = 0
        x_max = len(self.maze_[0]) - 1
        y_max = len(self.maze_) - 1
        maze_edge = [[x_min, y_min], [x_min, y_max], [x_max, y_min],
                     [x_max, y_max]]

        for id, player_dict in enumerate(self.client_to_server_data_):
            self.id_list_.append(id)
            name_list.append(player_dict[PLAYER_NAME])
            color_list.append(COLORS[id])
            posi_list.append(maze_edge[id])
            #print(player_dict)
        #参加プレイヤーの情報を生成
        self.player_info_manager_.init_player_info(self.id_list_, name_list,
                                                   color_list, posi_list)

        print("プレイヤー情報生成完了")

    def up_date_game(self):
        '''
            セットされた情報をもとにゲームの情報を更新する
        '''
        if (self.client_to_server_data_ == None):
            print("クライアント側からの情報がセットされていません。")
            return
        if (self.is_init_game_ == False):
            #完成まではランダムに決めない
            #self.maze_ = MAZE_LIST[random.randint(0,2)]
            self.maze_ = MAZE_LIST[1]
            print("迷路を決定しました。")
            self.create_player_info()
            print("ゲームの情報を生成しました。")
            self.is_init_game_ = True
        else:
            self.up_date_all_object_info()

        self.turn_ += 1
        self.game_info_ = GameInfo()
        self.game_info_.set_maze(self.maze_)
        self.game_info_.set_turn(self.turn_)
        self.game_info_.set_player_info_list(
            self.player_info_manager_.get_all_object_info())
        self.game_info_.set_bullet_info_list(
            self.bullet_info_manager_.get_all_object_info())
        self.game_info_.set_item_info_list(
            self.item_info_manager_.get_all_object_info())
        print("ゲームの情報を更新しました。")
        return

    def set_all_player_command(self):
        '''
            サーバーから受け取ったプレイヤーのコマンドを設定する。
        '''
        for player_info in self.client_to_server_data_:
            id = player_info[PLAYER_ID]
            next_command = player_info[NEXT_COMMAND]
            print(id, next_command)
            self.player_info_manager_.set_next_command(id, next_command)
        print("すべてのプレイヤーの次のコマンドをセットしました")

    def create_id(self):
        '''
            まだ生成されていないidを生成して返す
        '''
        #とりあえず1000個までオブジェクト作れるようにしておこう
        for id in range(1000):
            if (not (id in self.id_list_)):
                self.id_list_.append(id)
                print("id = ", id, "を生成しました。")
                return id
        print("これ以上idを生成できませんでした。")
        return -1

    def delete_id(self, id):
        '''
            指定したidを削除する
        '''
        self.id_list_.remove(id)
        print("id = ", id, "を削除しました。")

    def up_date_all_object_info(self):
        '''
            ゲーム上のすべてのオブジェクトを更新する
        '''
        print("オブジェクトの情報を更新します。")

        ###################################################################################ここの処理まだ不安
        #弾丸を生成してから移動させるのは面倒なので最初に弾丸を移動させる
        print("全ての弾丸の座標を移動させます。")
        bullet_info_list = self.bullet_info_manager_.get_all_object_info()
        for i in range(len(bullet_info_list)):
            bullet_info = bullet_info_list[i]
            bullet_info.update_posi()
            if (bullet_info.is_posi_error()):
                id = bullet_info.get_id()
                self.bullet_info_manager_.delete_object_info(id)
                self.delete_id(id)
            else:
                self.bullet_info_manager_.update_object_info(bullet_info)
        ################################################################################################

        self.set_all_player_command()
        #########################################################################################################プレイヤーのコマンドを実行
        print("すべてのプレイヤーオブジェクトのコマンドを実行します")
        player_info_list = self.player_info_manager_.get_all_object_info()
        for i in range(len(player_info_list)):
            player_info = player_info_list[i]
            command_type = player_info.get_next_command_type()
            if (command_type == JOIN):
                #############################これ起こりえない
                print(JOIN)
                pass
            elif (command_type == MOVE):
                print(MOVE)
                #print(player_info.get_posi())
                #print(player_info.get_next_command())
                player_info.update_posi()
                self.player_info_manager_.update_object_info(player_info)
                #print(player_info.get_posi())
            elif (command_type == ATTACK):
                print(ATTACK)
                id = self.create_id()
                self.bullet_info_manager_.create_bullet_info(id, player_info)
                #print(len(self.bullet_info_manager_.get_all_object_info()))
                self.bullet_info_manager_.object_info_list_[-1].show_info()
                bullet_info = self.bullet_info_manager_.object_info_list_[-1]
                if (bullet_info.is_posi_error()):
                    id = bullet_info.get_id()
                    self.bullet_info_manager_.delete_object_info(id)
                    self.delete_id(id)
                else:
                    self.bullet_info_manager_.update_object_info(bullet_info)
                #print(len(self.bullet_info_manager_.get_all_object_info()))

                #self.bullet_info_manager_.object_info_list_[-1].update_posi()
                #self.bullet_info_manager_.object_info_list_[-1].show_info()
            else:
                print("何もコマンドがない")
        ############################################################################################################

        ##############################################################################################################全てのオブジェクトの変化後の座標位置をもとに処理を行う
        print("全てのオブジェクトの座標を更新しました。")
        print("衝突処理に入ります。")

        #きれいではないけど時間がないから以下の方法でやる
        maze_object_dict = [[{
            PLAYER_INFO: [],
            BULLET_INFO: []
        } for x in range(10)] for y in range(10)]

        player_info_list = self.player_info_manager_.get_all_object_info()
        for player_info in player_info_list:
            object_type = player_info.get_object_type()
            posi = player_info.get_posi()
            x = posi[X]
            y = posi[Y]
            maze_object_dict[x][y][object_type].append(player_info)
            if (self.turn_ >= 1):
                last_posi = player_info.get_last_posi()
                x = last_posi[X]
                y = last_posi[Y]
                maze_object_dict[x][y][object_type].append(player_info)

        bullet_info_list = self.bullet_info_manager_.get_all_object_info()
        for bullet_info in bullet_info_list:
            object_type = bullet_info.get_object_type()
            posi = bullet_info.get_posi()
            x = posi[X]
            y = posi[Y]
            maze_object_dict[x][y][object_type].append(bullet_info)

        ####TEST
        #for x in range(10):
        #    for y in range(10):
        #        print("x,y",x,y)
        #        dic = maze_object_dict[x][y]
        #        print(dic)
        #        for player_info in dic[PLAYER_INFO]:
        #            player_info.show_info()
        #        for bullet_info in dic[BULLET_INFO]:
        #            bullet_info.show_info()
        ####TEST

        ########################################衝突処理
        for x in range(10):
            for y in range(10):
                object_dict = maze_object_dict[x][y]
                player_info_list = object_dict[PLAYER_INFO]
                bullet_info_list = object_dict[BULLET_INFO]
                player_num = len(player_info_list)
                bullet_num = len(bullet_info_list)
                #print("x,y",x,y,"にあるプレイヤーオブジェクトの数",player_num)
                #print("x,y",x,y,"にあるバレットオブジェクトの数",bullet_num)

                ##################################################################壁の衝突
                if (self.maze_[y][x] == W):
                    #print("ここは壁やで プレイヤーは元の位置に戻して、弾丸は破壊するよ。")
                    if (player_num >= 1):
                        #time.sleep(2)
                        pass
                    for player_info in player_info_list:
                        player_info.back_last_posi()
                        #print("もどりまーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーす")
                        self.player_info_manager_.update_object_info(
                            player_info)
                    for bullet_info in bullet_info_list:
                        id = bullet_info.get_id()
                        self.bullet_info_manager_.delete_object_info(id)
                        self.delete_id(id)
                    continue
                ##################################################################ここまで壁の衝突

                ##################################################################オブジェクト同士の衝突
                if (player_num == 0 and bullet_num == 0):
                    print("オブジェクト無し 衝突無し")
                elif (player_num == 1 and bullet_num == 0):
                    print("プレイヤーオブジェクトのみ 衝突無し")
                elif (player_num == 0 and bullet_num == 1):
                    print("弾丸オブジェクトのみ 衝突無し")
                elif (player_num >= 2 and bullet_num == 0):
                    print("プレイヤー同士の衝突が発生 それぞれのプレイヤーを元の座標に戻します。")
                    for player_info in player_info_list:
                        player_info.back_last_posi()
                        self.player_info_manager_.update_object_info(
                            player_info)
                elif (player_num == 0 and bullet_num >= 2):
                    print("弾丸同士の衝突が発生 それぞれの弾丸を破棄します。")
                    for bullet_info in bullet_info_list:
                        id = bullet_info.get_id()
                        self.bullet_info_manager_.delete_object_info(id)
                        self.delete_id(id)
                elif (player_num == 1 and bullet_num >= 1):
                    print("一人のプレイヤーと弾丸が衝突しました。プレイヤーのライフを減らして弾丸を破棄します。")
                    total_damage = 0
                    for bullet_info in bullet_info_list:
                        total_damage += bullet_info.get_power()
                        print("TOTAL DAMAGE:", total_damage)
                        #time.sleep(1)
                        id = bullet_info.get_id()
                        self.bullet_info_manager_.delete_object_info(id)
                        self.delete_id(id)
                    print("TOTAL DAMAGE = ", total_damage)
                    for player_info in player_info_list:
                        #応急処置
                        current_player_info = None
                        current_player_info_list = self.player_info_manager_.get_all_object_info(
                        )
                        for c_player_info in current_player_info_list:
                            if (c_player_info.get_id() == player_info.get_id()
                                ):
                                current_player_info = c_player_info
                                break
                        #取得した同じプレイヤーのHPがすでに更新されているものであればHPを最新のものに変更する
                        if (current_player_info.get_hp() <
                                player_info.get_hp()):
                            player_info.set_hp(current_player_info.get_hp())
                        ######################ここまで応急処置
                        player_info.decrease_hp(total_damage)
                        print("HP:", player_info.get_hp())
                        time.sleep(2)
                        self.player_info_manager_.update_object_info(
                            player_info)
                elif (player_num >= 2 and bullet_num >= 1):
                    print(
                        "複数のプレイヤーと弾丸が衝突しました。プレイヤーのライフを減らして弾丸を破棄します。その後プレイヤーを元居た座標に戻します。"
                    )
                    total_damage = 0
                    for bullet_info in bullet_info_list:
                        total_damage += bullet_info.get_power()
                        id = bullet_info.get_id()
                        self.bullet_info_manager_.delete_object_info(id)
                        self.delete_id(id)
                    print("TOTAL DAMAGE = ", total_damage)
                    for player_info in player_info_list:
                        player_info.decrease_hp(total_damage)
                        player_info.back_last_posi()
                        self.player_info_manager_.update_object_info(
                            player_info)
                ##############################################################################ここまでオブジェクト同士の衝突
        print("衝突処理完了")

        ##########################################ここまで衝突処理

        print("すべてのオブジェクトの情報が更新されました。")
        return
    def test_info(self):
        info = GameInfo()
        info.game_info_add("test 1", "15")
        info.away_team_add_info("test 2", "23")
        info.home_team_add_info("test 3", "2")
        info.game_info_add("test 4", "567")
        info.away_team_add_info("test 5", "345")
        info.home_team_add_info("test 6", "12")

        d = {
            "test 1": "15",
            "test 4": "567",
            "away test 2": "23",
            "away test 5": "345",
            "home test 3": "2",
            "home test 6": "12"
        }
        self.assertDictEqual(info.info, d)
Пример #13
0
import sys
from gameinfo import GameInfo
from architecture_class import Room, Furniture
from character import Enemy, Friend

Befriender = GameInfo()
GameInfo.getgamedata()
GameInfo.readrules(Befriender)
GameInfo.definelevel()

myitems = list()
optionlist = list()

"""
start the new room and its inhabitant
"""
GameInfo.current_room = GameInfo.defaultroom()
while GameInfo.lives > 0:
    GameInfo.banner()
    """
    checks if there is a character in the room
    for all cases, defines command options and the explore status of the room
    """
    inh_profile = GameInfo.current_room.get_ch_det()
    inhabitant = GameInfo.current_room.get_character()
    if inhabitant is not None:
        """
        checks the type of character
        """
        wtd = GameInfo.whatchoice(inhabitant, Room.current_room, myitems)
        command = wtd[0]
    def test_home_team(self):
        info = GameInfo()
        info.home_team_add_info("test 1", "15")
        info.home_team_add_info("test 2", "2315")
        info.home_team_add_info("test 3", 12)
        info.home_team_add_info("test 4", "Hello World")
        self.assertEqual(info.home_team_get("test 1"), "15")
        self.assertEqual(info.home_team_get("test 2"), "2315")
        self.assertEqual(info.home_team_get("test 3"), 12)
        self.assertEqual(info.home_team_get("test 4"), "Hello World")
        self.assertIsNone(info.home_team_get("test 5"))

        d = {
            "test 1": "15",
            "test 2": "2315",
            "test 3": 12,
            "test 4": "Hello World"
        }
        self.assertDictEqual(info.home_team, d)
 def test_game_info(self):
     info = GameInfo()
     info.game_info_add("test 1", "15")
     info.game_info_add("test 2", "2315")
     info.game_info_add("test 3", 12)
     info.game_info_add("test 4", "Hello World")
     self.assertEqual(info.game_info_get("test 1"), "15")
     self.assertEqual(info.game_info_get("test 2"), "2315")
     self.assertEqual(info.game_info_get("test 3"), 12)
     self.assertEqual(info.game_info_get("test 4"), "Hello World")
     self.assertIsNone(info.game_info_get("test 5"))
Пример #16
0
player_info3 = PlayerInfo(3,"Sunaga",YELLOW,[0,9])
#player_info3.prepare_next_command(DOWN_ATTACK)
player_info3.prepare_next_command(DOWN_MOVE)
player_info3.update_posi()

player_info_list = [player_info1, player_info2, player_info3]

bullet_info1 = BulletInfo(10,player_info1)
bullet_info2 = BulletInfo(11,player_info2)
bullet_info3 = BulletInfo(12,player_info3)
bullet_info_list = [bullet_info1, bullet_info2, bullet_info3]

item_info_list = []

game_info = GameInfo()
game_info.set_maze(maze)
game_info.set_turn(turn)
game_info.set_player_info_list(player_info_list)
game_info.set_bullet_info_list(bullet_info_list)
game_info.set_item_info_list(item_info_list)

########################Socket test用オブジェクト生成#########################

sc = Socket(game_info)
sc.listen()




 def __init__(self, url):
     self.url = url
     self._bs = None
     self._info = GameInfo()
Пример #18
0
from gameinfo import GameInfo

data = GameInfo().get_game_info(199561)
GameInfo().print_game_data(data)