--- /dev/null
+#!/usr/bin/env python
+#
+# A text-based adventure game, based on
+# https://github.com/codinggrace/text_based_adventure_game
+#
+# MIT License
+# Copyright (c) 2020 Coding Grace
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+from pictures import *
+from gamedata import *
+
+
+def get_next_state(curr_state):
+ succ = ADVENTURE_TREE.get(curr_state)
+ if len(succ) > 1:
+ for i, s in enumerate(succ):
+ print(f"{i + 1} {OPTIONS.get(s)}")
+ inp = input()
+ return succ[int(inp) - 1]
+ return succ[0]
+
+def print_desc(curr_state):
+ print(DESCRIPTIONS.get(curr_state))
+
+def print_pic(curr_state):
+ pic = PICTURES.get(curr_state)
+ if pic is not None:
+ pic()
+
+def main():
+ name = input("What's your name?\n>> ")
+ print("Welcome {} to the adventure of your life. Try to survive and find \
+ the treasure!".format(name.upper()))
+ current_state = "Start"
+ while current_state != "End":
+ print_pic(current_state)
+ print_desc(current_state)
+ current_state = get_next_state(current_state)
+
+
+def main_old():
+ current_state = "Start"
+ succ_states = ADVENTURE_TREE[current_state]
+
+ name = input("What's your name?\n>> ")
+ print("Welcome {} to the adventure of your life. Try to survive and find the \
+ treasure!".format(name.upper()))
+ text_box = "{}\n{} {}\n{} {}".format(DESCRIPTIONS[current_state],
+ "1", OPTIONS[succ_states[0]],
+ "2", OPTIONS[succ_states[1]])
+ print_doors()
+ print(text_box)
+ inp = input(">> ")
+
+ if inp == "1":
+ current_state = "Blue"
+ succ_states = ADVENTURE_TREE[current_state]
+ text_box = "{}\n{} {}\n{} {}".format(DESCRIPTIONS["Blue"],
+ "1", OPTIONS["Chest"],
+ "2", OPTIONS["Guard"])
+ print(text_box)
+ inp = input(">> ")
+
+ if inp == "1":
+ current_state = "Chest"
+ succ_states = ADVENTURE_TREE[current_state]
+ text_box = "{}\n{} {}\n{} {}".format(DESCRIPTIONS[current_state],
+ "1", OPTIONS[succ_states[0]],
+ "2", OPTIONS[succ_states[1]])
+ print_treasure()
+ print(text_box)
+ inp = input(">> ")
+
+ if inp == "1":
+ current_state = "Take"
+ succ_states = ADVENTURE_TREE[current_state]
+ text_box = "{}\n{} {}\n{} {}".format(DESCRIPTIONS[current_state],
+ "1", OPTIONS[succ_states[0]],
+ "2", OPTIONS[succ_states[1]])
+ print(text_box)
+ inp = input(">> ")
+
+ if inp == "1":
+ current_state = "Sneak"
+ succ_states = ADVENTURE_TREE[current_state]
+
+ text_box = "{}\n{} {}\n{} {}".format(DESCRIPTIONS[current_state],
+ "1", OPTIONS[succ_states[0]],
+ "2", OPTIONS[succ_states[1]])
+
+ print_guard()
+ print(text_box)
+ inp = input(">> ")
+
+ if inp == "1":
+ current_state = "Sneak_right"
+ succ_states = ADVENTURE_TREE[current_state]
+ text_box = "{}".format(DESCRIPTIONS[current_state])
+ print(text_box)
+
+ elif inp == "2":
+ current_state = "Sneak_left"
+ succ_states = ADVENTURE_TREE[current_state]
+ text_box = "{}".format(DESCRIPTIONS[current_state])
+ print_ded()
+ print(text_box)
+ print_game_over()
+
+
+ elif inp == "2":
+ current_state = "Talk"
+ succ_states = ADVENTURE_TREE[current_state]
+ text_box = "{}".format(DESCRIPTIONS[current_state])
+ print_guard()
+ print(text_box)
+ print_game_over()
+
+ elif inp == "2":
+ current_state = "Leave"
+ succ_states = ADVENTURE_TREE[current_state]
+ text_box = "{}\n{} {}\n{} {}".format(DESCRIPTIONS[current_state],
+ "1", OPTIONS[succ_states[0]],
+ "2", OPTIONS[succ_states[1]])
+ print(text_box)
+ inp = input(">> ")
+
+ if inp == "1":
+ current_state = "Sneak"
+ succ_states = ADVENTURE_TREE[current_state]
+ text_box = "{}\n{} {}\n{} {}".format(DESCRIPTIONS[current_state],
+ "1", OPTIONS[succ_states[0]],
+ "2", OPTIONS[succ_states[1]])
+
+ print_guard()
+ print(text_box)
+ inp = input(">> ")
+
+ if inp == "1":
+ current_state = "Sneak_right"
+ succ_states = ADVENTURE_TREE[current_state]
+ text_box = "{}".format(DESCRIPTIONS[current_state])
+ print(text_box)
+
+ elif inp == "2":
+ current_state = "Sneak_left"
+ succ_states = ADVENTURE_TREE[current_state]
+ text_box = "{}".format(DESCRIPTIONS[current_state])
+ print_ded()
+ print(text_box)
+ print_game_over()
+
+
+ elif inp == "2":
+ current_state = "Talk"
+ succ_states = ADVENTURE_TREE[current_state]
+ text_box = "{}".format(DESCRIPTIONS[current_state])
+ print_guard()
+ print(text_box)
+ print_game_over()
+
+ elif inp == "2":
+ current_state = "Guard"
+ succ_states = ADVENTURE_TREE[current_state]
+ text_box = "{}\n{} {}\n{} {}".format(DESCRIPTIONS[current_state],
+ "1", OPTIONS[succ_states[0]],
+ "2", OPTIONS[succ_states[1]])
+ print(text_box)
+ inp = input(">> ")
+
+ if inp == "1":
+ current_state = "Sneak"
+ succ_states = ADVENTURE_TREE[current_state]
+ text_box = "{}\n{} {}\n{} {}".format(DESCRIPTIONS[current_state],
+ "1", OPTIONS[succ_states[0]],
+ "2", OPTIONS[succ_states[1]])
+
+ print_guard()
+ print(text_box)
+ inp = input(">> ")
+
+ if inp == "1":
+ current_state = "Sneak_right"
+ succ_states = ADVENTURE_TREE[current_state]
+ text_box = "{}".format(DESCRIPTIONS[current_state])
+ print(text_box)
+
+ elif inp == "2":
+ current_state = "Sneak_left"
+ succ_states = ADVENTURE_TREE[current_state]
+ text_box = "{}".format(DESCRIPTIONS[current_state])
+ print_ded()
+ print(text_box)
+ print_game_over()
+
+
+ elif inp == "2":
+ current_state = "Talk"
+ succ_states = ADVENTURE_TREE[current_state]
+ text_box = "{}".format(DESCRIPTIONS[current_state])
+ print_guard()
+ print(text_box)
+ print_game_over()
+
+ elif inp == "2":
+ current_state = "Red"
+ succ_states = ADVENTURE_TREE[current_state]
+ text_box = "{}\n{} {}\n{} {}".format(DESCRIPTIONS[current_state],
+ "1", OPTIONS[succ_states[0]],
+ "2", OPTIONS[succ_states[1]])
+ print_dragon()
+ print(text_box)
+ inp = input(">> ")
+
+ if inp == "1":
+ current_state = "Flee"
+ succ_states = ADVENTURE_TREE[current_state]
+ text_box = "{}".format(DESCRIPTIONS[current_state])
+ print(text_box)
+
+ elif inp == "2":
+ current_state = "Attack"
+ succ_states = ADVENTURE_TREE[current_state]
+ text_box = "{}".format(DESCRIPTIONS[current_state])
+ print(text_box)
+ print_game_over()
+
+
+if __name__ == "__main__":
+ main()
+
def load_csv(filename):
- our_file = open(filename,"r")
+ our_file = open(filename, "r")
file_read = our_file.readlines()
our_file.close()
return file_read
-
--- /dev/null
+from pictures import *
+
+ADVENTURE_TREE = {
+ "Start": ["Blue", "Red"],
+ "Blue": ["Chest", "Guard"],
+ "Chest": ["Take", "Leave"],
+ "Take": ["Sneak", "Talk"],
+ "Sneak": ["Sneak_right", "Sneak_left"],
+ "Sneak_right": ["Win"],
+ "Sneak_left": ["Die"],
+ "Talk": ["Talk_good", "Talk_not_noice"],
+ "Leave": ["Sneak", "Take"],
+ "Guard": ["Sneak", "Talk", "Steal_axe"],
+ "Red": ["Flee", "Attack"],
+ "Flee": ["End"],
+ "Attack": ["Die"],
+ "Die": ["End"],
+ "Talk_good": ["Win"],
+ "Talk_not_noice": ["Die"],
+ "Win": ["End"],
+ "Steal_axe": ["Die"]
+}
+
+PICTURES = {
+ "Start": print_doors,
+ "Sneak": print_guard,
+ "Sneak_left": print_ded,
+ "Die": print_game_over,
+ "Talk": print_guard,
+ "Red": print_dragon,
+ "Chest": print_treasure,
+ "Talk_not_noice": print_ded,
+ "Win": print_win
+}
+
+DESCRIPTIONS = {
+ "Start": """You enter a room, and you see a blue door to your left and a \
+red door to your right.
+Which door do you pick?""",
+ "Blue": """You see a room with a wooden treasure chest on the left, and a \
+sleeping guard on the right in front of the door.
+What do you do?""",
+ "Chest": """Let's see what's in here... /grins
+The chest creaks open, and the guard is still sleeping. That's one heavy \
+sleeper! You find some diamonds, a shiny sword, and lots of gold coins.
+Do you take the treasure or leave it?""",
+ "Take": """Woohoo! Bounty and a shiney new sword. /drops your crappy \
+sword in the empty treasure chest.
+Ooops! The noise has woken up the guard.
+What do you do now?""",
+ "Leave":
+ """Leaving all the shinies behind hurts, but it feels safer for now.
+Hopefully, it will still be here, right after you gets past this guard.
+What do you do next?""",
+ "Guard": """The guard seems to be deep in sleep, but he has a mean \
+looking axe right beside him.
+What do you do?""",
+ "Sneak": "The guard is sleepy, what you do? right or left",
+ "Talk": "The guard aproches you!",
+ "Red": """There you see the great evil Slathborg.
+He, it, whatever stares at you and you go insane.
+Do you flee for your life or attack it with your bare hands?""",
+ "Flee": """You made it out alive, alas empty handed.""",
+ "Attack": """You died. Well, at least the dragon thought you were tasty""",
+ "Sneak_left": "The guard sees you, U ded!",
+ "Sneak_right": "The guard is missing his left eye and you snek past, hooray!",
+ "End": "",
+ "Die": "",
+ "Talk_not_noice": "The guard tells you fuck off and die!",
+ "Talk_good": "You can leave peasant.",
+ "Win": "",
+ "Steal_axe": "The axe is glued to the guard and he wakes up, u ded!"
+}
+
+OPTIONS = {
+ "Blue": "Blue",
+ "Red": "Red",
+ "Chest": "Explore the chest",
+ "Guard": "Advance toward the guard",
+ "Take": "Grab all of the treasures",
+ "Leave": "Leave them for another day",
+ "Sneak": "Try to sneak past the guard",
+ "Talk": "Talk to the guard",
+ "Flee": "Flee",
+ "Attack": "Attack",
+ "Sneak_left": "Sneak to the left of the guard",
+ "Sneak_right": "Sneak to the right of the guard",
+ "Talk_good": "Offer the guard some flowers and cake.",
+ "Talk_not_noice": "Talk with a danish accent.",
+ "Steal_axe": "Steal his axe and murder him in his sleep"
+}
+++ /dev/null
-import matplotlib
-import numpy as np
-import matplotlib.pyplot as plt
-import sys
-import common
-
-matplotlib.use('AGG')
-plt.figure()
-
-def main():
- try:
- csv_file_path = sys.argv[1]
- except IndexError:
- raise ValueError("Need csv file argument")
- d1 = common.load_csv(csv_file_path)
- x,y = prepare_data(d1)
- draw_diagram1(x,y)
- plt.savefig("figur2.png")
- return
-
-def prepare_data(data):
- new_list = []
- x_values = []
- y_values = []
- for rader in data:
- new_list.append(rader.split(";"))
-
- new_list = new_list[1:]
-
- for i, rad in enumerate(new_list):
- for j, s in enumerate(rad):
- new_list[i][j] = int(s.strip())
-
- #[int(s.strip()) for rad in new_list[1:] for s in rad]
- for rad in new_list:
- x_values.append(rad[0])
- y_values.append(sum(rad[1:]))
- return (x_values, y_values)
-
-def draw_diagram1(x_values, y_values):
- plt.plot(x_values, y_values)
- plt.ylabel("Cups of coffee")
- plt.xlabel("Time of day")
-
-
-
-if __name__ == "__main__":
- main()
-
-
\ No newline at end of file
--- /dev/null
+def print_doors():
+ print()
+ print(r" _________________________________________________________ ")
+ print(r" /| -_- _- |\ ")
+ print(r"/ |_-_- _ -_- _- -| \ ")
+ print(r" | _- _-- | ")
+ print(r" | , | ")
+ print(r" | .-'````````'. '(` .-'```````'-. | ")
+ print(r" | .` | `. `)' .` | `. | ")
+ print(r" | / | () \ U / | () \ | ")
+ print(r" | | | ; | o T o | | ; | | ")
+ print(r" | | | ; | . | . | | ; | | ")
+ print(r" | | | ; | . | . | | ; | | ")
+ print(r" | | | ; | .|. | | ; | | ")
+ print(r" | | |____;_________| | | |____;_________| | ")
+ print(r" | | / __ ; - | ! | / `'() _ - | | ")
+ print(r" | | / __ () -| - | / __-- - | | ")
+ print(r" | | / __-- _ | _- _ - | / __--_ | | ")
+ print(r" |__|/__________________|___________|/__________________|__| ")
+ print(r" / _ - lc \ ")
+ print(r"/ -_- _ - _- _--- -_- -_ \ ")
+ print()
+
+def print_dragon():
+ print()
+ print(r" | | ")
+ print(r" \ / \ / ")
+ print(r" -= .'> =- -= <'. =- ")
+ print(r" '.'. .'.' ")
+ print(r" '.'. .'.' ")
+ print(r" '.'.----^----.'.' ")
+ print(r" /'==========='\ ")
+ print(r" . / .-. .-. \ . ")
+ print(r" :'.\ '.O.') ('.O.' /.': ")
+ print(r" '. | | .' ")
+ print(r" '| / \ |' ")
+ print(r" \ (o'o) / ")
+ print(r" |\ /| ")
+ print(r" \('._________.')/ ")
+ print(r" '. \/|_|_|\/ .' ")
+ print(r" /'._______.'\ lc ")
+ print()
+
+
+def print_treasure():
+ print()
+ print(" _.--. ")
+ print(" _.-'_:-'|| ")
+ print(" _.-'_.-::::'|| ")
+ print(" _.-:'_.-::::::' || ")
+ print(" .'`-.-:::::::' || ")
+ print(" /.'`;|:::::::' ||_ ")
+ print(" || ||::::::' _.;._'-._ ")
+ print(" || ||:::::' _.-!oo @.!-._'-. ")
+ print(" ('. ||:::::.-!()oo @!()@.-'_.| ")
+ print(" '.'-;|:.-'.&$@.& ()$%-'o.'-U|| ")
+ print(" `>'-.!@%()@'@_%-'_.-o _.|'|| ")
+ print(" ||-._'-.@.-'_.-' _.-o |'|| ")
+ print(" ||=[ '-._.-+U/.-' o |'|| ")
+ print(" || '-.]=|| |'| o |'|| ")
+ print(" || || |'| _| '; ")
+ print(" || || |'| _.-'_.-' ")
+ print(" |'-._ || |'|_.-'_.-' ")
+ print(" '-._'-.|| |' `_.-' ")
+ print(" '-.||_/.-' ")
+ print()
+
+
+def print_guard():
+ print()
+ print(r" ___I___ ")
+ print(r" /= | #\ ")
+ print(r" /.__-| __ \ ")
+ print(r" |/ _\_/_ \| ")
+ print(r" (( __ \__)) ")
+ print(r" __ ((()))))()) __ ")
+ print(r" ,' |()))))(((()|# `. ")
+ print(r" / |^))()))))(^| =\ ")
+ print(r" / /^v^(())()()v^;' .\ ")
+ print(r" |__.'^v^v^))))))^v^v`.__| ")
+ print(r" /_ ' \______(()_____( | ")
+ print(r" _..-' _//_____[xxx]_____\.-| ")
+ print(r" /,_#\.=-' /v^v^v^v^v^v^v^v^| _| ")
+ print(r" \)|) v^v^v^v^v^v^v^v^v| _| ")
+ print(r" || :v^v^v^v^v^v`.-' |# \, ")
+ print(r" || v^v^v^v`_/\__,--.|\_=_/ ")
+ print(r" >< :v^v____| \_____|_ ")
+ print(r" , || v^ / \ / ")
+ print(r" //\_||_)\ `/_..-._\ )_...__\ ")
+ print(r" || \/ #| |_='_( | =_(_ ")
+ print(r" || _/\_ | / =\ / ' =\ ")
+ print(r" \\\/ \/ )/ |=____#| '=....#| ")
+ print()
+
+
+def print_game_over():
+ print()
+ print(r" _____ __ __ ______ ______ ________ _____ ")
+ print(r" / ____| /\ | \/ | ____| / __ \ \ / / ____| __ \ ")
+ print(r" | | __ / \ | \ / | |__ | | | \ \ / /| |__ | |__) | ")
+ print(r" | | |_ | / /\ \ | |\/| | __| | | | |\ \/ / | __| | _ / ")
+ print(r" | |__| |/ ____ \| | | | |____ | |__| | \ / | |____| | \ \ ")
+ print(r" \_____/_/ \_\_| |_|______| \____/ \/ |______|_| \_\ ")
+ print()
+
+
+def print_ded():
+ print()
+ print(r" _ ___I___ ")
+ print(r" /\_/ \_/\ /= | #\ ")
+ print(r" / \ /.__-| __ \ ")
+ print(r" || || |/ _\_/_ \| ")
+ print(r" \ _ _ / (( __ \__)) ")
+ print(r" \/ || \/ __ ((()))))()) __ ")
+ print(r" || ,' |()))))(((()|# `. ")
+ print(r" || / |^))()))))(^| =\ ")
+ print(r" || / /^v^(())()()v^;' .\ ")
+ print(r" || |__.'^v^v^))))))^v^v`.__| ")
+ print(r" || /_ ' \______(()_____( | ")
+ print(r" ||.-' _//_____[xxx]_____\.-| ")
+ print(r" /,_#\.=-' /v^v^v^v^v^v^v^v^| _| ")
+ print(r" \)|) v^v^v^v^v^v^v^v^v| _| ")
+ print(r" :v^v^v^v^v^v`.-' |# \, ")
+ print(r" v^v^v^v`_/\__,--.|\_=_/ ")
+ print(r" :v^v____| \_____|_ ")
+ print(r" v^ / \ / ")
+ print(r" `/_..-._\ )_...__\ ")
+ print(r" |_='_( | =_(_ ")
+ print(r" / =\ / ' =\ ")
+ print(r" |=____#| '=....#| ")
+ print()
+
+def print_win():
+ print(r" __ __ __ __ _ ")
+ print(r" \ \ / / \ \ / / | |")
+ print(r" \ \_/ /__ _ _ \ \ /\ / /__ _ __ | |")
+ print(r" \ / _ \| | | | \ \/ \/ / _ \| '_ \| |")
+ print(r" | | (_) | |_| | \ /\ / (_) | | | |_|")
+ print(r" |_|\___/ \__,_| \/ \/ \___/|_| |_(_)")
\ No newline at end of file
--- /dev/null
+import matplotlib
+import numpy as np
+import matplotlib.pyplot as plt
+import sys
+import common
+
+
+def main():
+ matplotlib.use('AGG')
+ plt.figure()
+ try:
+ csv_file_path = sys.argv[1]
+ except IndexError:
+ raise ValueError("Need csv file argument")
+ d1 = common.load_csv(csv_file_path)
+ x, y = prepare_data(d1)
+ draw_diagram1(x, y)
+ plt.ylabel("Cups of coffee")
+ plt.xlabel("Time of day")
+ plt.savefig("uppgift_1.png")
+ return
+
+
+def prepare_data(data):
+ new_list = []
+ x_values = []
+ y_values = []
+ for rader in data:
+ new_list.append(rader.split(";"))
+
+ new_list = new_list[1:]
+
+ for i, rad in enumerate(new_list):
+ for j, s in enumerate(rad):
+ new_list[i][j] = int(s.strip())
+
+ # [int(s.strip()) for rad in new_list[1:] for s in rad]
+ for rad in new_list:
+ x_values.append(rad[0])
+ y_values.append(sum(rad[1:]))
+ return (x_values, y_values)
+
+
+def draw_diagram1(x_values, y_values):
+ plt.plot(x_values, y_values)
+
+
+
+if __name__ == "__main__":
+ main()
--- /dev/null
+import common
+import sys
+import matplotlib
+import matplotlib.pyplot as plt
+
+def main():
+ matplotlib.use('AGG')
+ plt.figure()
+ try:
+ csv_file_path = sys.argv[1]
+ except IndexError:
+ raise ValueError("Need csv file argument")
+ data = common.load_csv(csv_file_path)
+ x, y = prepare_data2(data)
+ draw_diagram2([x, y], csv_file_path[4:])
+ plt.ylabel("Antal koppar")
+ plt.xlabel("Koppar kaffe per dag")
+ plt.legend(loc='upper left', bbox_to_anchor=(1, 0, 1, 1))
+ plt.savefig("uppgift_2.png", bbox_inches="tight")
+
+
+
+def prepare_data2(d):
+ days = d[0].split(';')
+ cups_per_day = [0] * 7
+ data = d[1:]
+ for line in data:
+ for day_i, cups in enumerate(line.split(';')[1:]):
+ cups_per_day[day_i] += int(cups)
+ days.pop(0)
+ days = [day.strip() for day in days]
+ return [days, cups_per_day]
+
+
+def draw_diagram2(values, name):
+ plt.plot(values[0], values[1], label=name)
+
+
+if __name__ == "__main__":
+ main()
\ No newline at end of file
--- /dev/null
+import common
+import uppgift_1
+import uppgift_2
+import matplotlib
+import matplotlib.pyplot as plt
+import sys
+
+matplotlib.use("AGG")
+plt.figure()
+
+def main():
+ arg_len = len(sys.argv) - 1
+ csv_files = list()
+ for i in range(arg_len):
+ csv_files.append(sys.argv[i + 1])
+
+ for filer in csv_files:
+ data = common.load_csv(filer)
+ # uppgift_1.draw_diagram(uppgift_1.prepare_data(data))
+ uppgift_2.draw_diagram2(uppgift_2.prepare_data2(data), filer[4:])
+
+ plt.xlabel("Dagar")
+ plt.ylabel("Antal koppar")
+ plt.legend(loc='upper left', bbox_to_anchor=(1, 0, 1, 1))
+ plt.savefig(__file__[0:-3] + ".png", bbox_inches="tight")
+
+
+if __name__ == "__main__":
+ main()