我正在做一个基于文本的小游戏,我的一个if/else语句没有给我预期的结果.当用户输掉它时,立即跳转到"Game Over!" 应该说monsterName +"击败了你!" 然后跳到游戏结束.
你们能帮忙指出我的逻辑错误吗?
// Main Game Loop
while (playerHealth > 0 && monsterHealth > 0)
{
bool playerAct = askAction();
if (playerAct == true)// User attacks
{
monsterHealth = monsterHealth - playerAtk;
if (monsterHealth < 0)
{
Console.WriteLine(monsterName + " falls to the ground, defeated. Congradulation, " + name + "!");
}
else
{
Console.WriteLine(monsterName + " takes a mighty swing back at you!");
playerHealth = playerHealth - monsterAtk;
}
}
else// User defends
{
playerHealth = …Run Code Online (Sandbox Code Playgroud) 我确定这是一个简单的错误,我已将其本地化为代码中的特定位置:
class NewProduct(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
tLabel = ttk.Label(self, text="Title: ", font=NORM_FONT).grid(row=0, padx=5, pady=5)
qLabel = ttk.Label(self, text="Quantity: ", font=NORM_FONT).grid(row=1, padx=5, pady=5)
pLabel = ttk.Label(self, text="Price: $", font=NORM_FONT).grid(row=2, padx=5, pady=5)
te = ttk.Entry(self).grid(row=0, column=1, padx=5, pady=5) # Add validation in the future
qe = ttk.Entry(self).grid(row=1, column=1, padx=5, pady=5)
pe = ttk.Entry(self).grid(row=2, column=1, padx=5, pady=5)
saveButton = ttk.Button(self, text="Save", command=lambda: self.save(self.te.get(), self.qe.get(), self.pe.get()))
#WHY IS THIS WRONG!!!!!???!?!?!?!?!?
saveButton.grid(row=4, padx=5)
cancelButton = ttk.Button(self, text="Cancel", command=lambda: popupmsg("Not functioning yet."))
cancelButton.grid(row=4, …Run Code Online (Sandbox Code Playgroud)