-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
143 lines (117 loc) · 4.44 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.widget import Widget
from kivy.uix.button import Button, Label
from kivy.properties import ListProperty, ObjectProperty
from game import Game
from player import Player
from helpers import new_targets
class PlayerMenuButtons(GridLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.cols = 2
self.btn1 = Button(text='1')
self.btn1.bind(on_press=self.update)
self.btn2 = Button(text='2')
self.btn2.bind(on_press=self.update)
self.btn3 = Button(text='3')
self.btn3.bind(on_press=self.update)
self.btn4 = Button(text='4')
self.btn4.bind(on_press=self.update)
self.add_widget(self.btn1)
self.add_widget(self.btn2)
self.add_widget(self.btn3)
self.add_widget(self.btn4)
def update(self, instance):
print(instance)
app = App.get_running_app()
app.root.configure_players(instance)
instance.parent.parent.show_current_players()
class PlayerMenu(BoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.orientation = "vertical"
self.label = Label(text="Select # of Players:")
self.add_widget(self.label)
self.player_menu_buttons = PlayerMenuButtons()
self.add_widget(self.player_menu_buttons)
def show_current_players(self):
app = App.get_running_app()
self.label.text = 'Current Players:'
self.remove_widget(self.player_menu_buttons)
self.current_players_label = Label(text=str(len(app.root.players)))
self.add_widget(self.current_players_label)
class TurnMenu(BoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.orientation = "vertical"
self.add_widget(Button(text='Undo'))
self.add_widget(Button(text='Clear'))
class Menu(BoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.orientation = "vertical"
self.add_widget(PlayerMenu())
self.add_widget(TurnMenu())
class ScoreColumn(BoxLayout):
def __init__(self, player, **kwargs):
super().__init__(**kwargs)
self.orientation = "vertical"
self.player = player
self.add_widget(Label(text=self.player.name))
for target in self.player.targets:
self.add_widget(Label(text=str(target['shots'])))
self.add_widget(Label(text=""))
class TargetsColumn(BoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.orientation = "vertical"
self.add_widget(Label(text="P", underline=True))
self.add_widget(Label(text="20"))
self.add_widget(Label(text="19"))
self.add_widget(Label(text="18"))
self.add_widget(Label(text="17"))
self.add_widget(Label(text="16"))
self.add_widget(Label(text="15"))
self.add_widget(Label(text="B"))
self.add_widget(Label(text=""))
class Sheet(BoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.orientation = "horizontal"
self.targets = TargetsColumn()
self.add_widget(self.targets)
def sync_players_to_sheet(self, players):
for player in players:
self.add_widget(ScoreColumn(player))
class Root(BoxLayout):
players = ListProperty([])
game = ObjectProperty(Game(players))
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.orientation = "horizontal"
self.label = Label(id='instruction', text=self.game.state.value)
self.add_widget(self.label)
self.sheet = Sheet()
self.add_widget(self.sheet)
self.menu = Menu()
self.add_widget(self.menu)
def configure_players(self, instance):
self.players = []
print("Set number to %s", instance.text)
number = int(instance.text) - 1
while (len(self.players) <= number):
name = str(len(self.players) + 1)
self.players.append(Player(name, 0, new_targets()))
print(self.players)
self.sheet.sync_players_to_sheet(self.players)
self.set_game_players()
def set_game_players(self):
self.game.set_players(self.players)
print(self.game.state.value)
self.label.text = self.game.state.value
class CrayketApp(App):
def build(self):
return Root()
CrayketApp().run()