fog-dungeon 3.5.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fog_dungeon-3.5.9/LICENSE +21 -0
- fog_dungeon-3.5.9/PKG-INFO +150 -0
- fog_dungeon-3.5.9/README.md +134 -0
- fog_dungeon-3.5.9/dungeon/__init__.py +39 -0
- fog_dungeon-3.5.9/dungeon/__main__.py +4 -0
- fog_dungeon-3.5.9/dungeon/board.py +149 -0
- fog_dungeon-3.5.9/dungeon/cli_args.py +119 -0
- fog_dungeon-3.5.9/dungeon/dashboard.py +180 -0
- fog_dungeon-3.5.9/dungeon/engine.py +160 -0
- fog_dungeon-3.5.9/dungeon/game.py +73 -0
- fog_dungeon-3.5.9/dungeon/io_utils.py +238 -0
- fog_dungeon-3.5.9/fog_dungeon.egg-info/PKG-INFO +150 -0
- fog_dungeon-3.5.9/fog_dungeon.egg-info/SOURCES.txt +19 -0
- fog_dungeon-3.5.9/fog_dungeon.egg-info/dependency_links.txt +1 -0
- fog_dungeon-3.5.9/fog_dungeon.egg-info/entry_points.txt +2 -0
- fog_dungeon-3.5.9/fog_dungeon.egg-info/top_level.txt +1 -0
- fog_dungeon-3.5.9/pyproject.toml +28 -0
- fog_dungeon-3.5.9/setup.cfg +4 -0
- fog_dungeon-3.5.9/tests/test_board.py +54 -0
- fog_dungeon-3.5.9/tests/test_engine.py +94 -0
- fog_dungeon-3.5.9/tests/test_io_and_cli.py +66 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Parthiv Maheshwari
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fog-dungeon
|
|
3
|
+
Version: 3.5.9
|
|
4
|
+
Summary: A cross-platform terminal Fog-of-War dungeon crawler and 2-player split-screen race.
|
|
5
|
+
Author: Parthiv Maheshwari
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: terminal,game,cli,dungeon,fog-of-war,roguelike
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Topic :: Games/Entertainment
|
|
12
|
+
Requires-Python: >=3.8
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
\# Terminal Fog-of-War Dungeon Explorer
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
A fast-paced, zero-dependency terminal dungeon crawler and split-screen 2-player race built entirely with Python's standard library. Cross-platform compatible with Windows, macOS, and Linux.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
\## Features
|
|
26
|
+
|
|
27
|
+
 1-Player Solo \& 2-Player Split-Screen Race Race head-to-head on the exact same procedural map in real time (no `Enter` key required while moving).
|
|
28
|
+
|
|
29
|
+
 Minesweeper-Style Trap Radar Uncovered safe floors display `0–4`, indicating how many traps are orthogonally adjacent.
|
|
30
|
+
|
|
31
|
+
 On-Demand Power-Ups \& Special Tiles Collect and trigger Shields (`S`), 3x3 Radars (`R`), 2x Money Multipliers (`M`), 2-Player Sabotage (`B`), linked Teleporters (`O`), Compass Shrines (`C`), and Mystery Crates (``).
|
|
32
|
+
|
|
33
|
+
 Anti-Clumping Map Generator Spreads traps, gold, and special items evenly so spawns are never boxed in.
|
|
34
|
+
|
|
35
|
+
 Persistent High Scores \& Daily Seeds Saves separate records per player name, board size, and difficulty in `highscore.json`, plus persistent `--daily` seed mode.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
\## Project Structure
|
|
40
|
+
|
|
41
|
+
 `explore.py` — Main CLI entry point.
|
|
42
|
+
|
|
43
|
+
 `cli\_args.py` — Command-line argument parsing and persistent `--daily` configuration.
|
|
44
|
+
|
|
45
|
+
 `game.py` — Multithreaded real-time game loop and terminal cursor lifecycle.
|
|
46
|
+
|
|
47
|
+
 `dashboard.py` — Instructions screen, flicker-free ANSI HUD renderer, scoreboard, and map reveal.
|
|
48
|
+
|
|
49
|
+
 `engine.py` — Core movement rules, trap resolution, and power-up logic.
|
|
50
|
+
|
|
51
|
+
 `board.py` — Procedural grid generation, anti-clumping placement, and teleporter linking.
|
|
52
|
+
|
|
53
|
+
 `io\_utils.py` — Cross-platform single-key reader (`msvcrt` `termios`), ANSI colors, and JSON storage.
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
\## Controls
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
 Action 1-Player Solo Player 1 (2P Left) Player 2 (2P Right)
|
|
62
|
+
|
|
63
|
+
 --- --- --- ---
|
|
64
|
+
|
|
65
|
+
 Move `W A S D` or `Arrow Keys` `W A S D` `Arrow Keys`
|
|
66
|
+
|
|
67
|
+
 Use Radar (`R`) `1` or `,` `1` `,` (Comma)
|
|
68
|
+
|
|
69
|
+
 Use 2x Money (`M`) `2` or `.` `2` `.` (Period)
|
|
70
|
+
|
|
71
|
+
 Use Sabotage (`B`) 2P Only `3` `` (Slash)
|
|
72
|
+
|
|
73
|
+
 Quit Match `Q` or `Ctrl+C` `Q` or `Ctrl+C` `Q` or `Ctrl+C`
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
(Note Shields `S` trigger automatically when you step on a Trap `T`.)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
\## Tile Legend
|
|
82
|
+
|
|
83
|
+
 `@` Highlighted Tile Your current position (`--hard` hides the number beneath you).
|
|
84
|
+
|
|
85
|
+
 `#` Unexplored fog.
|
|
86
|
+
|
|
87
|
+
 `0–4` Safe floor showing adjacent trap count.
|
|
88
|
+
|
|
89
|
+
 `$` Treasure (`+$10`).
|
|
90
|
+
|
|
91
|
+
 `T` Trap (`-$10` in Normal mode, resets to `$0` in `--hard` mode).
|
|
92
|
+
|
|
93
|
+
 `E` Exit (reach this to finish).
|
|
94
|
+
|
|
95
|
+
 `S` `R` `M` `B` Shield, Radar, 2x Multiplier, and Sabotage power-ups.
|
|
96
|
+
|
|
97
|
+
 `O` Linked Teleporter pad.
|
|
98
|
+
|
|
99
|
+
 `C` Compass Shrine (points toward the Exit).
|
|
100
|
+
|
|
101
|
+
 `` Mystery Crate (`+$30`, `+1 Shield`, `+1 Radar`, or a Mimic trap).
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
\## CLI Arguments \& Examples
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
|
|
109
|
+
\# Default 2-player race (10x10 Normal)
|
|
110
|
+
|
|
111
|
+
python explore.py
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
\# 1-player solo run with post-game map reveal
|
|
116
|
+
|
|
117
|
+
python explore.py --one-player --reveal
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
\# Hard mode (15x15 grid, blind cursor, $0 trap penalty) with 60s sudden death
|
|
122
|
+
|
|
123
|
+
python explore.py --hard --sudden-death 60
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
\# Custom grid size, custom player names, and custom densities
|
|
128
|
+
|
|
129
|
+
python explore.py --size 12 --name1 Alex --name2 Sam --traps 35 --gold 40
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
\# Enable persistent daily seed mode (stays on until --no-daily is passed)
|
|
134
|
+
|
|
135
|
+
python explore.py --one-player --daily
|
|
136
|
+
|
|
137
|
+
python explore.py --no-daily
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
\# View or reset saved high scores (optionally in a custom folder)
|
|
142
|
+
|
|
143
|
+
python explore.py --scores --save-json .my\_saves
|
|
144
|
+
|
|
145
|
+
python explore.py --reset-scores --save-json .my\_saves
|
|
146
|
+
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
\# Terminal Fog-of-War Dungeon Explorer
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
A fast-paced, zero-dependency terminal dungeon crawler and split-screen 2-player race built entirely with Python's standard library. Cross-platform compatible with Windows, macOS, and Linux.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
\## Features
|
|
10
|
+
|
|
11
|
+
 1-Player Solo \& 2-Player Split-Screen Race Race head-to-head on the exact same procedural map in real time (no `Enter` key required while moving).
|
|
12
|
+
|
|
13
|
+
 Minesweeper-Style Trap Radar Uncovered safe floors display `0–4`, indicating how many traps are orthogonally adjacent.
|
|
14
|
+
|
|
15
|
+
 On-Demand Power-Ups \& Special Tiles Collect and trigger Shields (`S`), 3x3 Radars (`R`), 2x Money Multipliers (`M`), 2-Player Sabotage (`B`), linked Teleporters (`O`), Compass Shrines (`C`), and Mystery Crates (``).
|
|
16
|
+
|
|
17
|
+
 Anti-Clumping Map Generator Spreads traps, gold, and special items evenly so spawns are never boxed in.
|
|
18
|
+
|
|
19
|
+
 Persistent High Scores \& Daily Seeds Saves separate records per player name, board size, and difficulty in `highscore.json`, plus persistent `--daily` seed mode.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
\## Project Structure
|
|
24
|
+
|
|
25
|
+
 `explore.py` — Main CLI entry point.
|
|
26
|
+
|
|
27
|
+
 `cli\_args.py` — Command-line argument parsing and persistent `--daily` configuration.
|
|
28
|
+
|
|
29
|
+
 `game.py` — Multithreaded real-time game loop and terminal cursor lifecycle.
|
|
30
|
+
|
|
31
|
+
 `dashboard.py` — Instructions screen, flicker-free ANSI HUD renderer, scoreboard, and map reveal.
|
|
32
|
+
|
|
33
|
+
 `engine.py` — Core movement rules, trap resolution, and power-up logic.
|
|
34
|
+
|
|
35
|
+
 `board.py` — Procedural grid generation, anti-clumping placement, and teleporter linking.
|
|
36
|
+
|
|
37
|
+
 `io\_utils.py` — Cross-platform single-key reader (`msvcrt` `termios`), ANSI colors, and JSON storage.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
\## Controls
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
 Action 1-Player Solo Player 1 (2P Left) Player 2 (2P Right)
|
|
46
|
+
|
|
47
|
+
 --- --- --- ---
|
|
48
|
+
|
|
49
|
+
 Move `W A S D` or `Arrow Keys` `W A S D` `Arrow Keys`
|
|
50
|
+
|
|
51
|
+
 Use Radar (`R`) `1` or `,` `1` `,` (Comma)
|
|
52
|
+
|
|
53
|
+
 Use 2x Money (`M`) `2` or `.` `2` `.` (Period)
|
|
54
|
+
|
|
55
|
+
 Use Sabotage (`B`) 2P Only `3` `` (Slash)
|
|
56
|
+
|
|
57
|
+
 Quit Match `Q` or `Ctrl+C` `Q` or `Ctrl+C` `Q` or `Ctrl+C`
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
(Note Shields `S` trigger automatically when you step on a Trap `T`.)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
\## Tile Legend
|
|
66
|
+
|
|
67
|
+
 `@` Highlighted Tile Your current position (`--hard` hides the number beneath you).
|
|
68
|
+
|
|
69
|
+
 `#` Unexplored fog.
|
|
70
|
+
|
|
71
|
+
 `0–4` Safe floor showing adjacent trap count.
|
|
72
|
+
|
|
73
|
+
 `$` Treasure (`+$10`).
|
|
74
|
+
|
|
75
|
+
 `T` Trap (`-$10` in Normal mode, resets to `$0` in `--hard` mode).
|
|
76
|
+
|
|
77
|
+
 `E` Exit (reach this to finish).
|
|
78
|
+
|
|
79
|
+
 `S` `R` `M` `B` Shield, Radar, 2x Multiplier, and Sabotage power-ups.
|
|
80
|
+
|
|
81
|
+
 `O` Linked Teleporter pad.
|
|
82
|
+
|
|
83
|
+
 `C` Compass Shrine (points toward the Exit).
|
|
84
|
+
|
|
85
|
+
 `` Mystery Crate (`+$30`, `+1 Shield`, `+1 Radar`, or a Mimic trap).
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
\## CLI Arguments \& Examples
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
|
|
93
|
+
\# Default 2-player race (10x10 Normal)
|
|
94
|
+
|
|
95
|
+
python explore.py
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
\# 1-player solo run with post-game map reveal
|
|
100
|
+
|
|
101
|
+
python explore.py --one-player --reveal
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
\# Hard mode (15x15 grid, blind cursor, $0 trap penalty) with 60s sudden death
|
|
106
|
+
|
|
107
|
+
python explore.py --hard --sudden-death 60
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
\# Custom grid size, custom player names, and custom densities
|
|
112
|
+
|
|
113
|
+
python explore.py --size 12 --name1 Alex --name2 Sam --traps 35 --gold 40
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
\# Enable persistent daily seed mode (stays on until --no-daily is passed)
|
|
118
|
+
|
|
119
|
+
python explore.py --one-player --daily
|
|
120
|
+
|
|
121
|
+
python explore.py --no-daily
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
\# View or reset saved high scores (optionally in a custom folder)
|
|
126
|
+
|
|
127
|
+
python explore.py --scores --save-json .my\_saves
|
|
128
|
+
|
|
129
|
+
python explore.py --reset-scores --save-json .my\_saves
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""
|
|
2
|
+
explorer: A cross-platform terminal Fog-of-War dungeon game & utility package.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from . import io_utils, board, engine, cli_args, dashboard, game
|
|
7
|
+
|
|
8
|
+
def play(**kwargs):
|
|
9
|
+
"""
|
|
10
|
+
Launch a game session directly from Python code using keyword options.
|
|
11
|
+
Supported kwargs: one_player, hard_mode, size, seed, daily, no_daily,
|
|
12
|
+
sudden_death, traps, gold, no_powerups, peaceful, reveal, no_color,
|
|
13
|
+
no_instructions, name1, name2, save_dir.
|
|
14
|
+
"""
|
|
15
|
+
cfg = cli_args.build_config(**kwargs)
|
|
16
|
+
if io_utils.IS_WINDOWS and not cfg["no_color"]:
|
|
17
|
+
os.system("")
|
|
18
|
+
game.run_session(cfg)
|
|
19
|
+
|
|
20
|
+
def run_cli(argv=None):
|
|
21
|
+
"""
|
|
22
|
+
Run the game using CLI-style arguments (defaults to sys.argv[1:] if argv is None).
|
|
23
|
+
Example: explorer.run_cli(["--one-player", "--hard"])
|
|
24
|
+
"""
|
|
25
|
+
cfg = cli_args.parse_game_config(argv=argv)
|
|
26
|
+
if io_utils.IS_WINDOWS and not cfg["no_color"]:
|
|
27
|
+
os.system("")
|
|
28
|
+
game.run_session(cfg)
|
|
29
|
+
|
|
30
|
+
__all__ = [
|
|
31
|
+
"play",
|
|
32
|
+
"run_cli",
|
|
33
|
+
"io_utils",
|
|
34
|
+
"board",
|
|
35
|
+
"engine",
|
|
36
|
+
"cli_args",
|
|
37
|
+
"dashboard",
|
|
38
|
+
"game",
|
|
39
|
+
]
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import random
|
|
2
|
+
|
|
3
|
+
def count_nearby_traps(hidden, r, c, size):
|
|
4
|
+
traps = 0
|
|
5
|
+
for dr, dc in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
|
|
6
|
+
nr, nc = r + dr, c + dc
|
|
7
|
+
if 0 <= nr < size and 0 <= nc < size and hidden[nr][nc] == "T":
|
|
8
|
+
traps += 1
|
|
9
|
+
return str(traps)
|
|
10
|
+
|
|
11
|
+
def _pick_spaced_spot(candidates, placed, min_dist):
|
|
12
|
+
random.shuffle(candidates)
|
|
13
|
+
for pos in candidates:
|
|
14
|
+
r1, c1 = pos
|
|
15
|
+
if all(abs(r1 - r2) + abs(c1 - c2) >= min_dist for r2, c2 in placed):
|
|
16
|
+
return pos
|
|
17
|
+
return next(iter(candidates), None)
|
|
18
|
+
|
|
19
|
+
def create_board(size, one_player=False, seed=None, trap_pct=28, gold_pct=30, no_powerups=False, peaceful=False):
|
|
20
|
+
if seed is not None:
|
|
21
|
+
random.seed(seed)
|
|
22
|
+
|
|
23
|
+
total = size * size
|
|
24
|
+
hidden = [["."] * size for _ in range(size)]
|
|
25
|
+
available = [(r, c) for r in range(size) for c in range(size) if (r, c) != (0, 0)]
|
|
26
|
+
|
|
27
|
+
# 1. Place Exit (E) in the far half of the board
|
|
28
|
+
far_spots = [(r, c) for (r, c) in available if r + c >= size - 1]
|
|
29
|
+
exit_pos = random.choice(far_spots if far_spots else available)
|
|
30
|
+
er, ec = exit_pos
|
|
31
|
+
hidden[er][ec] = "E"
|
|
32
|
+
available.remove(exit_pos)
|
|
33
|
+
|
|
34
|
+
# 2. Place Special Tiles unless --no-powerups is set
|
|
35
|
+
if not no_powerups:
|
|
36
|
+
pwr_each = max(1, total // 80)
|
|
37
|
+
specials = ["O", "O", "C", "?"] + ["S"] * pwr_each + ["R"] * pwr_each + ["M"] * pwr_each
|
|
38
|
+
if not one_player:
|
|
39
|
+
specials += ["B"] * pwr_each
|
|
40
|
+
|
|
41
|
+
special_placed = [exit_pos]
|
|
42
|
+
for sym in specials:
|
|
43
|
+
if not available:
|
|
44
|
+
break
|
|
45
|
+
spot = _pick_spaced_spot(available, special_placed, min_dist=2)
|
|
46
|
+
if spot:
|
|
47
|
+
sr, sc = spot
|
|
48
|
+
hidden[sr][sc] = sym
|
|
49
|
+
available.remove(spot)
|
|
50
|
+
special_placed.append(spot)
|
|
51
|
+
|
|
52
|
+
# 3. Place Traps (T) unless --peaceful or trap_pct == 0
|
|
53
|
+
effective_trap_pct = 0 if peaceful else max(0, min(80, trap_pct))
|
|
54
|
+
trap_target = int(total * (effective_trap_pct / 100.0))
|
|
55
|
+
trap_placed = []
|
|
56
|
+
safe_start_neighbors = {(0, 1), (1, 0)}
|
|
57
|
+
|
|
58
|
+
for _ in range(trap_target):
|
|
59
|
+
if not available:
|
|
60
|
+
break
|
|
61
|
+
non_adjacent = [
|
|
62
|
+
(r, c) for (r, c) in available
|
|
63
|
+
if (r, c) not in safe_start_neighbors
|
|
64
|
+
and all(abs(r - tr) + abs(c - tc) >= 2 for tr, tc in trap_placed)
|
|
65
|
+
]
|
|
66
|
+
if non_adjacent:
|
|
67
|
+
spot = random.choice(non_adjacent)
|
|
68
|
+
else:
|
|
69
|
+
fallback = [p for p in available if p not in safe_start_neighbors]
|
|
70
|
+
spot = random.choice(fallback if fallback else available)
|
|
71
|
+
tr, tc = spot
|
|
72
|
+
hidden[tr][tc] = "T"
|
|
73
|
+
available.remove(spot)
|
|
74
|
+
trap_placed.append(spot)
|
|
75
|
+
|
|
76
|
+
# 4. Place Gold ($) spaced out among remaining tiles
|
|
77
|
+
effective_gold_pct = max(0, min(80, gold_pct))
|
|
78
|
+
gold_target = int(total * (effective_gold_pct / 100.0))
|
|
79
|
+
gold_placed = []
|
|
80
|
+
for _ in range(gold_target):
|
|
81
|
+
if not available:
|
|
82
|
+
break
|
|
83
|
+
spot = _pick_spaced_spot(available, gold_placed, min_dist=2)
|
|
84
|
+
if spot:
|
|
85
|
+
gr, gc = spot
|
|
86
|
+
hidden[gr][gc] = "$"
|
|
87
|
+
available.remove(spot)
|
|
88
|
+
gold_placed.append(spot)
|
|
89
|
+
|
|
90
|
+
display = [["#"] * size for _ in range(size)]
|
|
91
|
+
display.__setitem__(0, [count_nearby_traps(hidden, 0, 0, size)] + ["#"] * (size - 1))
|
|
92
|
+
|
|
93
|
+
# Link the two teleporter coordinates
|
|
94
|
+
portal_coords = [(r, c) for r in range(size) for c in range(size) if hidden[r][c] == "O"]
|
|
95
|
+
portal_map = {}
|
|
96
|
+
if len(portal_coords) == 2:
|
|
97
|
+
p_a, p_b = portal_coords
|
|
98
|
+
portal_map[p_a] = p_b
|
|
99
|
+
portal_map[p_b] = p_a
|
|
100
|
+
|
|
101
|
+
return hidden, display, portal_map, exit_pos
|
|
102
|
+
|
|
103
|
+
def create_players(size, one_player, seed=None, name1="Player 1", name2="Player 2",
|
|
104
|
+
trap_pct=28, gold_pct=30, no_powerups=False, peaceful=False):
|
|
105
|
+
base_hidden, base_display, portal_map, exit_pos = create_board(
|
|
106
|
+
size, one_player=one_player, seed=seed,
|
|
107
|
+
trap_pct=trap_pct, gold_pct=gold_pct,
|
|
108
|
+
no_powerups=no_powerups, peaceful=peaceful
|
|
109
|
+
)
|
|
110
|
+
players = {
|
|
111
|
+
"P1": {
|
|
112
|
+
"label": name1,
|
|
113
|
+
"name": f"{name1} (WASD/Arrows)" if one_player else f"{name1} (WASD | 1,2,3)",
|
|
114
|
+
"hidden": [row[:] for row in base_hidden],
|
|
115
|
+
"display": [row[:] for row in base_display],
|
|
116
|
+
"portals": portal_map,
|
|
117
|
+
"exit_pos": exit_pos,
|
|
118
|
+
"coords": list((0, 0)),
|
|
119
|
+
"money": 0,
|
|
120
|
+
"steps": 0,
|
|
121
|
+
"shields": 0,
|
|
122
|
+
"radars": 0,
|
|
123
|
+
"multipliers": 0,
|
|
124
|
+
"sabotages": 0,
|
|
125
|
+
"status": "Ready!",
|
|
126
|
+
"done": False,
|
|
127
|
+
"finish_time": None
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if not one_player:
|
|
131
|
+
players["P2"] = {
|
|
132
|
+
"label": name2,
|
|
133
|
+
"name": f"{name2} (Arrows | , . /)",
|
|
134
|
+
"hidden": [row[:] for row in base_hidden],
|
|
135
|
+
"display": [row[:] for row in base_display],
|
|
136
|
+
"portals": portal_map,
|
|
137
|
+
"exit_pos": exit_pos,
|
|
138
|
+
"coords": list((0, 0)),
|
|
139
|
+
"money": 0,
|
|
140
|
+
"steps": 0,
|
|
141
|
+
"shields": 0,
|
|
142
|
+
"radars": 0,
|
|
143
|
+
"multipliers": 0,
|
|
144
|
+
"sabotages": 0,
|
|
145
|
+
"status": "Ready!",
|
|
146
|
+
"done": False,
|
|
147
|
+
"finish_time": None
|
|
148
|
+
}
|
|
149
|
+
return players
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import random
|
|
3
|
+
import sys
|
|
4
|
+
from datetime import datetime
|
|
5
|
+
from . import io_utils
|
|
6
|
+
|
|
7
|
+
def build_config(
|
|
8
|
+
one_player=False,
|
|
9
|
+
hard_mode=False,
|
|
10
|
+
size=None,
|
|
11
|
+
seed=None,
|
|
12
|
+
daily=False,
|
|
13
|
+
no_daily=False,
|
|
14
|
+
sudden_death=None,
|
|
15
|
+
traps=28,
|
|
16
|
+
gold=30,
|
|
17
|
+
no_powerups=False,
|
|
18
|
+
peaceful=False,
|
|
19
|
+
reveal=False,
|
|
20
|
+
no_color=False,
|
|
21
|
+
no_instructions=False,
|
|
22
|
+
name1=None,
|
|
23
|
+
name2="Player 2",
|
|
24
|
+
save_dir=None,
|
|
25
|
+
):
|
|
26
|
+
"""Builds a validated game configuration dictionary programmatically."""
|
|
27
|
+
daily_active = io_utils.sync_daily_setting(
|
|
28
|
+
enable_daily=daily,
|
|
29
|
+
disable_daily=no_daily,
|
|
30
|
+
save_dir=save_dir,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
if seed is not None:
|
|
34
|
+
resolved_seed = str(seed)
|
|
35
|
+
elif daily_active:
|
|
36
|
+
resolved_seed = f"DAILY-{datetime.now().strftime('%Y-%m-%d')}"
|
|
37
|
+
else:
|
|
38
|
+
resolved_seed = str(random.randint(10000, 99999))
|
|
39
|
+
|
|
40
|
+
if size is not None:
|
|
41
|
+
resolved_size = max(5, min(30, int(size)))
|
|
42
|
+
else:
|
|
43
|
+
resolved_size = 15 if hard_mode else 10
|
|
44
|
+
|
|
45
|
+
resolved_p1 = name1 if name1 else ("Solo" if one_player else "Player 1")
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
"one_player": bool(one_player),
|
|
49
|
+
"hard_mode": bool(hard_mode),
|
|
50
|
+
"size": resolved_size,
|
|
51
|
+
"seed": resolved_seed,
|
|
52
|
+
"daily_active": daily_active,
|
|
53
|
+
"sudden_death": sudden_death,
|
|
54
|
+
"traps": int(traps),
|
|
55
|
+
"gold": int(gold),
|
|
56
|
+
"no_powerups": bool(no_powerups),
|
|
57
|
+
"peaceful": bool(peaceful),
|
|
58
|
+
"reveal": bool(reveal),
|
|
59
|
+
"no_color": bool(no_color),
|
|
60
|
+
"no_instructions": bool(no_instructions),
|
|
61
|
+
"name1": resolved_p1,
|
|
62
|
+
"name2": str(name2),
|
|
63
|
+
"save_dir": save_dir,
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
def parse_game_config(argv=None):
|
|
67
|
+
"""Parses CLI flags (or a custom list of argument strings) into a config dictionary."""
|
|
68
|
+
parser = argparse.ArgumentParser(
|
|
69
|
+
prog="explorer",
|
|
70
|
+
description="Terminal Fog-of-War Dungeon Explorer"
|
|
71
|
+
)
|
|
72
|
+
parser.add_argument("--one-player", action="store_true", help="Play solo instead of 2-player split-screen")
|
|
73
|
+
parser.add_argument("--hard", action="store_true", help="15x15 grid (default), blind cursor, and $0 trap penalty")
|
|
74
|
+
parser.add_argument("--size", type=int, default=None, help="Custom grid size (e.g., --size 12)")
|
|
75
|
+
parser.add_argument("--seed", type=str, default=None, help="Custom seed for reproducible dungeon layouts")
|
|
76
|
+
parser.add_argument("--daily", action="store_true", help="Enable daily date-based seed (persists in JSON until --no-daily)")
|
|
77
|
+
parser.add_argument("--no-daily", action="store_true", help="Disable persistent daily seed mode")
|
|
78
|
+
parser.add_argument("--sudden-death", type=float, default=None, help="Countdown time limit in seconds (default: None)")
|
|
79
|
+
parser.add_argument("--traps", type=int, default=28, help="Trap density percentage 0-80 (default: 28)")
|
|
80
|
+
parser.add_argument("--gold", type=int, default=30, help="Gold density percentage 0-80 (default: 30)")
|
|
81
|
+
parser.add_argument("--no-powerups", action="store_true", help="Disable all power-ups, portals, compasses, and crates")
|
|
82
|
+
parser.add_argument("--peaceful", action="store_true", help="Spawn 0 traps for a pure speedrun")
|
|
83
|
+
parser.add_argument("--reveal", action="store_true", help="Reveal the full uncovered map after the game ends")
|
|
84
|
+
parser.add_argument("--no-color", action="store_true", help="Disable ANSI terminal colors")
|
|
85
|
+
parser.add_argument("--no-instructions", action="store_true", help="Skip the instructions screen and start immediately")
|
|
86
|
+
parser.add_argument("--name1", type=str, default=None, help="Custom name for Player 1 / Solo")
|
|
87
|
+
parser.add_argument("--name2", type=str, default="Player 2", help="Custom name for Player 2")
|
|
88
|
+
parser.add_argument("--scores", action="store_true", help="View saved high scores")
|
|
89
|
+
parser.add_argument("--reset-scores", action="store_true", help="Clear all saved high scores after confirmation")
|
|
90
|
+
parser.add_argument("--save-json", type=str, default=None, help="Custom directory (or .json path) to save highscores")
|
|
91
|
+
args = parser.parse_args(argv)
|
|
92
|
+
|
|
93
|
+
if args.reset_scores:
|
|
94
|
+
io_utils.reset_highscores(save_dir=args.save_json)
|
|
95
|
+
sys.exit(0)
|
|
96
|
+
|
|
97
|
+
if args.scores:
|
|
98
|
+
io_utils.display_highscores(save_dir=args.save_json)
|
|
99
|
+
sys.exit(0)
|
|
100
|
+
|
|
101
|
+
return build_config(
|
|
102
|
+
one_player=args.one_player,
|
|
103
|
+
hard_mode=args.hard,
|
|
104
|
+
size=args.size,
|
|
105
|
+
seed=args.seed,
|
|
106
|
+
daily=args.daily,
|
|
107
|
+
no_daily=args.no_daily,
|
|
108
|
+
sudden_death=args.sudden_death,
|
|
109
|
+
traps=args.traps,
|
|
110
|
+
gold=args.gold,
|
|
111
|
+
no_powerups=args.no_powerups,
|
|
112
|
+
peaceful=args.peaceful,
|
|
113
|
+
reveal=args.reveal,
|
|
114
|
+
no_color=args.no_color,
|
|
115
|
+
no_instructions=args.no_instructions,
|
|
116
|
+
name1=args.name1,
|
|
117
|
+
name2=args.name2,
|
|
118
|
+
save_dir=args.save_json,
|
|
119
|
+
)
|