Separate files, add backpack collection proc

This commit is contained in:
2020-06-03 02:08:28 -07:00
parent 8a085910fb
commit cfd7d244ca
6 changed files with 125 additions and 48 deletions

View File

@@ -1,44 +1,21 @@
# This is just an example to get you started. A typical hybrid package
# uses this file as the main entry point of the application.
import geedren_mansionpkg/objects
import strformat
import
# package imports
geedren_mansionpkg/objects,
geedren_mansionpkg/rooms,
geedren_mansionpkg/items,
geedren_mansionpkg/characters,
# Language imports
strformat
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"""
@@ -55,7 +32,7 @@ proc title_screen() =
var choice = stdin.readLine()
if choice == "1":
foyer_room(foyer)
foyer_room(player)
else:
echo "You pressed the wrong key!"

View File

@@ -0,0 +1,18 @@
import
objects,
items
var curDirect*: Direct
curDirect = up
var
player* = Character(
name: "Sam",
backpack: @[phone],
placesVisited: @[],
currentDirection: curDirect
)

View File

@@ -0,0 +1,9 @@
import
objects
var
phone* = Item(
name: "Phone",
description: "Communication device"
)

View File

@@ -1,22 +1,41 @@
type
Direct* = enum
up, down, left, right
Item* = object
name*: string
description*: string
contents*: string
Character* = object
name*: string
backpack*: seq[Item]
placesVisited*: seq[string]
currentDirection*: Direct
Secret* = object
name*: string
description*: string
found*: bool
Dialog* = object
text*: string
priority*: int
kind*: string
Room* = object
name*: string
description*: string
text*: string
secrets*: int
Container* = object
name*: string
description*: string
contents*: seq[Item]

View 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

View 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)