-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_game.py
More file actions
65 lines (51 loc) · 1.94 KB
/
test_game.py
File metadata and controls
65 lines (51 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
"""
Test script to verify the Retro Space Defender game works
"""
import pygame
import sys
import os
# Set SDL to use a dummy video driver for headless testing
os.environ['SDL_VIDEODRIVER'] = 'dummy'
def test_game():
"""Test that the game initializes properly"""
try:
# Import our game
from retro_space_defender import Game, Player, Enemy, Bullet, PowerUp
print("✅ All game classes imported successfully")
# Test pygame initialization
pygame.init()
screen = pygame.display.set_mode((800, 600))
print("✅ Pygame initialized successfully")
# Test game object creation
player = Player(400, 550)
enemy = Enemy(100, 50, 0)
bullet = Bullet(400, 500, -5, (0, 255, 0))
powerup = PowerUp(200, 100, 0)
print("✅ All game objects created successfully")
print(f" Player at ({player.x}, {player.y})")
print(f" Enemy at ({enemy.x}, {enemy.y})")
print(f" Bullet at ({bullet.x}, {bullet.y})")
print(f" PowerUp at ({powerup.x}, {powerup.y})")
# Test game initialization
game = Game()
print("✅ Game initialized successfully")
print(f" Score: {game.score}")
print(f" Level: {game.level}")
print(f" Player Health: {game.player.health}")
pygame.quit()
print("✅ All tests passed! Game is ready to play.")
return True
except Exception as e:
print(f"❌ Error during testing: {e}")
return False
if __name__ == "__main__":
print("🚀 Testing Retro Space Defender...")
print("=" * 40)
success = test_game()
print("=" * 40)
if success:
print("🎮 Game is ready! Run 'python3 retro_space_defender.py' to play!")
else:
print("💥 Game has issues that need to be fixed.")
sys.exit(0 if success else 1)