Merge branch 'dev'

This commit is contained in:
Shadow15510 2022-01-08 22:48:38 +01:00
commit d94ae4c9f5
3 changed files with 109 additions and 16 deletions

29
asci.py
View File

@ -1,4 +1,4 @@
# Asci (version 1.5.4)
# Asci (version 1.6.0)
class Screen:
def __init__(self, screen_width=21, screen_height=6):
@ -137,6 +137,10 @@ class Asci:
# Get the event
event = self._game_events_mapping[cell_content](data_copy, self.stat)
if type(event) == tuple:
quest, event = event
else:
quest = "main"
# data modification
self.data[0] = data_copy[0]
@ -149,10 +153,10 @@ class Asci:
if data_copy[3] != y: self.data[3] = data_copy[3] - 3
if not event: return
event = read_event(self.data[0], event)
event = read_event(self.data, event, quest)
# XP and stat modification
self.data[0] += event.xp_earned
self.data[0][quest] += event.xp
for index, value in event.stat:
self.stat[index] += value
@ -160,7 +164,7 @@ class Asci:
if event.text:
answer_selected = convert(self.screen.display_text(event.text), True)
if event.answer and (0 < answer_selected <= event.answer):
self.data[0] += answer_selected
self.data[0][quest] += answer_selected
self._interaction(direction, cell_content)
def _get_map(self, direction):
@ -181,19 +185,19 @@ class Asci:
if not stat or type(stat) != list: self.stat = [100]
else: self.stat = stat
if not data: self.data = [0, 0, 0, 0]
if not data: self.data = [{"main": 0}, 0, 0, 0]
else: self.data = [data[0], data[1], data[2] - 10, data[3] - 3]
self.legend.append(door)
self.legend.append(walkable)
# Screen and map configuration
self.screen.set_world(self.maps[data[1]].map_data)
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
while key != exit_key and self.stat[0] > 0 and self.data[0] < end_game:
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)
@ -214,8 +218,8 @@ class Asci:
class Event:
def __init__(self, xp_earned, text, answer=0, *stat):
self.xp_earned = xp_earned
def __init__(self, xp, text, answer=0, *stat):
self.xp = xp
self.text = text
self.answer = answer
self.stat = stat
@ -258,9 +262,12 @@ def text_formater(string, screen_width=21, screen_height=6):
return paragraph_formater(lines, screen_height).split("\n\n")
def read_event(xp, event):
def read_event(data, event, quest):
if not quest in data[0]:
data[0][quest] = 0
if type(event) == dict:
if xp in event: event = event[xp]
if data[0][quest] in event: event = event[data[0][quest]]
else: event = event["base"]
if type(event) != list:

View File

@ -41,8 +41,9 @@ cartes = (
def pnj(data, stat):
xp, carte_actuelle, x, y = data
coords = (x, y)
carte_actuelle = data[1]
coords = data[2], data[3]
xp = data[0]["main"]
if carte_actuelle == 0:
if coords == (24, 4):
@ -74,8 +75,9 @@ def pnj(data, stat):
def ennemi(data, stat):
xp, carte_actuelle, x, y = data
coords = (x, y)
carte_actuelle = data[1]
coords = data[2], data[3]
xp = data[0]["main"]
if carte_actuelle == 0:
if coords == (4, 7):
@ -130,7 +132,7 @@ evenements = {"*": pnj, "$": ennemi}
touche = {7: affichage_stat}
def mon_jeu(stat=[100, 0, 0], data=[0, 0, 0, 0]):
def mon_jeu(stat=[100, 0, 0], data=[{"main": 0}, 0, 10, 3]):
rpg_python = Asci(cartes, evenements, touche)
stat, data = rpg_python.mainloop(5, stat, data=data)
print("Pour reprendre :")

84
samples/sample_4.py Normal file
View File

@ -0,0 +1,84 @@
from asci import *
cartes = (
(r"""
_ ###
/o\__ #####
|_ <>\ ###
|^|__| /_\
?
|==|==|==|==|==|==|==|""",
(1, 3, 1, 5, 7)),
(r"""
+--+--+--------+--+--+
| | | ? | | ?|
| + + + + |
| |
| + + + + |
+--/ \--------/ \--+
| |
+---|^|--------------+""",
(5, 7, 0, 1, 3))
)
def pnj(data, stat):
xp, carte_actuelle, x, y = data
coords = (x, y)
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 xp["main"] == 1:
data[0]["pain"] = 1
data[0]["journal"] = 1
return [2, "Tu es un ange !"] # data[0]["main"] = 3
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'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 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 !"]
return [0, "Hmm ?"]
def affichage_statistique(data, stat):
print("Statistiques :")
print("Points de Vie : {}".format(stat[0]))
evenements = {"?*": pnj}
touche = {8: affichage_statistique}
def mon_jeu():
rpg_python = Asci(cartes, evenements, touche)
stat, data = rpg_python.mainloop(5, [100])
print(stat, data)