Ejemplo n.º 1
0
 def try_handle_click(self, mouse_position):
     # logger.debug('CreateNewTowerClickHandler')
     if sprite_groups.selected_tower_icon_sprite:
         new_tower = tower.create_tower(sprite_groups.selected_tower_icon_sprite.sprite._tower_type, mouse_position,
                                        DISPLAYSURF)
         #make sure player has enough money to make this tower
         if bank.balance >= new_tower.buy_price:
             bank.withdraw(new_tower.buy_price)
             sprite_groups.tower_sprites.add(new_tower)
         sprite_groups.selected_tower_icon_sprite.empty()
         return True
     return False
Ejemplo n.º 2
0
 def try_handle_click(self, mouse_position):
     # logger.debug('CreateNewTowerClickHandler')
     if sprite_groups.selected_tower_icon_sprite:
         new_tower = tower.create_tower(
             sprite_groups.selected_tower_icon_sprite.sprite._tower_type,
             mouse_position, DISPLAYSURF)
         #make sure player has enough money to make this tower
         if bank.balance >= new_tower.buy_price:
             bank.withdraw(new_tower.buy_price)
             sprite_groups.tower_sprites.add(new_tower)
         sprite_groups.selected_tower_icon_sprite.empty()
         return True
     return False
Ejemplo n.º 3
0
 def general_upgrade(self, upgrade_object):
     """
     :param upgrade_object: a type inheriting from Upgrade, eg, SpeedUpgrade
     :param attack_value: the attack value to change, eg, self._attack_values.spee
     """
     logger.debug('upgrade_speed called')
     if upgrade_object.is_next_upgrade_exists():
         # logger.debug('inside if for is_next_upgrade_exists')
         upgrade_value, upgrade_price = upgrade_object.get_next_upgrade_value_and_price()
         if bank.balance >= upgrade_price:  # if enough money in bank, change the appropriate attack value, withdraw the price from bank, increase sell price, remove existing icon and add new one
             # attack_value_to_upgrade = upgrade_value #Python function parameters are references, passed by value, thus, changing this here doesn't change self._....
             bank.withdraw(upgrade_price)
             self.sell_price += int(upgrade_price / 2)
             upgrade_object.update_upgrade_icon()
             return upgrade_value
     else:
         # create a placeholder icon
         self._speed_upgrade_values_and_prices_and_icons.update_with_placeholder_icon()
Ejemplo n.º 4
0
 def try_handle_click(self, mouse_position):
     # logger.debug('CreateNewTowerClickHandler')
     if sprite_groups.selected_tower_icon_sprite:
         new_tower = tower.create_tower(sprite_groups.selected_tower_icon_sprite.sprite._tower_type, mouse_position,
                                        DISPLAYSURF)
         # make sure player has enough money to make this tower
         if bank.balance >= new_tower.buy_price:
             bank.withdraw(new_tower.buy_price)
             sprite_groups.tower_sprites.add(new_tower)
             # logger.debug('about to send message')
             message_buffer.push_create_new_tower_message(tower_id=id(new_tower),
                                                          tower_type=new_tower.tower_type,
                                                          speed=new_tower._attack_values.speed,
                                                          radius=new_tower._attack_values.radius,
                                                          pop_power=new_tower._attack_values.pop_power,
                                                          x_pos=new_tower.rect.centerx,
                                                          y_pos=new_tower.rect.centery)
         sprite_groups.selected_tower_icon_sprite.empty()
         return True
     return False
Ejemplo n.º 5
0
 def try_handle_click(self, mouse_position):
     # logger.debug('CreateNewTowerClickHandler')
     if sprite_groups.selected_tower_icon_sprite:
         new_tower = tower.create_tower(
             sprite_groups.selected_tower_icon_sprite.sprite._tower_type,
             mouse_position, DISPLAYSURF)
         # make sure player has enough money to make this tower
         if bank.balance >= new_tower.buy_price:
             bank.withdraw(new_tower.buy_price)
             sprite_groups.tower_sprites.add(new_tower)
             # logger.debug('about to send message')
             message_buffer.push_create_new_tower_message(
                 tower_id=id(new_tower),
                 tower_type=new_tower.tower_type,
                 speed=new_tower._attack_values.speed,
                 radius=new_tower._attack_values.radius,
                 pop_power=new_tower._attack_values.pop_power,
                 x_pos=new_tower.rect.centerx,
                 y_pos=new_tower.rect.centery)
         sprite_groups.selected_tower_icon_sprite.empty()
         return True
     return False
Ejemplo n.º 6
0
def buy_stock(session, times):
    key = "stocks"

    timeExpiry = times.get(key)

    if timeExpiry == None or time.time() > timeExpiry:

        shares = 1000
        ticker, price = __get_cheapest_stock(session)

        if ticker is not None:
            funds = True

            source = web.get(session, Constants.NEO_STOCK_BUY + ticker)
            balance = bank.getOnHandBalance(source)

            # Not enough nps get money from bank
            if balance < shares * price:
                funds = bank.withdraw(session, shares * price - balance)

            # If we have enough then buy the stocks
            if funds:
                soup = BeautifulSoup(source, "html.parser")
                ref = soup.find("input", {"name": "_ref_ck"})["value"]

                postFields = {
                    "_ref_ck": ref,
                    "type": "buy",
                    "ticker_symbol": ticker,
                    "amount_shares": shares
                }
                web.post(session, Constants.NEO_STOCK_BUY_PROCESS, postFields,
                         Constants.NEO_STOCK_BUY + ticker)
                print("Bought " + str(shares) + " of " + ticker + "!")

                times[key] = timestamp.endOfDay()

                file = open('times.pkl', 'wb')
                pickle.dump(times, file)
                file.close()

        else:
            print("No stocks currently trading below 20np")
            times[key] = timestamp.end_of_hour()
Ejemplo n.º 7
0
import bank

acct = bank.account('Justin', '123-4567', 1000)
bank.deposit(acct, 500)
bank.withdraw(acct, 200)

# 顯示 Account(Justin, 123-4567, 1300)
print(bank.desc(acct))
Ejemplo n.º 8
0
import code  # importing module code
# importing specific attributes from bank module
from bank import ACT, withdraw, deposit
# importing all attributes from area module
from area import *

amt = code.get_maintainance(1500)
print("Monthly Charge : %0.2f Rs" % amt)
code.call_cost(190, "std")

print(ACT)
withdraw(4545, 10000)
deposit(4545, 15000)

area_circle(100)
area_rect(20, 10.5)
b1 = Book(1201, "python", 1050.50)
b1.getBookInfo()
# module info
print(code.__doc__)
print(code.__file__)
print(code.__name__)
print(code.__package__)
# returns list of attributes of given module
print(dir(code))
Ejemplo n.º 9
0
    def test_withdraw(self):
        bank.balance = 100
        bank.withdraw(50)

        self.assertEqual(bank.balance, 50)
Ejemplo n.º 10
0
  print("You have no loans outstanding")
  return False

def readAllLoans():
  check = False
  for a, b in enumerate(bank.master.loans):
    if b[0] == bank.master.accounts[account] and b[1] > 0:
      temp, check = bank.master.loans[a], True
      print("Loan #%d: %.2f outstanding out of %.2f" % (a+1, temp[1], temp[3]))
  return check or print("You have no loans") or False #If check is false, will print that and return false
  

menu = [] #Form is: text, function | All functions must return true or false
menu.append(["Check Account Info", lambda: print("Balance: %.2f, Account Interest Rate: %.2f, # of Transactions %d" % (bank.getInfo(account)[1:4])) or True])
menu.append(["Deposit Money", lambda: bank.deposit(account, inputInt("Invalid Number","How much money would you like to deposit?"))])
menu.append(["Withdraw Money", lambda: (bank.withdraw(account, inputInt("Invalid Number","How much money would you like to withdraw?")))[0]])
menu.append(["Apply for Loan", applyForLoan] )
menu.append(["Pay off Loan", payLoan])
menu.append(["Read Loan Info", readAllLoans])
menu.append(["Sign Out", lambda: "Signing Out"])

while True: #Actual program loop
  #Getting user information before we give options
  while True: #This is a makeshift "repeat ... until" loop that will go through at least once
    test, account = welcome()
    if test:
      break
    else:
      cls()
      print("Account not found, try again\n") #Newlines to differentiate from regular program
  while True: #Selection of items loop
Ejemplo n.º 11
0
# importing basic module into main module
import basic
# importing specific attributes from bank module
from bank import ACT, withdraw, deposit
# importing all attributes from code module
from code import *

print(basic.MAX)
amt = basic.get_maintainance(1500)
print("Monthly Charge : %0.2f Rs" % amt)
basic.get_sum_digits("Gits@20$121$35, Raj")

print(ACT)
withdraw(2323, 10000)
deposit(2323, 5000)

area_circle(200)
area_rect(10, 15.5)
b1 = Book(1201, "Python", 450.90)
b1.getBInfo()
# getting module info
print(basic.__name__)
print(basic.__file__)
print(basic.__doc__)
print(basic.__package__)
# returns list of attributes in given module
print(dir(basic))
print(__name__)
Ejemplo n.º 12
0
    def test_withdraw(self):
        bank.balance = 100
        bank.withdraw(50)

        self.assertEqual(bank.balance, 50)