diff --git a/res/layout/main.json b/res/layout/main.json index a5a0e28..3af625e 100755 --- a/res/layout/main.json +++ b/res/layout/main.json @@ -84,6 +84,12 @@ "skin":{"type":"haxework.gui.skin.ButtonColorSkin"}, "text":"Logout" }, + { + "id":"restart", "type":"haxework.gui.ButtonView", + "width":100, "height":30, + "skin":{"type":"haxework.gui.skin.ButtonColorSkin"}, + "text":"Restart" + }, { "id":"render", "type":"ru.m.tankz.render.Render", "contentSize":true diff --git a/src/client/haxe/ru/m/tankz/view/frames/GameFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/GameFrame.hx index b39c6ad..a7d2e75 100755 --- a/src/client/haxe/ru/m/tankz/view/frames/GameFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/frames/GameFrame.hx @@ -22,21 +22,12 @@ class GameFrame extends VGroupView { private var render:IRender; private var game:ITankz; + private var config:TankzConfig; + public function new() { super(); game = new Tankz(); - } - - public function init():Void { - render = findViewById("render"); - findViewById("logout", ButtonView).onPress = this; - } - - public function onShow():Void { - var person = Provider.get(GameData).person; - findViewById("name", LabelView).text = person.name; - - var config:TankzConfig = { + config = { map: { cellWidth: 20, cellHeight: 20, @@ -44,6 +35,17 @@ class GameFrame extends VGroupView { gridHeight: 26 } }; + } + + public function init():Void { + render = findViewById("render"); + findViewById("logout", ButtonView).onPress = this; + findViewById("restart", ButtonView).onPress = this; + } + + public function onShow():Void { + var person = Provider.get(GameData).person; + findViewById("name", LabelView).text = person.name; game.init(config); content.addEventListener(Event.ENTER_FRAME, updateGame); } @@ -62,6 +64,9 @@ class GameFrame extends VGroupView { switch (view.id) { case "logout": Provider.get(IConnection).disconnect(); + case "restart": + game.clear(); + game.init(config); } } }