Merge branch 'dev'

This commit is contained in:
Shadow15510 2022-01-28 23:14:03 +01:00
commit 07601114c4
6 changed files with 319 additions and 214 deletions

314
asci.py
View File

@ -1,101 +1,56 @@
# Asci (version 1.6.3)
class Screen:
def __init__(self, screen_width=21, screen_height=6):
# Screen configuration
self.screen_width = screen_width
self.screen_height = screen_height
self._data = [[" " for _ in range(screen_width)] for _ in range(screen_height)]
def clear(self):
print("\n" * self.screen_height)
def set_world(self, world):
self._world = [[char for char in line] for line in world.split("\n")[1:]]
self.map_width = max([len(line) for line in self._world])
self.map_height = len(self._world)
def set_data(self, coords):
x, y = coords
for x_map in range(x, x + self.screen_width):
for y_map in range(y, y + self.screen_height):
self._data[y_map - y][x_map - x] = " "
if 0 <= x_map < self.map_width and 0 <= y_map < self.map_height:
try: self._data[y_map - y][x_map - x] = self._world[y_map][x_map]
except: pass
def set_cell(self, x, y, value):
self._data[y][x] = value
def display(self, return_input=True):
for line in self._data:
print("".join(line))
if return_input: return input(">")
def display_text(self, string):
paragraphs = [i for i in text_formater(string) if i]
nb_par = len(paragraphs)
for index in range(nb_par):
self.clear()
print(paragraphs[index])
if index + 1 == nb_par: return input(">")
else: input()
def get_cell(self, x, y):
return self._data[y][x]
def get_map_size(self):
return self.map_width, self.map_height
# Asci (1.7.0)
class Asci:
def __init__(self, maps, events_mapping, keys_mapping, screen_width=21, screen_height=6):
def __init__(self, maps, events_mapping, keys_mapping, behaviors=None, screen_width=21, screen_height=6):
# Load maps
self.maps = [Map(*i) for i in maps]
# Custom functions
self.legend = list(events_mapping.keys())
self._game_events_mapping = [events_mapping[i] for i in self.legend]
self._legend = list(events_mapping.keys())
self._game_events_mapping = [events_mapping[i] for i in self._legend]
self._game_keys_mapping = {key: keys_mapping[key] for key in keys_mapping if not key in (1, 2, 3, 5)}
# Custom entities behavior
self._behaviors = {"stand by": stand_by, "follow": follow, "walk": walk}
if behaviors:
for i in behaviors: self._behaviors[i] = behaviors[i]
# Screen initialisation
self.screen = Screen(screen_width, screen_height)
self.current_map = None
self.visible_entities = []
def _looked_case(self, direction):
# Left
if direction == 1:
return self.data[2] + 9, self.data[3] + 3
if direction == 1: # Left
return self.data[2] - 1, self.data[3]
# Right
elif direction == 3:
return self.data[2] + 11, self.data[3] + 3
elif direction == 3: # Right
return self.data[2] + 1, self.data[3]
# Up
elif direction == 5:
return self.data[2] + 10, self.data[3] + 2
elif direction == 5: # Up
return self.data[2], self.data[3] - 1
# Down
elif direction == 2:
return self.data[2] + 10, self.data[3] + 4
elif direction == 2: # Down
return self.data[2], self.data[3] + 1
return self.data[2] + 10, self.data[3] + 3
return self.data[2], self.data[3]
def _cell_test(self, direction):
if direction == 1:
if self.data[-2] + 9 < 0: return -1
else: cell = self.screen.get_cell(9, 3)
if self.data[2] - 1 < 0: return -1
else: cell = self.screen.get_cell(self.data[2: 4], self.data[2] - 1, self.data[3])
if direction == 3:
if self.data[-2] + 11 >= self.map_width: return -1
else: cell = self.screen.get_cell(11, 3)
if self.data[2] + 1 >= self.map_width: return -1
else: cell = self.screen.get_cell(self.data[2: 4], self.data[2] + 1, self.data[3])
if direction == 5:
if self.data[-1] + 2 < 0: return -1
else: cell = self.screen.get_cell(10, 2)
if self.data[3] - 1 < 0: return -1
else: cell = self.screen.get_cell(self.data[2: 4], self.data[2], self.data[3] - 1)
if direction == 2:
if self.data[-1] + 4 >= self.map_height: return -1
else: cell = self.screen.get_cell(10, 4)
if self.data[3] + 1 >= self.map_height: return -1
else: cell = self.screen.get_cell(self.data[2: 4], self.data[2], self.data[3] + 1)
cell_patterns = self.legend
print(f"'{cell}'")
cell_patterns = self._legend
for pattern_index in range(len(cell_patterns)):
if cell in cell_patterns[pattern_index]: return pattern_index
@ -107,18 +62,16 @@ class Asci:
cell_test = self._cell_test(key)
# Move
if cell_test == len(self.legend) - 1:
if cell_test == len(self._legend) - 1:
if key == 1: self.data[2] -= 1
if key == 3: self.data[2] += 1
if key == 5: self.data[3] -= 1
if key == 2: self.data[3] += 1
# Change map
elif interaction and cell_test == len(self.legend) - 2: # or (self.data[1] and cell_test < 0):
self.data[1], self.data[2], self.data[3] = self._get_map(key)
self.screen.set_world(self.maps[self.data[1]].map_data)
self.map_width, self.map_height = self.screen.get_map_size()
elif interaction and cell_test == len(self._legend) - 2:
new_map, self.data[2], self.data[3] = self._get_map(key)
self._change_map(new_map)
# Interaction
elif interaction and cell_test >= 0: self._interaction(key, cell_test)
@ -128,12 +81,39 @@ class Asci:
self.screen.clear()
self._game_keys_mapping[key](self.data, self.stat)
def _get_map(self, direction):
current_coords = self._looked_case(direction)
for coords in self.current_map.coords:
if coords[:2] == current_coords:
return coords[2], coords[3], coords[4]
return self.data[1], self.data[2], self.data[3]
def _change_map(self, new_map):
# Update entities
if self.current_map:
for i in range(len(self.current_map.entities)):
entity = self.current_map.entities[i]
if entity.behavior == "follow":
self.maps[new_map].entities.append(entity)
self.maps[self.data[1]].entities.pop(i)
# Update current map
self.data[1] = new_map
self.current_map = self.maps[self.data[1]]
# Update screen configuration
self.screen.set_world(self.current_map.map_data)
self.map_width, self.map_height = self.screen.get_map_size()
self._get_visible_entities()
def _interaction(self, direction, cell_content):
x, y = self._looked_case(direction)
data_copy = [self.data[0], self.data[1], x, y]
data_copy = [self.data[0], self.data[1], x, y, self.data[4]]
# Get the event
event = self._game_events_mapping[cell_content](data_copy, self.stat)
event = self._game_events_mapping[cell_content](data_copy, self.stat, self.current_map.entities, self._get_entity_id(x, y))
if type(event) == tuple:
quest, event = event
else:
@ -142,12 +122,10 @@ class Asci:
# data modification
self.data[0] = data_copy[0]
if self.data[1] != data_copy[1]:
self.data[1] = data_copy[1]
self.screen.set_world(self.maps[self.data[1]].map_data)
self.map_width, self.map_height = self.screen.get_map_size()
self._change_map(data_copy[1])
if data_copy[2] != x: self.data[2] = data_copy[2] - 10
if data_copy[3] != y: self.data[3] = data_copy[3] - 3
if data_copy[2] != x: self.data[2] = data_copy[2]
if data_copy[3] != y: self.data[3] = data_copy[3]
if not event: return
event = read_event(self.data, event, quest)
@ -164,16 +142,26 @@ class Asci:
self.data[0][quest] += answer_selected
self._interaction(direction, cell_content)
def _get_map(self, direction):
current_coords = self._looked_case(direction)
current_map = self.data[1]
# Entities gestion
def _get_visible_entities(self):
self.visible_entities = {}
for entity in self.current_map.entities:
if (0 <= entity.pos_x - self.data[2] + 10 < self.screen.screen_width) and (0 <= entity.pos_y - self.data[3] + 3 < self.screen.screen_height):
self.visible_entities[entity.entity_id] = entity
for coords in self.maps[current_map].coords:
if coords[:2] == current_coords:
return coords[2], coords[3] - 10, coords[4] - 3
def _get_entity_id(self, x, y):
for entity_id in self.visible_entities:
entity = self.visible_entities[entity_id]
if entity.pos_x == x and entity.pos_y == y:
return entity_id
return current_map, self.data[2], self.data[3]
def _run_entities_behaviors(self):
for entity in self.current_map.entities:
data_copy = get_data_copy(self.data)
self._behaviors[entity.behavior](entity, data_copy, self.stat, self.screen, self.walkable)
self._get_visible_entities()
# Mainloop
def mainloop(self, end_game, stat=None, data=None, routine=None, player="@", door="^", walkable=" ", exit_key=9, multi_move="."):
if exit_key in self._game_keys_mapping:
raise ValueError("'{}' is already assigned to a function.".format(exit_key))
@ -182,42 +170,102 @@ class Asci:
if not stat or type(stat) != list: self.stat = [100]
else: self.stat = stat
if not data: self.data = [{"main": 0}, 0, 0, 0]
else: self.data = [data[0], data[1], data[2] - 10, data[3] - 3]
if not data: self.data = [{"main": 0}, 0, 0, 0, 0]
else: self.data = [data[0], data[1], data[2], data[3], 0]
self.legend.append(door)
self.legend.append(walkable)
# Configuration
self.walkable = walkable
self._legend.append(door)
self._legend.append(walkable)
self._change_map(data[1])
# Screen and map configuration
self.screen.set_world(self.maps[self.data[1]].map_data)
self.map_width, self.map_height = self.screen.get_map_size()
key = key_buffer = 0
key = 0
while key != exit_key and self.stat[0] > 0 and self.data[0]["main"] < end_game:
self.screen.set_data(self.data[-2:])
self.screen.set_cell(10, 3, player)
# Update the map
self.screen.set_screen(self.data[2], self.data[3])
# Compute the player's and entities' positions
self.screen.set_cell(self.data[2] - 10, self.data[3] - 3, self.data[2], self.data[3], player)
self._run_entities_behaviors()
for entity in self.visible_entities.values():
self.screen.set_cell(self.data[2] - 10, self.data[3] - 3, entity.pos_x, entity.pos_y, entity.symbol)
# Display map and get the key
key = convert(self.screen.display())
if not key: key = key_buffer
else: key_buffer = key
if not key: key = self.data[4]
else: self.data[4] = key
if type(key) == str and key[0] == multi_move:
for i in list(key[1:]):
self._keyboard(convert(i), False)
self.data[4] = convert(key[-1])
else:
self._keyboard(key)
# Launching the game routine
if routine: routine(self.data, self.stat)
if routine:
data_copy = get_data_copy(self.data)
routine(data_copy, self.stat)
if self.stat[0] <= 0: self.stat[0] = 100
self.data[2] += 10
self.data[3] += 3
return self.stat, self.data
return self.stat, self.data[:-1]
# Classes used by Asci
class Screen:
def __init__(self, screen_width=21, screen_height=6):
# Screen configuration
self.screen_width = screen_width
self.screen_height = screen_height
self._on_screen = [[" " for _ in range(screen_width)] for _ in range(screen_height)]
def get_map_size(self):
return self.map_width, self.map_height
def set_world(self, world):
self._world = [[char for char in line] for line in world.split("\n")[1:]]
self.map_width = max([len(line) for line in self._world])
self.map_height = len(self._world)
def set_screen(self, x, y):
x -= 10 ; y -= 3
for x_map in range(x, x + self.screen_width):
for y_map in range(y, y + self.screen_height):
self._on_screen[y_map - y][x_map - x] = " "
if 0 <= x_map < self.map_width and 0 <= y_map < self.map_height:
try: self._on_screen[y_map - y][x_map - x] = self._world[y_map][x_map]
except: pass
def display(self, return_input=True):
for line in self._on_screen:
print("".join(line))
if return_input: return input(">")
def clear(self):
print("\n" * self.screen_height)
def display_text(self, string):
paragraphs = [i for i in text_formater(string) if i]
nb_par = len(paragraphs)
for index in range(nb_par):
self.clear()
print(paragraphs[index])
if index + 1 == nb_par: return input(">")
else: input()
def set_cell(self, x_offset, y_offset, x, y, value):
self._on_screen[y - y_offset][x - x_offset] = value
def get_cell(self, offsets, x, y):
x = x - (offsets[0] - 10)
y = y - (offsets[1] - 3)
if 0 <= x < self.screen_width and 0 <= y <= self.screen_height:
return self._on_screen[y][x]
else: return " "
class Event:
def __init__(self, xp, text, answer=0, *stat):
self.xp = xp
@ -227,11 +275,26 @@ class Event:
class Map:
def __init__(self, map_data, *coords):
def __init__(self, map_data, entities, *coords):
self.map_data = map_data
if entities: self.entities = [Entity(*i) for i in entities]
else: self.entities = []
self.coords = coords
class Entity:
def __init__(self, entity_id, symbol, x, y, behavior, *args):
self.entity_id = entity_id
self.symbol = symbol
self.pos_x = x
self.pos_y = y
self.behavior = behavior
self.args = list(args)
def change_behavior(self, new_behavior):
self.behavior = new_behavior
# Functions used by Asci
def convert(string, force_int=False):
try: return int(string)
except:
@ -277,6 +340,11 @@ def read_event(data, event, quest):
return Event(*event)
def get_data_copy(data):
return [data[0], data[1], data[2], data[3], data[4]]
# Extra functions
def print_text(text, min_value=0, max_value=0, default_value=0):
paragraphs = [i for i in text_formater(text) if i]
nb = len(paragraphs)
@ -293,3 +361,21 @@ def print_text(text, min_value=0, max_value=0, default_value=0):
return result
else: input()
def stand_by(entity, data, stat, screen, walkable):
pass
def follow(entity, data, stat, screen, walkable):
if data[4] == 1 and screen.get_cell(data[2: 4], data[2] + 1, data[3]) in walkable: entity.pos_x, entity.pos_y = data[2] + 1, data[3]
elif data[4] == 2 and screen.get_cell(data[2: 4], data[2], data[3] - 1) in walkable: entity.pos_x, entity.pos_y = data[2], data[3] - 1
elif data[4] == 3 and screen.get_cell(data[2: 4], data[2] - 1, data[3]) in walkable: entity.pos_x, entity.pos_y = data[2] - 1, data[3]
elif data[4] == 5 and screen.get_cell(data[2: 4], data[2], data[3] + 1) in walkable: entity.pos_x, entity.pos_y = data[2], data[3] + 1
def walk(entity, data, stat, screen, walkable):
frame = (entity.args[0] + 1) % len(entity.args[1])
new_x, new_y = entity.args[1][frame]
print(new_x, new_y)
if screen.get_cell(data[2: 4], new_x, new_y) in walkable:
entity.pos_x, entity.pos_y = new_x, new_y
entity.args[0] = frame

View File

@ -1,29 +1,40 @@
from asci import *
carte_monde = ((
r"""
maison = (r"""
_ ###
/o\__ #####
| <>\ ###
|____| /_\
*
|==|==|==|==|==|==|==|""",),)
|==|==|==|==|==|==|==|""",
# Entités
[
("sdf", "*", 2, 5, "stand by")
])
carte_monde = (maison,)
def pnj(data, stat):
xp, carte_actuelle, x, y = data
coords = (x, y)
def pnj(data, stat, entites, identifiant):
xp = data[0]["main"]
if carte_actuelle == 0:
if coords == (2, 5): return {
0: [0, "Mon bon monsieur, vous n'auriez pas quelques sous pour moi ? 1. He non mon brave... 2. Mais si, bien sur, tenez.", 2],
1: [2, "Radin !"],
# 0 réponse possibles, -1 Argent
2: [1, "Merci !", 0, (1, -1)],
if identifiant == "sdf":
if xp == 2: entites["sdf"].change_behavior("follow")
elif xp == 4: entites["sdf"].change_behavior("stand by")
return {
0: [0, "Mon bon monsieur, vous n'auriez pas quelques sous pour moi ?\n1. He non mon brave...\n2. Mais si, bien sur, tenez.", 2],
1: [5, "Radin !"],
2: [1, "Merci !", 0, (1, -1)], # 0 réponse possibles, -1 Argent
3: [0, "Hmm ?\n1. Arretez de me suivre !\n2. Non rien.", 2],
4: [2, "Soit..."],
5: [-2, "Bien"],
"base": [0, "Hmm ?"]
}
@ -31,6 +42,7 @@ def pnj(data, stat):
return [0, "Hmm ?"]
def affichage_stat(data, stat):
pv, argent = stat
print("Statistiques")
@ -45,4 +57,4 @@ touche = {6: affichage_stat}
def mon_jeu():
rpg_python = Asci(carte_monde, evenements, touche)
rpg_python.mainloop(4, stat=[100, 5])
rpg_python.mainloop(7, stat=[100, 5], data=[{"main": 0}, 0, 10, 3])

View File

@ -8,57 +8,64 @@ cartes = (
|_ <>\ ###
|^|__| /_\
?
|==|==|==|==|==|==|==|""",
[
(1, "*", 2, 5, "stand by")
],
(1, 3, 1, 5, 7)),
(r"""
+--+--+--------+--+--+
| | | ? | | ?|
| | | | | |
| + + + + |
| |
| + + + + |
+--/ \--------/ \--+
| |
+---|^|--------------+""",
[
("habitant", "?", 9, 1, "stand by"),
("voleur", "?", 20, 1, "stand by")
],
(5, 7, 0, 1, 3))
)
def pnj(data, stat):
xp, carte_actuelle, x, y = data
coords = (x, y)
def pnj(data, stat, entites, identifiant):
carte_actuelle = data[1]
if carte_actuelle == 0:
if coords == (2, 5): return {
if identifiant == 1: return {
0: [0, "Hey ! J'ai entendu du bruit dans la maison, mais je n'ose pas rentrer... 1. Rien entendu. 2. Je vais jeter un oeil.", 2],
1: [3, "Etes-vous sourd ?"],
2: [1, "J'etais sur que vous m'ecouteriez !"],
3: [2, "C'est la maison juste au nord."],
3: [2, "C'est la maison juste au nord. Soyez prudent !"],
4: [0, "Enfin, vous entendez bien du bruit la ? Et si c'etait un voleur ? 1. Bon ok j'y vais. 2. Mais foutez moi la paix !", 2],
6: [0, "..."],
5: [2, "Soyez prudent !"],
5: [0, "Alors ?"],
12: [1, "J'etais sur d'avoir entendu un truc !"],
10: [1, "J'etais sur d'avoir entendu un truc !"],
"base": [0, "Vous avez entendu quelque chose ?"]
}
elif carte_actuelle == 1:
if coords == (9, 1): return {
7: [0, "Je crois que le voleur est dans la piece d'a cote... 1. Je vais regarder. 2. Debrouillez-vous !", 2],
8: [2, "Merci !"],
9: [0, "Pleutre ! Hors de ma vue !"],
if identifiant == "habitant": return {
5: [0, "Je crois que le voleur est dans la piece d'a cote... 1. Je vais regarder. 2. Debrouillez-vous !", 2],
6: [2, "Merci !"],
7: [0, "Pleutre ! Hors de ma vue !"],
11: [1, "Ah, merci !"],
9: [1, "Ah, merci !"],
"base": [0, "J'ai peur de sortir de cette piece"]
}
elif coords == (20, 1): return {
10: [1, "Ciel, je suis fait !"],
elif identifiant == "voleur": return {
8: [1, "Ciel, je suis fait !"],
9: [0, "Je pars, je pars !"],
"base": [0, "File avant que je ne te detrousse !"]
}
@ -77,4 +84,4 @@ touche = {8: affichage_statistique}
def mon_jeu():
rpg_python = Asci(cartes, evenements, touche)
rpg_python.mainloop(13, [100])
rpg_python.mainloop(11, [100], [{"main": 0}, 0, 10, 3])

View File

@ -5,16 +5,21 @@ from random import randint
cartes = (
(r"""
__
/ \___ ### *
/ \___ ###
|<> \ ##### _
|^|____| ### / \
/_\ |^| *
/_\ |^|
__ __
$ ## / \___/ \ ##
## / \___/ \ ##
#### |<> <>| ####
## |_________| ##
|| ||""",
[
("medecin", "*", 24, 4, "stand by"),
("ami", "*", 16, 1, "stand by"),
("bandit", "$", 4, 7, "walk", 0, ((4, 7), (3, 7), (3, 6), (4, 6)))
],
(1, 3, 1, 5, 7),
(19, 4, 2, 4, 4)),
@ -24,9 +29,10 @@ cartes = (
| + + + + |
| |
| + + + + |
+--/ *\--------/ \--+
+--/ \--------/ \--+
| |
+---|^|--------------+""",
[(0, "*", 5, 5, "stand by")],
(5, 7, 0, 1, 3)),
(r"""
@ -36,51 +42,41 @@ cartes = (
| |
+--|^|--+
""",
[],
(4, 4, 0, 19, 4))
)
def pnj(data, stat):
def pnj(data, stat, entites, identifiant):
carte_actuelle = data[1]
coords = data[2], data[3]
xp = data[0]["main"]
if carte_actuelle == 0:
if coords == (24, 4):
if identifiant == "medecin":
if stat[0] < 100: return [0, "Oh, mais tu es blesse !", 0, (0, 50)]
else: return [0, "Reviens me voir quand tu seras blesse."]
elif coords == (16, 1): return {
elif identifiant == "ami": return {
"base": [0, "Alors ? T'en sorts-tu ?"],
0: [0, "J'ai une quete pour toi ! Un ami a moi a des problemes : un personnage louche traine autour de sa maison... Si tu pouvais l'en debarasser, il t'en serai reconnaissant. 1. Je m'en charge ! 2. Trouve quelqu'un d'autre.", 2],
1: [2, "J'etais sur que je pouvais compter sur toi ! Tiens, voila une dague et une petit bouclier.", 0, 0, 10, 10],
1: [2, "J'etais sur que je pouvais compter sur toi ! Tiens, voila une dague et une petit bouclier.", 0, (1, 10), (2, 10)],
2: [3, "Si un jour tu as besoin de moi, tu seras sympa de m'oublier."],
3: [0, "Alors ? Il est mort ce bandit ?"],
4: [1, "Merci, tu as rendu un grand service a mon ami !"]
}
elif coords == (4, 7):
# Si le bandit vient d'être tué
if xp == 3: return [1, "Vous avez reussi la quete !"]
# Si le bandit est encore vivant
elif xp < 3: return [0, "Qu'est-ce que tu regardes toi ? Casses-toi !"]
# Si le bandit est déjà mort
else: return [0, "Vous regardez le cadavre froid du bandit."]
return [0, "Hmm ?"]
def ennemi(data, stat):
def ennemi(data, stat, entites, identifiant):
carte_actuelle = data[1]
coords = data[2], data[3]
xp = data[0]["main"]
if carte_actuelle == 0:
if coords == (4, 7):
if identifiant == "bandit":
# Bandit vivant
if xp == 3:
if combat(stat, [75, randint(5, 10), randint(5, 10)]):

View File

@ -8,61 +8,62 @@ cartes = (
|_ <>\ ###
|^|__| /_\
?
|==|==|==|==|==|==|==|""",
[
("pnj", "?", 2, 5, "stand by")
],
(1, 3, 1, 5, 7)),
(r"""
+--+--+--------+--+--+
| | | ? | | ?|
| | | | | |
| + + + + |
| |
| + + + + |
+--/ \--------/ \--+
| |
+---|^|--------------+""",
[
("boulanger", "?", 9, 1, "stand by"),
("kiosque", "?", 20, 1, "stand by")
],
(5, 7, 0, 1, 3))
)
def pnj(data, stat):
xp, carte_actuelle, x, y = data
coords = (x, y)
def pnj(data, stat, entites, identifiant):
if identifiant == "pnj":
# Si les deux quêtes annexes sont terminées, on incrémente la quête principale
if "pain" in data[0] and "journal" in data[0] and data[0]["pain"] == 3 and data[0]["journal"] == 3:
data[0]["main"] += 1
if carte_actuelle == 0:
if coords == (2, 5):
# Si les deux quêtes annexes sont terminées, on incrémente la quête principale
if "pain" in xp and "journal" in xp and xp["pain"] == 3 and xp["journal"] == 3:
data[0]["main"] += 1
# Si le joueur accepte la quête, on initialise les deux quêtes annexes
if data[0]["main"] == 1:
data[0]["pain"] = 1
data[0]["journal"] = 1
return [2, "Tu es un ange !"] # data[0]["main"] = 3
# Si le joueur accepte la quête, on initialise les deux quêtes annexes
if xp["main"] == 1:
data[0]["pain"] = 1
data[0]["journal"] = 1
return [2, "Tu es un ange !"] # data[0]["main"] = 3
elif "pain" in data[0] and data[0]["pain"] == 2: return "pain", [1, "Ah merci pour le pain."] # Si joueur a été chercher le pain
elif "journal" in data[0] and data[0]["journal"] == 2: return "journal", [1, "Aha enfin de la lecture !"] # Si le joueur a été chercher le journal
elif "pain" in xp and xp["pain"] == 2: return "pain", [1, "Ah merci pour le pain."] # Si joueur a été chercher le pain
elif "journal" in xp and xp["journal"] == 2: return "journal", [1, "Aha enfin de la lecture !"] # Si le joueur a été chercher le journal
else:
return {
0: [0, "J'aimerais que que tu ailles m'acheter un journal et du pain.\n1. J'y vais m'sieur !\n2. Humm... Non.", 2],
2: [-2, "Vilain garnement !"], # Si le joueur refuse la quête
3: [0, "Alors ? J'attend moi !"], # Si le joueur a accepté la quête, mais n'a été cherché ni le pain, ni le journal
4: [1, "Merci, pour ces commissions !"] # Si le joueur a terminé la quête
}
else:
return {
0: [0, "J'ai que tu ailles m'acheter un journal et du pain.\n1. J'y vais m'sieur !\n2. Humm... Non.", 2],
2: [-2, "Vilain garnement !"], # Si le joueur refuse la quête
3: [0, "Alors ? J'attend moi !"], # Si le joueur a accepté la quête, mais n'a été cherché ni le pain, ni le journal
4: [1, "Merci, pour ces commissions !"] # Si le joueur a terminé la quête
}
elif identifiant == "boulanger":
if "pain" in data[0] and data[0]["pain"] == 1: return "pain", [1, "Tient voila pour toi ! [+PAIN]"]
else: return [0, "Je suis boulanger mon jeune ami !"]
elif carte_actuelle == 1:
if coords == (9, 1):
if "pain" in xp and xp["pain"] == 1: return "pain", [1, "Tient voila pour toi ! [+PAIN]"]
else: return [0, "Je suis boulanger mon jeune ami !"]
elif coords == (20, 1):
if "journal" in xp and xp["journal"] == 1: return "journal", [1, "Voila ton journal"]
else: return [0, "Ce kiosque est dans la famille depuis plusieurs générations !"]
elif identifiant == "kiosque":
if "journal" in data[0] and data[0]["journal"] == 1: return "journal", [1, "Voila ton journal"]
else: return [0, "Ce kiosque est dans la famille depuis plusieurs générations !"]
return [0, "Hmm ?"]
@ -80,5 +81,4 @@ touche = {8: affichage_statistique}
def mon_jeu():
rpg_python = Asci(cartes, evenements, touche)
stat, data = rpg_python.mainloop(5, [100])
print(stat, data)
stat, data = rpg_python.mainloop(5, [100])

View File

@ -3,7 +3,7 @@ from sys import argv
import xmltodict
def convert_to_string(filename, doors, misc):
def convert_to_string(filename, doors, entities):
output_filename, extension = filename.split('.')
char_list = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ "
@ -18,32 +18,36 @@ def convert_to_string(filename, doors, misc):
data = [[int(char_id) for char_id in line.split(",") if char_id] for line in data]
doors_coords = []
misc_coords = []
entities_data = []
entities_count = 0
output = r""
for line_index, line in enumerate(data):
for char_index, char_id in enumerate(line):
output += char_list[char_id]
if char_list[char_id] not in entities:
output += char_list[char_id]
else:
output += " "
entities_data.append(f"({entities_count}, '{char_list[char_id]}', {char_index}, {line_index}, 'stand_by'),")
entities_count += 1
if char_list[char_id] in doors:
doors_coords.append(f"\t({char_index}, {line_index}, , 0, 0),")
if char_list[char_id] in misc:
misc_coords.append(f"# {char_list[char_id]} : ({char_index}, {line_index})")
output += "\n"
doors_coords = "\n".join(doors_coords)
misc_coords = "\n".join(misc_coords)
entities_data = "[\n\t" + "\n\t".join(entities_data) + "\n]"
with open(f"{output_filename}.py", "w") as file:
file.write(f"{output_filename} = (r\"\"\"\n{output[:-1]}\"\"\",\n{doors_coords}\n)\n\n{misc_coords}")
file.write(f"{output_filename} = (r\"\"\"\n{output[:-1]}\"\"\",\n{entities_data},\n\n{doors_coords}\n)")
filename, doors, misc = argv[1], "", ""
for arg in argv[2:]:
if arg.startswith("door"):
doors = arg.split("=", 1)[1]
elif arg.startswith("misc"):
misc = arg.split("=", 1)[1]
elif arg.startswith("entities"):
entities = arg.split("=", 1)[1]
convert_to_string(filename, doors, misc)
convert_to_string(filename, doors, entities)