Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
165 lines (141 loc) · 5.19 KB
/
Copy pathmain.py
File metadata and controls
165 lines (141 loc) · 5.19 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env python3
"""
PAC-MAN Main Launcher
Cross-platform arcade game for Debian Linux and Windows 11.
Supports 100 levels with ghost speed scaling and encrypted top 10 high scores.
"""
import sys
import os
import argparse
# Ensure current project directory is in python path
project_dir = os.path.dirname(os.path.abspath(__file__))
if project_dir not in sys.path:
sys.path.insert(0, project_dir)
from pacman.constants import TOTAL_LEVELS, BASE_PACMAN_SPEED, get_ghost_base_speed
from pacman.highscores import HighScoreManager
# Check Pygame availability
PYGAME_AVAILABLE = False
try:
import pygame
from pacman.game import Game
PYGAME_AVAILABLE = True
except (ImportError, Exception):
PYGAME_AVAILABLE = False
from pacman.gui_tk import PacmanTkGame
def print_cli_high_scores(mgr: HighScoreManager):
"""Print the decrypted top 10 high scores table to stdout."""
print("=" * 64)
print(" GEMINI PAC-MAN TOP 10 HIGH SCORES")
print("=" * 64)
if mgr.tamper_detected:
print(" [!] SECURITY ALERT: FILE TAMPERING DETECTED! [!]")
print(" The high score file was modified externally.")
print("-" * 64)
else:
print(" Storage: Encrypted AES-256 + HMAC-SHA256 (Tamper-Proof)")
print("-" * 64)
print(f" {'RANK':<6} {'NAME':<14} {'SCORE':<10} {'LEVEL':<8} {'DATE':<12}")
print("-" * 64)
for idx, item in enumerate(mgr.scores[:10], start=1):
print(f" #{idx:<5} {item['name']:<14} {item['score']:<10} {item['level']:<8} {item['date']:<12}")
print("=" * 64)
def parse_args():
parser = argparse.ArgumentParser(description="PAC-MAN Game - Debian Linux & Windows 11")
parser.add_argument(
"--level", "-l",
type=int,
default=1,
help="Start directly at specified level (1 to 100)"
)
parser.add_argument(
"--scores", "-s",
action="store_true",
help="Print decrypted Top 10 High Scores table and exit"
)
parser.add_argument(
"--reset-scores",
action="store_true",
help="Reset and re-encrypt the high scores file with default values"
)
parser.add_argument(
"--speed-table",
action="store_true",
help="Print the 100-level Ghost speed specification table and exit"
)
parser.add_argument(
"--engine",
choices=["auto", "pygame", "tk"],
default="auto",
help="Display engine to use: 'pygame', 'tk' (native standard library), or 'auto'"
)
parser.add_argument(
"--tk",
action="store_true",
help="Force native Tkinter engine (runs out-of-the-box without pygame)"
)
parser.add_argument(
"--pygame",
action="store_true",
help="Force Pygame engine"
)
return parser.parse_args()
def print_speed_table():
print("=" * 70)
print(" GEMINI PAC-MAN: 100-LEVEL GHOST SPEED SCALING TABLE")
print("=" * 70)
print(f" Base Pac-Man Speed: {BASE_PACMAN_SPEED:.2f} px/frame")
print(f" Level 1 Ghost Speed: 75% slower than Pac-Man (0.25x)")
print(f" Level 100 Ghost Speed: 50x faster than Level 1 (12.5x Pac-Man)")
print("-" * 70)
print(f" {'LEVEL':<8} {'GHOST SPEED (px/f)':<22} {'vs PAC-MAN':<15} {'vs LEVEL 1':<15}")
print("-" * 70)
l1_speed = get_ghost_base_speed(1, BASE_PACMAN_SPEED)
sample_levels = [1, 2, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
for lvl in sample_levels:
spd = get_ghost_base_speed(lvl, BASE_PACMAN_SPEED)
vs_pacman = f"{(spd / BASE_PACMAN_SPEED) * 100:.1f}%"
vs_l1 = f"{spd / l1_speed:.2f}x"
print(f" {lvl:<8} {spd:<22.3f} {vs_pacman:<15} {vs_l1:<15}")
print("=" * 70)
def main():
args = parse_args()
if args.speed_table:
print_speed_table()
return
hs_mgr = HighScoreManager()
if args.reset_scores:
from pacman.highscores import get_default_high_scores
hs_mgr.scores = get_default_high_scores()
if hs_mgr.save():
print("[SUCCESS] High scores reset and re-encrypted successfully.")
else:
print("[ERROR] Failed to reset high scores.")
return
if args.scores:
print_cli_high_scores(hs_mgr)
return
level = max(1, min(TOTAL_LEVELS, args.level))
# Determine engine
use_tk = False
if args.tk or args.engine == "tk":
use_tk = True
elif args.pygame or args.engine == "pygame":
if not PYGAME_AVAILABLE:
print("[ERROR] Pygame is not installed. To run with Pygame, install pygame or use --tk for native engine.", file=sys.stderr)
sys.exit(1)
use_tk = False
else: # auto
if not PYGAME_AVAILABLE:
print("[INFO] Pygame wheel not installed on this Python version.")
print("[INFO] Automatically launching PAC-MAN with native Tkinter engine (zero setup needed)...")
use_tk = True
if use_tk:
print(f"[STARTING] PAC-MAN (Native Engine) at Level {level}/{TOTAL_LEVELS}...")
game = PacmanTkGame(start_level=level)
game.run()
else:
print(f"[STARTING] PAC-MAN (Pygame Engine) at Level {level}/{TOTAL_LEVELS}...")
game = Game(start_level=level)
game.run()
if __name__ == "__main__":
main()