state.ts
1 /** 2 * Game state types and initial state for Dunnet 3 */ 4 5 export type Direction = 'north' | 'south' | 'east' | 'west' | 6 'northeast' | 'southeast' | 'northwest' | 'southwest' | 7 'up' | 'down' | 'in' | 'out'; 8 9 export const DIRECTIONS: Direction[] = [ 10 'north', 'south', 'east', 'west', 11 'northeast', 'southeast', 'northwest', 'southwest', 12 'up', 'down', 'in', 'out' 13 ]; 14 15 export const DIRECTION_ABBREV: Record<string, Direction> = { 16 'n': 'north', 's': 'south', 'e': 'east', 'w': 'west', 17 'ne': 'northeast', 'se': 'southeast', 'nw': 'northwest', 'sw': 'southwest', 18 'u': 'up', 'd': 'down' 19 }; 20 21 export interface ObjectDef { 22 id: number; 23 roomDesc: string; // Description when in room 24 invDesc: string; // Description in inventory 25 weight: number; // Weight in pounds 26 points: number; // Points when delivered to treasure room 27 examineDesc?: string; // When examined 28 isTreasure?: boolean; 29 } 30 31 export interface RoomDef { 32 id: number; 33 name: string; // Short name 34 longDesc: string; // Full description 35 shortDesc?: string; // If visited before 36 } 37 38 export interface GameState { 39 // Location 40 currentRoom: number; 41 visitedRooms: Set<number>; 42 43 // Inventory 44 inventory: number[]; 45 jarContents: number[]; 46 47 // Objects in rooms (roomId -> objectIds) 48 roomObjects: Map<number, number[]>; 49 roomSilents: Map<number, number[]>; // Objects described but can't be taken 50 51 // Flags 52 hasLamp: boolean; 53 computerOn: boolean; 54 ethernetWorking: boolean; 55 blackLightOn: boolean; 56 inBus: boolean; 57 hasMail: boolean; 58 keyLevel: number; 59 saunaLevel: number; 60 holeOpened: boolean; 61 bearGone: boolean; 62 weightOnButton: boolean; 63 floppyUsed: boolean; 64 floppyUncompressed: boolean; 65 66 // Endgame 67 endgameStarted: boolean; 68 endgameQuestions: string[][]; 69 correctAnswer: string[] | null; 70 71 // Game progress 72 commands: number; 73 saves: number; 74 dead: boolean; 75 deathMessage: string | null; 76 77 // UNIX/DOS emulation 78 unixLoggedIn: boolean; 79 cdPath: string; 80 cdRoom: number; 81 82 // Combination for cave entrance 83 caveCombination: string; 84 } 85 86 export function createInitialState(caveCombination: string, treasureRoom: number): GameState { 87 return { 88 currentRoom: 1, // Start at dead-end 89 visitedRooms: new Set([27]), // Room 27 is "Lit room at beginning" 90 91 inventory: [1], // Start with lamp (id 1) 92 jarContents: [], 93 94 roomObjects: new Map(), 95 roomSilents: new Map(), 96 97 hasLamp: true, 98 computerOn: false, 99 ethernetWorking: true, 100 blackLightOn: false, 101 inBus: false, 102 hasMail: true, 103 keyLevel: 0, 104 saunaLevel: 0, 105 holeOpened: false, 106 bearGone: false, 107 weightOnButton: false, 108 floppyUsed: false, 109 floppyUncompressed: false, 110 111 endgameStarted: false, 112 endgameQuestions: [], 113 correctAnswer: null, 114 115 commands: 0, 116 saves: 0, 117 dead: false, 118 deathMessage: null, 119 120 unixLoggedIn: false, 121 cdPath: '/usr/toukmond', 122 cdRoom: -10, 123 124 caveCombination 125 }; 126 }