-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogic.py
327 lines (291 loc) · 12.1 KB
/
Logic.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#All of the Game Logic and main character classes are in here
import random
import math
import Config
import sys
from PyQt5 import QtGui, QtCore, QtWidgets
from copy import deepcopy
import UI.NameCaptain
import time
from functools import partial
def test(Window):
"""Another Test"""
Window.stackedWidget.setCurrentIndex(1)
Window.Welcome.setText("Welcome to {}".format("Barbados"))
def sail_something(Window):
"""Some more testing shit"""
Window.Welcome.setText("Now you're sailing to {}".format(
Config.list_ports[random.randint(0, len(Config.list_ports) - 1)]))
def initiate_players(num_players, ports, window):
"""Creates a certain number of players and assigns them a port"""
class name_player_dia(QtWidgets.QDialog, UI.NameCaptain.Ui_Dialog):
"""The Dialog for initiation"""
def __init__(self):
super(name_player_dia, self).__init__()
self.setupUi(self)
players = []
for i in range(num_players):
dia = name_player_dia()
dia.label.setText("Player {}".format(i + 1))
if dia.exec_() == QtWidgets.QDialog.Accepted:
name = dia.lineEdit.text()
each = Player(None, ports[random.choice(Config.list_ports)], name)
players.append(each)
return players
def instance_ports(port_list):
"""creates classes all ports in the port list
and assigns players with the correct port for where they are"""
ports = [Port(i) for i in port_list]
port_dict = {ports[i].name: ports[i] for i in range(len(ports))}
return port_dict
class Ship():
"""Ship with all the fun"""
def __init__(self, name):
super(Ship, self).__init__()
self.name = name
self.cost = Config.ship_type[name][0]
self.max_cargo = Config.ship_type[name][2]
self.max_crew = Config.ship_type[name][3]
self.speed = Config.ship_type[name][4]
self.max_health = Config.ship_type[name][5]
self.health = self.max_health
self.damage_red = Config.ship_type[name][6]
self.max_cannons = Config.ship_type[name][1]
self.cannons = 0
self.cargo = {"Spices": 0,
"Cannons": 0,
"Tea": 0,
"Contraband": 0,
"Fruit": 0,
"Textiles": 0
}
def random_ship(self):
current_cargo = random.randint(0, self.max_cargo)
while current_cargo > 0:
sel_cargo = list(self.cargo.items())[random.choice(
range(len(self.cargo)))][0]
adder = random.randint(0, current_cargo)
self.cargo[sel_cargo] += adder
current_cargo -= adder
self.cannons = random.randint(0, self.max_cannons)
def upgrade_ship(self, i):
"""Upgrades ship based on the config available"""
i = int(i)
for x in range(1, len(Config.upgrade_items[i])):
attribute = Config.upgrade_items[i][x][0]
value = Config.upgrade_items[i][x][1]
if hasattr(self, attribute):
setattr(self, attribute, getattr(self, attribute) + value)
self.cost += value
else:
#print(""""###Can't upgrade non-existent attribute '{}'
#.""".format(attribute))
raise AttributeError(
"""Can't upgrade non-existent attribute
'{}'.""".format(attribute)
)
def equip_cannons(self, window): # no UI
"""Takes cannons out of cargo and puts them in bays"""
if self.cargo["Cannons"] == 0:
window.textBrowser.append("You have no cannons to equip")
elif self.cannons == self.max_cannons:
window.textBrowser.append("Cannon bays full")
else:
bays = self.max_cannons - self.cannons
equipped = min(self.cargo["Cannons"], bays)
self.cannons += equipped
self.cargo["Cannons"] -= equipped
window.textBrowser.append("{} cannons equipped".format(equipped))
def unequip_cannons(self, window): # no UI
"""cannons from bays to cargo"""
if self.cannons == 0:
window.textBrowser.append("No Cannons")
elif sum(self.cargo.values()) == self.max_cargo:
window.textBrowser.append("No Room")
else:
equip = min(self.max_cargo - sum(self.cargo.values()), self.cannons)
self.cannons -= equip
self.cargo["Cannons"] += equip
window.textBrowser.append("{} cannons unequipped". format(equip))
class Player:
def __init__(self, ship, port, name):
"""Starts the player off with 0 everything and 5000 deblunes"""
super(Player, self).__init__()
self.name = name
if self.name in ["Hollinger", "Dan", "Daniel", "Quadratix", "Quad"]:
print("Hollinger, you sir are a douche")
self.name = "My love"
elif self.name.lower() in ["michelle", "mccune"]:
self.name = "Dave"
self.ship = Ship(ship)
self.money = 5000
self.port = port
self.turn_loss = 0
self.crew = Crew()
self.port_location = "Pier"
self.stat_sailing = .20
self.stat_manuever = .20
self.stat_board = .20
self.stat_murder = .20
def change_money(self, direction, amount, window):
if direction == "up":
self.money += amount
elif direction == "down":
self.money -= amount
else:
window.textBrowser.append("not 'up' or 'down'")
def buy_cargo(self, window):
#opens the buy cargo dialog
dia = Game.Cargo_UI(self, window, "buy")
dia.show()
def sell_cargo(self, window):
#opens the sell cargo dialog
dia = Game.Cargo_UI(self, window, "sell")
dia.show()
def update_cargo(self, window):
for i in self.ship.cargo:
getattr(window, i).setNum(self.ship.cargo[i])
window.Player_Name.setText(self.name)
window.Crew.setNum(self.crew.number)
window.V_Money.setNum(self.money)
window.Eq_Cannons.setNum(self.ship.cannons)
window.Health.setText(str(self.ship.health) +
"/" + str(self.ship.max_health))
def buy_upgrade(self): # old
"""Selects an upgrade, checks money then runs upgrade_ship"""
print("Here are our available upgrades")
print("You currently have {} deblunes".format(self.money))
pprint(Config.upgrade_items, "Select", "Name", "Description",
"Cost", sub=True)
print("Please choose an upgrade to purchase.")
try:
i = int(input())
if i not in Config.upgrade_items:
print("Sorry, That's not an option")
elif self.money < Config.upgrade_items[i][0][2]:
print("Are you trying to cheat me")
else:
self.ship.upgrade_ship(i)
except ValueError:
print("A number please")
def hire_crew(self, window): # basic
self.crew.number = self.ship.max_crew
self.crew.price = self.port.crew_price
window.textBrowser.append("{} hired at \u06de{}/day".format(
self.crew.number, self.crew.price))
def fire_crew(self, window): # basic
self.crew.number = 0
self.crew.price = 0
window.textBrowser.append("Fired all Crew")
def pay_crew(self, window): # Needs update
"""Pays your crew everyday"""
if self.crew.number > 0:
cost = self.crew.price * self.crew.number
if self.money > cost:
self.change_money("down", cost, window)
window.textBrowser.append("Paid Crew \u06de{}".format(cost))
self.crew.attitude = min(self.crew.attitude + .5, 100)
else:
self.crew.attitude = max(self.crew.attitude - 5, 0)
window.textBrowser.append("You can't afford your crew, UhOh")
def buy_ship(self, window):
"""Stops execution until ok/cancel is pressed"""
window.change_ship("NA", "Galleon")
window.stackedWidget.setCurrentIndex(4)
#window.fake = QtGui.QLabel(window.gridLayoutWidget)
#window.fake.setText("FAKE!")
#window.fake.setAlignment(QtCore.Qt.AlignCenter)
#window.gridLayout.addWidget(window.fake, 5, 0, 1, 0)
def purchase_ship(self, window):
"""buys the ship and updates money""" # needs sell old ship
if self.money < int(window.V_Price.text()):
window.textBrowser.append("You can't afford that brokearse")
elif sum(self.ship.cargo.values()) > int(window.V_Cargo.text()):
window.textBrowser.append("You should sell some cargo first")
else:
temp = self.ship
new = window.H_Ship_Name.text()
self.ship = Ship(new)
self.ship.cargo = temp.cargo
self.change_money("down", self.ship.cost, window)
window.textBrowser.append(self.ship.name)
window.Icon_Health.setPixmap(
QtGui.QPixmap(":/icons/" + new + ".jpg"))
window.to_shipyard()
def cancel_purchase_ship(self, window):
"""If you don't want to make a purchase"""
if self.ship.name is None:
window.textBrowser.append("You need a ship")
else:
window.to_shipyard()
def repair(self, window): # no UI
"""Use time to repair your ship"""
time = math.floor((self.ship.max_health - self.ship.health) / 10)
self.ship.health = self.ship.max_health
self.turn_loss = time
window.textBrowser.append("Losing {} turns".format(time))
window.game.myturn = False
def buy_repair(self, window): # no UI
"""Use Money to Repair your ship"""
cost = (self.ship.max_health - self.ship.health) * 10
if self.money >= cost:
self.money -= cost
self.ship.health = self.ship.max_health
window.textBrowser.append("Fixed, it cost {}".format(cost))
else:
window.textBrowser.append("Too Broke")
class Port:
"""Where all the port prices are kept"""
"""For a pricing system we need:
generation (slightly variable)
demand (slightly variable)
coordinates (fixed)
could I just make shipping lanes?
"""
def __init__(self, name):
super(Port, self).__init__()
self.name = name
self.price, self.sell_price, self.crew_price = self.make_prices()
self.owner = None
self.generation = Config.new_port[name][0]
self.demand = Config.new_port[name][1]
self.coordinates = Config.new_port[name][2]
def make_prices(self):
"""creates the prices when the port is initiated"""
price = {}
for i in Config.port_prices:
cost = math.floor(random.gauss(
Config.port_prices[i][0],
Config.port_prices[i][1]))
price[i] = cost
sell_price = deepcopy(price)
for i in sell_price:
sell_price[i] = math.floor(price[i] * Config.port_prices[i][2])
crew_price = random.randint(Config.crew_price[0], Config.crew_price[1])
return price, sell_price, crew_price
def change_prices(self):
"""Changes the prices in the port based on current prices of the port"""
for i in self.price:
new_price = math.floor(random.gauss(self.price[i],
Config.port_prices[i][1]))
if new_price > Config.port_prices[i][4]:
new_price = Config.port_prices[i][4]
elif new_price < Config.port_prices[i][3]:
new_price = Config.port_prices[i][3]
self.price[i] = new_price
self.sell_price = deepcopy(self.price)
for i in self.sell_price:
self.sell_price[i] = math.floor(self.price[i] *
Config.port_prices[i][2])
self.crew_price = random.randint(Config.crew_price[0],
Config.crew_price[1])
class Crew:
#If I want crew to be more than just a number
def __init__(self):
super(Crew, self).__init__()
self.number = 0
self.attitude = 70
self.accuracy = 20
self.inebriation = 10
self.price = 0
import Game