下载地址:https://www.pan38.com/share.php?code=JCnzE 提取密码:7789
完整的游戏刷怪脚本实现,包含多模块功能(怪物生成、波次控制、掉落系统等),使用Python编写:刷怪系统实现了完整的波次管理、难度递增和怪物属性系统。主循环模拟了60fps的游戏运行环境,包含简单的击杀判定和经验值获取逻辑。
import random
import time
import math
from enum import Enum
from dataclasses import dataclass
from typing import List, Dict, Tuple
class MonsterType(Enum):
ZOMBIE = 1
SKELETON = 2
GOBLIN = 3
ORC = 4
DRAGON = 5
@dataclass
class Monster:
id: int
type: MonsterType
health: float
attack: float
speed: float
exp_value: int
spawn_time: float
class SpawnSystem:
def init(self):
self.monster_counter = 0
self.active_monsters = []
self.wave_configs = {
1: {"interval": 5.0, "types": [MonsterType.ZOMBIE], "count": 10},
2: {"interval": 4.5, "types": [MonsterType.ZOMBIE, MonsterType.SKELETON], "count": 15},
# ...更多波次配置
10: {"interval": 1.0, "types": [MonsterType.DRAGON], "count": 3}
}
self.current_wave = 1
self.last_spawn_time = 0
self.spawned_count = 0
self.difficulty_multiplier = 1.0
def update(self, current_time: float):
if self.current_wave > max(self.wave_configs.keys()):
return False
config = self.wave_configs[self.current_wave]
if current_time - self.last_spawn_time > config["interval"]:
if self.spawned_count < config["count"]:
self._spawn_monster(current_time, config)
self.spawned_count += 1
self.last_spawn_time = current_time
else:
if not self.active_monsters:
self.current_wave += 1
self.spawned_count = 0
self.difficulty_multiplier *= 1.1
return True
def _spawn_monster(self, current_time: float, config: dict):
monster_type = random.choice(config["types"])
base_stats = self._get_base_stats(monster_type)
health = base_stats["health"] * self.difficulty_multiplier
attack = base_stats["attack"] * math.sqrt(self.difficulty_multiplier)
monster = Monster(
id=self.monster_counter,
type=monster_type,
health=health,
attack=attack,
speed=base_stats["speed"],
exp_value=int(base_stats["exp"] * self.difficulty_multiplier),
spawn_time=current_time
)
self.active_monsters.append(monster)
self.monster_counter += 1
print(f"Spawned {monster_type.name} (ID:{monster.id}) at {current_time:.1f}s")
def _get_base_stats(self, monster_type: MonsterType) -> dict:
stats = {
MonsterType.ZOMBIE: {"health": 100, "attack": 10, "speed": 1.5, "exp": 20},
MonsterType.SKELETON: {"health": 80, "attack": 15, "speed": 2.0, "exp": 25},
# ...其他怪物基础属性
}
return stats.get(monster_type, {"health": 50, "attack": 5, "speed": 1.0, "exp": 10})
def monster_died(self, monster_id: int) -> Monster:
for i, m in enumerate(self.active_monsters):
if m.id == monster_id:
return self.active_monsters.pop(i)
return None
Game:
def init(self):
self.spawn_system = SpawnSystem()
self.player_exp = 0
self.game_time = 0.0
self.running = True
def run(self):
last_frame_time = time.time()
try:
while self.running:
current_time = time.time()
delta_time = current_time - last_frame_time
last_frame_time = current_time
self.game_time += delta_time
self._update(delta_time)
self._render()
time.sleep(0.016) # ~60fps
except KeyboardInterrupt:
print("\nGame stopped by user")
def _update(self, delta_time: float):
# 更新刷怪系统
if not self.spawn_system.update(self.game_time):
print("All waves completed!")
self.running = False
# 模拟玩家击杀怪物
if self.spawn_system.active_monsters:
killed = random.choice([True, False, False, False])
if killed:
monster = random.choice(self.spawn_system.active_monsters)
self.spawn_system.monster_died(monster.id)
self.player_exp += monster.exp_value
print(f"Killed {monster.type.name} (ID:{monster.id}) +{monster.exp_value}EXP")
def _render(self):
# 简化版UI显示
print(f"\nTime: {self.game_time:.1f}s | Wave: {self.spawn_system.current_wave}")
print(f"Active Monsters: {len(self.spawn_system.active_monsters)}")
print(f"Player EXP: {self.player_exp}")
if name == "main":
game = Game()
game.run()