import random
class CakeGame:
def __init__(self):
self.ingredients = ['面粉', '糖', '鸡蛋', '牛奶', '香草精']
self.cake = []
def mix_ingredients(self):
for ingredient in self.ingredients:
self.cake.append(ingredient)
print("蛋糕材料已混合:", self.cake)
def bake_cake(self):
if len(self.cake) == len(self.ingredients):
print("蛋糕烘烤成功!")
else:
print("蛋糕烘烤失败,请确保所有材料都已混合。")
def play(self):
print("欢迎来到做蛋糕游戏!")
print("你需要按照顺序将以下材料混合:")
for i, ingredient in enumerate(self.ingredients):
print(f"{i + 1}. {ingredient}")
while True:
choice = input("请输入你要混合的材料的序号(输入q退出游戏):")
if choice == 'q':
break
elif choice.isdigit() and 1 <= int(choice) <= len(self.ingredients):
chosen_ingredient = self.ingredients[int(choice) - 1]
if chosen_ingredient not in self.cake:
self.cake.append(chosen_ingredient)
print(f"已添加{chosen_ingredient}到蛋糕中。")
else:
print(f"{chosen_ingredient}已经在蛋糕中了。")
else:
print("无效的输入,请重新输入。")
self.mix_ingredients()
self.bake_cake()
if __name__ == "__main__":
game = CakeGame()
game.play()