This repository has been archived by the owner on Jun 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.main.py.1677493487~
114 lines (100 loc) · 3.58 KB
/
.main.py.1677493487~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/python3
# preparing
import csv
write = [None, None, [], []]
f = open("data.csv", 'r+')
read = [i[1] for i in csv.reader(f)]
def save(*save):
print("...") #oh no dont leave
global write
for i in enumerate(save):
write[i[0]] = i[1]; read[i[0]] = write[i[0]] # what happened to mr. walrus
f.truncate(0)
csv.writer(f).writerow(["location", read[0]])
csv.writer(f).writerow(["action", read[1]])
csv.writer(f).writerow(["battle", *read[2]])
csv.writer(f).writerow(["inventory", *read[3]])
# TODO: fix everything else for battle
print('')#ok now
# ask function
def ask(options: list, question="What do you do?", other=""):
print("\t\b", question, '\n\t')
for i in options:
print(f"\t{i[0]}: {i[1]}")
if (x := input('\tة<( ')) in [i[0] for i in options]: return x
elif x == 'quit': save(*write); exit(0) #
else: return other
actions = {}
class Action:
def __init__(self, id: str, nickname: str, str: str, opt: list, print: bool, dict=actions) -> None:
self.id = id
self.nickname = nickname
self.str = str
self.opt = opt
self.print = print
self.question = "What do you want to do now?"
self.dict = dict
self.dict[self.id] = self
def next(self):
if self.print:
print(self.str)
save(ask(self.opt, self.question)) if not self.question == None else save(ask(*self.opt))
# until save fixed
return self.dict[ask(self.opt, self.question) if self.question is not None else ask(self.opt)]
def __repr__(self):
return f"{self.id}\n{self.nickname}\nclass: {self.__class__.__name__}\n\
{self.str}\n{self.question}({self.print})\n{[self.id for i in self.opt]}"
scenes = {}
class Scene(Action):
def __init__(self, id: str, nickname: str, desc: str, *nextl):
super().__init__(id, nickname, desc, [[scenes[i].nick, scenes[i].str] for i in nextl], True, scenes)
self.question = f"Where do you want to go from {self.nickname}?"
for i in [self.dict[i] for i in nextl]:
# i finally fixed it!!!
self.opt.append([i.nickname, i.str])
i.opt.append([self.nickname, self.str])
def forth(self, to):
self.opt.append([to.nickname, to.str])
def link(self, to):
self.forth(to)
to.forth(self)
attacks = {}
class Attack(Action):
def __init__(self, id: str, name: str, desc: str, does: list):
super().__init__(id, name, desc, [], False, attacks)
self.does = does
def __call__(self, opp=False):
if opp:
return [[i[1] + self.does[i[0]] for i in enumerate(write[3])][i:i+2] for i in range(0, len([i[1] + self.does[i[0]] for i in enumerate(write[3])]), 2)]
return [i[1] + self.does[i[0]] for i in enumerate(write[3])]
# dont even try to think of it
opps = {}
class Battle(Action):
def __init__(self, id: str, name: str, desc="yea", *opp):
super().__init__(id, name, desc, opp, False, opps)
def __call__(self):
while write[3][0] > 0 and write[3][1] > 0: # no one's dead
print(f"Your HP: {write[3][0]}\nOpponent's HP: {write[3][1]}")
action[self.next()]
#--- adding to the dicts --#
# switch to json? i mean... vvv
#:village -> :village:goat -> :village:goat;milk -> :village:goat;slaughter!
def SET():
Scene(':village', 'the village',
"A village.")
Scene(':village:shop', 'the shop',
"A shop with three merchants.",
':village')
Scene(':village:shop:1', 'the first merchant',
"A merchant that can sell various items")
Scene(':village:shop:2', 'the second merchant',
"A merchant that can sell various items",
':village:shop:1', ':village:shop')
Scene(':village:shop:3', 'the third merchant',
"A merchant that can sell various items",
':village:shop:1', ':village:shop:2', ':village:shop')
#--- thank you for coming --#
SET()
def step():
if write[2] != []:
pass