Separate files, add backpack collection proc
This commit is contained in:
@@ -1,67 +1,44 @@
|
|||||||
# This is just an example to get you started. A typical hybrid package
|
# This is just an example to get you started. A typical hybrid package
|
||||||
# uses this file as the main entry point of the application.
|
# uses this file as the main entry point of the application.
|
||||||
|
|
||||||
import geedren_mansionpkg/objects
|
import
|
||||||
import strformat
|
# package imports
|
||||||
|
geedren_mansionpkg/objects,
|
||||||
|
geedren_mansionpkg/rooms,
|
||||||
|
geedren_mansionpkg/items,
|
||||||
|
geedren_mansionpkg/characters,
|
||||||
|
# Language imports
|
||||||
|
strformat
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
|
|
||||||
var phone = Item(
|
|
||||||
name: "Phone",
|
|
||||||
description: "Communication device/ pocket computer"
|
|
||||||
)
|
|
||||||
|
|
||||||
var player = Character(
|
|
||||||
name: "Sam",
|
|
||||||
backpack: @[phone]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Room 1 of mansion
|
|
||||||
|
|
||||||
proc foyer_room() =
|
|
||||||
|
|
||||||
var foyer = Room(
|
|
||||||
name: "Foyer",
|
|
||||||
description: "Entrance Hall of the Geedren Mansion",
|
|
||||||
text: """
|
|
||||||
zdsfgzdfg
|
|
||||||
""",
|
|
||||||
secrets: 2
|
|
||||||
)
|
|
||||||
|
|
||||||
var desk = Item(
|
|
||||||
name: "Desk",
|
|
||||||
description: "A small wooden desk",
|
|
||||||
contents: "key"
|
|
||||||
)
|
|
||||||
|
|
||||||
echo foyer.text
|
proc title_screen() =
|
||||||
|
echo fmt"""
|
||||||
|
Welcome to Geedren Mansion. You are {player.name}, a capable 24 year old adventurer.
|
||||||
|
Your uncle Rob has been missing for 10 years. He went hunting for the secrets and treasure rumored to
|
||||||
|
be hidden deep within the walls of the mysterious Geedren Mansion. Now that you are of age and have
|
||||||
|
trained in adventuring, you have decided to find your uncle. Your mission is dangerous as many men
|
||||||
|
have gone missing with the mansion being their last known whereabouts. The door is unlocked and you
|
||||||
|
walk right in the doors of the massive mansion.
|
||||||
|
|
||||||
proc title_screen() =
|
"""
|
||||||
echo fmt"""
|
|
||||||
Welcome to Geedren Mansion. You are {player.name}, a capable 24 year old adventurer.
|
|
||||||
Your uncle Rob has been missing for 10 years. He went hunting for the secrets and treasure rumored to
|
|
||||||
be hidden deep within the walls of the mysterious Geedren Mansion. Now that you are of age and have
|
|
||||||
trained in adventuring, you have decided to find your uncle. Your mission is dangerous as many men
|
|
||||||
have gone missing with the mansion being their last known whereabouts. The door is unlocked and you
|
|
||||||
walk right in the doors of the massive mansion.
|
|
||||||
|
|
||||||
"""
|
stdout.write("Press 1 to contnue: ")
|
||||||
|
var choice = stdin.readLine()
|
||||||
|
|
||||||
stdout.write("Press 1 to contnue: ")
|
if choice == "1":
|
||||||
var choice = stdin.readLine()
|
foyer_room(player)
|
||||||
|
else:
|
||||||
if choice == "1":
|
echo "You pressed the wrong key!"
|
||||||
foyer_room(foyer)
|
|
||||||
else:
|
|
||||||
echo "You pressed the wrong key!"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
title_screen()
|
title_screen()
|
||||||
|
18
src/geedren_mansionpkg/characters.nim
Normal file
18
src/geedren_mansionpkg/characters.nim
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import
|
||||||
|
objects,
|
||||||
|
items
|
||||||
|
|
||||||
|
|
||||||
|
var curDirect*: Direct
|
||||||
|
curDirect = up
|
||||||
|
|
||||||
|
var
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
player* = Character(
|
||||||
|
name: "Sam",
|
||||||
|
backpack: @[phone],
|
||||||
|
placesVisited: @[],
|
||||||
|
currentDirection: curDirect
|
||||||
|
)
|
9
src/geedren_mansionpkg/items.nim
Normal file
9
src/geedren_mansionpkg/items.nim
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import
|
||||||
|
objects
|
||||||
|
|
||||||
|
|
||||||
|
var
|
||||||
|
phone* = Item(
|
||||||
|
name: "Phone",
|
||||||
|
description: "Communication device"
|
||||||
|
)
|
@@ -1,22 +1,41 @@
|
|||||||
type
|
type
|
||||||
|
|
||||||
|
Direct* = enum
|
||||||
|
up, down, left, right
|
||||||
|
|
||||||
Item* = object
|
Item* = object
|
||||||
name*: string
|
name*: string
|
||||||
description*: string
|
description*: string
|
||||||
contents*: string
|
|
||||||
|
|
||||||
Character* = object
|
Character* = object
|
||||||
name*: string
|
name*: string
|
||||||
backpack*: seq[Item]
|
backpack*: seq[Item]
|
||||||
|
placesVisited*: seq[string]
|
||||||
|
currentDirection*: Direct
|
||||||
|
|
||||||
Secret* = object
|
Secret* = object
|
||||||
|
name*: string
|
||||||
description*: string
|
description*: string
|
||||||
found*: bool
|
found*: bool
|
||||||
|
|
||||||
|
|
||||||
|
Dialog* = object
|
||||||
|
text*: string
|
||||||
|
priority*: int
|
||||||
|
kind*: string
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Room* = object
|
Room* = object
|
||||||
name*: string
|
name*: string
|
||||||
description*: string
|
description*: string
|
||||||
text*: string
|
text*: string
|
||||||
secrets*: int
|
secrets*: int
|
||||||
|
|
||||||
|
Container* = object
|
||||||
|
name*: string
|
||||||
|
description*: string
|
||||||
|
contents*: seq[Item]
|
||||||
|
|
||||||
|
|
||||||
|
|
15
src/geedren_mansionpkg/procs.nim
Normal file
15
src/geedren_mansionpkg/procs.nim
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import
|
||||||
|
strformat,
|
||||||
|
sequtils,
|
||||||
|
objects
|
||||||
|
|
||||||
|
|
||||||
|
proc addToBackpack*(player: Character , container: Container): seq[Item] =
|
||||||
|
|
||||||
|
var player = player
|
||||||
|
echo(fmt"Adding contents of {container.name} to backpack")
|
||||||
|
for b in container.contents:
|
||||||
|
player.backpack.add(b)
|
||||||
|
return player.backpack
|
||||||
|
|
||||||
|
|
39
src/geedren_mansionpkg/rooms.nim
Normal file
39
src/geedren_mansionpkg/rooms.nim
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import
|
||||||
|
objects,
|
||||||
|
characters,
|
||||||
|
items,
|
||||||
|
procs,
|
||||||
|
strformat
|
||||||
|
|
||||||
|
proc foyer_room*(player: Character) =
|
||||||
|
|
||||||
|
var
|
||||||
|
player = player
|
||||||
|
|
||||||
|
foyer = Room(
|
||||||
|
name: "Foyer",
|
||||||
|
description: "Entrance Hall of the Geedren Mansion",
|
||||||
|
text: "",
|
||||||
|
secrets: 2
|
||||||
|
)
|
||||||
|
|
||||||
|
cathDoorKey = Item(
|
||||||
|
name: "Cathedral Door Key",
|
||||||
|
description: "This key opens the door to the cathedral"
|
||||||
|
)
|
||||||
|
|
||||||
|
desk = Container(
|
||||||
|
name: "Desk",
|
||||||
|
description: "A small wooden desk",
|
||||||
|
contents: @[cathDoorKey]
|
||||||
|
)
|
||||||
|
#[
|
||||||
|
player.placesVisited.add(foyer.name)
|
||||||
|
|
||||||
|
player.backpack.add(desk.contents)
|
||||||
|
|
||||||
|
for backpack in player.backpack:
|
||||||
|
echo(fmt"{backpack.name}: {backpack.description}")
|
||||||
|
]#
|
||||||
|
|
||||||
|
discard addToBackpack(player, desk)
|
Reference in New Issue
Block a user