Add some features

This commit is contained in:
Shadow15510 2021-08-22 13:57:49 +02:00
parent a0e48ea23c
commit 16d6d4baba
5 changed files with 39 additions and 32 deletions

View File

@ -3,6 +3,7 @@ from sys import argv
def convert_to_string(csv_filename):
output_filename = csv_filename.split('.')[0]
char_list = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ "
with open(csv_filename, "r") as file:
@ -14,7 +15,7 @@ def convert_to_string(csv_filename):
output += char_list[char_id]
output += "\n"
with open(f"{csv_filename.split(".")[0]}.py", "w") as file:
with open(f"{output_filename}.py", "w") as file:
file.write(f"{output_filename}_map = r\"\"\"\n{output}\n\"\"\"")
convert_to_string(*argv[1:])

View File

@ -47,17 +47,9 @@ class Screen:
class Asci:
def __init__(self, maps, fn_events, fn_fight, fn_stat, fn_custom, end_game, stat, data=[0, 0, 0, 0], screen_width=21, screen_height=6):
# Load save ; data = [XP, map_id, x, y]
self.data = data
if not stat or type(stat) != list:
self.stat = [100]
else:
self.stat = stat
# Load data
def __init__(self, maps, fn_events, fn_fight, fn_stat, fn_custom, screen_width=21, screen_height=6):
# Load maps
self.maps = maps
self.end_game = end_game
# Custom functions
self._game_event = fn_events
@ -65,11 +57,8 @@ class Asci:
self._game_stat = fn_stat
self._game_custom = fn_custom
# Screen configuration
# Screen initialisation
self.screen = Screen(screen_width, screen_height)
if data[1]: self.screen.set_world(maps[data[1]][0])
else: self.screen.set_world(maps[0])
self.map_width, self.map_height = self.screen.get_map_size()
def _looked_case(self, direction):
# Left
@ -104,11 +93,11 @@ class Asci:
if self.data[-1] + 4 >= self.map_height: return -1
else: cell = self.screen.get_cell(10, 4)
cell_patterns = (" @", "^", "*", "$")
cell_patterns = self.legend
for pattern_index in range(len(cell_patterns)):
if cell in cell_patterns[pattern_index]: return pattern_index + 1
return 0
return cell == " "
def _keyboard(self, key):
# Interaction with map
@ -150,7 +139,7 @@ class Asci:
# Custom display function
elif key == 8:
self.screen.clear()
self._game_custom(self.stat)
self._game_custom(*self.data, self.stat)
# Quit
elif key == 9:
@ -204,12 +193,29 @@ class Asci:
return current_map, self.data[2], self.data[3]
def mainloop(self):
def mainloop(self, end_game, stat=None, data=[0, 0, 0, 0], legend=("@", "^", "*", "$")):
# Load save ; data = [XP, map_id, x, y]
self.data = data[:]
if not stat or type(stat) != list:
self.stat = [100]
else:
self.stat = stat
# Load legend
self.legend = legend[:]
# Screen and map configuration
if data[1]: self.screen.set_world(self.maps[data[1]][0])
else: self.screen.set_world(self.maps[0])
self.map_width, self.map_height = self.screen.get_map_size()
key = key_buffer = 0
while key != 9 and self.stat[0] > 0 and self.data[0] < self.end_game:
while key != 9 and self.stat[0] > 0 and self.data[0] < end_game:
self.screen.set_data(self.data[-2:])
self.screen.set_cell(10, 3, "@")
self.screen.set_cell(10, 3, self.legend[0][0])
key = convert(self.screen.display())
if not key: key = key_buffer

View File

@ -39,10 +39,10 @@ def affichage_stat(stat):
print("PV : {}".format(pv))
print("Argent : {}".format(argent))
def custom(stat):
def custom(xp, carte_actuelle, x, y, stat):
pass
def mon_jeu():
rpg_python = Asci(carte_monde, evenements, combat, affichage_stat, custom, 4, [100, 5])
rpg_python.mainloop()
rpg_python = Asci(carte_monde, evenements, combat, affichage_stat, custom)
rpg_python.mainloop(4, [100, 5])

View File

@ -8,14 +8,14 @@ r"""
|_ <>\ ###
|^|__| /_\
*
?
|==|==|==|==|==|==|==|""",
(r"""
+--+--+--------+--+--+
| | | * | | *|
| | | ? | | ?|
| + + + + |
| |
| + + + + |
@ -71,10 +71,10 @@ def affichage_statistique(stat):
print("Points de Vie : {}".format(stat[0]))
def custom(stat):
def custom(xp, carte_actuelle, x, y, stat):
pass
def mon_jeu():
rpg_python = Asci(cartes, evenements, combat, affichage_statistique, custom, 13, [100])
rpg_python.mainloop()
rpg_python = Asci(cartes, evenements, combat, affichage_statistique, custom)
rpg_python.mainloop(13, [100], legend=("$", "^", "?", "!"))

View File

@ -116,12 +116,12 @@ def affichage_stat(stat):
print("Points defense : {}".format(pd))
def custom(stat):
def custom(xp, carte_actuelle, x, y, stat):
pass
def mon_jeu(stat=[100, 0, 0], data=[0, 0, 0, 0]):
rpg_python = Asci(cartes, evenements, combats, affichage_stat, custom 5, stat, data)
stat, data = rpg_python.mainloop()
rpg_python = Asci(cartes, evenements, combats, affichage_stat, custom)
stat, data = rpg_python.mainloop(5, stat, data=data)
print("Pour reprendre :")
print("mon_jeu({}, {})".format(stat, data))