Added basic battle structure
This commit is contained in:
parent
c0233ebd93
commit
b4b37a46d2
|
@ -21,7 +21,7 @@
|
|||
|
||||
<script>
|
||||
window.onload = function() {
|
||||
new SpaceTac.Game();
|
||||
new SpaceTac.GameRouter();
|
||||
};
|
||||
</script>
|
||||
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
/// <reference path="definitions/phaser.d.ts"/>
|
||||
|
||||
module SpaceTac {
|
||||
export class Game extends Phaser.Game {
|
||||
constructor() {
|
||||
super(800, 600, Phaser.CANVAS, '-space-tac');
|
||||
|
||||
this.state.add('boot', State.Boot);
|
||||
this.state.add('preload', State.Preload);
|
||||
this.state.add('main', State.Main);
|
||||
|
||||
this.state.start('boot');
|
||||
}
|
||||
}
|
||||
}
|
17
src/scripts/GameRouter.ts
Normal file
17
src/scripts/GameRouter.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
/// <reference path="definitions/phaser.d.ts"/>
|
||||
|
||||
module SpaceTac {
|
||||
// Router between game views
|
||||
export class GameRouter extends Phaser.Game {
|
||||
constructor() {
|
||||
super(800, 600, Phaser.CANVAS, '-space-tac');
|
||||
|
||||
this.state.add('boot', View.Boot);
|
||||
this.state.add('preload', View.Preload);
|
||||
this.state.add('main', View.Main);
|
||||
this.state.add('battle', View.BattleView);
|
||||
|
||||
this.state.start('boot');
|
||||
}
|
||||
}
|
||||
}
|
25
src/scripts/game/Battle.ts
Normal file
25
src/scripts/game/Battle.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
module SpaceTac.Game {
|
||||
// A turn-based battle between fleets
|
||||
export class Battle {
|
||||
// List of fleets engaged in battle
|
||||
fleets: Fleet[];
|
||||
|
||||
// List of ships, sorted by their initiative throw
|
||||
play_order: Ship[];
|
||||
|
||||
// Create a battle between two fleets
|
||||
constructor(fleet1: Fleet, fleet2: Fleet) {
|
||||
this.fleets = [fleet1, fleet2];
|
||||
// TODO Initiative throws to set the play order
|
||||
}
|
||||
|
||||
// Create a quick random battle, for testing purposes
|
||||
static newQuickRandom(): Battle {
|
||||
var player1 = Player.newQuickRandom();
|
||||
var player2 = Player.newQuickRandom();
|
||||
|
||||
var result = new Battle(player1.fleet, player2.fleet);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
15
src/scripts/game/Fleet.ts
Normal file
15
src/scripts/game/Fleet.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
module SpaceTac.Game {
|
||||
// A fleet of ships
|
||||
export class Fleet {
|
||||
// Fleet owner
|
||||
player: Player;
|
||||
|
||||
// List of ships
|
||||
ships: Ship[];
|
||||
|
||||
// Create a fleet, bound to a player
|
||||
constructor(player: Player) {
|
||||
this.player = player;
|
||||
}
|
||||
}
|
||||
}
|
18
src/scripts/game/Player.ts
Normal file
18
src/scripts/game/Player.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
module SpaceTac.Game {
|
||||
// One player (human or IA)
|
||||
export class Player {
|
||||
// Current fleet
|
||||
fleet: Fleet;
|
||||
|
||||
// Create a player, with an empty fleet
|
||||
constructor() {
|
||||
this.fleet = new Fleet(this);
|
||||
}
|
||||
|
||||
// Create a quick random player, with a fleet, for testing purposes
|
||||
static newQuickRandom(): Player {
|
||||
var player = new Player();
|
||||
return player;
|
||||
}
|
||||
}
|
||||
}
|
19
src/scripts/game/Ship.ts
Normal file
19
src/scripts/game/Ship.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
module SpaceTac.Game {
|
||||
// A single ship in a Fleet
|
||||
export class Ship {
|
||||
// Fleet this ship is a member of
|
||||
fleet: Fleet;
|
||||
|
||||
// Current level
|
||||
level: number;
|
||||
|
||||
// Number of shield points
|
||||
shield: number;
|
||||
|
||||
// Number of hull points
|
||||
hull: number;
|
||||
|
||||
// Current initiative (high numbers will allow this ship to play sooner)
|
||||
initiative: number;
|
||||
}
|
||||
}
|
7
src/scripts/game/Universe.ts
Normal file
7
src/scripts/game/Universe.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
module SpaceTac.Game {
|
||||
// Main game universe
|
||||
export class Universe {
|
||||
// Current connected player
|
||||
player: Player;
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
module SpaceTac.State {
|
||||
export class Boot extends Phaser.State {
|
||||
preload() {
|
||||
this.load.image('preload-bar', 'assets/images/preloader.gif');
|
||||
}
|
||||
|
||||
create() {
|
||||
this.game.stage.backgroundColor = 0xFFFFFF;
|
||||
|
||||
this.input.maxPointers = 1;
|
||||
this.stage.disableVisibilityChange = true;
|
||||
|
||||
this.game.state.start('preload');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
module SpaceTac.State {
|
||||
export class Main extends Phaser.State {
|
||||
|
||||
create() {
|
||||
this.add.text(10, 10, "Let's code !", { font: "65px Arial" });
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
module SpaceTac.State {
|
||||
export class Preload extends Phaser.State {
|
||||
private preloadBar:Phaser.Sprite;
|
||||
|
||||
preload() {
|
||||
this.preloadBar = this.add.sprite(290, 290, 'preload-bar');
|
||||
}
|
||||
|
||||
create() {
|
||||
this.game.state.start('main');
|
||||
}
|
||||
}
|
||||
}
|
23
src/scripts/view/BattleView.ts
Normal file
23
src/scripts/view/BattleView.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
module SpaceTac.View {
|
||||
// Interactive view of a Battle
|
||||
export class BattleView extends Phaser.State {
|
||||
|
||||
// Displayed battle
|
||||
battle: Game.Battle;
|
||||
|
||||
// Init the view, binding it to a specific battle
|
||||
init(battle) {
|
||||
this.battle = battle;
|
||||
}
|
||||
|
||||
// Create view graphics
|
||||
create() {
|
||||
this.game.stage.backgroundColor = 0x000000;
|
||||
}
|
||||
|
||||
// Leaving the view, we unbind the battle
|
||||
shutdown() {
|
||||
this.battle = null;
|
||||
}
|
||||
}
|
||||
}
|
16
src/scripts/view/Boot.ts
Normal file
16
src/scripts/view/Boot.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
module SpaceTac.View {
|
||||
export class Boot extends Phaser.State {
|
||||
preload() {
|
||||
this.load.image('preload-bar', 'assets/images/preloader.gif');
|
||||
}
|
||||
|
||||
create() {
|
||||
this.game.stage.backgroundColor = 0xFFFFFF;
|
||||
|
||||
this.input.maxPointers = 1;
|
||||
this.stage.disableVisibilityChange = true;
|
||||
|
||||
this.game.state.start('preload');
|
||||
}
|
||||
}
|
||||
}
|
11
src/scripts/view/Main.ts
Normal file
11
src/scripts/view/Main.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
module SpaceTac.View {
|
||||
export class Main extends Phaser.State {
|
||||
|
||||
create() {
|
||||
this.add.text(10, 10, "Let's code !", {font: "65px Arial"});
|
||||
|
||||
// Switch to a test battle
|
||||
this.game.state.start("battle", true, false, Game.Battle.newQuickRandom());
|
||||
}
|
||||
}
|
||||
}
|
13
src/scripts/view/Preload.ts
Normal file
13
src/scripts/view/Preload.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
module SpaceTac.View {
|
||||
export class Preload extends Phaser.State {
|
||||
private preloadBar: Phaser.Sprite;
|
||||
|
||||
preload() {
|
||||
this.preloadBar = this.add.sprite(290, 290, 'preload-bar');
|
||||
}
|
||||
|
||||
create() {
|
||||
this.game.state.start('main');
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue