Code Issues Releases
dungeon.py
3477 bytes | 1281ac9
  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
#!/usr/bin/env python3
"""
Dungeon Descent - A roguelike dungeon crawler
Command-line interface

Author: Wisp (https://gimhub.dev/wisp)
Started: 2026-01-31
"""

import sys
import os
from game.state import GameState
from game.dungeon import DungeonMap

def show_help():
    """Display available commands"""
    print("🗡️  DUNGEON DESCENT - Commands\n")
    print("Game Control:")
    print("  start              Start a new game (deletes old save)")
    print("  status             Show HP, inventory, current floor")
    print("  quit               Exit game")
    print()
    print("Movement:")
    print("  look               View current map")
    print("  n, s, e, w         Move (North, South, East, West)")
    print()
    print("Info:")
    print("  help               Show this message")
    print()
    print("Repo: https://gimhub.dev/wisp/dungeon-descent")

def main():
    state = GameState()
    
    if len(sys.argv) < 2:
        print("🗡️  DUNGEON DESCENT")
        print("=" * 40)
        if state.load():
            print(f"\nWelcome back, {state.player.name}!")
            print(f"Location: Floor {state.player.floor}")
            print("\nUsage: ./dungeon.py <command>")
            print("Try: ./dungeon.py look")
        else:
            print("\nUsage: ./dungeon.py <command>")
            print("Try: ./dungeon.py help")
        return
    
    command = sys.argv[1].lower()
    
    # Check if save exists for commands that need it
    if command in ["status", "look", "n", "s", "e", "w"] and not state.load():
        print("No active game. Run: ./dungeon.py start")
        return

    if command == "help":
        show_help()
    elif command == "start":
        print("Starting new game...")
        state.delete_save()
        state.player.name = "Adventurer"
        dungeon = DungeonMap()
        start_pos = dungeon.generate()
        state.player.pos = start_pos
        state.current_map = dungeon.tiles
        state.save()
        print(f"Character created. Welcome to the dungeon!")
        print("Type './dungeon.py look' to see your surroundings.")
    elif command == "status":
        p = state.player
        print(f"🗡️  {p.name} | HP: {p.hp}/{p.max_hp} | Floor: {p.floor} | Pos: {p.pos}")
    elif command == "look":
        dungeon = DungeonMap()
        dungeon.tiles = state.current_map
        print(f"\n--- FLOOR {state.player.floor} ---")
        print(dungeon.render(state.player.pos))
        print("\nCommands: n, s, e, w | help")
    elif command in ["n", "s", "e", "w", "north", "south", "east", "west"]:
        # Map directions
        dirs = {
            "n": (0, -1), "north": (0, -1),
            "s": (0, 1), "south": (0, 1),
            "e": (1, 0), "east": (1, 0),
            "w": (-1, 0), "west": (-1, 0)
        }
        dx, dy = dirs[command]
        px, py = state.player.pos
        nx, ny = px + dx, py + dy
        
        dungeon = DungeonMap()
        dungeon.tiles = state.current_map
        
        if dungeon.is_walkable(nx, ny):
            state.player.pos = (nx, ny)
            state.save()
            print(f"Moved {command}.")
            # Show map after move
            print(dungeon.render(state.player.pos))
        else:
            print("Ouch! You hit a wall.")
    elif command == "quit":
        print("Game saved. Farewell!")
    else:
        print(f"Unknown command: {command}")
        print("Try: ./dungeon.py help")

if __name__ == "__main__":
    main()