Ejemplo n.º 1
0
def generate_treasure(b, row, column):
    t = random.choice(list(b.treasures.keys()))
    if (random.randint(0, 100) >= 100 - b.treasures[t]["rate"]
            and b.treasures[t]["count"] > 0):
        # The value of each treasure object is used differently.
        if t == "scorers":
            b.place_item(
                Treasure(
                    model=bg_color + Graphics.Sprites.TANABATA_TREE +
                    Graphics.Style.RESET_ALL,
                    value=25,
                    type="treasure.scorers",
                ),
                row,
                column,
            )
        elif t == "timers":
            b.place_item(
                Treasure(
                    model=bg_color + Graphics.Sprites.HOURGLASS_NOT_DONE +
                    Graphics.Style.RESET_ALL,
                    value=15,
                    type="treasure.timers",
                ),
                row,
                column,
            )
        elif t == "diamond":
            b.place_item(
                Treasure(
                    model=bg_color + Graphics.Sprites.GEM_STONE +
                    Graphics.Style.RESET_ALL,
                    value=30,
                    type="treasure.diamond",
                ),
                row,
                column,
            )
        elif t == "1UP":
            b.place_item(
                Treasure(
                    model=bg_color + Graphics.Sprites.HEART_WITH_RIBBON +
                    Graphics.Style.RESET_ALL,
                    value=30,
                    type="treasure.1UP",
                ),
                row,
                column,
            )
        b.treasures[t]["count"] -= 1
        b.treasures[t]["placed"] += 1
Ejemplo n.º 2
0
import examples_includes  # noqa: F401
from gamelib.Inventory import Inventory
from gamelib.Structures import Treasure

inv = Inventory(max_size=5)
print("Inventory size:" + str(inv.size()))
print("Adding a new item to inventory")
inv.add_item(Treasure(name="money"))
print("Inventory size:" + str(inv.size()))
print("Adding a new item to inventory")
inv.add_item(Treasure(name="money"))
print("Inventory size:" + str(inv.size()))
print("Adding a new item to inventory")
inv.add_item(Treasure(name="money"))
print("Inventory size:" + str(inv.size()))
print("Adding a new item to inventory")
inv.add_item(Treasure(name="money"))
print("Inventory size:" + str(inv.size()))
print("Adding a new item to inventory")
inv.add_item(Treasure(name="money"))
print("Inventory size:" + str(inv.size()))

print(inv)
print("Inventory value:" + str(inv.value()))

print("Retrieving item named 'money':" + str(inv.get_item("money")))
print("Deleting this item from inventory")
inv.delete_item("money")
print("Inventory size:" + str(inv.size()))
print("Inventory value:" + str(inv.value()))
print(inv)
Ejemplo n.º 3
0
game = Game(name='HAC Game')
p = Player(model=sprite_player['right'], name='Nazbrok')
npc1 = NPC(model=sprite_npc, name='Bad guy 1', step=1)
# Test of the PathActuator
npc1.actuator = PathActuator(path=[
    cst.UP, cst.UP, cst.UP, cst.UP, cst.UP, cst.UP, cst.UP, cst.UP, cst.RIGHT,
    cst.RIGHT, cst.RIGHT, cst.RIGHT, cst.DOWN, cst.DOWN, cst.DOWN, cst.DOWN,
    cst.DOWN, cst.DOWN, cst.DOWN, cst.DOWN, cst.LEFT, cst.LEFT, cst.LEFT,
    cst.LEFT
])

game.add_board(1, lvl1)
game.add_board(2, lvl2)

t = Treasure(model=sprite_treasure, name='Cool treasure', type='gem')
money_bag = Treasure(model=sprite_treasure2, name='money', value=20)

tree = GenericStructure(model=sprite_tree)
tree.set_overlappable(False)
tree.set_pickable(False)

portal2 = GenericActionableStructure(model=sprite_portal)
portal2.set_overlappable(False)
portal2.action = change_current_level
portal2.action_parameters = [game, 2]

portal1 = GenericActionableStructure(model=sprite_portal)
portal1.set_overlappable(False)
portal1.action = change_current_level
portal1.action_parameters = [game, 1]
Ejemplo n.º 4
0
    retry = 0
    while True :
        if row == None:
            row = random.randint(0,bonus_board.size[1]-1)
        if column == None:
            column = random.randint(0,bonus_board.size[0]-1)
        # print(f"Game.add_npc() finding a position for NPC {npc.name} trying ({x},{y})")
        if isinstance(bonus_board.item(row,column), BoardItemVoid):
            break
        elif retry > 20:
            break
        else:
            row = None
            column = None
            retry += 1
    bonus_board.place_item(Treasure(model=Sprites.MONEY_BAG, value=100, name=f'gold_bag_{k}'), row, column)

# And finally let's put 100 diamonds. Each diamond increase the score by 1000.
for k in range(0,100):
    row = None
    column = None
    retry = 0
    while True :
        if row == None:
            row = random.randint(0,bonus_board.size[1]-1)
        if column == None:
            column = random.randint(0,bonus_board.size[0]-1)
        # print(f"Game.add_npc() finding a position for NPC {npc.name} trying ({x},{y})")
        if isinstance(bonus_board.item(row,column), BoardItemVoid):
            break
        elif retry > 20:
Ejemplo n.º 5
0
    retry = 0
    while True:
        if row is None:
            row = random.randint(0, bonus_board.size[1] - 1)
        if column is None:
            column = random.randint(0, bonus_board.size[0] - 1)
        if isinstance(bonus_board.item(row, column), BoardItemVoid):
            break
        elif retry > 20:
            break
        else:
            row = None
            column = None
            retry += 1
    bonus_board.place_item(
        Treasure(model=Sprites.MONEY_BAG, value=100, name=f"gold_bag_{k}"),
        row, column)

# And finally let's put 100 diamonds. Each diamond increase the score by 1000.
for k in range(0, 100):
    row = None
    column = None
    retry = 0
    while True:
        if row is None:
            row = random.randint(0, bonus_board.size[1] - 1)
        if column is None:
            column = random.randint(0, bonus_board.size[0] - 1)
        if isinstance(bonus_board.item(row, column), BoardItemVoid):
            break
        elif retry > 20:
Ejemplo n.º 6
0
import examples_includes
from gamelib.Inventory import Inventory
from gamelib.Structures import Treasure

inv = Inventory(max_size=5)
print('Inventory size:'+str(inv.size()))
print('Adding a new item to inventory')
inv.add_item(Treasure(name='money'))
print('Inventory size:'+str(inv.size()))
print('Adding a new item to inventory')
inv.add_item(Treasure(name='money'))
print('Inventory size:'+str(inv.size()))
print('Adding a new item to inventory')
inv.add_item(Treasure(name='money'))
print('Inventory size:'+str(inv.size()))
print('Adding a new item to inventory')
inv.add_item(Treasure(name='money'))
print('Inventory size:'+str(inv.size()))
print('Adding a new item to inventory')
inv.add_item(Treasure(name='money'))
print('Inventory size:'+str(inv.size()))

print(inv)
print("Inventory value:"+str(inv.value()))

print( "Retrieving item named 'money':" + str(inv.get_item('money')) )
print('Deleting this item from inventory')
inv.delete_item('money')
print('Inventory size:'+str(inv.size()))
print("Inventory value:"+str(inv.value()))
print(inv)