feat: add level in game param

This commit is contained in:
Kylin_on_Mac 2023-09-22 16:19:10 +08:00
parent 9f5b5136e1
commit 3ec08f8510
4 changed files with 90 additions and 72 deletions

View File

@ -8,7 +8,8 @@
"https://raw.githubusercontent.com/PAIA-Playful-AI-Arena/Paia-Desktop/master/media/easygame.svg" "https://raw.githubusercontent.com/PAIA-Playful-AI-Arena/Paia-Desktop/master/media/easygame.svg"
], ],
"user_num": { "user_num": {
"min": 1,"max": 1 "min": 1,
"max": 1
}, },
"game_params": [ "game_params": [
{ {
@ -24,19 +25,42 @@
"name": "green_food_count", "name": "green_food_count",
"verbose": "綠色食物數量", "verbose": "綠色食物數量",
"type": "int", "type": "int",
"choices":[ 5 ,10 ,15,20,25,30,35,40,45,50], "choices": [
"help": "set the total number of points", 5,
"default": 10 10,
}, { 15,
"name": "black_food_count", 20,
"verbose": "黑色食物數量", 25,
"type": "int", 30,
"choices":[ 5 ,10 ,15,20,25,30,35,40,45,50], 35,
40,
45,
50
],
"help": "set the total number of points", "help": "set the total number of points",
"default": 10 "default": 10
}, },
{ {
"name": "score_to_win", "name": "black_food_count",
"verbose": "黑色食物數量",
"type": "int",
"choices": [
5,
10,
15,
20,
25,
30,
35,
40,
45,
50
],
"help": "set the total number of points",
"default": 10
},
{
"name": "score_to_pass",
"verbose": "通關分數", "verbose": "通關分數",
"type": "int", "type": "int",
"min": 1, "min": 1,
@ -48,9 +72,17 @@
"name": "playground_size", "name": "playground_size",
"verbose": "場地尺寸", "verbose": "場地尺寸",
"type": "list", "type": "list",
"default": "400,400",
"default": "500,400",
"help": "set the size of playground " "help": "set the size of playground "
},
{
"name": "level",
"verbose": "內建關卡編號",
"type": "int",
"min": -1,
"max": 5,
"default": "-1",
"help": "選定內建關卡,請注意,使用此設定將會覆蓋掉其他設定,預設為 -1 不選擇任何關卡。"
} }
] ]
} }

View File

@ -1,27 +1,10 @@
{ {
"frame_limit": 1200, "time_to_play": 1200,
"screen_size": [ "playground_size": [
100, 100,
100 200
], ],
"score_to_pass": 20, "score_to_pass": 20,
"mebo_init_lv": 1, "green_food_count": 3,
"green_food_counts": [ "black_food_count": 0
8,
5,
2,
1
],
"red_food_counts": [
8,
5,
2,
1
],
"black_food_counts": [
8,
5,
2,
1
]
} }

View File

@ -1,27 +1,10 @@
{ {
"frame_limit": 1200, "time_to_play": 1200,
"screen_size": [ "playground_size": [
100, 500,
100 200
], ],
"score_to_pass": 20, "score_to_pass": 20,
"mebo_init_lv": 1, "green_food_count": 3,
"green_food_counts": [ "black_food_count": 1
8,
5,
2,
1
],
"red_food_counts": [
8,
5,
2,
1
],
"black_food_counts": [
8,
5,
2,
1
]
} }

View File

@ -1,4 +1,6 @@
import copy import copy
import json
import os.path
from os import path from os import path
import pygame import pygame
@ -25,26 +27,44 @@ class EasyGame(PaiaGame):
""" """
def __init__( def __init__(
self, time_to_play, score_to_win, green_food_count, black_food_count, self, time_to_play, score_to_pass, green_food_count, black_food_count,
playground_size: list, playground_size: list,
level: int = -1,
# level_file,
*args, **kwargs): *args, **kwargs):
super().__init__(user_num=1) super().__init__(user_num=1)
self.playground_w = int(playground_size[0])
self.playground_h = int(playground_size[1])
self.game_result_state = GameResultState.FAIL self.game_result_state = GameResultState.FAIL
self.scene = Scene(width=WIDTH, height=HEIGHT, color=BG_COLOR, bias_x=0, bias_y=0) self.scene = Scene(width=WIDTH, height=HEIGHT, color=BG_COLOR, bias_x=0, bias_y=0)
if level != -1:
with open(os.path.join(LEVEL_PATH, f"{level:03d}.json")) as f:
game_params = json.load(f)
self.playground_w = int(game_params["playground_size"][0])
self.playground_h = int(game_params["playground_size"][1])
self.playground = pygame.Rect(
0, 0,
self.playground_w,
self.playground_h
)
self.green_food_count = int(game_params["green_food_count"])
self.black_food_count = int(game_params["black_food_count"])
self.score_to_win = int(game_params["score_to_pass"])
self.frame_limit = int(game_params["time_to_play"])
pass
else:
self.playground_w = int(playground_size[0])
self.playground_h = int(playground_size[1])
self.playground = pygame.Rect( self.playground = pygame.Rect(
0, 0, 0, 0,
self.playground_w, self.playground_w,
self.playground_h self.playground_h
) )
self.playground.center = (WIDTH / 2, HEIGHT / 2)
self.green_food_count = green_food_count self.green_food_count = green_food_count
self.black_food_count = black_food_count self.black_food_count = black_food_count
self.score_to_win = score_to_win self.score_to_win = score_to_pass
self.frame_limit = time_to_play self.frame_limit = time_to_play
self.playground.center = (WIDTH / 2, HEIGHT / 2)
self.foods = pygame.sprite.Group() self.foods = pygame.sprite.Group()
self.init_game() self.init_game()