Skip to content

Commit

Permalink
Main Bug Fixed
Browse files Browse the repository at this point in the history
Added min/max to prices
fixed main dup bug
  • Loading branch information
VDFaller committed Jan 7, 2014
1 parent 5315ec5 commit 7b08b91
Showing 3 changed files with 65 additions and 29 deletions.
16 changes: 8 additions & 8 deletions Config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Cargo = ["Spices", "Cannons", "Tea", "Contraband", "Fruit", "Textiles"]
cargo = ["Spices", "Cannons", "Tea", "Contraband", "Fruit", "Textiles"]

upgrade_items = {
1: [["Iron Hull", "Damage Reduction +.05, Speed -1", 1000],
@@ -21,13 +21,13 @@


port_prices = {
# initial, mu, sell_price
"Spices": [30, 3, .8],
"Cannons": [100, 10, .8],
"Tea": [40, 5, .8],
"Contraband": [400, 40, .8],
"Fruit": [60, 8, .8],
"Textiles": [40, 5, .8]
# initial, mu, sell price coefficient, min, max
"Spices": [30, 3, .8, 10, 60],
"Cannons": [100, 10, .8, 30, 200],
"Tea": [40, 5, .8, 10, 80],
"Contraband": [400, 40, .8, 200, 800],
"Fruit": [60, 8, .8, 20, 120],
"Textiles": [40, 5, .8, 4, 65]
}

list_ports = ["Barbados", "Bermuda", "Bahamas", "Tortuga"]
70 changes: 50 additions & 20 deletions Game.py
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ def __init__(self, parent=None):
aren't created yet)"""
super(MainWindow, self).__init__(parent)
self.setupUi(self)
self.setWindowTitle("Faller's a Pirate")
self.btn_hire_crew.clicked.connect(
lambda: self.game.current_player.hire_crew(self))
self.btn_fire_crew.clicked.connect(
@@ -199,13 +200,14 @@ def trade_ships(p1, p2):

class Cargo_UI(QtWidgets.QDialog, UI.Buy_Cargo.Ui_Dialog):
"""The Dialog for initiation"""
def __init__(self, player, window, trade):
def __init__(self, player, window, trade, p2=None):
"""Just initiate"""
super().__init__()
self.window = window
self.player = player
self.setupUi(self)
self.trade = trade
self.p2 = p2
# initiates all the buttons and sets up buy/sell prices
for i in Config.port_prices:
up = getattr(self, "btn_" + i + "_up")
@@ -215,40 +217,63 @@ def __init__(self, player, window, trade):
add_price = getattr(self, "H_" + i)
if trade == "buy":
add_price.setText(i +
" (" + str(self.player.port.price[i]) + ")")
" ($" + str(self.player.port.price[i]) + ")")
elif trade == "sell":
add_price.setText(i +
" (" + str(self.player.port.sell_price[i]) + ")")
" ($" + str(self.player.port.sell_price[i]) + ")")
elif trade == "Pirate":
add_price.setText(i +
" (" + str(p2.ship.cargo[i]) + ")")
self.buttonBox.accepted.connect(
partial(self.accept_, self.player, self.window))

def count_cargo(self, player):
def count_cargo(self):
"""counts total cargo selected as well as on ship"""
want = int(self.V_Cannons.text()) + \
int(self.V_Contraband.text()) + \
int(self.V_Spices.text()) + \
int(self.V_Fruit.text()) + \
int(self.V_Textiles.text()) + \
int(self.V_Tea.text())
have = sum(player.ship.cargo.values())
have = sum(self.player.ship.cargo.values())
cargo = want + have
return cargo

def up(self, item):
"""makes selects direction of button with some error checking"""
total_cargo = self.count_cargo(self.player)
total_cargo = self.count_cargo()
total_cost = int(self.V_Total.text())
label = getattr(self, "V_" + str(item))
current = int(label.text())
#conditional for buy
if self.trade == "buy":
price = self.player.port.price[item]
okaygo = total_cargo < self.player.ship.max_cargo
no_str = "That's max cargo"
if total_cargo + 1 > self.player.ship.max_cargo:
okaygo = False
no_str = "That's max cargo"
elif total_cost + price > self.player.money:
okaygo = False
no_str = "You have no more money"
else:
okaygo = True
#conditional for sell
elif self.trade == "sell":
price = self.player.port.sell_price[item]
#just to make sure you have enough 'item' to sell
okaygo = self.player.ship.cargo[item] > current
no_str = "You have no more to sell"
#Much weirder
elif self.trade == "Pirate":
price = 0
if total_cargo + 1 > self.player.ship.max_cargo:
okaygo = False
no_str = "That's max cargo"
elif current >= self.p2.ship.cargo[item]:
okaygo = False
no_str = "That's all they have"
else:
okaygo = True

if okaygo:
label.setNum(current + 1)
self.V_Total.setNum(total_cost + price)
@@ -263,6 +288,8 @@ def down(self, item):
price = self.player.port.price[item]
elif self.trade == "sell":
price = self.player.port.sell_price[item]
elif self.trade == "Pirate":
price = 0
current = int(label.text())
if current > 0:
label.setNum(current - 1)
@@ -271,23 +298,25 @@ def down(self, item):
def accept_(self, player, window):
"""checks for enough money and buys/sells"""
if self.trade == "buy":
if int(self.V_Total.text()) <= player.money:
for i in player.ship.cargo:
num = int(getattr(self, "V_" + i).text())
player.ship.cargo[i] += num
window.to_pe()
player.change_money("down",
int(self.V_Total.text()), window)
self.close()
else:
window.textBrowser.append("Go get more moolah")
if self.trade == "sell":
for i in player.ship.cargo:
num = int(getattr(self, "V_" + i).text())
player.ship.cargo[i] += num
window.to_pe()
player.change_money("down",
int(self.V_Total.text()), window)
self.close()
elif self.trade == "sell":
for i in player.ship.cargo:
num = int(getattr(self, "V_" + i).text())
player.ship.cargo[i] -= num
player.change_money("up", int(self.V_Total.text()), window)
window.to_pe()
self.close()
elif self.trade == "Pirate":
#Pirates the number with no money exchange
for i in player.ship.cargo:
num = int(getattr(self, "V_" + i).text())
player.ship.cargo[i] += num


class Battle(object):
@@ -363,7 +392,8 @@ def board(self, attacker, attackee, window):
"""Attempt to board"""
if attacker.ship.health / attackee.ship.health > 1.5:
window.textBrowser.append("You successfully boarded")
self.pirate_cargo(attacker, attackee, window)
dia = Cargo_UI(attacker, window, "Pirate", attackee)
dia.show()
window.game.myturn = False
else:
window.textBrowser.append("You can't board")
8 changes: 7 additions & 1 deletion Logic.py
Original file line number Diff line number Diff line change
@@ -202,6 +202,7 @@ def pay_crew(self, window): # Needs update
cost = self.crew.price * self.crew.number
if self.money > cost:
self.change_money("down", cost, window)
window.textBrowser.append("Paid Crew ${}".format(cost))
self.crew.attitude = min(self.crew.attitude + .5, 100)
else:
self.crew.attitude = max(self.crew.attitude - 5, 0)
@@ -280,8 +281,13 @@ def make_prices(self):
def change_prices(self):
"""Changes the prices in the port based on current prices of the port"""
for i in self.price:
self.price[i] = math.floor(random.gauss(self.price[i],
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] *

0 comments on commit 7b08b91

Please sign in to comment.