nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
neo: Correct the documentation of neo.nit according to PR #734.
[nit.git]
/
lib
/
bucketed_game.nit
diff --git
a/lib/bucketed_game.nit
b/lib/bucketed_game.nit
index
40f4753
..
b680079
100644
(file)
--- a/
lib/bucketed_game.nit
+++ b/
lib/bucketed_game.nit
@@
-38,7
+38,7
@@
class Buckets[G: Game]
super Turnable[G]
type BUCKET: HashSet[Bucketable[G]]
super Turnable[G]
type BUCKET: HashSet[Bucketable[G]]
- private var buckets: Array[BUCKET]
+ private var buckets: Array[BUCKET] is noinit
private var next_bucket: nullable BUCKET = null
private var current_bucket_key: Int = -1
private var next_bucket: nullable BUCKET = null
private var current_bucket_key: Int = -1
@@
-93,7
+93,8
@@
class Buckets[G: Game]
end
# Game related event
end
# Game related event
-class GameEvent
+interface GameEvent
+ fun apply( game : ThinGame ) is abstract
end
# Event raised at the first turn
end
# Event raised at the first turn
@@
-103,14
+104,14
@@
end
# Game logic on the client
class ThinGame
# Game logic on the client
class ThinGame
- var tick: Int protected writable = 0
+ var tick: Int = 0 is protected writable
end
# Game turn on the client
class ThinGameTurn[G: ThinGame]
end
# Game turn on the client
class ThinGameTurn[G: ThinGame]
- var tick: Int protected writable = 0
+ var tick: Int = 0 is protected writable
- var events: List[GameEvent] protected writable = new List[GameEvent]
+ var events: List[GameEvent] = new List[GameEvent] is protected writable
init (t: Int) do tick = t
end
init (t: Int) do tick = t
end
@@
-135,6
+136,12
@@
class GameTurn[G: Game]
do
game.buckets.add_at(e, tick + t)
end
do
game.buckets.add_at(e, tick + t)
end
+
+ fun add_event( event : GameEvent )
+ do
+ event.apply( game )
+ events.add( event )
+ end
end
# Full game logic
end
# Full game logic
@@
-144,6
+151,11
@@
class Game
var buckets: Buckets[G] = new Buckets[G]
var buckets: Buckets[G] = new Buckets[G]
+ # Last turn executed in this game
+ # Can be used to consult the latest events (by the display for example),
+ # but cannot be used to add new Events.
+ var last_turn: nullable ThinGameTurn[G] = null
+
init do end
fun do_turn: GameTurn[G]
init do end
fun do_turn: GameTurn[G]
@@
-154,6
+166,8
@@
class Game
buckets.do_turn(turn)
do_post_turn(turn)
buckets.do_turn(turn)
do_post_turn(turn)
+ last_turn = turn
+
tick += 1
return turn
tick += 1
return turn