-
This commit is contained in:
@@ -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<Sprite>;
|
||||
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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
46
src/client/haxe/ru/m/tankz/view/frames/GameReadyFrame.hx
Executable file
46
src/client/haxe/ru/m/tankz/view/frames/GameReadyFrame.hx
Executable file
@@ -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<Person>;
|
||||
|
||||
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":
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
31
src/client/haxe/ru/m/tankz/view/frames/game/PersonView.hx
Executable file
31
src/client/haxe/ru/m/tankz/view/frames/game/PersonView.hx
Executable file
@@ -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<Person> {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
4
src/common/haxe/ru/m/tankz/core/PlayerTank.hx
Normal file → Executable file
4
src/common/haxe/ru/m/tankz/core/PlayerTank.hx
Normal file → Executable file
@@ -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();
|
||||
|
||||
@@ -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<Int, Int>();
|
||||
}
|
||||
|
||||
public function getGames():Array<Game> {
|
||||
return Lambda.array(games);
|
||||
public function getReadyGames():Array<Game> {
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user