game round

This commit is contained in:
yanshaoting 2024-03-12 12:51:37 +08:00
parent a44371801e
commit 362ba0384a
4 changed files with 38 additions and 6 deletions

View File

@ -24,10 +24,12 @@
game = SwimmingSquid(
level: int = 1,
level_file: str = None,
game_times: int = 1,
sound: str = "off")
```
- `level`: 選定內建關卡,預設為 1 選擇第一關。
- `level_file`: 使用外部檔案作為關卡,請注意,使用此設定將會覆蓋掉關卡編號,並且不會自動進入下一關。
- `game_times`:選擇要對戰幾次決勝負,可選擇一戰決勝負、三戰兩勝制、五戰三勝制。預設為一戰決勝負。
- `sound`: 音效。
## 玩法
@ -234,12 +236,14 @@ class MLPlay:
{
"squid": "1P",
"score": 0,
"rank": 2
"rank": 2,
"wins": 1 / 3
},
{
"squid": "2P",
"score": 10,
"rank": 1
"rank": 1,
"wins": 2 / 3
}
]
}
@ -253,6 +257,7 @@ class MLPlay:
- `squid`:玩家編號
- `score`:吃到的食物總數
- `rank`:排名
- `wins`:目前勝場數
---

BIN
asset/demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 MiB

View File

@ -1,6 +1,6 @@
{
"game_name": "swimming-squid",
"version": " 1.0",
"version": " 1.0.2",
"url": "https://github.com/PAIA-Playful-AI-Arena/swimming-squid",
"description": "這是一個魷魚吃東西小遊戲,你需要找到正確的食物、避開海中的垃圾,還要提防敵人的攻擊!(當然你也可以主動攻擊他人)",
"logo": [
@ -27,6 +27,17 @@
"default": "",
"help": "可匯入自定義的關卡資料,請參考內建範例的資料格式來設定。使用此設定會覆蓋掉其他關卡設定,也不會使用關卡編號,也不會自動進入下一關。"
},
{
"name": "game_times",
"verbose": "對站次數",
"type": "int",
"choices": [
1, 3, 5
],
"default": 1,
"help": "選擇要對戰幾次決勝負,可選擇一戰決勝負、三戰兩勝制、五戰三勝制。預設為一戰決勝負。"
},
{
"name": "sound",
"verbose": "遊戲音效",

View File

@ -37,6 +37,7 @@ class SwimmingSquid(PaiaGame):
self,
level: int = -1,
level_file: str = "",
game_times: int = 1,
sound: str = "off",
*args, **kwargs):
super().__init__(user_num=1)
@ -48,6 +49,8 @@ class SwimmingSquid(PaiaGame):
self.foods = pygame.sprite.Group()
self.sound_controller = SoundController(sound)
self._overtime_count = 0
self._game_times = game_times
self._winner = []
self._init_game()
@ -238,6 +241,15 @@ class SwimmingSquid(PaiaGame):
self.sound_controller.play_cheer()
else:
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()
@ -258,7 +270,6 @@ class SwimmingSquid(PaiaGame):
self._overtime_count += 1
print("同分延長賽")
return False
# print("達成目標分數")
return True
else:
return False
@ -382,13 +393,15 @@ class SwimmingSquid(PaiaGame):
{
"player": get_ai_name(0),
"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
},
{
"player": get_ai_name(1),
"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
}
]
@ -444,9 +457,12 @@ class SwimmingSquid(PaiaGame):
if self.squid1.score > self.squid2.score:
self.squid1.rank = 1
self.squid2.rank = 2
self._winner.append("1P")
elif self.squid1.score < self.squid2.score:
self.squid1.rank = 2
self.squid2.rank = 1
self._winner.append("2P")
else:
self.squid1.rank = 1
self.squid2.rank = 1
self._winner.append("DRAW")