コード例 #1
0
ファイル: player.py プロジェクト: nozawaTak/LineBotDevelop
 def __init__(self, userId):
     self.userId = userId
     dbinfo = config.getInfoToConnectDB()
     self.connection = pymysql.connect(host = dbinfo['host'],
                                     user = dbinfo['user_name'],
                                     password = dbinfo['password'],
                                     db = dbinfo['db_name'],
                                     charset = 'utf8',
                                     cursorclass = pymysql.cursors.DictCursor)
     with self.connection.cursor() as cursor:
         cursor.execute("SELECT * from USER WHERE id = %s", (self.userId))
         userInfo = cursor.fetchone()
         self.__hp = userInfo['hp']
         self.name = userInfo['name']
         self.__money = userInfo['money']
         self.__position_x = userInfo['position_x']
         self.__position_y = userInfo['position_y']
         self.__state = userInfo['state']
         self.__battleID = userInfo['battleID']
         self.equipment = userInfo['equipment']
         cursor.execute("SELECT * from EQUIPMENT WHERE id = %s", (self.equipment))
         equipInfo = cursor.fetchone()
         cursor.execute("SELECT attack from WEAPON WHERE id = %s", (equipInfo['equip_weapon']))
         weaponInfo = cursor.fetchone()
         self.attack = weaponInfo['attack']
         cursor.execute("SELECT * from ARMOR WHERE id = %s", (equipInfo['equip_armor']))
         armorInfo = cursor.fetchone()
         self.defense = armorInfo['defense']
         self.speed = armorInfo['speed']
コード例 #2
0
ファイル: game.py プロジェクト: nozawaTak/LineBotDevelop
 def __init__(self, userID):
     self.player = None
     dbinfo = config.getInfoToConnectDB()
     self.connection = pymysql.connect(
         host=dbinfo['host'],
         user=dbinfo['user_name'],
         password=dbinfo['password'],
         db=dbinfo['db_name'],
         charset='utf8',
         cursorclass=pymysql.cursors.DictCursor)
     if self._exist(userID):
         self.player = Player(userID)
         self.Registered = True
     else:
         self.Registered = False
コード例 #3
0
ファイル: battle.py プロジェクト: nozawaTak/LineBotDevelop
 def spawnNewBattle(self, enemyID):
     enemy = Enemy(enemyID)
     dbinfo = config.getInfoToConnectDB()
     connection = pymysql.connect(host = dbinfo['host'],
                                 user = dbinfo['user_name'],
                                 password = dbinfo['password'],
                                 db = dbinfo['db_name'],
                                 charset = 'utf8',
                                 cursorclass = pymysql.cursors.DictCursor)
     with connection.cursor() as cursor:
         sql = "INSERT INTO BATTLEINFO (enemyHP, enemyAttack, enemyDefense, enemySpeed, enemyMoney, enemyName, enemyId) VALUES (%s, %s, %s, %s, %s, %s, %s)"
         values = (enemy.hp, enemy.attack, enemy.defense, enemy.speed, enemy.money, enemy.name, enemyID)
         cursor.execute(sql, values)
         battleID = cursor.lastrowid
         connection.commit()
     connection.close()
     return battleID
コード例 #4
0
ファイル: battle.py プロジェクト: nozawaTak/LineBotDevelop
 def _randomEnemyID(self):
     enemyIDs = []
     dbinfo = config.getInfoToConnectDB()
     connection = pymysql.connect(host = dbinfo['host'],
                                 user = dbinfo['user_name'],
                                 password = dbinfo['password'],
                                 db = dbinfo['db_name'],
                                 charset = 'utf8',
                                 cursorclass = pymysql.cursors.DictCursor)
     with connection.cursor() as cursor:
         sql = "SELECT id FROM ENEMY"
         cursor.execute(sql)
         results = cursor.fetchall()
         for r in results:
             enemyIDs.append(r['id'])
     connection.close()
     index = random.randint(0, len(enemyIDs)-1)
     return enemyIDs[index]
コード例 #5
0
ファイル: enemy.py プロジェクト: nozawaTak/LineBotDevelop
 def __init__(self, enemyID):
     self.enemyID = enemyID
     dbinfo = config.getInfoToConnectDB()
     connection = pymysql.connect(host = dbinfo['host'],
                                 user = dbinfo['user_name'],
                                 password = dbinfo['password'],
                                 db = dbinfo['db_name'],
                                 charset = 'utf8',
                                 cursorclass = pymysql.cursors.DictCursor)
     with connection.cursor() as cursor:
         cursor.execute("SELECT * from ENEMY WHERE id = %s", (self.enemyID))
         enemyInfo = cursor.fetchone()
         self.name = enemyInfo['name']
         self.hp = enemyInfo['hp']
         self.attack = enemyInfo['attack']
         self.defense = enemyInfo['defense']
         self.speed = enemyInfo['speed']
         self.money = enemyInfo['money']
         self.imagePath = enemyInfo['imagePath']
     connection.close()
コード例 #6
0
ファイル: world.py プロジェクト: nozawaTak/LineBotDevelop
 def randomEncount(self):
     rnd = random.random()
     if rnd < 0.2:
         battle = Battle(self.userID)
         text = battle.enemy.name + "が現れた!"
         dbinfo = config.getInfoToConnectDB()
         self.connection = pymysql.connect(
             host=dbinfo['host'],
             user=dbinfo['user_name'],
             password=dbinfo['password'],
             db=dbinfo['db_name'],
             charset='utf8',
             cursorclass=pymysql.cursors.DictCursor)
         with self.connection.cursor() as cursor:
             cursor.execute("SELECT * FROM ENEMY WHERE id = %s",
                            (battle.enemy.enemyId))
             enemyInfo = cursor.fetchone()
             imageURI = "https://nozawa-linebot.tk/" + enemyInfo['imagePath']
         return True, {"img": imageURI, "text": text}
     return False, {}
コード例 #7
0
 def __init__(self, battleID):
     self.battleID = battleID
     dbinfo = config.getInfoToConnectDB()
     self.connection = pymysql.connect(
         host=dbinfo['host'],
         user=dbinfo['user_name'],
         password=dbinfo['password'],
         db=dbinfo['db_name'],
         charset='utf8',
         cursorclass=pymysql.cursors.DictCursor)
     with self.connection.cursor() as cursor:
         cursor.execute("SELECT * FROM BATTLEINFO WHERE id = %s",
                        (battleID))
         enemyInfo = cursor.fetchone()
         self.__hp = enemyInfo['enemyHP']
         self.attack = enemyInfo['enemyAttack']
         self.defense = enemyInfo['enemyDefense']
         self.speed = enemyInfo['enemySpeed']
         self.money = enemyInfo['enemyMoney']
         self.name = enemyInfo['enemyName']
         self.enemyId = enemyInfo['enemyId']