import solver
import mnit::tileset
import app::data_store
-import md5
intrude import grid
intrude import level
else if self.level.get_state >= l.l_open then
if game.levels[9].get_state >= l.l_open then self.over += " --- ?/{self.level.gold}"
end
- #self.enabled = l.get_state >= l.l_open
+ self.enabled = l.get_state >= l.l_open or game.cheated
end
redef fun draw(ctx)
do
print "***STATUS** {txt}"
self.tmp_txt = txt
- self.tmp_txt_ttl = 20
+ self.tmp_txt_ttl = 60
self.tmp_txt_color = color
end
# ResizeButton
var button_size = new ResizeButton(self)
+ # Cheat mode enabled?
+ var cheated = false
+
init
do
load_levels
fun play(l: Level)
do
level = l
- grid.load(level.str)
+ grid.load(level.saved_str or else level.str)
init_play_menu(false)
if level.status != "" then
statusbar.main_txt = level.status
fun onKeyDown(ev: Event) do
var kc = ev.char_code
if kc == "e" then
+ set_tmp("RUN EDITOR")
grid_edit = grid.copy(true)
edit_grid(grid)
+ else if kc == "c" then
+ if cheated then
+ set_tmp("CHEAT: OFF")
+ snd_duh.play
+ cheated = false
+ else
+ set_tmp("CHEAT: ON")
+ snd_win.play
+ cheated = true
+ end
else if kc == "s" then
if solver == null then
solver = (new FriendzProblem(grid)).solve
else
solver_pause = not solver_pause
end
+ if solver_pause then
+ set_tmp("SOLVER: PAUSED")
+ else
+ set_tmp("SOLVER: ON")
+ end
#solver.step
else if kc == "d" then
if solver == null then
solver = (new FriendzProblem(grid)).solve
solver_pause = true
+ set_tmp("SOLVER: ON")
else
+ solver_pause = true
solver.run_steps(1)
+ set_tmp("SOLVER: ONE STEP")
end
else if kc == "+" then
solver_steps += 100
- print solver_steps
+ set_tmp("SOLVER: {solver_steps} STEPS")
else if kc == "-" then
solver_steps -= 100
- print solver_steps
+ set_tmp("SOLVER: {solver_steps} STEPS")
else for g in entities do
if kc == g.shortcut then
g.click(ev)
end
end
+ fun set_tmp(s: String)
+ do
+ statusbar.set_tmp(s, "cyan")
+ end
+
redef fun load_levels
do
super
for level in levels do
- var score = app.data_store["s{level.str.md5}"]
+ var score = app.data_store["s{level.str}"]
if score isa Int then
level.score = score
end
+ var saved_str = app.data_store["g{level.str}"]
+ if saved_str isa String then
+ print "LOAD {level.name}: {saved_str}"
+ level.saved_str = saved_str
+ end
end
end
end
redef class Level
redef fun save
do
- app.data_store["s{str.md5}"] = if score > 0 then score else null
+ app.data_store["s{str}"] = if score > 0 then score else null
+ var saved = game.grid.save
+ saved_str = saved
+ app.data_store["g{str}"] = saved
+ print "SAVE: {name}: {saved}"
end
+
+ # The saved player grid (to continue games)
+ var saved_str: nullable String = null
end