[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);
}
}

View File

@@ -3,7 +3,6 @@ map:
cellHeight: 22
gridWidth: 26
gridHeight: 26
bricks: []
bricks:
# border
@@ -37,7 +36,6 @@ bricks:
teams:
- id: human
size: 2
spawnInterval: 0
points:
- type: eagle
@@ -56,7 +54,6 @@ teams:
y: 24
direction: top
- id: bot
size: 6
spawnInterval: 3000
points:
- type: tank

View File

@@ -1,161 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
<svg xmlns="http://www.w3.org/2000/svg"
><metadata
></metadata
><defs
><font horiz-adv-x="300"
><font-face font-family="8BIT WONDER" units-per-em="300" ascent="300" descent="0"
></font-face
><missing-glyph horiz-adv-x="150" d="M19 0V300H131V0H19ZM38 19h75V281H38V19Z"
></missing-glyph
><glyph unicode=" " horiz-adv-x="150" d=""
></glyph
><glyph unicode="#" d="M300 0H0V300H300V0ZM250 50V250H50V50H250Z"
></glyph
><glyph unicode="(" horiz-adv-x="150" d="M150 0H25V25H0V225H25v25H150V200H100V50h50V0Z"
></glyph
><glyph unicode=")" horiz-adv-x="150" d="M150 25H125V0H0V50H50V200H0v50H125V225h25V25Z"
></glyph
><glyph unicode="*" d="M250 220L230 200H220l-20 20v10l20 20h10l20 -20V220ZM200 165L185 150H165l-15 15v20l15 15h20l15 -15V165ZM150 110L140 100H110l-10 10v30l10 10h30l10 -10V110ZM50 220L30 200H20L0 220v10l20 20H30L50 230V220ZM100 165L85 150H65L50 165v20l15 15H85l15 -15V165ZM200 65L185 50H165L150 65V85l15 15h20L200 85V65ZM250 20L230 0H220L200 20V30l20 20h10L250 30V20ZM100 65L85 50H65L50 65V85l15 15H85L100 85V65ZM50 20L30 0H20L0 20V30L20 50H30L50 30V20Z"
></glyph
><glyph unicode="0" d="M250 25H225V0H25V25H0V225H25v25H225V225h25V25ZM150 150v50H100V150h50ZM150 50v50H100V50h50Z"
></glyph
><glyph unicode="1" horiz-adv-x="150" d="M100 0H0V200H-25v50H75V225h25V0Z"
></glyph
><glyph unicode="2" d="M250 0H0V125H25v25H150v50H0v50H225V225h25V125H225V100H100V50H250V0Z"
></glyph
><glyph unicode="3" d="M250 25H225V0H0V50H150v50H75v50h75v50H0v50H225V225h25V150H225V100h25V25Z"
></glyph
><glyph unicode="4" d="M250 0H150V100H25v25H0V250H100V150h50V250H250V0Z"
></glyph
><glyph unicode="5" d="M250 25H225V0H0V50H150v50H25v25H0V250H250V200H100V150H225V125h25V25Z"
></glyph
><glyph unicode="6" d="M250 25H225V0H25V25H0V225H25v25H250V200H100V150H225V125h25V25ZM150 50v50H100V50h50Z"
></glyph
><glyph unicode="7" d="M250 0H150V200H0v50H225V225h25V0Z"
></glyph
><glyph unicode="8" d="M250 25H225V0H25V25H0v75H25v50H0v75H25v25H225V225h25V150H225V100h25V25ZM150 150v50H100V150h50ZM150 50v50H100V50h50Z"
></glyph
><glyph unicode="9" d="M250 25H225V0H0V50H150v50H25v25H0V225H25v25H225V225h25V25ZM150 150v50H100V150h50Z"
></glyph
><glyph unicode="A" d="M250 0H150V100H100V0H0V225H25v25H225V225h25V0ZM150 150v50H100V150h50Z"
></glyph
><glyph unicode="B" d="M250 25H225V0H0V250H225V225h25V150H225V100h25V25ZM150 150v50H100V150h50ZM150 50v50H100V50h50Z"
></glyph
><glyph unicode="C" d="M250 0H25V25H0V225H25v25H250V200H100V50H250V0Z"
></glyph
><glyph unicode="D" d="M250 25H225V0H0V250H225V225h25V25ZM150 50V200H100V50h50Z"
></glyph
><glyph unicode="E" d="M250 0H25V25H0V225H25v25H250V200H100V150h75V100H100V50H250V0Z"
></glyph
><glyph unicode="F" d="M250 200H100V150h75V100H100V0H0V225H25v25H250V200Z"
></glyph
><glyph unicode="G" d="M250 0H25V25H0V225H25v25H250V200H100V50h50v50H125v50H250V0Z"
></glyph
><glyph unicode="H" d="M250 0H150V100H100V0H0V250H100V150h50V250H250V0Z"
></glyph
><glyph unicode="I" horiz-adv-x="150" d="M100 0H0V250H100V0Z"
></glyph
><glyph unicode="J" d="M250 25H225V0H0V50H150V250H250V25Z"
></glyph
><glyph unicode="K" d="M250 0H150V100H100V0H0V250H100V150h50V250H250V150H225V100h25V0Z"
></glyph
><glyph unicode="L" d="M250 0H0V250H100V50H250V0Z"
></glyph
><glyph unicode="M" horiz-adv-x="450" d="M400 0H300V200H250V0H150V200H100V0H0V250H375V225h25V0Z"
></glyph
><glyph unicode="N" d="M250 0H150V200H100V0H0V250H225V225h25V0Z"
></glyph
><glyph unicode="O" d="M250 25H225V0H25V25H0V225H25v25H225V225h25V25ZM150 50V200H100V50h50Z"
></glyph
><glyph unicode="P" d="M250 125H225V100H100V0H0V250H225V225h25V125ZM150 150v50H100V150h50Z"
></glyph
><glyph unicode="Q" d="M250 25H225V0H25V25H0V225H25v25H225V225h25V25ZM150 50V200H100V50h50Z"
></glyph
><glyph unicode="R" d="M250 0H150V100H100V0H0V250H225V225h25V150H225V100h25V0ZM150 150v50H100V150h50Z"
></glyph
><glyph unicode="S" d="M250 25H225V0H0V50H150v50H25v25H0V225H25v25H250V200H100V150H225V125h25V25Z"
></glyph
><glyph unicode="T" d="M250 200H175V0H75V200H0v50H250V200Z"
></glyph
><glyph unicode="U" d="M250 25H225V0H25V25H0V250H100V50h50V250H250V25Z"
></glyph
><glyph unicode="V" d="M250 25H225V0H0V250H100V50h50V250H250V25Z"
></glyph
><glyph unicode="W" horiz-adv-x="450" d="M400 25H375V0H0V250H100V50h50V250H250V50h50V250H400V25Z"
></glyph
><glyph unicode="X" d="M250 0H150V100H100V0H0V100H25v50H0V250H100V150h50V250H250V150H225V100h25V0Z"
></glyph
><glyph unicode="Y" d="M250 125H225V100H175V0H75V100H25v25H0V250H100V150h50V250H250V125Z"
></glyph
><glyph unicode="Z" d="M250 0H0V125H25v25H150v50H0v50H250V125H225V100H100V50H250V0Z"
></glyph
><glyph unicode="[" horiz-adv-x="150" d="M150 0H0V250H150V200H100V50h50V0Z"
></glyph
><glyph unicode="]" horiz-adv-x="150" d="M150 0H0V50H50V200H0v50H150V0Z"
></glyph
><glyph unicode="a" d="M250 0H150V100H100V0H0V225H25v25H225V225h25V0ZM150 150v50H100V150h50Z"
></glyph
><glyph unicode="b" d="M250 25H225V0H0V250H225V225h25V150H225V100h25V25ZM150 150v50H100V150h50ZM150 50v50H100V50h50Z"
></glyph
><glyph unicode="c" d="M250 0H25V25H0V225H25v25H250V200H100V50H250V0Z"
></glyph
><glyph unicode="d" d="M250 25H225V0H0V250H225V225h25V25ZM150 50V200H100V50h50Z"
></glyph
><glyph unicode="e" d="M250 0H25V25H0V225H25v25H250V200H100V150h75V100H100V50H250V0Z"
></glyph
><glyph unicode="f" d="M250 200H100V150h75V100H100V0H0V225H25v25H250V200Z"
></glyph
><glyph unicode="g" d="M250 0H25V25H0V225H25v25H250V200H100V50h50v50H125v50H250V0Z"
></glyph
><glyph unicode="h" d="M250 0H150V100H100V0H0V250H100V150h50V250H250V0Z"
></glyph
><glyph unicode="i" horiz-adv-x="150" d="M100 0H0V250H100V0Z"
></glyph
><glyph unicode="j" d="M250 25H225V0H0V50H150V250H250V25Z"
></glyph
><glyph unicode="k" d="M250 0H150V100H100V0H0V250H100V150h50V250H250V150H225V100h25V0Z"
></glyph
><glyph unicode="l" d="M250 0H0V250H100V50H250V0Z"
></glyph
><glyph unicode="m" horiz-adv-x="450" d="M400 0H300V200H250V0H150V200H100V0H0V250H375V225h25V0Z"
></glyph
><glyph unicode="n" d="M250 0H150V200H100V0H0V250H225V225h25V0Z"
></glyph
><glyph unicode="o" d="M250 25H225V0H25V25H0V225H25v25H225V225h25V25ZM150 50V200H100V50h50Z"
></glyph
><glyph unicode="p" d="M250 125H225V100H100V0H0V250H225V225h25V125ZM150 150v50H100V150h50Z"
></glyph
><glyph unicode="q" d="M250 25H225V0H25V25H0V225H25v25H225V225h25V25ZM150 50V200H100V50h50Z"
></glyph
><glyph unicode="r" d="M250 0H150V100H100V0H0V250H225V225h25V150H225V100h25V0ZM150 150v50H100V150h50Z"
></glyph
><glyph unicode="s" d="M250 25H225V0H0V50H150v50H25v25H0V225H25v25H250V200H100V150H225V125h25V25Z"
></glyph
><glyph unicode="t" d="M250 200H175V0H75V200H0v50H250V200Z"
></glyph
><glyph unicode="u" d="M250 25H225V0H25V25H0V250H100V50h50V250H250V25Z"
></glyph
><glyph unicode="v" d="M250 25H225V0H0V250H100V50h50V250H250V25Z"
></glyph
><glyph unicode="w" horiz-adv-x="450" d="M400 25H375V0H0V250H100V50h50V250H250V50h50V250H400V25Z"
></glyph
><glyph unicode="x" d="M250 0H150V100H100V0H0V100H25v50H0V250H100V150h50V250H250V150H225V100h25V0Z"
></glyph
><glyph unicode="y" d="M250 125H225V100H175V0H75V100H25v25H0V250H100V150h50V250H250V125Z"
></glyph
><glyph unicode="z" d="M250 0H0V125H25v25H150v50H0v50H250V125H225V100H100V50H250V0Z"
></glyph
></font
></defs
><g style="font-family: &quot;8BIT WONDER&quot;; font-size:50;fill:black"
><text x="20" y="50"
>!&quot;#$%&amp;&#39;()*+,-./0123456789:;&#229;&lt;&gt;?</text
><text x="20" y="100"
>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_</text
><text x="20" y="150"
>` abcdefghijklmnopqrstuvwxyz|{}~</text
></g
></svg
>

Before

Width:  |  Height:  |  Size: 7.4 KiB