本文整理汇总了Python中UI.waitForKey方法的典型用法代码示例。如果您正苦于以下问题:Python UI.waitForKey方法的具体用法?Python UI.waitForKey怎么用?Python UI.waitForKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UI
的用法示例。
在下文中一共展示了UI.waitForKey方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: doBuyWeapon
# 需要导入模块: import UI [as 别名]
# 或者: from UI import waitForKey [as 别名]
def doBuyWeapon(self, Player):
ShopWaresMenu = UI.MenuClass()
ShopWaresMenu.Title = "Weapons"
# Do bying menu
while not ShopWaresMenu.Returned:
# Fill with with items & information and trade-in value
ShopWaresMenu.clear()
for ShopItem in self.WeaponList:
Name = ShopItem.descString()
ShopWaresMenu.addItem(Name)
ShopWaresMenu.CustomText = (
"You have " + str(Player.Gold) + " gp\nYour weapon: " + Player.Equipment["Weapon"].Base.descString()
)
Index = ShopWaresMenu.doMenu()
if ShopWaresMenu.Returned:
break
ShopItem = self.WeaponList[Index]
if Player.Gold < ShopItem.Value:
print("You cannot afford that!")
UI.waitForKey()
continue
# Secure the transaction
self.WeaponList.remove(ShopItem)
Player.addItem(ShopItem)
Player.Gold -= ShopItem.Value
print(ShopItem.Name, "bought")
UI.waitForKey()
示例2: save
# 需要导入模块: import UI [as 别名]
# 或者: from UI import waitForKey [as 别名]
def save():
"""Saves user character progress, returns 0 on success, -1 on failure"""
global Player
FileName = UI.xInput("Enter filename to save to (default: player.dat): ", "player.dat")
FileName = "".join(("saves/", FileName))
try:
if os.path.exists(FileName):
if input("Warning! File already exists. Type \'yes\' if you want to continue: ") != "yes":
return 0
Out = open(FileName, "wb")
pickle.dump(Player, Out)
Out.close()
except Exception:
print ("Error: " + sys.exc_info()[0])
UI.waitForKey()
return -1
print("Complete")
UI.waitForKey()
return 0
示例3: doShop
# 需要导入模块: import UI [as 别名]
# 或者: from UI import waitForKey [as 别名]
def doShop(self, Player):
"""Starts the shop interface with Player"""
# If player is dead or doesn't exist, exit the shop
if Player.Exists == 0:
print("You have to create a character first!")
UI.waitForKey()
UI.clrScr()
return
if Player.Health == 0:
print("Your character is dead! Create a new one!")
UI.waitForKey()
UI.clrScr()
return
while not self.ShopMenu.Returned:
Choice = self.ShopMenu.doMenu()
if self.ShopMenu.Returned:
self.ShopMenu.Returned = 0
break
if Choice == 0:
self.doBuyWeapon(Player)
elif Choice == 1:
self.doBuyArmor(Player)
else:
self.doSell(Player)
示例4: doBuyArmor
# 需要导入模块: import UI [as 别名]
# 或者: from UI import waitForKey [as 别名]
def doBuyArmor(self, Player):
"""Initializes armor buy dialogue with player"""
# Generate shop inventory menu
ShopWaresMenu = UI.MenuClass()
ShopWaresMenu.Title = "Armor"
while not ShopWaresMenu.Returned:
# Fill with with items & information and trade-in value
ShopWaresMenu.clear()
for ShopItem in self.ArmorList:
Name = ShopItem.descString()
ShopWaresMenu.addItem(Name)
ShopWaresMenu.CustomText = (
"You have " + str(Player.Gold) + " gp\nYour armor: " + Player.Equipment["Armor"].Base.descString()
)
Index = ShopWaresMenu.doMenu()
if ShopWaresMenu.Returned:
break
ShopItem = self.ArmorList[Index]
if Player.Gold < ShopItem.Value:
print("You cannot afford that!")
UI.waitForKey()
continue
# Secure the transaction
self.ArmorList.remove(ShopItem)
Player.Gold -= ShopItem.Value
Player.addItem(ShopItem)
print(ShopItem.Name, "bought")
UI.waitForKey()
示例5: doExamine
# 需要导入模块: import UI [as 别名]
# 或者: from UI import waitForKey [as 别名]
def doExamine(self, Player):
"""Starts cell object examination dialogue"""
while 1:
ObjectMenu = UI.MenuClass()
ObjectMenu.Title = "Objects"
for Object in self.Items:
ObjectMenu.addItem(Object.Name)
Choice = ObjectMenu.doMenu()
if ObjectMenu.Returned: break
Chosen = self.Items[Choice]
print(Chosen.descString())
ChosenMenu = UI.MenuClass()
ChosenMenu.DoCLS = 0
ChosenMenu.addItem("Take", UI.emptyCallback, "t")
Choice = ChosenMenu.doMenu()
if ChosenMenu.Returned: continue
if Choice == 0:
self.Items.remove(Chosen)
Player.Inventory.addItem(Chosen)
print("You take", Chosen.Name)
UI.waitForKey()
示例6: doSell
# 需要导入模块: import UI [as 别名]
# 或者: from UI import waitForKey [as 别名]
def doSell(self, Player):
"""Initializes sell dialogue with Player"""
while 1:
ChosenItem = Player.Inventory.chooseInventoryItem("Sell")
if ChosenItem == None:
break
Player.removeItem(ChosenItem.Base)
Player.Gold += ChosenItem.Base.Value
print(ChosenItem.Base.Name, "sold")
UI.waitForKey()
示例7: doWorld
# 需要导入模块: import UI [as 别名]
# 或者: from UI import waitForKey [as 别名]
def doWorld(self, Player):
#If player's cell not defined, find player in current cell list
if self.PlayerCell == None:
for Cell in self.Cells:
if Player in Cell.Chars:
self.PlayerCell = Cell
break
#If no player found, bail out
if self.PlayerCell == None:
print("No player detected!")
UI.waitForKey()
return
while 1:
NewCell = self.PlayerCell.doCell(Player)
if NewCell == None:
break
else:
self.PlayerCell = NewCell
示例8: doInventory
# 需要导入模块: import UI [as 别名]
# 或者: from UI import waitForKey [as 别名]
def doInventory(self, MyCell):
"""Shows character inventory menu"""
while 1:
ChosenItem = self.Inventory.chooseInventoryItem("Your inventory")
if ChosenItem == None:
break
InventoryItemMenu = UI.MenuClass()
InventoryItemMenu.Title = ChosenItem.Base.Name
if ChosenItem.Base.CanEquip:
if ChosenItem.Equipped:
InventoryItemMenu.addItem("Unequip", lambda: self.unequip(ChosenItem.Base), "U", 1)
else:
InventoryItemMenu.addItem("Equip", lambda: self.equip(ChosenItem.Base), "E", 1)
InventoryItemMenu.addItem("Drop", UI.emptyCallback, "D")
Choice = InventoryItemMenu.doMenu()
if InventoryItemMenu.Returned:
continue
if InventoryItemMenu.Items[Choice].Text == "Drop":
if ChosenItem.Count == 1:
self.removeItem((ChosenItem.Base))
MyCell.Items.append(ChosenItem.Base)
print(ChosenItem.Base.Name, "dropped")
break
while 1:
ToDrop = UI.inputNumber("Enter count of items to drop (max " + str(ChosenItem.Count) + "): ")
if ToDrop in range(ChosenItem.Count + 1):
break
print("Invalid choice")
self.removeItem(ChosenItem.Base, ToDrop)
print(ChosenItem.Base.Name, "x", ToDrop, "dropped")
MyCell.Items.append(ChosenItem.Base)
UI.waitForKey()
示例9: load
# 需要导入模块: import UI [as 别名]
# 或者: from UI import waitForKey [as 别名]
def load():
global Player
global Arena
FileName = UI.xInput("Enter filename to load from (default: player.dat): ", "player.dat")
FileName = "".join(("saves/", FileName))
try:
if not os.path.exists(FileName):
print("File doesn't exist!")
UI.waitForKey()
return -1
Out = open(FileName, "rb")
Player = pickle.load(Out)
Out.close()
# Resolve player's items to pointers
# TODO: Use ID's to do it, save IDs to file
for InvItem in Player.Inventory:
for MasterItem in Item.ItemList:
if InvItem.Base.Name == MasterItem.Name:
InvItem.Base = MasterItem
for InvItem in Player.Inventory:
if not InvItem.Equipped: break
Player.Equipment[InvItem.Base.Type] = InvItem
Arena.Opponent1 = Player
except Exception:
print ("Error: " + sys.exc_info()[0])
UI.waitForKey()
return -1
print("Complete")
UI.waitForKey()
return 0
示例10: PotionClass
# 需要导入模块: import UI [as 别名]
# 或者: from UI import waitForKey [as 别名]
class PotionClass(ItemClass):
def __init__(self):
self.Type = "Potion"
self.Effects = []
ItemList = {}
try:
dom = minidom.parse("items.xml")
except Exception:
print("Error while loading items.xml!")
UI.waitForKey()
exit()
#Unarmed & Unarmed
NoWeapon = WeaponClass()
NoWeapon.Name = "Fists"
NoWeapon.Probability = 0
NoWeapon = InventoryItemClass(NoWeapon)
NoArmor = ArmorClass()
NoArmor.Name = "Unarmored"
NoArmor.Probability = 0
NoArmor.AR = 0
NoArmor = InventoryItemClass(NoArmor)
NoItem = {"Weapon": NoWeapon, "Armor": NoArmor}
示例11: doShowInfo
# 需要导入模块: import UI [as 别名]
# 或者: from UI import waitForKey [as 别名]
def doShowInfo(self, Player):
"""Show player' info + waits for key"""
Player.showInfo()
UI.waitForKey()
示例12: battle
# 需要导入模块: import UI [as 别名]
# 或者: from UI import waitForKey [as 别名]
def battle(self, Op1 = None, Op2 = None):
"""Simulates a battle between two opponents"""
UI.clrScr()
if Op1 != None: self.Opponent1 = Op1
if Op2 != None: self.Opponent1 = Op2
if self.Opponent1 == None:
print("Battle error: opponent 1 not defined")
UI.waitForKey()
return
if self.ClassicMode:
self.Opponent2 = genOpponent(self.Opponent1.MaxWon+1)
#Shortcuts for Opponents 1 and 2
P1 = self.Opponent1
P2 = self.Opponent2
#If no player amongst the combatants, do not display any information
if not P1.IsPlayer and not P2.IsPlayer:
Silent = 1
else:
Silent = 0
#Battle choice menu
BattleChoiceMenu = UI.MenuClass()
BattleChoiceMenu.DoCLS = 0
BattleChoiceMenu.HasReturn = 0
BattleChoiceMenu.addItem("Attack", UI.emptyCallback, "A")
BattleChoiceMenu.addItem("Flee", UI.emptyCallback, "F")
BattleChoiceMenu.addItem("Use Potion", UI.emptyCallback, "P")
if not Silent: print("Battle between", P1.Name, "and", P2.Name)
P1.calcModifiers()
P2.calcModifiers()
if self.Initiative == None:
P1.calcInitiative()
P2.calcInitiative()
if P1.Initiative > P2.Initiative:
self.Initiative = P1
else:
self.Initiative = P2
#Who goes first is based on the initiative.
#Opponents exchange blows until someone is dead.
#Turn == 0 - first opponent's turn
if self.Initiative == P1:
BattleQueue = deque([P1, P2])
else:
BattleQueue = deque([P2, P1])
while BattleQueue[0].Health > 0 and BattleQueue[1].Health > 0:
for Fighter in BattleQueue:
Fighter.doEffects()
Fighter.calcModifiers()
Fighter = BattleQueue[0]
if Fighter.IsPlayer:
while 1:
Choice = BattleChoiceMenu.doMenu()
if Choice != 2: break
ToDrink = Fighter.Inventory.chooseInventoryItem("Potions", ["Potion"])
if ToDrink == None: continue
else: break
else:
if not Silent: time.sleep(2)
Choice = 0
#Attack, drink potion or flee?
if Choice == 0:
Fighter.attack(BattleQueue[1])
elif Choice == 1:
print("You flee the battle!")
Fighter.Health = Fighter.MaxHealth
UI.waitForKey()
return
elif Choice == 2:
print("You drink", ToDrink.Base.Name)
Fighter.useItem(ToDrink.Base)
UI.waitForKey()
BattleQueue.popleft()
BattleQueue.append(Fighter)
#Battle over
#Expire all effects
for Fighter in BattleQueue:
Fighter.clearEffects()
if Fighter.Health == 0:
if not Silent: print(Fighter.Name, "is dead!")
if Fighter.IsPlayer:
UI.waitForKey()
return
#If we are there, a player is here and he's still alive
if BattleQueue[0].Health == 0:
Player = BattleQueue[1]
Monster = BattleQueue[0]
#.........这里部分代码省略.........