本文整理汇总了Python中state.State.save_cur_state方法的典型用法代码示例。如果您正苦于以下问题:Python State.save_cur_state方法的具体用法?Python State.save_cur_state怎么用?Python State.save_cur_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类state.State
的用法示例。
在下文中一共展示了State.save_cur_state方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sell_item
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import save_cur_state [as 别名]
def sell_item():
cur_state = State()
ins_state = cur_state.load_quicksave()
player = ins_state['player']
player_inventory = player.inventory
cur_state.save_cur_state()
if len(player_inventory) == 0:
print("Your inventory is empty!")
return
idx = 0
for idx, val in enumerate(player_inventory):
print("[{}] {}".format((idx+1), val))
print("[{}] Go Back".format(idx+2))
print("------")
print()
item_idx = input("Which item do you want to sell? ")
print("------")
print()
item_keys = ["{}".format(x) for x in range(1, len(player_inventory)+2)]
if item_idx in item_keys:
if int(item_idx) == len(player_inventory)+1 \
or item_idx == 'exit' \
or item_idx == 'back':
return
print("Sold: {}".format(player_inventory[int(item_idx)-1]))
cur_state = State()
ins_state = cur_state.load_quicksave()
player = ins_state['player']
player.gold += (player_inventory[int(item_idx)-1].value * 0.7)
player.inventory.pop(int(item_idx)-1)
cur_state.save_cur_state()
print()
示例2: buy_item
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import save_cur_state [as 别名]
def buy_item(self):
cur_state = State()
ins_state = cur_state.load_quicksave()
player = ins_state['player']
player_gold = player.gold
cur_state.save_cur_state()
self.print_inventory()
print("[{}] Go Back".format(len(self.inventory)+1))
print("------")
print()
item_idx = input("Which item do you want? ")
item_keys = ["{}".format(x) for x in range(1, len(self.inventory)+2)]
if item_idx in item_keys:
if int(item_idx) == len(self.inventory)+1 \
or item_idx == 'exit' \
or item_idx == 'back':
return
if player_gold >= self.inventory[int(item_idx)-1].value:
print("Bought: {}".format(self.inventory[int(item_idx)-1]))
cur_state = State()
ins_state = cur_state.load_quicksave()
player = ins_state['player']
player.gold -= self.inventory[int(item_idx)-1].value
player.inventory.append(self.inventory[int(item_idx)-1])
cur_state.save_cur_state()
else:
print("You can't afford that!")
print()
示例3: add_to_inv
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import save_cur_state [as 别名]
def add_to_inv(item):
from state import State
cur_state = State()
ins_state = cur_state.load_quicksave()
player = ins_state['player']
player_inventory = player.inventory
player_inventory.append(item)
cur_state.save_cur_state()
示例4: add_gold
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import save_cur_state [as 别名]
def add_gold(amount):
from state import State
cur_state = State()
ins_state = cur_state.load_quicksave()
player = ins_state['player']
player_gold = player.gold
player_gold += amount
cur_state.save_cur_state()
示例5: take_loot
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import save_cur_state [as 别名]
def take_loot(enemies):
cur_state = State()
cur_state.load_quicksave()
player = cur_state.game_state["player"]
for enemy in enemies:
print("Gold dropped: {}".format(enemy.gold))
player.gold += enemy.gold
cur_state.save_cur_state()
示例6: battle
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import save_cur_state [as 别名]
def battle(self, all_combatants):
all_combatants = self.turn_order(all_combatants)
party_alive = True
enemies_alive = True
while party_alive and enemies_alive:
cur_party = []
cur_enemies = []
print()
print("*-------------------*")
for char in all_combatants:
print("{}'s HP: {} / MP: {}".format(char.name, char.cur_stats['health'], char.cur_stats['mana']))
print("Stats: {}".format(char.cur_stats))
print("Effects: {}".format(char.effects))
if issubclass(char.__class__, monsters.classes.Monster):
cur_enemies.append(char)
else:
cur_party.append(char)
print("*-------------------*")
print()
for cur_char in all_combatants:
for idx, cur_effect in enumerate(cur_char.effects):
self.init_effect(cur_char, idx)
print("{}'s Turn".format(cur_char.name))
if issubclass(cur_char.__class__, monsters.classes.Monster):
self.basic_attack(cur_char, self.get_random_target(cur_party))
else:
self.get_character_action(cur_char, cur_party, cur_enemies)
party_alive = self.check_health(cur_party)
if not party_alive:
break
enemies_alive = self.check_health(cur_enemies)
if not enemies_alive:
break
if not party_alive and enemies_alive:
print("You're party has died...")
elif not enemies_alive and party_alive:
print("All enemies have been defeated!")
for character in cur_party:
self.calculate_experience(character, cur_enemies)
self.take_loot(cur_enemies)
for enemy in cur_enemies:
del enemy
del cur_enemies
cur_state = State()
cur_state.load_quicksave()
cur_state.game_state["party"] = cur_party
cur_state.save_cur_state()
示例7: equip_item
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import save_cur_state [as 别名]
def equip_item():
from state import State
cur_state = State()
ins_state = cur_state.load_quicksave()
player = ins_state['player']
party = ins_state['party']
player_inventory = player.inventory
if len(player_inventory) == 0:
print("Nothing to equip!")
return
print("Inventory: ")
for idx, val in enumerate(player_inventory):
print("[{}] {}".format(idx+1, val))
print("------")
print()
item_idx = input("Which item do you want to equip? ")
print("------")
print()
item_keys = ["{:01d}".format(x) for x in range(1, len(player_inventory)+1)]
if item_idx in item_keys:
print("Party: ")
print()
for idx, val in enumerate(party):
print("[{}] {}".format(idx+1, val))
print("------")
print()
party_idx = input("Who do you want to equip it to? ")
print("------")
print()
party_keys = ["{:01d}".format(x) for x in range(1, len(player_inventory)+1)]
if party_idx in party_keys:
cur_character = party[int(party_idx)-1]
cur_character.equip_item(player_inventory[int(item_idx)-1], party_idx)
cur_state = State()
ins_state = cur_state.load_quicksave()
player = ins_state['player']
player_inventory = player.inventory
player_inventory.pop(int(item_idx)-1)
cur_state.save_cur_state()
cur_state.save_cur_state()
示例8: equip_item
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import save_cur_state [as 别名]
def equip_item(item, party_member):
from state import State
cur_state = State()
ins_state = cur_state.load_quicksave()
player = ins_state['player']
player_inventory = player.inventory
party = ins_state['party']
character = party[int(party_member)-1]
if issubclass(type(item), weapons.Weapon):
player_inventory.append(character.weapon)
character.weapon = item
else:
player_inventory.append(character.armor)
character.armor = item
cur_state.save_cur_state()
示例9: rest
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import save_cur_state [as 别名]
def rest():
from state import State
from time import sleep
cur_state = State()
ins_state = cur_state.load_quicksave()
party = ins_state['party']
print(".")
sleep(0.5)
print(".")
sleep(0.5)
print(".")
for idx, val in enumerate(party):
val.cur_stats = val.stats
val.effects = []
print("Your party has been healed!")
print()
cur_state.save_cur_state()
示例10: change_location
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import save_cur_state [as 别名]
def change_location(location):
cur_state = State()
ins_state = cur_state.load_quicksave()
player = ins_state['player']
player.location = location
cur_state.save_cur_state()
示例11: use_item
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import save_cur_state [as 别名]
def use_item(self, character, party, enemies):
cur_state = State()
cur_state.load_quicksave()
player = cur_state.game_state["player"]
player_inventory = player.inventory
for idx, val in enumerate(player_inventory):
if player_inventory[idx].item_type == "Equipment":
player_inventory.pop(idx)
if len(player_inventory) == 0:
print("Your inventory is empty!")
self.get_character_action(character, party, enemies)
for idx, val in enumerate(player_inventory):
print("[{}] {}".format((idx+1), val))
print("[{}] Go Back".format(len(player_inventory)+1))
print("------")
print()
item_idx = input("Which item do you want to use? ")
print("------")
print()
item_keys = ["{}".format(x) for x in range(1, len(player_inventory)+2)]
if item_idx in item_keys:
if int(item_idx) == len(player_inventory)+1 \
or item_idx == 'exit' \
or item_idx == 'back':
return None
os.system('clear') # For OSX / Linux
os.system('cls') # For Windows
cur_item = player_inventory[int(item_idx)-1]
if cur_item.default_target == 'enemy':
target_options = enemies
else:
target_options = party
target = self.pick_target(target_options)
if target is None:
return None
if cur_item.effect.scale_type == 'percent':
effectiveness = target.stats[cur_item.effect.stat] * (cur_item.effect.amount / 100)
target.cur_stats[cur_item.effect.stat] += effectiveness
else:
effectiveness = cur_item.effect.amount
target.cur_stats[cur_item.effect.stat] += effectiveness
if int(effectiveness) < 0:
print("{} did {} damage with {}!".format(character.name, abs(effectiveness), cur_item))
else:
print("{} healed for {} with {}!".format(character.name, effectiveness, cur_item))
if cur_item.effect.turns > 1:
cur_item.effect.turns -= 1
target.effects.append(cur_item.effect)
player_inventory.pop(int(item_idx)-1)
cur_state.save_cur_state()
return True