给出一段格斗游戏连招系统的代码
时间: 2023-12-23 20:05:08 浏览: 26
这里是一个简单的格斗游戏连招系统的 Python 代码示例:
```python
# 连招类
class Combo:
def __init__(self, name, moves):
self.name = name
self.moves = moves
def execute(self):
for move in self.moves:
move()
# 招式类
class Move:
def __init__(self, name, strength):
self.name = name
self.strength = strength
def execute(self):
print(f"{self.name} with {self.strength} strength")
# 定义一些招式
punch = Move("Punch", 10)
kick = Move("Kick", 20)
block = Move("Block", 5)
# 定义一些连招
combo1 = Combo("Punch-Kick", [punch, kick])
combo2 = Combo("Punch-Punch-Kick", [punch, punch, kick])
# 执行连招
combo1.execute()
combo2.execute()
```
这个例子中,我们定义了一个 `Combo` 类和一个 `Move` 类。`Combo` 类代表一个连招,包含了多个 `Move` 类的实例,通过 `execute` 方法执行连招中的每个招式。`Move` 类代表一个单独的招式,包含了招式名称和强度,并通过 `execute` 方法执行该招式的动作。在主程序中,我们定义了一些招式和连招,并通过调用 `execute` 方法来执行它们。