150 lines
3.7 KiB
Python
150 lines
3.7 KiB
Python
from casioplot import clear_screen, show_screen, set_pixel, draw_string
|
|
from img.bg import pal,data
|
|
|
|
|
|
# Constants
|
|
|
|
ITEMS = ["coffre", "echelle", "cle", "calculatrice"]
|
|
CLICK_ZONES = [
|
|
("le pied du monument", (155, 150), lambda d: True),
|
|
("la colonne a gauche", (31, 81), lambda d: "echelle" not in d.inventory),
|
|
("la colonne a droite", (351, 140), lambda d: True),
|
|
("le haut du monument", (171, 48),
|
|
lambda d: "echelle" in d.inventory and not "cle" in d.inventory)
|
|
]
|
|
RED = (255, 0, 0)
|
|
|
|
|
|
# Functions
|
|
|
|
def enumerate(l):
|
|
i = 0
|
|
for e in l:
|
|
yield i, e
|
|
i += 1
|
|
|
|
def zones_available(d):
|
|
zones = []
|
|
for c in CLICK_ZONES:
|
|
if c[2](d):
|
|
zones.append(c)
|
|
return zones
|
|
|
|
def draw_img(d):
|
|
clear_screen()
|
|
x = 0
|
|
y = 0
|
|
for i in data:
|
|
set_pixel(x, y, pal[i & 0xf])
|
|
set_pixel(x+1, y, pal[i >> 4])
|
|
x += 2
|
|
if x > 382:
|
|
x = 0
|
|
y += 1
|
|
n = 1
|
|
for n, z in enumerate(zones_available(d)):
|
|
draw_string(z[1][0], z[1][1], str(n+1), RED, 'small')
|
|
|
|
def wait_action():
|
|
show_screen()
|
|
try:
|
|
while True:
|
|
pass
|
|
except KeyboardInterrupt:
|
|
pass
|
|
|
|
def get_action(d):
|
|
print("Inspecter :")
|
|
zones = zones_available(d)
|
|
for n, z in enumerate(zones):
|
|
print(n+1, z[0])
|
|
while True:
|
|
try:
|
|
a = int(input("> "))
|
|
return zones[a-1]
|
|
except (ValueError, IndexError):
|
|
pass
|
|
|
|
# Classes
|
|
|
|
class GameData():
|
|
def __init__(self, data=0):
|
|
try:
|
|
data = int(data)
|
|
except ValueError:
|
|
data = 0
|
|
if not (0 <= data <= 2**len(ITEMS) - 1):
|
|
data = 0
|
|
|
|
self.inventory = []
|
|
for n, item in enumerate(ITEMS):
|
|
if data & (1 << n):
|
|
self.inventory.append(item)
|
|
def to_int(self):
|
|
"""Export the GameData to a int"""
|
|
return sum([1 << n for n, item in enumerate(ITEMS) if item in self.inventory])
|
|
|
|
|
|
# Actions
|
|
|
|
save = input("Sauvegarde > ")
|
|
d = GameData(save)
|
|
|
|
draw_img(d)
|
|
|
|
while "calculatrice" not in d.inventory:
|
|
wait_action()
|
|
a = get_action(d)
|
|
print("Vous inspectez")
|
|
print(a[0])
|
|
|
|
if a[0] == "le pied du monument":
|
|
if not "coffre" in d.inventory:
|
|
print("Vous trouvez une")
|
|
print("etrange boite.")
|
|
print("En la retournant,")
|
|
print("vous remarquez une")
|
|
print("serrure sur le cote.")
|
|
d.inventory.append("coffre")
|
|
elif not "cle" in d.inventory:
|
|
print("Le coffre est tou-")
|
|
print("jours la. Peut-etre")
|
|
print("qu'une cle traine")
|
|
print("dans les parages.")
|
|
else:
|
|
print("Vous utilisez la")
|
|
print("cle pour ouvrir")
|
|
print("le coffre. A l'in-")
|
|
print("terieur se trouve")
|
|
print("une calculatrice.")
|
|
d.inventory.append("calculatrice")
|
|
|
|
if a[0] == "la colonne a gauche":
|
|
print("Une echelle se trou-")
|
|
print("vait derriere.")
|
|
print("Cela peut etre utile.")
|
|
d.inventory.append("echelle")
|
|
draw_img(d)
|
|
|
|
if a[0] == "la colonne a droite":
|
|
print("A part quelques flo-")
|
|
print("cons, il n'y a rien.")
|
|
|
|
if a[0] == "le haut du monument":
|
|
print("Un objet brillant")
|
|
print("attire votre atten-")
|
|
print("tion. C'est une cle.")
|
|
d.inventory.append("cle")
|
|
draw_img(d)
|
|
|
|
c = input("(C)ontinuer (q)")
|
|
if c == "q" or c == "Q":
|
|
print("Code de sauvegarde")
|
|
print(d.to_int())
|
|
break
|
|
|
|
if "calculatrice" in d.inventory:
|
|
print("Bravo, vous etes")
|
|
print("arrives au bout de")
|
|
print("l'aventure !")
|