Add comprehensive test suite for game mechanics and level handling
- Introduced `test_final_level_flow.py` to validate final level transitions and game end scenarios. - Created `test_game_over_flow.py` to ensure game over conditions trigger correctly based on rat counts. - Implemented `test_keybindings.py` to verify keybinding configurations and their context-specific actions. - Developed `test_level_editor.py` to assess level editor functionalities and layout computations. - Added `test_level_io.py` for testing level data serialization and deserialization. - Established `test_loop_logic_parity.py` to ensure consistent game state across multiple simulation runs. - Created `test_non_regression.py` to simulate game behavior and capture states for future verification. - Implemented `test_verify.py` to compare current game states against a golden master for regression detection.
This commit is contained in:
+21
-5
@@ -4,6 +4,8 @@ from units import gas, rat, bomb, mine
|
||||
|
||||
|
||||
|
||||
from units.unit import UnitType
|
||||
|
||||
class UnitManager:
|
||||
def __init__(self, game):
|
||||
self.game = game
|
||||
@@ -24,11 +26,10 @@ class UnitManager:
|
||||
|
||||
def has_weapon_at(self, position):
|
||||
"""Check if there's a weapon (bomb, gas, mine) at the given position"""
|
||||
weapon_types = {UnitType.BOMB_TIMER, UnitType.BOMB_NUCLEAR, UnitType.GAS, UnitType.MINE}
|
||||
for unit in self.game.units.values():
|
||||
if unit.position == position:
|
||||
# Check if it's a weapon type (not a rat or points)
|
||||
if isinstance(unit, (bomb.Timer, bomb.NuclearBomb, gas.Gas, mine.Mine)):
|
||||
return True
|
||||
if unit.position == position and unit.type in weapon_types:
|
||||
return True
|
||||
return False
|
||||
|
||||
def can_place_weapon_at(self, position):
|
||||
@@ -43,11 +44,26 @@ class UnitManager:
|
||||
|
||||
def count_rats(self):
|
||||
count = 0
|
||||
rat_types = {UnitType.RAT_MALE, UnitType.RAT_FEMALE}
|
||||
for unit in self.game.units.values():
|
||||
if isinstance(unit, rat.Rat):
|
||||
if unit.type in rat_types:
|
||||
count += 1
|
||||
return count
|
||||
|
||||
def refill_ammo(self):
|
||||
"""Randomly refill ammo during gameplay."""
|
||||
import random
|
||||
for ammo_type, data in self.game.ammo.items():
|
||||
if ammo_type == "bomb":
|
||||
if random.random() < 0.02:
|
||||
data["count"] = min(data["count"] + 1, data["max"])
|
||||
elif ammo_type == "mine":
|
||||
if random.random() < 0.05:
|
||||
data["count"] = min(data["count"] + 1, data["max"])
|
||||
elif ammo_type == "gas":
|
||||
if random.random() < 0.01:
|
||||
data["count"] = min(data["count"] + 1, data["max"])
|
||||
|
||||
def spawn_gas(self, parent_id=None):
|
||||
if not self.can_place_weapon_at(self.game.pointer):
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user