[common] added GameState

This commit is contained in:
2018-01-25 22:55:39 +03:00
parent 36c5f161fe
commit 7ac181ed5a
16 changed files with 121 additions and 208 deletions

View File

@@ -1,5 +1,7 @@
package ru.m.tankz;
import ru.m.tankz.game.ClassicGame;
import ru.m.tankz.game.Game;
import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
import flash.text.Font;
@@ -10,8 +12,6 @@ import haxework.resources.IResources;
import haxework.gui.VGroupView;
import haxework.gui.ViewBuilder;
import haxework.gui.ButtonView;
import flash.display.Sprite;
import haxework.gui.IGroupView;
import ru.m.tankz.PacketBuilder;
import haxework.log.JSLogger;
import haxework.gui.frame.IFrameSwitcher;
@@ -74,6 +74,8 @@ class Client implements IConnectionHandler {
view.switcher.change(StartFrame.ID);
}
});
Provider.setFactory(Game, ClassicGame, ClassicGame.TYPE);
}
public function onPress(view:ButtonView):Void {

View File

@@ -1,6 +1,6 @@
package ru.m.tankz.view.frames;
import ru.m.tankz.config.Config;
import ru.m.tankz.game.GameState;
import ru.m.tankz.control.PlayerControl;
import flash.events.Event;
import haxe.Timer;
@@ -9,8 +9,6 @@ import haxework.gui.ViewBuilder;
import haxework.provider.Provider;
import protohx.Message;
import ru.m.connect.IConnection;
import ru.m.tankz.config.ConfigBundle;
import ru.m.tankz.game.ClassicGame;
import ru.m.tankz.game.Game;
import ru.m.tankz.proto.pack.GameUpdateResponse;
@@ -29,15 +27,15 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
}
public function onShow():Void {
var config:Config = Provider.get(Config);
game = switch (config.type) {
case ClassicGame.TYPE: new ClassicGame(config);
case x: throw 'Unsupported game type "${x}"';
var state:GameState = Provider.get(GameState);
game = Provider.build(Game, state.type);
if (game == null) {
throw 'Unsupported game type "${state.type}"';
}
game.engine.listeners.push(render);
game.start();
for (index in 0...game.config.getTeam('human').size) {
game.setControl({team:'human', index:index}, PlayerControl.forPlayer(index));
game.start(state);
for (human in state.players['human'].iterator()) {
game.setControl({team:'human', index:human.index}, PlayerControl.forPlayer(human.index));
}
content.addEventListener(Event.ENTER_FRAME, redraw);
Provider.get(IConnection).packetHandler.addListener(this);

View File

@@ -1,14 +1,14 @@
package ru.m.tankz.view.frames;
import ru.m.tankz.config.Config;
import ru.m.tankz.game.GameState;
import ru.m.tankz.game.ClassicGame;
import ru.m.tankz.config.ConfigBundle;
import haxework.gui.frame.IFrameSwitcher;
import haxework.provider.Provider;
import haxework.gui.ButtonView;
import haxework.gui.ViewBuilder;
import haxework.gui.VGroupView;
@:template("layout/frames/start.json", "layout/styles.json")
class StartFrame extends VGroupView implements ViewBuilder {
@@ -28,11 +28,8 @@ class StartFrame extends VGroupView implements ViewBuilder {
}
}
private function startGame(players:Int):Void {
var config = ConfigBundle.get(ClassicGame.TYPE, 0);
config.getTeam('human').size = players;
config.getTeam('bot').size = 2 + 2 * players;
Provider.set(Config, config);
private function startGame(humans:Int):Void {
Provider.set(GameState, ClassicGame.buildState(0, humans));
Provider.get(IFrameSwitcher).change(GameFrame.ID);
}
}