This repository was archived by the owner on Jul 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
104 lines (77 loc) · 3.13 KB
/
main.py
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
from src.scripts import pageManager as pageManager
from src.scripts import printText
from src.scripts import tools as tool
from src.scripts import save
import time
idPageSave = 0
fileSave = ""
pseudo = ""
level = 0 # 0 : easy | 1 : medium | 2 : hard
PROGRESS_JSON = "./src/assets/progress.json"
STRUCTURE_JSON = "./src/assets/structure.json"
GAME_XML = "./src/assets/game.xml"
END_MD = "./adventure.md"
SAVES_FOLDER = "./src/assets/saves/"
def start():
global pseudo, level
save.clearJSON(PROGRESS_JSON)
save.clearXML(GAME_XML)
pageManager.setPath(STRUCTURE_JSON)
# get the current id of page in function of save
idPageSave = save.loadOrNewGame(savesFolder=SAVES_FOLDER, progressJson=PROGRESS_JSON, structureJson=STRUCTURE_JSON)
if idPageSave == 0:
pseudo = tool.getName()
level = tool.getLevel()
if int(level) == 1:
printText.setTextColor("gray")
elif int(level) == 2:
printText.setTextColor("black")
else:
printText.setTextColor("white")
# ===x=== Save into the XML ===x===
save.saveToXML(GAME_XML, pseudo, "Player_name")
save.saveToXML(GAME_XML, level, "Level")
# ===x=== Launch the game ===x===
page = readPage(idPageSave)
if page:
save.savePage(fileSave, savesFolder=SAVES_FOLDER, progressJson=PROGRESS_JSON)
# ===x=== Save into the JSON / MD ===x===
pagesSaved = save.readFromJSON(PROGRESS_JSON)["idPages"]
content = []
for pageID in pagesSaved:
content.append({"page": pageManager.getPage(pageID), "id": pageID})
MDcontent = save.constructMarkdownFile(content)
save.saveInMarkdown(END_MD, MDcontent)
save.clearJSON(PROGRESS_JSON)
def readPage(idPage):
tool.clearConsole()
if idPage == -1:
printText.writeTextWithoutTypingEffect("Vous avez déjà terminé cette partie ! Vous pouvez rejouer ou voir le résumé de la partie dans le fichier 'adventure.md'")
return False
page = pageManager.getPage(idPage)
question = page["question"]
choices = page["choices"]
typeChoice = page["type"]
winPage = page["win"]
if typeChoice != "end":
playerName = save.getFromXML(GAME_XML, "Player_name")
if playerName == "" or playerName == None:
playerName = "Banane Anonyme"
if "{{player}}" in question:
question = question.replace("{{player}}",playerName)
pageManager.writeQuestion(question=question, timeout=0.01, color=printText.getTextColor())
nextId = pageManager.writeChoices(typeChoice=typeChoice, choices=choices, question=question, timeout=0.01)
#& ---------- JSON Save ----------
save.saveToJSON(PROGRESS_JSON, nextId)
readPage(nextId)
else :
if winPage == True:
pageManager.writeQuestion(question=question, color="green", timeout=0.01)
elif winPage == False:
pageManager.writeQuestion(question=question, color="red", timeout=0.01)
time.sleep(3)
printText.writeEndGame()
pass
return True
if __name__ == '__main__':
start()