-
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
package ru.m.tankz.view.frames;
|
||||
|
||||
import ru.m.tankz.proto.ExitGameResponse;
|
||||
import haxework.frame.IFrameSwitcher;
|
||||
import ru.m.tankz.proto.GamesResponse;
|
||||
import ru.m.tankz.proto.ExitGameRequest;
|
||||
import ru.m.tankz.proto.StartGameResponse;
|
||||
import ru.m.tankz.proto.StartGameRequest;
|
||||
import ru.m.tankz.data.GameData;
|
||||
import protohx.Message;
|
||||
import haxework.gui.ButtonView;
|
||||
@@ -33,14 +39,23 @@ class GameReadyFrame extends VGroupView implements IPacketHandler {
|
||||
list.data = Provider.get(GameData).game.persons;
|
||||
}
|
||||
|
||||
public function onStartGameResponse(packet:StartGameResponse):Void {
|
||||
Provider.get(GameData).game = packet.game;
|
||||
Provider.get(IFrameSwitcher).change(GameFrame.ID);
|
||||
}
|
||||
|
||||
public function onExitGameResponse(packet:ExitGameResponse):Void {
|
||||
Provider.get(IFrameSwitcher).change(GameListFrame.ID);
|
||||
}
|
||||
|
||||
public function onPacket(packet:Message):Void {}
|
||||
|
||||
public function onPress(view:ButtonView):Void {
|
||||
switch (view.id) {
|
||||
case "start":
|
||||
|
||||
Provider.get(IConnection).send(new StartGameRequest());
|
||||
case "exit":
|
||||
|
||||
Provider.get(IConnection).send(new ExitGameRequest());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,10 @@ import ru.m.tankz.proto.CreateGameRequest;
|
||||
import ru.m.tankz.proto.CreateGameResponse;
|
||||
import ru.m.tankz.proto.JoinGameRequest;
|
||||
import ru.m.tankz.proto.JoinGameResponse;
|
||||
import ru.m.tankz.proto.StartGameRequest;
|
||||
import ru.m.tankz.proto.StartGameResponse;
|
||||
import ru.m.tankz.proto.ExitGameRequest;
|
||||
import ru.m.tankz.proto.ExitGameResponse;
|
||||
|
||||
class PacketBuilder implements IPacketBuilder {
|
||||
|
||||
@@ -33,6 +37,10 @@ class PacketBuilder implements IPacketBuilder {
|
||||
0x0004 => CreateGameResponse,
|
||||
0x0005 => JoinGameRequest,
|
||||
0x0006 => JoinGameResponse,
|
||||
0x0007 => StartGameRequest,
|
||||
0x0008 => StartGameResponse,
|
||||
0x0009 => ExitGameRequest,
|
||||
0x000a => ExitGameResponse
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package ru.m.tankz.server.session;
|
||||
|
||||
import ru.m.tankz.proto.ExitGameResponse;
|
||||
import ru.m.tankz.proto.ExitGameRequest;
|
||||
import ru.m.tankz.proto.StartGameRequest;
|
||||
import ru.m.tankz.proto.StartGameResponse;
|
||||
import ru.m.tankz.proto.GameState;
|
||||
import ru.m.tankz.proto.Person;
|
||||
import ru.m.tankz.proto.JoinGameResponse;
|
||||
@@ -28,10 +32,12 @@ class GameCenter {
|
||||
|
||||
private var game_id:Int = 0;
|
||||
private var games:Map<Int, Game>;
|
||||
private var created:Map<Int, Int>;
|
||||
private var persons:Map<Int, Int>;
|
||||
|
||||
public function new() {
|
||||
games = new Map<Int, Game>();
|
||||
created = new Map<Int, Int>();
|
||||
persons = new Map<Int, Int>();
|
||||
}
|
||||
|
||||
@@ -39,9 +45,17 @@ class GameCenter {
|
||||
return Lambda.array(games).filter(function(g) return g.state == GameState.READY);
|
||||
}
|
||||
|
||||
public function getCreatedGame(person_id:Int):Game {
|
||||
return games.get(created.get(person_id));
|
||||
}
|
||||
|
||||
public function createGame(person:Person):Game {
|
||||
var game:Game = new Game().setId(game_id++).setState(GameState.READY);
|
||||
var game:Game = new Game()
|
||||
.setId(game_id++)
|
||||
.setState(GameState.READY)
|
||||
.setCreator(person);
|
||||
games.set(game.id, game);
|
||||
created.set(person.id, game.id);
|
||||
join(person, game.id);
|
||||
return game;
|
||||
}
|
||||
@@ -158,6 +172,17 @@ class Session implements IConnectionHandler implements IPacketHandler {
|
||||
connection.send(new JoinGameResponse().setGame(game));
|
||||
}
|
||||
|
||||
public function onStartGameRequest(packet:StartGameRequest):Void {
|
||||
var game:Game = games.getCreatedGame(person.id);
|
||||
game.setState(GameState.STARTED);
|
||||
connection.send(new StartGameResponse().setGame(game));
|
||||
}
|
||||
|
||||
public function onExitGameRequest(packet:ExitGameRequest):Void {
|
||||
games.exit(person.id);
|
||||
connection.send(new ExitGameResponse());
|
||||
}
|
||||
|
||||
public function onPacket(packet:Message):Void {
|
||||
trace("Unknown packet: " + Type.getClassName(Type.getClass(packet)).split(".").pop());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user