//
// File.swift
//
//
// Created by Coty Ryan Miller on 10/5/17.
//
// Willy wonka gotta lot o' paper
//
import Foundation
var playGame = true // set to false on exit.
var HealthPoints = 7
let maxHealthPoints = 80
var causeOfDeath = 0
//
// CurrentRoomNumber will let us check what room we are in to find what
// options we have in the room as well as the dungeon text to display.
//
var currentRoomNumber = 6
let actions: [String:Int] = ["look":1,
"go":2, // Best part of using dictionaries is the actions
"walk":2, // "go" and "walk" can easaly be treated as the same.
"use":3,
"throw":4,
"drop":4,
"take":5, // See?
"pick up":5, // We did it again! ;-)
"consume":6,
"eat":6,
"check pockets":7
]
let directions: [String:Int] = ["north":1,
"east":2,
"south":3,
"west": 4,
"up": 5,
"down": 6]
//---------------------------------------------------------------------
// An array for all known items names to check the "itemLocation"
// Dictionary.
//
let allItems: [String] = ["sand", "cypher", "sword"]
//
// Item location, ie: if "Cypher":6, then the cypher is in room 6.
// But if cypher is 0, then it's in the invintory.
//
var itemLocation: [String:Int] = ["cypher":6, "sword":8]
//---------------------------------------------------------------------
let stringAteSand = "You ate the sand, your mouth is now very dry."
let StringLookUp0 = "You Look up and see "
let whatsUp0 = "Darkness"
let whatsUp1 = "A beutiful sky with some birds."
let stringLookDown0 = "You look down to see your feet "
let stringLookDown1 = stringLookDown0 + " and a mysterious object"
let ColoredBlock = "█"
let ShadedBlock = "░"
var items: [String:Int] = ["sand":1] // You start out with just sand in your pocket...
// Imma use room six as an example for how items work here.
// If we pick up the cypher from room six then we remove data
// from the string "roomSixItems" so that the name no longer anounces
// that there is an item there. We will then set have "haveCypher" to
// "true" so that it apears in the invintory.
//
let DungeonText: [Int:String] = [
0:"Man you evil.",
5:"You need to play Adventure Quest 1 to go that way!",
6:"You are in a dark room, to the south you see the tunnel from where you came. You see light shining through some cracks that make out a faint image of a door to the east. ",
7:"Whoah, budy! Can't let you do that yet!"
]
//
// These lines allow us to keep track of what rooms are North/East/South/west
// of "currentRoomNumber" So we know what text/items to load when user types
// something like "go north"
//
let whatsNorthOf: [Int:Int] = [4:5, 5:6]
let whatsEastOf: [Int:Int] = [6:7]
let whatsSouthOf: [Int:Int] = [6:5]
let whatsWestOf: [Int:Int] = [1:2, 7:6]
/************************************************************************
* Battle Screen Handler
***********************************************************************/
var battleMap: [Int:Bool] = [4:true] // If room number is true, then an
// Un-fought battle resides in that
// room and
// doBattle(RoomNum: currentRoomNumber)
// should be launched.
func doBattle(roomNum: Int)
{
//--------------------------------------------------------------------
// An example battle in room 4.
//--------------------------------------------------------------------
if(roomNum == 4)
{
print("A crazed wub wub apeared!")
print("")
print("Throw sand? ")
print("[yes/no]:", terminator: "")
let wubwub = readLine()!
if wubwub == "yes"
{
print("You threw sand at the wub wub")
print("")
print("The wub wub ran away.")
battleMap[4] = false
}
else
{
HealthPoints = HealthPoints - 40
print("The crazed WubWub WubWubed you and ran off.")
print(" ")
print("The wub wub dealt 40 damage.")
causeOfDeath = 4
}
}
}
/************************************************************************
* Draw the fancy @$$ dope status bar YOOO!
***********************************************************************/
func drawCountDown(outOf: Int)
{
if outOf < 80 {
for _ in 1...outOf
{
print(ColoredBlock, terminator:"")
}
let outIn = 80 - outOf
for _ in 1...outIn
{
print(ShadedBlock, terminator:"")
}
}
// If the request is to draw 80 or more blocks...
// just draw a solid black bar.
else
{
for _ in 1...80
{
print(ColoredBlock, terminator:"")
}
}
}
/************************************************************************
* Print a string with blocks at both sides
***********************************************************************/
func printWithBlocks(text: String) {
print(ColoredBlock, terminator:"")
print(text, terminator: "")
// some maths
var maths = text.characters.count
maths = 78 - maths
for _ in 1...maths
{
print(" ", terminator: "")
}
print(ColoredBlock)
}
/************************************************************************
* Clear lines/screen function or whatever
***********************************************************************/
func clear(times: Int) {
for _ in 1...times {
print(" ")
}
}
/************************************************************************
* Clear lines/screen function with blocks on both sides
***********************************************************************/
func clearWithBlocks(times: Int) {
for _ in 1...times {
print(ColoredBlock, terminator:"")
for _ in 1...78
{
print(" ", terminator:"")
}
print(ColoredBlock)
}
}
/************************************************************************
* print the cypher key... It's a seperate function because, fuck you.
***********************************************************************/
func printCypherKey()
{
print(" Z A B")
print(" Y C")
print(" X D")
print(" W E")
print(" V F")
print(" U G")
print(" T @ H")
print(" S I")
print(" R J")
print(" Q K")
print(" P L ")
print(" O N M")
}
/************************************************************************
* main loop yo.
***********************************************************************/
clear(times: 24)
print("Your HP is \(HealthPoints)/\(maxHealthPoints)")
print(" ")
while playGame == true
{
//
// If current room has an undefeated monster... KILL IT
//
if(battleMap[currentRoomNumber]==true){doBattle(roomNum: currentRoomNumber)}
//
// Print Dungeon area desciption...
//
print(
DungeonText[currentRoomNumber] ?? // diplay room text.
"room# \(currentRoomNumber) in Library is NIL" // Displays if room doesn't exsist.
)
print(" ")
//--------------------------------------------------------------
// Print Items in the room.
//--------------------------------------------------------------
var temp0 = allItems.count - 1
repeat {
if(itemLocation[allItems[temp0]] == currentRoomNumber)
{
print("At your feet you see a shadowy silhouette.")
print(" ")
}
temp0 = temp0 - 1
} while(temp0 != 0)
//
// Print Player HealthPoints
//
print(" ")
print(": ", terminator:"")
var inputBuffer0 = readLine()!
//-----------------------------------------------------------------
// Handle "look"
//-----------------------------------------------------------------
if(actions[inputBuffer0] == 1)
{
print("Look at what?")
print(" ")
print(": ", terminator:"")
var inputBuffer1 = readLine()!
if(inputBuffer1 == allItems[0])
{
print("You take the sand out of your pocket and run it's course grain through your fingers")
print(" ")
}
if(inputBuffer1 == allItems[1])
{
if(itemLocation["cypher"] == 0){printCypherKey()}
}
}
//-----------------------------------------------------------------
// Handle "go"
//-----------------------------------------------------------------
if(actions[inputBuffer0] == 2)
{
print("Go where?")
print(" ")
print(": ", terminator:"")
var inputBuffer1 = readLine()!
let roomBackUp = currentRoomNumber // save the room number incase
// we get an invalid request.
//-------------------------------------------------------------
// Handle go north
//-------------------------------------------------------------
if(directions[inputBuffer1] == 1)
{currentRoomNumber = whatsNorthOf[currentRoomNumber] ?? 0}
//-------------------------------------------------------------
// Handle go east
//-------------------------------------------------------------
if(directions[inputBuffer1] == 2)
{currentRoomNumber = whatsEastOf[currentRoomNumber] ?? 0}
//-------------------------------------------------------------
// Handle go south
//-------------------------------------------------------------
if(directions[inputBuffer1] == 3)
{currentRoomNumber = whatsSouthOf[currentRoomNumber] ?? 0}
//-------------------------------------------------------------
// Handle go south.
//-------------------------------------------------------------
if(directions[inputBuffer1] == 4)
{currentRoomNumber = whatsWestOf[currentRoomNumber] ?? 0}
//-------------------------------------------------------------
// Temporary handlers for go up/down...
//-------------------------------------------------------------
if(directions[inputBuffer1] == 5){print("You jumped, but nothing happened...")}
if(directions[inputBuffer1] == 6){print("You layed down, but nothing happened...")}
//-------------------------------------------------------------
// If the "currentRoomNumber" is 0 then we have an invalid
// request. So let the player know and restore
// "currentRoomNumber" from "roomBackUp"
//-------------------------------------------------------------
if currentRoomNumber == 0
{
print("You cannot transverse that direction")
currentRoomNumber = roomBackUp
}
causeOfDeath = 0
}
if(actions[inputBuffer0] == 3)
{
print("Cannot go Use Things yet...")
}
//-----------------------------------------------------------
// Throw Item Handler
//-----------------------------------------------------------
if(actions[inputBuffer0] == 4)
{
print("Throw what?")
print(" ")
print(": ", terminator:"")
var inputBuffer1 = readLine()!
if inputBuffer1 == "sand" {print("You threw sand and watched it scatter.")}
print(" ")
var temp0 = allItems.count - 1
repeat {
if(itemLocation[allItems[temp0]] == 0)
{
if inputBuffer1 == allItems[temp0]
{
print(" ")
print("You tossed " + inputBuffer1)
print(" ")
//
// Place the item on the floor of current room.
//
itemLocation[allItems[temp0]] = currentRoomNumber
}
}
temp0 = temp0 - 1
} while(temp0 != 0)
}
//-----------------------------------------------------------
// Pick up item handler.
//-----------------------------------------------------------
if(actions[inputBuffer0] == 5)
{
// check if there is an item in the room
var temp1 = allItems.count - 1
var itemInRoom = " "
repeat {
if(itemLocation[allItems[temp1]] == currentRoomNumber)
{
print("You pick up a, "
+ allItems[temp1]
+ " and place it in your pocket."
)
print(" ")
itemLocation[allItems[temp1]] = 0
}
temp1 = temp1 - 1
} while(temp1 != 0)
}
//-----------------------------------------------------------
// Food Handler
//-----------------------------------------------------------
if(actions[inputBuffer0] == 6)
{
print("Eat what?")
print(" ")
print(": ", terminator:"")
var inputBuffer1 = readLine()!
if(items[inputBuffer1] == 1)
{
print(stringAteSand)
print(" ")
print("You lost 10 HP")
HealthPoints = HealthPoints - 10
causeOfDeath = 1
}
}
//-----------------------------------------------------------
// check pockets action (TODO: make less sloppy)
//-----------------------------------------------------------
if(actions[inputBuffer0] == 7)
{
print("You check your pockets to find:")
print("Sand(∞)")
print("Peanuts(3)")
if(itemLocation["Cypher"] == 0){print("Cypher Key")}
if(itemLocation["Sword"] == 0){print("Basic Sword")}
print(" ")
}
//-----------------------------------------------------------
// Handle player death
//-----------------------------------------------------------
if HealthPoints <= 0
{
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You have died~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print(" ")
print("Cause of death:")
print(" ")
if(causeOfDeath==0){print(" - Unknown.")}
if(causeOfDeath==1){print(" - Sheer stupidity.")}
if(causeOfDeath==2){print(" - Killed by troll.")}
if(causeOfDeath==3){print(" - Burned Alive.")}
if(causeOfDeath==4){print(" - Killed by a WubWub.")}
print(" ")
playGame = false
}
//drawCountDown(outOf: 80)
//printWithBlocks(text: " Hello World")
//clearWithBlocks(times: 21)
//drawCountDown(outOf: 40)
//playGame = false
}