diff --git a/project.xml b/project.xml
index e0afab1..7386f3b 100755
--- a/project.xml
+++ b/project.xml
@@ -19,4 +19,5 @@
+
\ No newline at end of file
diff --git a/proto/base.proto b/proto/base.proto
index f56954a..50704e9 100755
--- a/proto/base.proto
+++ b/proto/base.proto
@@ -34,10 +34,16 @@ message ErrorResponse {
}
+enum GameState {
+ READY = 1;
+ STARTED = 2;
+ ENDED = 3;
+}
message Game {
required int32 id = 1;
repeated Person persons = 2;
+ required GameState state = 3;
}
message GamesRequest {
diff --git a/res/layout/main.json b/res/layout/main.json
index 7c7c42c..0ccb43e 100755
--- a/res/layout/main.json
+++ b/res/layout/main.json
@@ -1,135 +1,174 @@
{
- "type":"haxework.frame.FrameSwitcher",
- "skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0x000000"},
- "views":[
+ "type": "haxework.gui.VGroupView",
+ "pWidth": 100, "pHeight": 100,
+ "views": [
{
- "id":"auth", "type":"ru.m.tankz.view.frames.AuthFrame",
- "skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xa0a0a0"},
- "pWidth":100, "pHeight":100, "layoutMargin":3,
- "views":[
+ "id":"top", "type": "haxework.gui.HGroupView",
+ "pWidth": 100, "height": 30,
+ "skin": {"type": "haxework.gui.skin.ColorSkin", "color": "0x105000"},
+ "views": [
{
- "id":"login", "type":"haxework.gui.HGroupView",
- "contentSize":true,
- "views":[
+ "id": "logout", "type": "haxework.gui.ButtonView",
+ "width": 100, "height": 30,
+ "skin": {"type": "haxework.gui.skin.ButtonColorSkin"},
+ "text": "Logout"
+ }
+ ]
+ },
+ {
+ "id": "switcher", "type": "haxework.frame.FrameSwitcher",
+ "pWidth": 100, "pHeight": 100,
+ "skin": {"type": "haxework.gui.skin.ColorSkin", "color": "0x50a000"},
+ "views": [
+ {
+ "id": "auth", "type": "ru.m.tankz.view.frames.AuthFrame",
+ "pWidth": 100, "pHeight": 100, "layoutMargin": 3,
+ "views": [
{
- "type":"haxework.gui.LabelView",
- "width":150, "height":25, "text":"Login"
+ "id": "login", "type": "haxework.gui.HGroupView",
+ "contentSize": true,
+ "views": [
+ {
+ "type": "haxework.gui.LabelView",
+ "width": 150, "height": 25, "text": "Login"
+ },
+ {
+ "id": "input", "type": "haxework.gui.InputView",
+ "skin": {"type": "haxework.gui.skin.ColorSkin", "color": "0xffffff"},
+ "width": 200, "height": 25, "text": ""
+ }
+ ]
},
{
- "id":"input", "type":"haxework.gui.InputView",
- "skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xffffff"},
- "width":200, "height":25, "text":""
- }
- ]
- },
- {
- "id":"password", "type":"haxework.gui.HGroupView",
- "contentSize":true,
- "views":[
- {
- "type":"haxework.gui.LabelView",
- "width":150, "height":25, "text":"Password"
+ "id": "password", "type": "haxework.gui.HGroupView",
+ "contentSize": true,
+ "views": [
+ {
+ "type": "haxework.gui.LabelView",
+ "width": 150, "height": 25, "text": "Password"
+ },
+ {
+ "id": "input", "type": "haxework.gui.InputView",
+ "skin": {"type": "haxework.gui.skin.ColorSkin", "color": "0xffffff"},
+ "width": 200, "height": 25, "text": ""
+ }
+ ]
},
+
{
- "id":"input", "type":"haxework.gui.InputView",
- "skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xffffff"},
- "width":200, "height":25, "text":""
+ "id": "auth",
+ "type": "haxework.gui.ButtonView",
+ "width": 100,
+ "height": 30,
+ "skin": {"type": "haxework.gui.skin.ButtonColorSkin"},
+ "text": "Auth"
}
]
},
+
{
- "id":"auth",
- "type":"haxework.gui.ButtonView",
- "width":100,
- "height":30,
- "skin":{"type":"haxework.gui.skin.ButtonColorSkin"},
- "text":"Auth"
- }
- ]
- },
-
-
- {
- "id":"person_list", "type":"ru.m.tankz.view.frames.PersonListFrame",
- "skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xa0a0a0"},
- "pWidth":100, "pHeight":100, "layoutMargin":3, "paddings":10,
- "views":[
- {
- "id":"list", "type":"haxework.gui.list.VListView",
- "factory":{
- "type":"~ru.m.tankz.view.frames.person.PersonView"
- },
- "scroll":{
- "type":"haxework.gui.list.VScrollView",
- "skin":{"type":"haxework.gui.list.VScrollSkin"}
- },
- "pWidth":100, "pHeight":100, "layoutMargin":5
- }
- ]
- },
-
-
- {
- "id":"game_list", "type":"ru.m.tankz.view.frames.GameListFrame",
- "skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xa0a0a0"},
- "pWidth":100, "pHeight":100,
- "views":[
- {
- "id":"name", "type":"haxework.gui.LabelView",
- "pWidth":100, "height":25, "text":""
- },
- {
- "id":"create", "type":"haxework.gui.ButtonView",
- "width":100, "height":30,
- "skin":{"type":"haxework.gui.skin.ButtonColorSkin"},
- "text":"Create"
- },
- {
- "id":"logout", "type":"haxework.gui.ButtonView",
- "width":100, "height":30,
- "skin":{"type":"haxework.gui.skin.ButtonColorSkin"},
- "text":"Logout"
- },
- {
- "id":"list", "type":"haxework.gui.list.VListView",
- "factory":{
- "type":"~ru.m.tankz.view.frames.game.GameView"
- },
- "scroll":{
- "type":"haxework.gui.list.VScrollView",
- "skin":{"type":"haxework.gui.list.VScrollSkin"}
- },
- "pWidth":100, "pHeight":100, "layoutMargin":5
- }
- ]
- },
-
-
- {
- "id":"game", "type":"ru.m.tankz.view.frames.GameFrame",
- "skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xa0a0a0"},
- "pWidth":100, "pHeight":100,
- "views":[
- {
- "id":"name", "type":"haxework.gui.LabelView",
- "pWidth":100, "height":25, "text":""
+ "id": "person_list", "type": "ru.m.tankz.view.frames.PersonListFrame",
+ "pWidth": 100, "pHeight": 100, "layoutMargin": 3, "paddings": 10,
+ "views": [
+ {
+ "id": "list", "type": "haxework.gui.list.VListView",
+ "factory": {
+ "type": "~ru.m.tankz.view.frames.person.PersonView"
+ },
+ "scroll": {
+ "type": "haxework.gui.list.VScrollView",
+ "skin": {"type": "haxework.gui.list.VScrollSkin"}
+ },
+ "pWidth": 100, "pHeight": 100, "layoutMargin": 5
+ }
+ ]
},
+
+
{
- "id":"logout", "type":"haxework.gui.ButtonView",
- "width":100, "height":30,
- "skin":{"type":"haxework.gui.skin.ButtonColorSkin"},
- "text":"Logout"
+ "id": "game_list", "type": "ru.m.tankz.view.frames.GameListFrame",
+ "pWidth": 100, "pHeight": 100,
+ "views": [
+ {
+ "id": "name", "type": "haxework.gui.LabelView",
+ "pWidth": 100, "height": 25, "text": ""
+ },
+ {
+ "id": "create", "type": "haxework.gui.ButtonView",
+ "width": 100, "height": 30,
+ "skin": {"type": "haxework.gui.skin.ButtonColorSkin"},
+ "text": "Create"
+ },
+ {
+ "id": "list", "type": "haxework.gui.list.VListView",
+ "factory": {
+ "type": "~ru.m.tankz.view.frames.game.GameView"
+ },
+ "scroll": {
+ "type": "haxework.gui.list.VScrollView",
+ "skin": {"type": "haxework.gui.list.VScrollSkin"}
+ },
+ "pWidth": 100, "pHeight": 100, "layoutMargin": 5
+ }
+ ]
},
+
+
{
- "id":"restart", "type":"haxework.gui.ButtonView",
- "width":100, "height":30,
- "skin":{"type":"haxework.gui.skin.ButtonColorSkin"},
- "text":"Restart"
+ "id": "game_ready", "type": "ru.m.tankz.view.frames.GameReadyFrame",
+ "pWidth": 100, "pHeight": 100,
+ "views": [
+ {
+ "id": "name", "type": "haxework.gui.LabelView",
+ "pWidth": 100, "height": 25, "text": ""
+ },
+ {
+ "id": "start", "type": "haxework.gui.ButtonView",
+ "width": 100, "height": 30,
+ "skin": {"type": "haxework.gui.skin.ButtonColorSkin"},
+ "text": "Start"
+ },
+ {
+ "id": "exit", "type": "haxework.gui.ButtonView",
+ "width": 100, "height": 30,
+ "skin": {"type": "haxework.gui.skin.ButtonColorSkin"},
+ "text": "Exit"
+ },
+ {
+ "id": "list", "type": "haxework.gui.list.VListView",
+ "factory": {
+ "type": "~ru.m.tankz.view.frames.game.PersonView"
+ },
+ "scroll": {
+ "type": "haxework.gui.list.VScrollView",
+ "skin": {"type": "haxework.gui.list.VScrollSkin"}
+ },
+ "pWidth": 100, "pHeight": 100, "layoutMargin": 5
+ }
+ ]
},
+
+
{
- "id":"render", "type":"ru.m.tankz.render.Render",
- "contentSize":true
+ "id": "game", "type": "ru.m.tankz.view.frames.GameFrame",
+ "pWidth": 100, "pHeight": 100,
+ "views": [
+ {
+ "id": "name", "type": "haxework.gui.LabelView",
+ "pWidth": 100, "height": 25, "text": ""
+ },
+ {
+ "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/Client.hx b/src/client/haxe/ru/m/tankz/Client.hx
index 8206a47..f644a2a 100755
--- a/src/client/haxe/ru/m/tankz/Client.hx
+++ b/src/client/haxe/ru/m/tankz/Client.hx
@@ -1,5 +1,9 @@
package ru.m.tankz;
+import haxework.gui.ButtonView;
+import flash.display.Sprite;
+import haxework.gui.IGroupView;
+import ru.m.tankz.view.frames.GameReadyFrame;
import ru.m.tankz.PacketBuilder;
import flash.text.TextFieldType;
import flash.Lib;
@@ -31,13 +35,18 @@ class Client implements IConnectionHandler {
}
+ private var view:IGroupView;
+ private var logout:ButtonView;
private var switcher:FrameSwitcher;
public function new() {
var bytes = Assets.getBytes("res/layout/main.json");
var form:Dynamic = Json.parse(bytes.readUTFBytes(bytes.bytesAvailable));
- switcher = GuiBuilder.build(form, {listener:this});
- new Root(switcher);
+ view = GuiBuilder.build(form, {listener:this});
+ new Root(view);
+ switcher = view.findViewById("switcher");
+ logout = view.findViewById("top:logout");
+ logout.onPress = this;
Provider.setFactory(GameData, GameData);
Provider.set(IFrameSwitcher, switcher);
@@ -58,6 +67,13 @@ class Client implements IConnectionHandler {
Lib.current.addChild(tf);*/
}
+ public function onPress(view:ButtonView):Void {
+ switch (view.id) {
+ case "logout":
+ Provider.get(IConnection).disconnect();
+ }
+ }
+
public function onConnected():Void {}
public function onDisconnected():Void {
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 a7d2e75..f06c69c 100755
--- a/src/client/haxe/ru/m/tankz/view/frames/GameFrame.hx
+++ b/src/client/haxe/ru/m/tankz/view/frames/GameFrame.hx
@@ -39,7 +39,6 @@ class GameFrame extends VGroupView {
public function init():Void {
render = findViewById("render");
- findViewById("logout", ButtonView).onPress = this;
findViewById("restart", ButtonView).onPress = this;
}
@@ -62,8 +61,6 @@ class GameFrame extends VGroupView {
public function onPress(view:ButtonView):Void {
switch (view.id) {
- case "logout":
- Provider.get(IConnection).disconnect();
case "restart":
game.clear();
game.init(config);
diff --git a/src/client/haxe/ru/m/tankz/view/frames/GameListFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/GameListFrame.hx
index 4a9d82a..a16b594 100755
--- a/src/client/haxe/ru/m/tankz/view/frames/GameListFrame.hx
+++ b/src/client/haxe/ru/m/tankz/view/frames/GameListFrame.hx
@@ -34,7 +34,6 @@ class GameListFrame extends VGroupView implements IPacketHandler implements List
public function init() {
list = findViewById("list");
list.dispatcher.addListener(this);
- findViewById("logout", ButtonView).onPress = this;
findViewById("create", ButtonView).onPress = this;
}
@@ -54,21 +53,21 @@ class GameListFrame extends VGroupView implements IPacketHandler implements List
}
public function onCreateGameResponse(packet:CreateGameResponse):Void {
- list.data.push(packet.game);
- list.update();
+ //list.data.push(packet.game);
+ //list.update();
+ Provider.get(GameData).game = packet.game;
+ Provider.get(IFrameSwitcher).change(GameReadyFrame.ID);
}
public function onJoinGameResponse(packet:JoinGameResponse):Void {
Provider.get(GameData).game = packet.game;
- Provider.get(IFrameSwitcher).change(GameFrame.ID);
+ Provider.get(IFrameSwitcher).change(GameReadyFrame.ID);
}
public function onPacket(packet:Message):Void {}
public function onPress(view:ButtonView):Void {
switch (view.id) {
- case "logout":
- Provider.get(IConnection).disconnect();
case "create":
Provider.get(IConnection).send(new CreateGameRequest());
}
diff --git a/src/client/haxe/ru/m/tankz/view/frames/GameReadyFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/GameReadyFrame.hx
new file mode 100755
index 0000000..4fb0dc9
--- /dev/null
+++ b/src/client/haxe/ru/m/tankz/view/frames/GameReadyFrame.hx
@@ -0,0 +1,46 @@
+package ru.m.tankz.view.frames;
+
+import ru.m.tankz.data.GameData;
+import protohx.Message;
+import haxework.gui.ButtonView;
+import haxework.gui.list.VListView;
+import ru.m.tankz.proto.Person;
+import haxework.provider.Provider;
+import haxework.gui.VGroupView;
+import ru.m.core.connect.IConnection;
+
+class GameReadyFrame extends VGroupView implements IPacketHandler {
+
+ private static inline var TAG = "GameReadyFrame";
+
+ public static inline var ID = "game_ready";
+
+ private var list:VListView;
+
+ public function new() {
+ super();
+ }
+
+ public function init() {
+ list = findViewById("list");
+ //list.dispatcher.addListener(this);
+ findViewById("start", ButtonView).onPress = this;
+ findViewById("exit", ButtonView).onPress = this;
+ }
+
+ public function onShow() {
+ Provider.get(IConnection).packetHandler = this;
+ list.data = Provider.get(GameData).game.persons;
+ }
+
+ public function onPacket(packet:Message):Void {}
+
+ public function onPress(view:ButtonView):Void {
+ switch (view.id) {
+ case "start":
+
+ case "exit":
+
+ }
+ }
+}
diff --git a/src/client/haxe/ru/m/tankz/view/frames/game/PersonView.hx b/src/client/haxe/ru/m/tankz/view/frames/game/PersonView.hx
new file mode 100755
index 0000000..421bc3d
--- /dev/null
+++ b/src/client/haxe/ru/m/tankz/view/frames/game/PersonView.hx
@@ -0,0 +1,31 @@
+package ru.m.tankz.view.frames.game;
+
+import ru.m.tankz.proto.Person;
+import haxework.gui.list.ListView.IListItemView;
+import haxework.gui.LabelView;
+import haxework.gui.skin.ColorSkin;
+import haxework.gui.HGroupView;
+
+class PersonView extends HGroupView implements IListItemView {
+
+ public var item_index(default, default):Int;
+ public var data(default, set):Person;
+
+ private var nameLabel:LabelView;
+
+ public function new() {
+ super();
+ pWidth = 100;
+ height = 50;
+ skin = new ColorSkin(0xffffff);
+
+ nameLabel = new LabelView();
+ addView(nameLabel);
+ }
+
+ private function set_data(value:Person):Person {
+ this.data = value;
+ nameLabel.text = value.name;
+ return this.data;
+ }
+}
\ No newline at end of file
diff --git a/src/common/haxe/ru/m/core/connect/flash/FlashConnection.hx b/src/common/haxe/ru/m/core/connect/flash/FlashConnection.hx
index 0bfea7b..dce9993 100755
--- a/src/common/haxe/ru/m/core/connect/flash/FlashConnection.hx
+++ b/src/common/haxe/ru/m/core/connect/flash/FlashConnection.hx
@@ -43,9 +43,11 @@ class FlashConnection extends BaseConnection {
}
override public function disconnect():Void {
- socket.close();
- connected = false;
- if (handler != null) handler.onDisconnected();
+ if (socket.connected) {
+ socket.close();
+ connected = false;
+ if (handler != null) handler.onDisconnected();
+ }
}
private function onError(event:ErrorEvent):Void {
diff --git a/src/common/haxe/ru/m/tankz/core/PlayerTank.hx b/src/common/haxe/ru/m/tankz/core/PlayerTank.hx
old mode 100644
new mode 100755
index dcd4df5..02d50f8
--- a/src/common/haxe/ru/m/tankz/core/PlayerTank.hx
+++ b/src/common/haxe/ru/m/tankz/core/PlayerTank.hx
@@ -19,7 +19,7 @@ class PlayerTank extends Tank {
}
private function onKeyDown(event:KeyboardEvent):Void {
- switch (keyBinding.get(event.keyCode)) {
+ if (keyBinding.exists(event.keyCode)) switch (keyBinding.get(event.keyCode)) {
case TankAction.MOVE(direction):
if (moveQueue.indexOf(event.keyCode) == -1) {
moveQueue.unshift(event.keyCode);
@@ -30,7 +30,7 @@ class PlayerTank extends Tank {
}
private function onKeyUp(event:KeyboardEvent):Void {
- switch (keyBinding.get(event.keyCode)) {
+ if (keyBinding.exists(event.keyCode)) switch (keyBinding.get(event.keyCode)) {
case TankAction.MOVE(direction):
moveQueue.remove(event.keyCode);
updateMove();
diff --git a/src/server/haxe/ru/m/tankz/server/session/Session.hx b/src/server/haxe/ru/m/tankz/server/session/Session.hx
index 85a8dae..e312efa 100755
--- a/src/server/haxe/ru/m/tankz/server/session/Session.hx
+++ b/src/server/haxe/ru/m/tankz/server/session/Session.hx
@@ -1,5 +1,6 @@
package ru.m.tankz.server.session;
+import ru.m.tankz.proto.GameState;
import ru.m.tankz.proto.Person;
import ru.m.tankz.proto.JoinGameResponse;
import ru.m.tankz.proto.JoinGameRequest;
@@ -34,13 +35,14 @@ class GameCenter {
persons = new Map();
}
- public function getGames():Array {
- return Lambda.array(games);
+ public function getReadyGames():Array {
+ return Lambda.array(games).filter(function(g) return g.state == GameState.READY);
}
- public function createGame():Game {
- var game:Game = new Game().setId(game_id++);
+ public function createGame(person:Person):Game {
+ var game:Game = new Game().setId(game_id++).setState(GameState.READY);
games.set(game.id, game);
+ join(person, game.id);
return game;
}
@@ -57,6 +59,9 @@ class GameCenter {
var game:Game = games.get(persons.get(personId));
for (person in game.persons) if (person.id == personId) {
game.persons.remove(person);
+ if (game.persons.length == 0) {
+ games.remove(game.id);
+ }
break;
}
persons.remove(personId);
@@ -140,11 +145,11 @@ class Session implements IConnectionHandler implements IPacketHandler {
}
public function onGamesRequest(packet:GamesRequest):Void {
- connection.send(new GamesResponse().setGames(games.getGames()));
+ connection.send(new GamesResponse().setGames(games.getReadyGames()));
}
public function onCreateGameRequest(packet:CreateGameRequest):Void {
- var game:Game = games.createGame();
+ var game:Game = games.createGame(person);
connection.send(new CreateGameResponse().setGame(game));
}