Skip to content

Commit

Permalink
Updates interaction and design of Activity 104 - part of issue #37
Browse files Browse the repository at this point in the history
  • Loading branch information
imiolek-ireneusz committed Jul 5, 2021
1 parent ef1de58 commit 932b43e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 20 deletions.
62 changes: 42 additions & 20 deletions game_boards/game104.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import random
import pygame
import os

import classes.board
import classes.drw.percentage_multi_hq
import classes.game_driver as gd
import classes.level_controller as lc
import classes.extras as ex


class Board(gd.BoardGame):
def __init__(self, mainloop, speaker, config, screen_w, screen_h):
self.level = lc.Level(self, mainloop, 10, 5)
Expand All @@ -23,8 +25,6 @@ def create_game_objects(self, level=1):
else:
white = (255, 255, 255)

transp = (0, 0, 0, 0)

data = [12, 7]
self.data = data

Expand All @@ -39,7 +39,6 @@ def create_game_objects(self, level=1):

self.board.board_bg.line_color = (20, 20, 20)
self.number_count = random.randint(2, 5)
#self.numbers = self.get_numbers(self.number_count, 5, 5)
self.numbers = self.get_numbers(self.number_count, 5, 1)
self.numbers_sh = self.numbers[:]
random.shuffle(self.numbers_sh)
Expand All @@ -52,38 +51,62 @@ def create_game_objects(self, level=1):
for i in range(1, self.number_count):
hues.append((hues[0] + step * i) % 255)

#colors = [ex.hsv_to_rgb(hues[i], 187, 200) for i in range(self.number_count)]
#b_colors = [ex.hsv_to_rgb(hues[i], 187, 180) for i in range(self.number_count)]
colors = [ex.hsv_to_rgb(hues[i], 150, 250) for i in range(self.number_count)]
b_colors = [ex.hsv_to_rgb(hues[i], 150, 220) for i in range(self.number_count)]


self.board.add_unit(0, 0, data[1], data[1], classes.board.Label, "", white, "", 0)
self.fraction_canvas = self.board.units[-1]
self.fraction = classes.drw.percentage_multi_hq.Percentage(1, self.board.scale * data[1],
colors, b_colors, self.numbers)
self.fraction_canvas.painting = self.fraction.get_canvas().copy()

# add color labels
for i in range(self.number_count):
self.board.add_unit(data[1] + 1, self.positions[self.number_count-2][i], 2, 1,
classes.board.Label, "", colors[i], "", 0)
self.board.units[-1].set_outline(b_colors[i], 2)
if self.mainloop.scheme is None:
dc_img_src = os.path.join('unit_bg', "universal_sq_dc.png")
else:
dc_img_src = None

bg_img_src = os.path.join('unit_bg', "universal_sq_bg.png")
bg_rect_img_src = os.path.join('unit_bg', "universal_r2x1_bg_plain_color.png")
frame_img_src = os.path.join('unit_bg', "universal_r2x1_door.png")
bg_door_img_src = os.path.join('unit_bg', "universal_sq_door.png")

self.board.add_door(data[1] + 3, self.positions[self.number_count-2][i], 1, 1,
classes.board.Door, "", colors[i], "")
self.board.units[-1].door_outline = True
number_color = ex.hsv_to_rgb(self.mainloop.cl.get_interface_hue(), self.mainloop.cl.bg_color_s, self.mainloop.cl.bg_color_v)
fg_number_color = ex.hsv_to_rgb(self.mainloop.cl.get_interface_hue(), self.mainloop.cl.fg_hover_s, self.mainloop.cl.fg_hover_v)

self.board.add_unit(data[1] + i + (data[0] - data[1] - self.number_count) // 2, 0, 1, 1,
classes.board.Letter, str(self.numbers_sh[i]) + "%", transp, "", 2, alpha=True)
for i in range(self.number_count):
# colour label
tint_color = ex.hsv_to_rgb(hues[i], self.mainloop.cl.bg_color_s, self.mainloop.cl.bg_color_v)
self.board.add_universal_unit(grid_x=data[1] + 1, grid_y=self.positions[self.number_count-2][i],
grid_w=2, grid_h=1, txt="", fg_img_src=frame_img_src,
bg_img_src=bg_rect_img_src, dc_img_src=None, bg_color=(0, 0, 0, 0),
border_color=None, font_color=None, bg_tint_color=tint_color,
fg_tint_color=None, txt_align=(0, 0), font_type=10,
multi_color=False, alpha=True, immobilized=True, fg_as_hover=False, mode=1)

# response placeholder
door_bg_tint = ex.hsv_to_rgb(hues[i], self.mainloop.cl.door_bg_tint_s, self.mainloop.cl.door_bg_tint_v)
self.board.add_universal_unit(grid_x=data[1] + 3, grid_y=self.positions[self.number_count-2][i],
grid_w=1, grid_h=1, txt=None, fg_img_src=None, bg_img_src=bg_door_img_src,
dc_img_src=None, bg_color=(0, 0, 0, 0), border_color=None, font_color=None,
bg_tint_color=door_bg_tint, fg_tint_color=None, txt_align=(0, 0),
font_type=10, multi_color=False, alpha=True, immobilized=True, mode=2)

# potential response
self.board.add_universal_unit(grid_x=data[1] + i + (data[0] - data[1] - self.number_count) // 2, grid_y=0,
grid_w=1, grid_h=1, txt=str(self.numbers_sh[i]) + "%", fg_img_src=bg_img_src,
bg_img_src=bg_img_src, dc_img_src=dc_img_src, bg_color=(0, 0, 0, 0),
border_color=None, font_color=[(0, 0, 0)], bg_tint_color=number_color,
fg_tint_color=fg_number_color, txt_align=(0, 0), font_type=3,
multi_color=False, alpha=True, immobilized=False, fg_as_hover=True)

self.units.append(self.board.ships[-1])
self.board.ships[-1].solution = self.numbers_sh[i]
self.board.ships[-1].highlight = False
self.board.ships[-1].checkable = True
self.board.ships[-1].init_check_images()

for each in self.board.ships:
each.readable = False
#each.immobilize()

def get_numbers(self, count, dist, step):
redraw = True
Expand Down Expand Up @@ -116,14 +139,14 @@ def auto_check_reset(self):

def handle(self, event):
gd.BoardGame.handle(self, event)
#if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
# active = self.board.active_ship
if event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN:
self.auto_check_reset()
elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
for each in self.board.units:
self.board.all_sprites_list.move_to_front(each)
self.auto_check()
if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP:
self.default_hover(event)

def update(self, game):
game.fill((255, 255, 255))
Expand Down Expand Up @@ -156,4 +179,3 @@ def check_result(self):
if all_correct:
self.level.next_board()
self.mainloop.redraw_needed[0] = True

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 932b43e

Please sign in to comment.