From 035b84a4802867ee53fa984c6a2edf3decf0cb42 Mon Sep 17 00:00:00 2001 From: Kylin_on_Mac Date: Fri, 22 Sep 2023 11:42:05 +0800 Subject: [PATCH] feat: change input parameter and food color --- game_config.json | 11 +++++++++-- src/game.py | 6 +++--- src/game_object.py | 4 +++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/game_config.json b/game_config.json index a1adc48..e8c0c82 100644 --- a/game_config.json +++ b/game_config.json @@ -21,8 +21,15 @@ "help": "set the limit of frame count , actually time will be revised according to your FPS ." }, { - "name": "total_point_count", - "verbose": "總食物數量", + "name": "green_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": "black_food_count", + "verbose": "黑色食物數量", "type": "int", "choices":[ 5 ,10 ,15,20,25,30,35,40,45,50], "help": "set the total number of points", diff --git a/src/game.py b/src/game.py index 2049764..c1b8620 100644 --- a/src/game.py +++ b/src/game.py @@ -19,17 +19,17 @@ class EasyGame(PaiaGame): This is a Interface of a game """ - def __init__(self, time_to_play, total_point_count, score, color, *args, **kwargs): + def __init__(self, time_to_play, green_food_count,black_food_count, score, color, *args, **kwargs): super().__init__(user_num=1) self.game_result_state = GameResultState.FAIL self.scene = Scene(width=800, height=600, color="#111111", bias_x=0, bias_y=0) - self.total_point_count = total_point_count + self.total_point_count = green_food_count self.color = color self.ball = Ball("#" + color) self.foods = pygame.sprite.Group() self.score = 0 self.score_to_win = score - self._create_foods(total_point_count) + self._create_foods(self.total_point_count) self._begin_time = time.time() self._frame_count_down = time_to_play self.frame_limit = time_to_play diff --git a/src/game_object.py b/src/game_object.py index 9eafbfb..fe9d06a 100644 --- a/src/game_object.py +++ b/src/game_object.py @@ -4,6 +4,8 @@ import pygame.sprite from mlgame.view.view_model import create_rect_view_data +FOOD_COLOR = "#009688" + BALL_VEL = 10.5 BALL_H = 50 @@ -54,7 +56,7 @@ class Food(pygame.sprite.Sprite): def __init__(self, group): pygame.sprite.Sprite.__init__(self, group) self.image = pygame.Surface([8, 8]) - self.color = "#E91E63" + self.color = FOOD_COLOR self.rect = self.image.get_rect() self.rect.centerx = random.randint(0, 800) self.rect.centery = random.randint(0, 600)