mirror of
https://github.com/chaoticbackup/chaoticbackup.github.io.git
synced 2026-04-23 09:07:14 -05:00
introduced phase and turn classes
This commit is contained in:
parent
d12f7421a0
commit
046f313eb1
|
|
@ -4,12 +4,12 @@ import {observable} from "mobx";
|
|||
import {observer, inject} from 'mobx-react';
|
||||
import API from '../SpreadsheetData';
|
||||
import Movement from './rules/movement';
|
||||
import {Phase} from './rules/turn';
|
||||
import '../../scss/play/battleboard.scss';
|
||||
|
||||
@observer
|
||||
export default class Board extends Base {
|
||||
@observable spaces = [];
|
||||
@observable phase = "none";
|
||||
@observable activeplayer = true;
|
||||
|
||||
constructor(props) {
|
||||
|
|
@ -56,7 +56,6 @@ export default class Board extends Base {
|
|||
return card;
|
||||
}
|
||||
|
||||
// TODO if the board state is changed externally
|
||||
// {'event': 'action'}
|
||||
makeChange = (change) => {
|
||||
// seriously calling without a change?
|
||||
|
|
@ -91,13 +90,6 @@ export default class Board extends Base {
|
|||
break;
|
||||
}
|
||||
|
||||
// change the game's phase
|
||||
case "phase": {
|
||||
// action: "string"
|
||||
this.phase = action;
|
||||
break;
|
||||
}
|
||||
|
||||
// add a card to a space
|
||||
case "add": {
|
||||
// action: {space, type, card}
|
||||
|
|
@ -140,7 +132,6 @@ export default class Board extends Base {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
resetCardSelection() {
|
||||
this.spaces.forEach((space) => {
|
||||
space.battlegear.forEach((card) => {
|
||||
|
|
@ -175,7 +166,7 @@ export default class Board extends Base {
|
|||
return this.resetCardSelection();
|
||||
}
|
||||
|
||||
if (this.phase == "movement" && type == "creatures") {
|
||||
if (Phase.phase == "movement" && type == "creatures") {
|
||||
// TODO combat
|
||||
// TODO if self selection, check activated ability
|
||||
if (this.movement.source == id) {
|
||||
|
|
@ -192,6 +183,9 @@ export default class Board extends Base {
|
|||
// don't select a blank space
|
||||
if (this.spaces[id].creatures[0].data == null) return;
|
||||
|
||||
// can't select opposing creatures
|
||||
if (this.spaces[id].creatures[0].controlled == false) return;
|
||||
|
||||
// select a card
|
||||
let src_card = this.spaces[id].creatures[0];
|
||||
this.movement.source = id;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import API from '../SpreadsheetData';
|
|||
import {Loading} from '../Snippets';
|
||||
import Board from './Board';
|
||||
import Gui from './Gui';
|
||||
import {Turn} from './rules/turn';
|
||||
|
||||
import '../../scss/play/play.scss';
|
||||
import '../../scss/play/gui.scss';
|
||||
|
|
@ -15,12 +16,14 @@ export default class Play extends React.Component {
|
|||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
const turn = new Turn(this.receiveTurnChange.bind(this));
|
||||
this.makeTurnChange = turn.makeChange;
|
||||
}
|
||||
|
||||
componentDidUpdate() {
|
||||
// todo remove / currently simulating
|
||||
this.makeBoardChange({event:"active", action: true});
|
||||
this.makeBoardChange({event: "phase", action: "movement"});
|
||||
this.makeTurnChange({event: "phase", action: "movement"});
|
||||
}
|
||||
|
||||
sendNetworkChange(change, destination) {
|
||||
|
|
@ -43,6 +46,9 @@ export default class Play extends React.Component {
|
|||
case "gui":
|
||||
this.makeGuiChange(change);
|
||||
break;
|
||||
case "turn":
|
||||
this.makeTurnChange(change);
|
||||
break;
|
||||
default:
|
||||
throw "invalid destination";
|
||||
}
|
||||
|
|
@ -60,6 +66,10 @@ export default class Play extends React.Component {
|
|||
this.sendNetworkChange(change, destination || "board");
|
||||
}
|
||||
|
||||
receiveTurnChange(change, destination) {
|
||||
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.loaded == false) {
|
||||
API.LoadDB([{'cards': 'attacks'}, {'cards': 'battlegear'}, {'cards': 'creatures'}, {'cards': 'locations'}, {'cards': 'mugic'}])
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import Rule from './rule';
|
||||
import Rule from './_rule';
|
||||
import {observable} from "mobx";
|
||||
|
||||
// array of array of accesible spaces per swift
|
||||
|
|
|
|||
48
src/components/play/rules/turn.js
Normal file
48
src/components/play/rules/turn.js
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import Rule from './_rule';
|
||||
|
||||
export class Turn extends Rule {
|
||||
activeplayer = 0;
|
||||
|
||||
constructor(receiveTurnChange, player1, player2) {
|
||||
super();
|
||||
this.submitChange = receiveTurnChange;
|
||||
}
|
||||
|
||||
// {'event': 'action'}
|
||||
makeChange = (change) => {
|
||||
if (!change) return;
|
||||
console.log('turn ->', change);
|
||||
// TODO
|
||||
let action = change.action;
|
||||
switch (change.event) {
|
||||
|
||||
// change the game's phase
|
||||
case "phase": {
|
||||
// action: "string"
|
||||
Phase.phase = action;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Phase_Singleton extends Rule {
|
||||
phase = "none";
|
||||
|
||||
// Singleton
|
||||
static getInstance() {
|
||||
if (!this.instance) { this.instance = new Phase_Singleton(); }
|
||||
return this.instance;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.phase = "game start";
|
||||
}
|
||||
|
||||
}
|
||||
const Phase = Phase_Singleton.getInstance();
|
||||
export {Phase};
|
||||
Loading…
Reference in New Issue
Block a user