1 # Monsterz - Chains of Friends
3 # 2010-2014 (c) Jean Privat <jean@pryen.org>
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the Do What The Fuck You Want To
7 # Public License, Version 2, as published by Sam Hocevar. See
8 # http://sam.zoy.org/projects/COPYING.WTFPL for more details.
20 init(game
: Game, i
: Int, code
: String)
23 var ls
= code
.split
(";")
26 self.gold
= ls
[1].to_i
27 if ls
.length
>= 3 then
30 self.is_tutorial
= i
<=4
31 self.is_challenge
= i
>=25
32 if self.is_tutorial
then
34 self.fullname
= "Tutorial level {i+1}"
35 else if not self.is_challenge
then
36 self.name
= (i-4
).to_s
37 self.fullname
= "Level {i-4}"
40 self.fullname
= "Challenge level {i-24}"
44 # number the level (0 for first)
47 # initial grid position
50 # top score to get gold
54 var status
: String = ""
56 # Is the level a tutorial level?
59 # Is the level a challenge level?
60 var is_challenge
: Bool
62 # The short name of the level (eg. "T1")
65 # The long name of the level (eg. "Tutorial level 1")
68 # The player best wining score.
79 if self.score
== 0 then
80 if self.number
== 0 or game
.levels
[self.number-1
].score
> 0 then return l_open
81 if self.number
== 25 and game
.levels
[19].score
> 0 then return l_open
else return l_disabled
82 else if self.score
< self.gold
or not game
.levels
[9].score
> 0 then
87 # Returns true if g is a wining condition for the level.
88 fun check_won
(g
: Grid): Bool
90 var w
= g
.won
and (not self.is_challenge
or g
.number
>= self.gold
)
91 if not w
then return false
92 if g
.number
> self.score
then
104 # Names of kind of monsters @constant
105 var colors
: Array[nullable String] = [null, "Red", "Cyan", "Green", "Purple", "Yellow", "Orange", "Blue", "Pink", "White"]
113 # Number of monster kinds (+1 for empty) @constant
116 # The grid to play on
117 var grid
= new Grid(gw
, gh
, monsters
)
119 # LEVELS ******************************************************************
121 # Raw level description
122 var levels_code
: Array[String] = [
123 ".3#|A2.A|3#.|;6;Connect two monsters",
124 ".#.|A.#|#.A|;5;Diagonals do not count",
125 "2.A|A#.|2.A|;8;Connect all monsters",
126 "3A.|3.A|2.A.|;10;Only 1 or 2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.CA3.|3.E8.|9.2.H|9.2.#|7.G4.|4.BG2.F3.|2.B6.E2.|9.G2.|.H8.C.|8.D3.|;140",
149 "2.F9..|2.C9..|9..C2.|8.AG3.|9.4.|4.2#5.F.|7.E4.#|3.A9.|.G.CF4.C.#.|9.2.E.|;125",
150 "9.HCB|.DH9.|.GC9.|9.3.|4.G7.|3.#8.|9.3.|3.B4.D3.|.G9..|8.#3.|2.C2.2#5.|9.3.|;135",
151 "9.6.A|6.C9.|2.A.B4.E3.#I.|9.I.#4.|9.7.|2.E3.C9.|7.B8.|5.G6.G3.|6.C6.G2.|9..H3.B.|.CH.#5.#2.C2.|4.H3.#3.H3.|.B3.F5.F4.|.D.D4.D5.D.|9.7.|6.C9.|;244",
153 "E6.|7.|.F.E.F.|.F.#.E.|.F.E.E.|7.|6.F|;48",
154 "3.2#3.|2.A2.A2.|.C4.C.|8.|3.2#3.|2.A2.A2.|.C4.C.|8.|;56",
155 "3.#3.A4.|5.#6.|3.#5.#2.|.#4.#4.#|4.#7.|#6.#4.|8.#3.|.#9..|.#3.#4.#.|3.2#3.#3.|;74",
156 "2.A7.|2.D7.|2.A4.A2.|2.G4.G2.|2.A4.D2.|2.D7.|2.A7.|2.G7.|2.D7.|2.G7.|;95",
157 "E9.6.|9.H4.#.|9.E2.#3.|9.F2.#2.#|9.3.H2.#|HEF9.3.#|9.7.|6.#9.|6.#2.H3.HEF|.6#2.E6.|9.F6.|5#9.2.|4.#9.#.|.F#3.7#.#.|9.5.#.|9.7.|;225"
161 var levels
= new Array[Level]
167 # Transform level strings into level objects. */
168 for i
in [0..levels_code
.length
[ do
169 var l
= new Level(self,i
, levels_code
[i
])
174 # The current played level (if any)
175 var level
: nullable Level = null