aboutsummaryrefslogtreecommitdiffstats
path: root/Sources/game/main.swift
diff options
context:
space:
mode:
authorMaksymilian Jopek <maks@jopek.eu>2022-02-15 21:42:58 +0100
committerMaksymilian Jopek <maks@jopek.eu>2022-02-15 21:42:58 +0100
commit445fa02406347e0fc1fb3c8dd778cb706ab4fda8 (patch)
tree7ac301e265ccb12fdb5aa87b348e2183c2dbf2be /Sources/game/main.swift
downloadkappalepeli-master.tar.gz
kappalepeli-master.tar.zst
kappalepeli-master.zip
Iniitial commit - v1.0.0HEADmaster
Diffstat (limited to 'Sources/game/main.swift')
-rw-r--r--Sources/game/main.swift241
1 files changed, 241 insertions, 0 deletions
diff --git a/Sources/game/main.swift b/Sources/game/main.swift
new file mode 100644
index 0000000..f0b5b17
--- /dev/null
+++ b/Sources/game/main.swift
@@ -0,0 +1,241 @@
+import Foundation
+
+var texts = [
+ "0": [
+ "toShow": "Hello dear player, this will be simple game, make your choices wisely as it is possible to die. Have a nice day. Click enter to play.",
+ "next": "1",
+ "where": [:],
+ ],
+]
+texts["1"] = [
+ "toShow": "You're next to small lake, you don't remember where you are, you have strong feeling that you have a mission and need to go to the nearest castle to find mage, luckily for you there's a sign pointing you with probably good direction. Go to the \n[1] castle, \n[2] stay here, \n[3] kill yourself, because of a very deep pain that you have always felt",
+ "next": "1",
+ "where": [
+ "1": "4",
+ "2": "3",
+ "3": "2",
+ ],
+ ]
+texts["2"] = [
+ "toShow": "You killed yourself. We could count that as a win I guess. <enter>",
+ "next": "-2",
+ "where": [:],
+ ]
+texts["3"] = [
+ "toShow": "You can stay here, please feel like home. \n[1] Stay for a bit longer, \n[2] go to the castle",
+ "next": "1",
+ "where": [
+ "1": "3",
+ "2": "4",
+ ],
+ ]
+texts["4"] = [
+ "toShow": "On your way to the castle a small witch alike monster crossed your way and made you fight him. It wasn't hard at all. <enter>",
+ "next": "5",
+ "where": [:],
+ ]
+texts["5"] = [
+ "toShow": "Finally, you've found the castle, you were almost there, but guard at the entrance said that he would never ever let somebody like you in. You have to find another way in. Look for it \n[1] left to the main entrance or \n[2] right",
+ "next": "1",
+ "where": [
+ "1": "8",
+ "2": "6",
+ ],
+ ]
+texts["6"] = [
+ "toShow": "You found a small cabin that looks like witch hut, \n[1]explore it or \n[2]go back",
+ "next": "1",
+ "where": [
+ "1": "30",
+ "2": "5",
+ ],
+ ]
+texts["7"] = [
+ "toShow": "You are waiting for the miracle, \n[1] wait more or \n[2] go back",
+ "next": "1",
+ "where": [
+ "1": "7",
+ "2": "5",
+ ],
+ ]
+texts["8"] = [
+ "toShow": "You have found sewage, big enough that theoratically you could go through it. \n[1] Try going through or\n[2] go back ",
+ "next": "1",
+ "where": [
+ "1": "9",
+ "2": "5",
+ ],
+ ]
+texts["9"] = [
+ "toShow": "You are in city! Maybe you smell like sh*t but you are in the city. You realised that it doesn't mean anything if you can't find a wizard and you don't know where he is. <enter>",
+ "next": "10",
+ "where": [:],
+ ]
+texts["10"] = [
+ "toShow": "[1] Ask about the mage in tavern, \n[2] look for magic tower in rich part of the city, \n[3] try screaming very loud, \n[4] try to remind yourself where he had to be",
+ "next": "1",
+ "where": [
+ "1": "11",
+ "2": "12",
+ "3": "14",
+ "4": "13",
+ ],
+ ]
+texts["11"] = [
+ "toShow": "People in tavern tells you that magic doesn't exist and you should drink something because you're talking nonsense. \n[1] Drink beer and go back outside, \n[2] go back outside",
+ "next": "1",
+ "where": [
+ "1": "10",
+ "2": "10",
+ ],
+ ]
+texts["12"] = [
+ "toShow": "There are no towers in the whole city, not even one small church tower, what a strange city you thought. Go back <enter>",
+ "next": "10",
+ "where": [:],
+ ]
+texts["13"] = [
+ "toShow": "You couldn't remind yourself anything, you realised that you dont know your name, or the name of your mother. Go back <enter>",
+ "next": "10",
+ "where": [:],
+ ]
+texts["14"] = [
+ "toShow": "You started screaming and next you remember is lying down on the floor in big old house. Was I teleported here? Did I drink too much? Look around and try to find out where you are <enter>",
+ "next": "15",
+ "where": [:],
+ ]
+texts["15"] = [
+ "toShow": "[1] Go through big old wooden doors, \n[2] search the wardrobe, \n[3] inspect the ceiling",
+ "next": "1",
+ "where": [
+ "1": "18",
+ "2": "17",
+ "3": "16",
+ ],
+ ]
+texts["16"] = [
+ "toShow": "That's very good ceiling, even you're house doesn't have such a good one. It's strange that you remember your house but not your name. You should probably try looking somewhere else <enter>",
+ "next": "15",
+ "where": [:],
+ ]
+texts["17"] = [
+ "toShow": "Wardrobe only has big old red hat. You decided to put it on, just because. You should probably try looking somewhere else <enter>",
+ "next": "31",
+ "where": [:],
+ ]
+texts["18"] = [
+ "toShow": "You found yourself in the middle of the ocean on remote island. So this what you get for pissing of the wizard or drinking too much. There's no hope from now on. \n[1] You can kill yourself or \n[2] wait till the death will come to you",
+ "next": "1",
+ "where": [
+ "1": "2",
+ "2": "19",
+ ],
+ ]
+texts["19"] = [
+ "toShow": "This is the end, maybe death can't find me here and I will be eternal? There's only one way to find out <enter>",
+ "next": "20",
+ "where": [:],
+ ]
+texts["20"] = [
+ "toShow": "Wait",
+ "next": "20",
+ "where": [:],
+ ]
+texts["30"] = [
+ "toShow": "Cabin looks very comfortable from the inside, you see some witch things that maybe will do something good for you. \n[1]Try wearing a witch hat or \n[2]try witch potion",
+ "next": "1",
+ "where": [
+ "1": "31",
+ "2": "32",
+ ],
+ ]
+texts["31"] = [
+ "toShow": "Hat seems pretty normal at first, but then you start to see only pink, and then you stop feeling the floor, and then you see completely new ideal world made up of cheese. To be continued... <enter>",
+ "next": "-2",
+ "where": [:],
+ ]
+texts["32"] = [
+ "toShow": "Potion tasted very well, but now you can see through walls and you can hear people thoughts. \n[1]Go to city to try your new skills or \n[2]stay here and study yourself",
+ "next": "1",
+ "where": [
+ "1": "34",
+ "2": "33",
+ ],
+ ]
+texts["33"] = [
+ "toShow": "You started thinking about fundamental questions about universe and you know answers to each one, you become so intelligent that you merge with the universe. {I would count that as I win}",
+ "next": "-2",
+ "where": [:],
+ ]
+texts["34"] = [
+ "toShow": "On your way to the city you see every living creature with small white border around it, unknowingly you start flying. You come to the guard and tell him that you see his wife with another man in the bed. He starts crying and runs to home, you fly to the king and tell him that this is now your kingdom. You became king and ruled those lands forever. {That's definitely a win}",
+ "next": "-2",
+ "where": [:],
+ ]
+
+@discardableResult
+func shell(_ args: String...) -> Int32 {
+ let task = Process()
+ task.launchPath = "/usr/bin/env"
+ task.arguments = args
+ do {
+ try task.run()
+ } catch {}
+ task.waitUntilExit()
+ return task.terminationStatus
+}
+
+struct Paragraph {
+ var textToShow = ""
+ var id = ""
+ var next = ""
+ var whereD: [String:String] = [:]
+
+ init(textToShow: String = "", id: String = "", next: String = "-1", whereD: Any = [:]) {
+ self.textToShow = textToShow
+ self.id = id
+ if next != "-1" {
+ self.next = next
+ }
+ self.whereD = whereD as! [String:String]
+ }
+
+ func play() {
+ shell("clear")
+ var path = "/home/maks/school/mobileApps/mendela/kappalepeli/Sources/game/imgs/"
+ // path += self.id + ".txt"
+ path += self.id + ".tpng"
+ do {
+ print(try NSString(contentsOfFile: path, encoding: 4))
+ } catch {}
+ print(self.textToShow)
+ let choice = readLine()!
+ var n = "-1"
+ if self.textToShow.contains("[") {
+ n = self.whereD[choice] ?? "-1"
+ } else {
+ n = self.next
+ }
+ if n != "-1" {
+ play_next(n)
+ } else if n == "-2" {
+ exit(0)
+ } else {
+ print("Invalid choice")
+ exit(1)
+ }
+ }
+}
+var ps: [Paragraph] = []
+func play_next(_ id: String) {
+ for p in ps {
+ if p.id == id {
+ p.play()
+ }
+ }
+}
+for (k, v) in texts {
+ let p = Paragraph(textToShow: v["toShow"]! as! String, id: k, next: v["next"]! as! String, whereD: v["where"]!)
+ ps.append(p)
+}
+ps.first(where: {$0.id == "0"})!.play()