Skip to content

Commit

Permalink
Continue the implementation of the game
Browse files Browse the repository at this point in the history
  • Loading branch information
LupaDevStudio committed Sep 14, 2023
1 parent 561f4c9 commit b1b8dd8
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 64 deletions.
54 changes: 29 additions & 25 deletions screens/game.kv
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#:import PATH_IMAGES tools.path.PATH_IMAGES
#:import PATH_TEXT_FONT tools.path.PATH_TEXT_FONT
#:import TEXT_FONT_COLOR tools.constants.TEXT_FONT_COLOR
#:import partial functools.partial
#:set center_x_faction 0.11
#:set center_x_resource 0.95
#:set upper_y_indic 0.93
Expand Down Expand Up @@ -151,96 +152,99 @@
pos_hint: {"center_x": 0.5, "center_y": center_img_center_y}
allow_stretch: True
keep_ratio:False
text: root.decision_text
text_font_name: root.font_name
text_color: TEXT_FONT_COLOR

# Decision left
ImageWithText:
ImageWithTextButton:
id: decision_no
source: PATH_IMAGES + "decision_choice_background.png"
size_hint: side_img_width, side_img_height
pos_hint: {"center_x": side_img_center_x, "center_y":side_img_center_y}
allow_stretch: True
keep_ratio: False
text: root.decision_no_text
text_font_name: root.font_name
text_color: TEXT_FONT_COLOR
Button:
size_hint: side_img_width, side_img_height
pos_hint: {"center_x": side_img_center_x, "center_y":side_img_center_y+0.1}
background_color: (0,1,0,0.5)
on_release:
root.choose_answer("left")
release_function: partial(root.choose_answer, "left")

# Decision right
ImageWithText:
ImageWithTextButton:
id: decision_yes
source: PATH_IMAGES + "decision_choice_background.png"
size_hint: side_img_width, side_img_height
pos_hint: {"center_x": 1-side_img_center_x, "center_y":side_img_center_y}
allow_stretch: True
keep_ratio: False
text: root.decision_yes_text
text_font_name: root.font_name
text_color: TEXT_FONT_COLOR
release_function: partial(root.choose_answer, "right")

# Decision guillotine
Image:
ImageWithTextButton:
id: decision_guillotine
source: PATH_IMAGES + "guillotine.png"
size_hint: None, 0.15
pos_hint: {"center_x": 0.5, "center_y": 0.1}
allow_stretch: True
keep_ratio: False
width: self.height
release_function: partial(root.choose_answer, "down")

# Event background
ImageWithText:
ImageWithTextButton:
id: event
source: PATH_IMAGES + "event_background.png"
size_hint: center_img_width, center_img_height
pos_hint: {"center_x": 0.5, "center_y": center_img_center_y}
allow_stretch: True
keep_ratio:False
text: root.event_text
keep_ratio: False
text_font_name: root.font_name
text_color: TEXT_FONT_COLOR
release_function: root.go_to_next_card

# Decree background
ImageWithText:
ImageWithTextButton:
id: decree_center
source: PATH_IMAGES + "decree_background.png"
size_hint: center_img_width, center_img_height
pos_hint: {"center_x": 0.5, "center_y": center_img_center_y}
allow_stretch: True
keep_ratio:False
text: root.decree_center_text
keep_ratio: False
text_font_name: root.font_name
text_color: TEXT_FONT_COLOR

# Decree left
ImageWithText:
ImageWithTextButton:
id: decree_left
source: PATH_IMAGES + "decree_choice_background.png"
size_hint: side_img_width, side_img_height
pos_hint: {"center_x": side_img_center_x, "center_y":side_img_center_y}
allow_stretch: True
keep_ratio:False
text: root.decree_left_text
keep_ratio: False
text_font_name: root.font_name
text_color: TEXT_FONT_COLOR
release_function: partial(root.choose_answer, "left")

# Decree right
ImageWithText:
ImageWithTextButton:
id: decree_right
source: PATH_IMAGES + "decree_choice_background.png"
size_hint: side_img_width, side_img_height
pos_hint: {"center_x": 1-side_img_center_x, "center_y":side_img_center_y}
allow_stretch: True
keep_ratio:False
text: root.decree_right_text
keep_ratio: False
text_font_name: root.font_name
text_color: TEXT_FONT_COLOR
release_function: partial(root.choose_answer, "right")


# Decree down
ImageWithTextButton:
id: decree_down
source: PATH_IMAGES + "decree_choice_background.png"
size_hint: side_img_width, side_img_height
pos_hint: {"center_x": 0.5, "center_y": 0.1}
allow_stretch: True
keep_ratio: False
text_font_name: root.font_name
text_color: TEXT_FONT_COLOR
release_function: partial(root.choose_answer, "down")
50 changes: 34 additions & 16 deletions screens/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
PATH_TEXT_FONT,
PATH_IMAGES,
)
from tools.constants import TEXT
from tools import (
music_mixer,
game
Expand Down Expand Up @@ -49,18 +48,8 @@ class GameScreen(ImprovedScreen):
weapons_value = StringProperty("0")
tools_value = StringProperty("0")

# Create text for decisions
decision_text = StringProperty()
decision_no_text = StringProperty()
decision_yes_text = StringProperty()

# Create text for events
event_text = StringProperty()

# Create text for decrees
decree_center_text = StringProperty(TEXT.game["decree"])
decree_right_text = StringProperty()
decree_left_text = StringProperty()
# Boolean indicating if the current moment is an answer or not
is_answer = False

def hide_cards(self, *_):
"""
Expand All @@ -73,7 +62,8 @@ def hide_cards(self, *_):
"decision_guillotine",
"decree_center",
"decree_left",
"decree_right"]
"decree_right",
"decree_down"]

for card in cards_list:
self.disable_widget(self.ids[card])
Expand All @@ -91,7 +81,8 @@ def __init__(self, **kw):

self.decree_cards = ["decree_center",
"decree_left",
"decree_right"]
"decree_right",
"decree_down"]

self.event_cards = ["event"]

Expand All @@ -100,6 +91,7 @@ def on_pre_enter(self, *args):
# Load the gameplay json
game.load_resources()
game.reset_variables()
self.update_display_resources()

# Hide all cards
self.hide_cards()
Expand Down Expand Up @@ -127,6 +119,7 @@ def display_card(self, *args):
self.ids["decree_center"].text = game.text_dict["card"]
self.ids["decree_left"].text = game.text_dict["left"]
self.ids["decree_right"].text = game.text_dict["right"]
self.ids["decree_down"].text = game.text_dict["down"]
for card in self.decree_cards:
self.enable_widget(self.ids[card])
if game.phase == "event":
Expand All @@ -137,6 +130,7 @@ def display_card(self, *args):
def choose_answer(self, choice: Literal["left", "right", "down"], *args):
game.make_choice(choice=choice)
game.end_day()
self.display_answer()
self.start_day()

def update_display_resources(self):
Expand All @@ -151,11 +145,35 @@ def update_display_resources(self):
self.weapons_value = str(game.weapons)
self.tools_value = str(game.tools)

def display_answer(self):
"""
Display the card containing the answer to the previous card.
It also displays the effects of the decision or the event. TODO
"""
self.is_answer = True
self.update_display_resources()

def go_to_next_card(self):
"""
Go to the next card when clicking on the next button.
When an answer is currently displayed, we'll go to the next day.
When an event is displayed, we'll go to the answer to this answer.
"""
if self.is_answer:
self.is_answer = False
self.start_day()
else:
game.end_day()
self.display_answer()

def start_day(self, *args):
"""
Start a new day with a new batch of cards.
"""
if not game.game_over:
game.start_day()
self.hide_cards()
self.display_card()
self.update_display_resources()
else:
self.update_display_resources()
self.manager.current = "game_over"
Expand Down
20 changes: 10 additions & 10 deletions tools/kivy_tools/image_with_text_button.kv
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#:kivy 2.1.0

<ImageWithTextButton>:
Image:
id: image_widget
source: root.image_source
pos_hint: root.image_pos_hint
size_hint: root.image_size_hint
allow_stretch: True
keep_ratio: False
Label:
id: text_widget
text: root.label_text
text: root.text
size: root.size
pos: root.pos
shorten: False
text_size: (root.width*root.text_filling_ratio,None)
color: root.label_text_color
font_name: root.label_font_name
color: root.text_color
font_name: root.text_font_name
font_size: root.text_font_size * root.parent.font_ratio
halign: root.text_halign
valign: root.text_valign
Button:
id: button_widget
size: root.size
pos: root.pos
background_color: (0, 0, 0, 0)
on_release:
root.release_function()
14 changes: 6 additions & 8 deletions tools/kivy_tools/image_with_text_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

### Kivy imports ###

from kivy.uix.button import Button
from kivy.uix.image import Image
from kivy.properties import (
StringProperty,
ObjectProperty
Expand All @@ -19,19 +19,17 @@
#############


class ImageWithTextButton(Button):
class ImageWithTextButton(Image):
"""
Image class with a text label on it and a transparent button.
"""

# Add new attributes to manage the text
image_source = StringProperty()
image_size_hint = ObjectProperty((1, 1))
image_pos_hint = ObjectProperty({"x":0, "y": 0})
label_text = StringProperty()
label_font_name = StringProperty("Roboto")
label_text_color = ObjectProperty([0, 1, 0, 1])
text = StringProperty()
text_font_name = StringProperty("Roboto")
text_color = ObjectProperty([0, 1, 0, 1])
text_filling_ratio = 0.9
text_halign = "center"
text_valign = "center"
text_font_size = 15
release_function = ObjectProperty()
9 changes: 7 additions & 2 deletions tools/kivy_tools/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from kivy.core.window import Window
from kivy.uix.screenmanager import Screen
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.properties import (
StringProperty,
NumericProperty,
Expand Down Expand Up @@ -131,11 +132,15 @@ def disable_widget(self, widget: Widget):
Disable the given widget.
"""
widget.opacity = 0
widget.disabled = True
if len(widget.children) == 2 and type(widget.children[0]) == Button:
print("toto")
widget.children[0].disabled = True

def enable_widget(self, widget: Widget):
"""
Enable the given widget.
"""
widget.opacity = 1
widget.disabled = False
if len(widget.children) == 2 and type(widget.children[0]) == Button:
widget.children[0].disabled = False
print(widget.children[0].disabled)
9 changes: 6 additions & 3 deletions tools/postrias.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def make_choice(self, choice: Literal["left", "down", "right"]):
if choice == "left":
choice = "no"
elif choice == "down":
choice = "execute"
choice = "guillotine"
elif choice == "right":
choice = "yes"

Expand All @@ -257,7 +257,10 @@ def make_choice(self, choice: Literal["left", "down", "right"]):
if self.phase in ("decree", "event"):
self.text_dict["answer"] = TEXT.answer[self.phase]
elif self.phase == "decision":
self.text_dict["answer"] = \
TEXT.answer[choice][self.gameplay["decision"][self.card_id]["complainant"]]
if choice in ["yes", "no"]:
self.text_dict["answer"] = \
TEXT.answer[choice][self.gameplay["decision"][self.card_id]["complainant"]]
else:
self.text_dict["answer"] = TEXT.answer[choice]

game = Game()

0 comments on commit b1b8dd8

Please sign in to comment.