File size: 2,964 Bytes
4c75d73 |
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
#!/usr/bin/env python3
"""
Test script to verify keyboard controls integration in the running MMORPG application.
"""
import requests
import time
from src.core.game_engine import GameEngine
from src.facades.game_facade import GameFacade
def test_keyboard_integration():
"""Test that keyboard controls are properly integrated."""
print("🎮 Testing Keyboard Controls Integration")
print("=" * 50)
try:
# Initialize game engine to test backend
engine = GameEngine()
facade = GameFacade(engine)
# Test player creation (needed for keyboard controls)
player_id = facade.join_game("KeyboardTester")
print(f"✅ Player created: {player_id}")
# Test movement operations that keyboard would trigger
movements = [
("up", "🔼"),
("down", "🔽"),
("left", "◀️"),
("right", "▶️")
]
print("\n🎯 Testing movement commands (keyboard backend):")
for direction, icon in movements:
try:
result = facade.move_player(player_id, direction)
print(f" {icon} Move {direction}: {'✅' if result else '❌'}")
except Exception as e:
print(f" {icon} Move {direction}: ❌ ({str(e)})")
# Test action command (spacebar equivalent)
try:
result = facade.action_command(player_id, "special")
print(f" ⚡ Special action: {'✅' if result else '❌'}")
except Exception as e:
print(f" ⚡ Special action: ❌ ({str(e)})")
# Check if server is responding
print(f"\n🌐 Testing server connectivity:")
try:
response = requests.get("http://localhost:7865", timeout=5)
print(f" Server status: {'✅ Online' if response.status_code == 200 else '❌ Error'}")
print(f" Response time: {response.elapsed.total_seconds():.2f}s")
except Exception as e:
print(f" Server status: ❌ ({str(e)})")
# Cleanup
facade.leave_game(player_id)
print(f"\n🧹 Cleanup: Player {player_id} removed")
except Exception as e:
print(f"❌ Test failed: {str(e)}")
return False
print("\n" + "=" * 50)
print("🎉 Keyboard Integration Test Complete!")
print("✅ Backend movement commands working")
print("✅ Server responding")
print("✅ Ready for frontend keyboard controls")
print("\n💡 To test keyboard controls:")
print(" 1. Open http://localhost:7865 in browser")
print(" 2. Join the game with a player name")
print(" 3. Try WASD or Arrow keys for movement")
print(" 4. Try Spacebar for special action")
return True
if __name__ == "__main__":
test_keyboard_integration()
|