From f6b1f5d919f2737d919e53fc2b2d36737f635914 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 15 Dec 2018 14:01:16 -0500 Subject: [PATCH] [fix] one move per turn --- src/components/play/Board.js | 150 +++++++++++++++++++---------------- src/components/play/index.js | 2 +- 2 files changed, 84 insertions(+), 68 deletions(-) diff --git a/src/components/play/Board.js b/src/components/play/Board.js index 320aed0..5344294 100644 --- a/src/components/play/Board.js +++ b/src/components/play/Board.js @@ -40,6 +40,33 @@ export default class Board extends React.Component { this.loadcards(); } + // TODO + loadcards() { + this.spaces[4].creatures[0].data = API.cards.creatures.findOne({'gsx$name': {'$regex': new RegExp("Maxxor", 'i')}}); + this.spaces[4].battlegear[0].data = API.cards.battlegear.findOne({'gsx$name': {'$regex': new RegExp("Maxxor's Torch", 'i')}}); + this.spaces[1].creatures[0].data = API.cards.creatures.findOne({'gsx$name': {'$regex': new RegExp("Staluk", 'i')}}); + this.spaces[1].battlegear[0].data = API.cards.battlegear.findOne({'gsx$name': {'$regex': new RegExp("Vlaric Shard", 'i')}}); + for (let i = 0; i < 6; i++) { + this.spaces[i].creatures[0].controlled = true; + this.spaces[i].battlegear[0].controlled = true; + } + this.spaces[7].creatures[0].data = API.cards.creatures.findOne({'gsx$name': {'$regex': new RegExp("Chaor", 'i')}}); + this.spaces[7].battlegear[0].data = API.cards.battlegear.findOne({'gsx$name': {'$regex': new RegExp("Whepcrack", 'i')}}); + } + + empty_card(type) { + let card = { + 'data': null, + 'selected': false, + 'selectable': true, + 'controlled': false + } + if (type == "creatures") { + card.moveable = true; + } + return card; + } + // This is a wraper function for preforming changes to game state // It preforms the change locally and propegates it higher // So that a network listener can reflect the change on the other client @@ -54,14 +81,13 @@ export default class Board extends React.Component { makeChange = (change) => { // seriously calling without a change? if (!change) return; - console.log(change.event, change.action); + console.log(change); // TODO remove let action = change.action; // change the game's phase if (change.event == "phase") { // action: "string" this.phase = action; - console.log(this.phase); } // add a card to a space @@ -88,32 +114,6 @@ export default class Board extends React.Component { } } - empty_card(type) { - let card = { - 'data': null, - 'selected': false, - 'selectable': true, - 'controlled': false - } - if (type == "creatures") { - card.moveable = true; - } - return card; - } - - // TODO - loadcards() { - this.spaces[5].creatures[0].data = API.cards.creatures.findOne({'gsx$name': {'$regex': new RegExp("Maxxor", 'i')}}); - this.spaces[5].battlegear[0].data = API.cards.battlegear.findOne({'gsx$name': {'$regex': new RegExp("Maxxor's Torch", 'i')}}); - this.spaces[2].creatures[0].data = API.cards.creatures.findOne({'gsx$name': {'$regex': new RegExp("Staluk", 'i')}}); - this.spaces[2].battlegear[0].data = API.cards.battlegear.findOne({'gsx$name': {'$regex': new RegExp("Vlaric Shard", 'i')}}); - for (let i = 0; i < 6; i++) { - this.spaces[i].creatures[0].controlled = true; - this.spaces[i].battlegear[0].controlled = true; - } - this.spaces[8].creatures[0].data = API.cards.creatures.findOne({'gsx$name': {'$regex': new RegExp("Chaor", 'i')}}); - this.spaces[8].battlegear[0].data = API.cards.battlegear.findOne({'gsx$name': {'$regex': new RegExp("Whepcrack", 'i')}}); - } resetCardSelection() { this.spaces.forEach((space) => { @@ -134,36 +134,6 @@ export default class Board extends React.Component { return false; } - moveSelection(source, destination, movement) { - if (source == destination) return false; - - let src_card = this.spaces[source].creatures[0]; - if (!src_card.moveable) return false; // If already moved, no valid movement - - let des_card = this.spaces[destination].creatures[0]; - - let valid = adjacency_6[source]; - // for each level of swift, increase moveable range - // TODO account for range - for (let i = 0; i < movement; i++) { - if (valid.includes(destination)) { - // Check if space occupied - if (des_card.data != null) { - // Can't move into occupied space of own tribe - if (des_card.controlled) return false; - // Check if can start combat - else return this.canAttack(); - } - return true; - } - valid.forEach((i) => { - valid = [].concat(valid, adjacency_6[i]); - }); - } - - return false; // if all else its probably not moveable - } - selectCard(e) { let id = e.target.id.substr(1); let type = (() => { @@ -174,7 +144,7 @@ export default class Board extends React.Component { } })(); - // Reset selection + // When clicking a non-valid target, reset selection if (this.spaces[id][type][0].selectable == false) { return this.resetCardSelection(); } @@ -188,7 +158,8 @@ export default class Board extends React.Component { // moving into a space if (this.source > 0) { this.submitChange({event: "movement", action: {src: this.source, dest: id}}); - this.spaces[id].moveable = false; + // Only one move per turn + this.spaces[id].creatures[0].moveable = false; return this.resetCardSelection(); } @@ -197,7 +168,9 @@ export default class Board extends React.Component { // select a card this.source = id; + let src_card = this.spaces[this.source].creatures[0]; + // Calculate range of spaces based on swift let mv = ((data) => { let swift = (new RegExp(/swift ([0-9]+)/gi).exec(data.gsx$ability)); if (swift) return parseInt(swift[1]) + 1; @@ -210,7 +183,34 @@ export default class Board extends React.Component { card.selectable = false; }); space.creatures.forEach((card) => { - card.selectable = this.moveSelection(id, i, mv); + let des_card = this.spaces[i].creatures[0]; + card.selectable = ((src_id, dest_id, movement) => { + // If already moved, no valid movement + if (!src_card.moveable) return false; + // No self space movement + if (src_id == dest_id) return false; + + // for each level of swift, increase moveable range + // TODO account for range + let valid = adjacency_6[parseInt(src_id) + 1]; // fix offset + for (let i = 0; i < movement; i++) { + if (valid.includes(parseInt(dest_id) + 1)) { // fix offset + // Check if space occupied + if (des_card.data != null) { + // Can't move into occupied space of own tribe + if (des_card.controlled) return false; + // Check if can start combat + else return this.canAttack(); + } + return true; + } + valid.forEach((i) => { + valid = [].concat(valid, adjacency_6[i]); + }); + } + + return false; // if all else its probably not moveable + })(id, i, mv); }); }); @@ -225,21 +225,25 @@ export default class Board extends React.Component {
- - + +
+
+ + +
+
+
-
-
@@ -248,12 +252,12 @@ export default class Board extends React.Component {
+
+
-
-
@@ -262,10 +266,22 @@ export default class Board extends React.Component {
+
+
+
+ + +
+
+
+
+ + +
); diff --git a/src/components/play/index.js b/src/components/play/index.js index fa2451f..a9f7ae0 100644 --- a/src/components/play/index.js +++ b/src/components/play/index.js @@ -19,7 +19,7 @@ export default class Play extends React.Component { } componentDidUpdate() { - this.makeChange(); + // this.makeChange(); } render() {