game round
This commit is contained in:
parent
a44371801e
commit
362ba0384a
|
@ -24,10 +24,12 @@
|
||||||
game = SwimmingSquid(
|
game = SwimmingSquid(
|
||||||
level: int = 1,
|
level: int = 1,
|
||||||
level_file: str = None,
|
level_file: str = None,
|
||||||
|
game_times: int = 1,
|
||||||
sound: str = "off")
|
sound: str = "off")
|
||||||
```
|
```
|
||||||
- `level`: 選定內建關卡,預設為 1 選擇第一關。
|
- `level`: 選定內建關卡,預設為 1 選擇第一關。
|
||||||
- `level_file`: 使用外部檔案作為關卡,請注意,使用此設定將會覆蓋掉關卡編號,並且不會自動進入下一關。
|
- `level_file`: 使用外部檔案作為關卡,請注意,使用此設定將會覆蓋掉關卡編號,並且不會自動進入下一關。
|
||||||
|
- `game_times`:選擇要對戰幾次決勝負,可選擇一戰決勝負、三戰兩勝制、五戰三勝制。預設為一戰決勝負。
|
||||||
- `sound`: 音效。
|
- `sound`: 音效。
|
||||||
|
|
||||||
## 玩法
|
## 玩法
|
||||||
|
@ -234,12 +236,14 @@ class MLPlay:
|
||||||
{
|
{
|
||||||
"squid": "1P",
|
"squid": "1P",
|
||||||
"score": 0,
|
"score": 0,
|
||||||
"rank": 2
|
"rank": 2,
|
||||||
|
"wins": 1 / 3
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"squid": "2P",
|
"squid": "2P",
|
||||||
"score": 10,
|
"score": 10,
|
||||||
"rank": 1
|
"rank": 1,
|
||||||
|
"wins": 2 / 3
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -253,6 +257,7 @@ class MLPlay:
|
||||||
- `squid`:玩家編號
|
- `squid`:玩家編號
|
||||||
- `score`:吃到的食物總數
|
- `score`:吃到的食物總數
|
||||||
- `rank`:排名
|
- `rank`:排名
|
||||||
|
- `wins`:目前勝場數
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 7.1 MiB |
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"game_name": "swimming-squid",
|
"game_name": "swimming-squid",
|
||||||
"version": " 1.0",
|
"version": " 1.0.2",
|
||||||
"url": "https://github.com/PAIA-Playful-AI-Arena/swimming-squid",
|
"url": "https://github.com/PAIA-Playful-AI-Arena/swimming-squid",
|
||||||
"description": "這是一個魷魚吃東西小遊戲,你需要找到正確的食物、避開海中的垃圾,還要提防敵人的攻擊!(當然你也可以主動攻擊他人)",
|
"description": "這是一個魷魚吃東西小遊戲,你需要找到正確的食物、避開海中的垃圾,還要提防敵人的攻擊!(當然你也可以主動攻擊他人)",
|
||||||
"logo": [
|
"logo": [
|
||||||
|
@ -27,6 +27,17 @@
|
||||||
"default": "",
|
"default": "",
|
||||||
"help": "可匯入自定義的關卡資料,請參考內建範例的資料格式來設定。使用此設定會覆蓋掉其他關卡設定,也不會使用關卡編號,也不會自動進入下一關。"
|
"help": "可匯入自定義的關卡資料,請參考內建範例的資料格式來設定。使用此設定會覆蓋掉其他關卡設定,也不會使用關卡編號,也不會自動進入下一關。"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "game_times",
|
||||||
|
"verbose": "對站次數",
|
||||||
|
"type": "int",
|
||||||
|
"choices": [
|
||||||
|
1, 3, 5
|
||||||
|
],
|
||||||
|
"default": 1,
|
||||||
|
"help": "選擇要對戰幾次決勝負,可選擇一戰決勝負、三戰兩勝制、五戰三勝制。預設為一戰決勝負。"
|
||||||
|
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "sound",
|
"name": "sound",
|
||||||
"verbose": "遊戲音效",
|
"verbose": "遊戲音效",
|
||||||
|
|
22
src/game.py
22
src/game.py
|
@ -37,6 +37,7 @@ class SwimmingSquid(PaiaGame):
|
||||||
self,
|
self,
|
||||||
level: int = -1,
|
level: int = -1,
|
||||||
level_file: str = "",
|
level_file: str = "",
|
||||||
|
game_times: int = 1,
|
||||||
sound: str = "off",
|
sound: str = "off",
|
||||||
*args, **kwargs):
|
*args, **kwargs):
|
||||||
super().__init__(user_num=1)
|
super().__init__(user_num=1)
|
||||||
|
@ -48,6 +49,8 @@ class SwimmingSquid(PaiaGame):
|
||||||
self.foods = pygame.sprite.Group()
|
self.foods = pygame.sprite.Group()
|
||||||
self.sound_controller = SoundController(sound)
|
self.sound_controller = SoundController(sound)
|
||||||
self._overtime_count = 0
|
self._overtime_count = 0
|
||||||
|
self._game_times = game_times
|
||||||
|
self._winner = []
|
||||||
|
|
||||||
self._init_game()
|
self._init_game()
|
||||||
|
|
||||||
|
@ -238,6 +241,15 @@ class SwimmingSquid(PaiaGame):
|
||||||
self.sound_controller.play_cheer()
|
self.sound_controller.play_cheer()
|
||||||
else:
|
else:
|
||||||
self.sound_controller.play_fail()
|
self.sound_controller.play_fail()
|
||||||
|
|
||||||
|
if self._winner.count("1P") > self._game_times/2: # 1P 贏
|
||||||
|
self._winner.clear()
|
||||||
|
print("玩家 1 獲勝!開啟新一輪對戰!")
|
||||||
|
elif self._winner.count("2P") > self._game_times/2: # 2P 贏
|
||||||
|
self._winner.clear()
|
||||||
|
print("玩家 2 獲勝!開啟新一輪對戰!")
|
||||||
|
else:
|
||||||
|
pass
|
||||||
self._init_game()
|
self._init_game()
|
||||||
|
|
||||||
|
|
||||||
|
@ -258,7 +270,6 @@ class SwimmingSquid(PaiaGame):
|
||||||
self._overtime_count += 1
|
self._overtime_count += 1
|
||||||
print("同分延長賽")
|
print("同分延長賽")
|
||||||
return False
|
return False
|
||||||
# print("達成目標分數")
|
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
@ -382,13 +393,15 @@ class SwimmingSquid(PaiaGame):
|
||||||
{
|
{
|
||||||
"player": get_ai_name(0),
|
"player": get_ai_name(0),
|
||||||
"rank": self.squid1.rank,
|
"rank": self.squid1.rank,
|
||||||
"score": self.squid1.score
|
"score": self.squid1.score,
|
||||||
|
"wins":f"{self._winner.count('1P')} / {self._game_times}"
|
||||||
# "passed": self.is_passed
|
# "passed": self.is_passed
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"player": get_ai_name(1),
|
"player": get_ai_name(1),
|
||||||
"rank": self.squid2.rank,
|
"rank": self.squid2.rank,
|
||||||
"score": self.squid2.score
|
"score": self.squid2.score,
|
||||||
|
"wins":f"{self._winner.count('2P')} / {self._game_times}"
|
||||||
# "passed": self.is_passed
|
# "passed": self.is_passed
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -444,9 +457,12 @@ class SwimmingSquid(PaiaGame):
|
||||||
if self.squid1.score > self.squid2.score:
|
if self.squid1.score > self.squid2.score:
|
||||||
self.squid1.rank = 1
|
self.squid1.rank = 1
|
||||||
self.squid2.rank = 2
|
self.squid2.rank = 2
|
||||||
|
self._winner.append("1P")
|
||||||
elif self.squid1.score < self.squid2.score:
|
elif self.squid1.score < self.squid2.score:
|
||||||
self.squid1.rank = 2
|
self.squid1.rank = 2
|
||||||
self.squid2.rank = 1
|
self.squid2.rank = 1
|
||||||
|
self._winner.append("2P")
|
||||||
else:
|
else:
|
||||||
self.squid1.rank = 1
|
self.squid1.rank = 1
|
||||||
self.squid2.rank = 1
|
self.squid2.rank = 1
|
||||||
|
self._winner.append("DRAW")
|
||||||
|
|
Loading…
Reference in New Issue