def nearest_railroad(self, pl_table, prop_table, card, player_id): # Calculates where nearest railroad is, moves player to that location # If railroad is owned, uses special payment function to pay double # amount. If unowned, gives option to buy self.con = sqlite3.connect(database_file) self.cur = self.con.cursor() move_amount = (5 - self.old_location) % 10 pl_table.location(player_id, move_amount) print "\nThe nearest Railroad is the %s.\n" % (prop_table.get_value( pl_table.location(player_id), "name")) _statement = """SELECT count(id), owner FROM property WHERE owner = (SELECT owner FROM property WHERE id = %d) AND type = 'rail' AND owner <> 9 GROUP BY owner;""" \ % (pl_table.location(player_id)) prop_table.cur.execute(_statement) number_owned_rails = prop_table.cur.fetchall() if len(number_owned_rails) == 0: railroad_owner = 9 number_owned_rails = 0 else: railroad_owner = number_owned_rails[0][1] number_owned_rails = number_owned_rails[0][0] if railroad_owner != 9: if railroad_owner == player_id: print "You own this property! Enjoy your free stay" else: owed_amount = (2**number_owned_rails) * 25 print "This property is owned by %s. Pay $%d." \ % (pl_table.name(railroad_owner), owed_amount) pl_table.money_transfer(prop_table, player_id, -owed_amount, railroad_owner) else: turn.location_action(pl_table, prop_table, self, player_id, 1) self.con.close()
def nearest_utility(self, pl_table, prop_table, card, player_id): # Calculates where nearest utility is, moves player to that location # If utility is owned, rolls dice and uses special payment function # to pay 10x dice amount amount. If unowned, gives option to buy. if self.old_location >= 28 or self.old_location < 12: move_amount = (12 - self.old_location) % 40 print "\nThe nearest utility is the Electric Company." else: move_amount = (28 - self.old_location) % 40 print "\nThe nearest utility is Water Works." pl_table.location(player_id, move_amount) _statement = "SELECT owner FROM property WHERE id = %d" \ % (pl_table.location(player_id)) prop_table.cur.execute(_statement) utility_owner = prop_table.cur.fetchall()[0][0] if not utility_owner == 9: if utility_owner == player_id: print "You own this property! Enjoy your free stay." else: die_1 = random.randint(1, 6) die_2 = random.randint(1, 6) roll = die_1 + die_2 owed_amount = roll * 10 print "This property is owned by %s. You must roll \ \nthe dice and pay ten times the amount shown.\ \n\nPress Enter to roll:" \ % (pl_table.name(utility_owner)) raw_input() print "You rolled a %d and a %d. Pay $%d to %s." \ % (die_1,die_2,owed_amount,pl_table.name(utility_owner)) pl_table.money_transfer(prop_table, player_id, -owed_amount, utility_owner) else: turn.location_action(pl_table, prop_table, self, player_id, 1)
def nearest_utility(self,pl_table,prop_table,card,player_id): # Calculates where nearest utility is, moves player to that location # If utility is owned, rolls dice and uses special payment function # to pay 10x dice amount amount. If unowned, gives option to buy. if self.old_location >= 28 or self.old_location < 12: move_amount = (12 - self.old_location) % 40 print "\nThe nearest utility is the Electric Company." else: move_amount = (28 - self.old_location) % 40 print "\nThe nearest utility is Water Works." pl_table.location(player_id,move_amount) _statement = "SELECT owner FROM property WHERE id = %d" \ % (pl_table.location(player_id)) prop_table.cur.execute(_statement) utility_owner = prop_table.cur.fetchall()[0][0] if not utility_owner == 9: if utility_owner == player_id: print "You own this property! Enjoy your free stay." else: die_1 = random.randint(1,6) die_2 = random.randint(1,6) roll = die_1 + die_2 owed_amount = roll * 10 print "This property is owned by %s. You must roll \ \nthe dice and pay ten times the amount shown.\ \n\nPress Enter to roll:" \ % (pl_table.name(utility_owner)) raw_input() print "You rolled a %d and a %d. Pay $%d to %s." \ % (die_1,die_2,owed_amount,pl_table.name(utility_owner)) pl_table.money_transfer(prop_table, player_id, -owed_amount, utility_owner) else: turn.location_action(pl_table, prop_table, self, player_id,1)
def nearest_railroad(self,pl_table,prop_table,card,player_id): # Calculates where nearest railroad is, moves player to that location # If railroad is owned, uses special payment function to pay double # amount. If unowned, gives option to buy self.con = sqlite3.connect(database_file) self.cur=self.con.cursor() move_amount = (5 - self.old_location) % 10 pl_table.location(player_id,move_amount) print "\nThe nearest Railroad is the %s.\n" % (prop_table.get_value(pl_table.location(player_id), "name")) _statement = """SELECT count(id), owner FROM property WHERE owner = (SELECT owner FROM property WHERE id = %d) AND type = 'rail' AND owner <> 9 GROUP BY owner;""" \ % (pl_table.location(player_id)) prop_table.cur.execute(_statement) number_owned_rails = prop_table.cur.fetchall() if len(number_owned_rails) == 0: railroad_owner = 9 number_owned_rails = 0 else: railroad_owner = number_owned_rails[0][1] number_owned_rails = number_owned_rails[0][0] if railroad_owner != 9: if railroad_owner == player_id: print "You own this property! Enjoy your free stay" else: owed_amount = (2 ** number_owned_rails) * 25 print "This property is owned by %s. Pay $%d." \ % (pl_table.name(railroad_owner), owed_amount) pl_table.money_transfer(prop_table, player_id, -owed_amount, railroad_owner) else: turn.location_action(pl_table, prop_table, self, player_id,1) self.con.close()
def set_spot(self, pl_table, prop_table, card, player_id, dice_value): # sets player position. if flag == 0, ensures they don't pass go if card[self._flag] == 0: move_amount = 30 - pl_table.location(player_id) elif card[self._flag] == 1: if pl_table.location(player_id) < card[self._amount]: move_amount = card[self._amount] - pl_table.location(player_id) else: move_amount = card[self._amount] + 40 - pl_table.location(player_id) else: move_amount = -3 pl_table.location(player_id, move_amount) # call turn.location_action from new location turn.location_action(pl_table, prop_table, self, player_id,dice_value)
def set_spot(self, pl_table, prop_table, card, player_id, dice_value): # sets player position. if flag == 0, ensures they don't pass go if card[self._flag] == 0: move_amount = 30 - pl_table.location(player_id) elif card[self._flag] == 1: if pl_table.location(player_id) < card[self._amount]: move_amount = card[self._amount] - pl_table.location(player_id) else: move_amount = card[self._amount] + 40 - pl_table.location( player_id) else: move_amount = -3 pl_table.location(player_id, move_amount) # call turn.location_action from new location turn.location_action(pl_table, prop_table, self, player_id, dice_value)
if doubles_count == 3: # If player rolls doubles 3x in a row, sends them to jail move_amount = 30 - pl.location(whose_turn) pl.location(whose_turn, move_amount) turn.goto_jail_action(pl, whose_turn, dice_roll) dice_roll[2] = False # This elif block happens when player isn't in jail elif pl.in_jail(whose_turn) == 0: # Move player's location by roll amount pl.location(whose_turn, (dice_roll[0] + dice_roll[1])) property_name = prop.get_value(pl.location(whose_turn), "name") print "\nYou moved %d spaces and are now at %s." \ % ((dice_roll[0] + dice_roll[1]), property_name) # Takes action on space turn.location_action(pl, prop, cards, whose_turn, dice_roll) print 'Cash for %s: $%d' % (pl.name(whose_turn), pl.cash(whose_turn)) # We set doubles at END because go to jail space modifies turn.roll()[2] doubles = dice_roll[2] print '\n======================================================' # If player died on this turn, don't let them roll again if not pl.in_game(whose_turn): doubles = False if doubles and doubles_count > 0: print "Congratulations %s, you rolled doubles! Go again." % ( pl.name(whose_turn)) print "\n%s, your turn is over. %s is up next. Press Enter to advance."\ % (pl.name(whose_turn), pl.name((whose_turn + 1) % pl.table_length)) raw_input() # Print blank lines to clear output
if doubles_count == 3: # If player rolls doubles 3x in a row, sends them to jail move_amount = 30 - pl.location(whose_turn) pl.location(whose_turn,move_amount) turn.goto_jail_action(pl,whose_turn,dice_roll) dice_roll[2] = False # This elif block happens when player isn't in jail elif pl.in_jail(whose_turn) == 0: # Move player's location by roll amount pl.location(whose_turn,(dice_roll[0] + dice_roll[1])) property_name = prop.get_value(pl.location(whose_turn),"name") print "\nYou moved %d spaces and are now at %s." \ % ((dice_roll[0] + dice_roll[1]), property_name) # Takes action on space turn.location_action(pl, prop, cards, whose_turn, dice_roll) print 'Cash for %s: $%d' % (pl.name(whose_turn),pl.cash(whose_turn)) # We set doubles at END because go to jail space modifies turn.roll()[2] doubles = dice_roll[2] print '\n======================================================' # If player died on this turn, don't let them roll again if not pl.in_game(whose_turn): doubles = False if doubles and doubles_count > 0: print "Congratulations %s, you rolled doubles! Go again." % (pl.name(whose_turn)) print "\n%s, your turn is over. %s is up next. Press Enter to advance."\ % (pl.name(whose_turn), pl.name((whose_turn + 1) % pl.table_length)) raw_input() # Print blank lines to clear output print '\n' * 50 whose_turn = (whose_turn + 1) % pl.table_length