From 3852f4d0fd053a78e3e24c312ccaf62ff45415e1 Mon Sep 17 00:00:00 2001 From: strinsberg Date: Mon, 25 May 2020 21:46:29 -0600 Subject: [PATCH 01/92] Rewrote all the data classes to have less things we don't really need. Except deck. Rewrote unit tests to test these new classes and to use better testing practice with beforeEach to reduce the duplicated code used. Removed other unit tests for now because changing data classes breaks everything else. they are safely saved and can be reintroduced if they don't need to be rewritten for the other functions and classes to work again. --- src/classes/Models/Card.js | 17 +- src/classes/Models/Deck.js | 61 +-- src/classes/Models/Player.js | 95 +---- src/classes/Models/Stack.js | 107 ++---- tests/unit/AiLogic.spec.js | 215 ----------- tests/unit/Card.spec.js | 136 +------ tests/unit/Deck.spec.js | 583 +++++++---------------------- tests/unit/Gambler.spec.js | 95 ----- tests/unit/Getters.spec.js | 125 ------- tests/unit/HackModal.spec.js | 13 - tests/unit/Hacker.spec.js | 95 ----- tests/unit/MainComponent.spec.js | 26 -- tests/unit/Mutations.spec.js | 349 ----------------- tests/unit/Player.spec.js | 134 +------ tests/unit/PlayerInfoPanel.spec.js | 25 -- tests/unit/Protector.spec.js | 103 ----- tests/unit/Safety.spec.js | 149 -------- tests/unit/Sprinter.spec.js | 103 ----- tests/unit/Stacks.spec.js | 104 ++--- tests/unit/TutorialDeck.spec.js | 321 ---------------- 20 files changed, 300 insertions(+), 2556 deletions(-) delete mode 100644 tests/unit/AiLogic.spec.js delete mode 100644 tests/unit/Gambler.spec.js delete mode 100644 tests/unit/Getters.spec.js delete mode 100644 tests/unit/HackModal.spec.js delete mode 100644 tests/unit/Hacker.spec.js delete mode 100644 tests/unit/MainComponent.spec.js delete mode 100644 tests/unit/Mutations.spec.js delete mode 100644 tests/unit/PlayerInfoPanel.spec.js delete mode 100644 tests/unit/Protector.spec.js delete mode 100644 tests/unit/Safety.spec.js delete mode 100644 tests/unit/Sprinter.spec.js delete mode 100644 tests/unit/TutorialDeck.spec.js diff --git a/src/classes/Models/Card.js b/src/classes/Models/Card.js index 55efe560..50c5b9e8 100755 --- a/src/classes/Models/Card.js +++ b/src/classes/Models/Card.js @@ -1,5 +1,6 @@ /** * @file Card.js file + * @author Steve modified on 2020-05-25 */ /** @@ -12,20 +13,12 @@ export default class Card { * @param {int} id The ID of the card * @param {int} value The value of the card * @param {char} type The type of the card - * @param {char} cardImg is a string pointing to the image of the card + * @param {char} image is a string pointing to the image of the card */ - constructor (id, value, type, cardImg) { + constructor (id, value, type, image) { + this.id = id this.value = value this.type = type - this.selected = false - this.id = id - this.cardImg = cardImg - this.showFace = false - this.isUsed = false - } - - flipCardFace () { - this.showFace = !this.showFace + this.image = image } } - diff --git a/src/classes/Models/Deck.js b/src/classes/Models/Deck.js index 51eae220..9f71a383 100755 --- a/src/classes/Models/Deck.js +++ b/src/classes/Models/Deck.js @@ -1,6 +1,6 @@ /** * @file Deck.js file - * @author Lance on 2017-03-10. + * @author Lance on 2017-03-10, Steven modified 2020-05-25 */ import Card from './Card' @@ -74,67 +74,72 @@ const cardDeck = [ ] /** - * This is the object representation of the games deck. - * We use one deck that grows depending on the number of players instead of multiple decks. + * A deck for a program wars game. + * Only a single deck is used. Its size is determined by the number of players + * it is initialized with. */ export default class Deck { /** - * The constructor for the Deck class - * @constructor Deck + * Constructor for the Deck class. + * @param {int} numPlayers The number of players using the deck. */ - constructor () { - // this.initDeck(); + constructor (numPlayers) { this.cards = [] - this.discard_cards = [] + this.discard = [] + this.initDeck(numPlayers) } /** - * initDeck function to initialize the deck with a pre determined number and type of cards - * @memberOf Deck + * Initializes the deck with a pre determined number and type of cards. + * @param {int} numPlayers The number of players using the deck. */ - initDeck (value) { + initDeck (numPlayers) { let cardId = 0 - for (let k = 0; k < value; k++) { + for (let k = 0; k < numPlayers; k++) { for (let i = 0; i < cardDeck.length; i++) { for (let j = 0; j < cardDeck[i].howMany; j++) { if (cardDeck[i].type === 'FIREWALL' && (k === 1 || k === 3)) { - this.cards.push(new Card(cardId, cardDeck[i].cardValue, cardDeck[i].type, cardDeck[i].imgSrc)) + this.cards.push(new Card(cardId, cardDeck[i].cardValue, + cardDeck[i].type, cardDeck[i].imgSrc)) cardId++ } else if (cardDeck[i].type === 'GENERATOR' && (k === 1 || k === 3)) { - this.cards.push(new Card(cardId, cardDeck[i].cardValue, cardDeck[i].type, cardDeck[i].imgSrc)) + this.cards.push(new Card(cardId, cardDeck[i].cardValue, + cardDeck[i].type, cardDeck[i].imgSrc)) cardId++ } else if (cardDeck[i].type === 'ANTIVIRUS' && (k === 1 || k === 3)) { - this.cards.push(new Card(cardId, cardDeck[i].cardValue, cardDeck[i].type, cardDeck[i].imgSrc)) + this.cards.push(new Card(cardId, cardDeck[i].cardValue, + cardDeck[i].type, cardDeck[i].imgSrc)) cardId++ - } else if (cardDeck[i].type !== 'ANTIVIRUS' && cardDeck[i].type !== 'FIREWALL' && cardDeck[i].type !== 'GENERATOR') { - this.cards.push(new Card(cardId, cardDeck[i].cardValue, cardDeck[i].type, cardDeck[i].imgSrc)) + } else if (cardDeck[i].type !== 'ANTIVIRUS' + && cardDeck[i].type !== 'FIREWALL' + && cardDeck[i].type !== 'GENERATOR') { + this.cards.push(new Card(cardId, cardDeck[i].cardValue, + cardDeck[i].type, cardDeck[i].imgSrc)) cardId++ } } } } this.shuffle(this.cards) - }// end Init game + } /** - * draw function returns the card at the front (top) of the deck and removes it from the deck - * @memberOf Deck - * @returns {Card} + * Removes and returns the top card of the deck. + * @returns {Card} the top card. */ draw () { - let card = this.cards[0]// [0] is the top of the deck - this.cards.shift()// unshift removes the first element. + let card = this.cards[0] // [0] is the top of the deck + this.cards.shift() return card } /** - * shuffle function that will psuedo shuffle the contents of the deck into a random order - * @memberOf Deck + * Shuffle the contents of the a deck into a psuedo random order. */ - shuffle (event) { - for (let i = event.length; i; i--) { + shuffle (cards) { + for (let i = cards.length; i; i--) { let j = Math.floor(Math.random() * i); - [event[i - 1], event[j]] = [event[j], event[i - 1]] + [cards[i - 1], cards[j]] = [cards[j], cards[i - 1]] } } } diff --git a/src/classes/Models/Player.js b/src/classes/Models/Player.js index 4a7c57e5..a79065a8 100755 --- a/src/classes/Models/Player.js +++ b/src/classes/Models/Player.js @@ -1,8 +1,7 @@ /** * @file player.js file - * @author Lance on 2017-03-10. + * @author Lance on 2017-03-10, Steven modified on 2020-05-25 */ -import Personality from '../AiActions/Personality' export default class Player { /** @@ -10,94 +9,28 @@ export default class Player { * @constructor Player * @param {int} id The ID of the Player * @param {string} name The name of the Player - * @param {int} hand The hand ID of the player - * @param {int} instructions The current number of instructions of the player */ - constructor (id, name, hand, instructions, isAi) { - this.name = name - this.hand = hand - this.usedBonusCards = [] - this.attackedCards = [] - this.instructions = instructions + constructor (id, name) { this.id = id - this.hasGenerator = false - this.hasAntiVirus = false - this.hasFirewall = false - this.hasPowerOutage = false - this.hasBatteryBackup = false - this.isAi = isAi - this.hasOverclock = false - this.hasVirus = false - this.hasHadOverclock = false - this.hasPlayedInstruction = false - this.instructionBonus = 0 - this.numInstructions = 0 - this.completionBonus = 0 - this.virusBonus = 0 - this.overClockBonus = 0 - this.defensiveBonus = 0 - this.protectionCardsBonus = 0 - this.groupingBonus = 0 - this.numGroups = 0 - this.repetitionBonus = 0 - this.numRepeats = 0 - this.variablesBonus = 0 - this.numVariables - this.overclockIncrease = 0 - this.cards = [] - this.bonus = 0 - this.isDefensive = false - this.isCleanSystem = true - this.totalInstructions = 0 - this.totalScore = 0 - this.redrawing = false - if (this.isAi) { - this.type = new Personality() - } - } - - updateBonus (score) { - this.bonus += score - } - - /** - * Checks to see if the player is under the effect of a given safety - * or remedy card. - * @param {string} cardType the type of card to check for. - * @return true if the player is protected by the card type, otherwise false - */ - protectedBy (cardType) { - if (cardType === "BATTERYBACKUP" && this.hasGenerator) { - return true - } - return this.usedBonusCards.find(c => c.type === cardType) !== undefined + this.name = name + this.positiveEffects = [] + this.negativeEffects = [] + this.cardsPlayed = [] } /** - * Check to see if a player is under the effects of a given attack type. - * @param {string} cardType the type of card to check for. - * @return true if the player is already affected by the cardType, - * otherwise false. + * Checks to see if the player has a positive effect. + * @param {string} effect The effect to check for. */ - underAttackBy (cardType) { - return this.attackedCards.find(c => c.type === cardType) !== undefined + hasPositive (effect) { + return this.positiveEffects.find(e => e === effect) !== undefined } /** - * Check to see if a player is protected from a given attack type. - * @param {string} attackType the type of attack. - * @return true if the player is protected, otherwise false. + * Check to see if a player has a negative effect. + * @param {string} effect The effect to check for. */ - protectedFrom (attackType) { - // Some are not checked because they protect on a one time basis so it - // needs to be possible to play the attack to remove the protection - // Ie) BatteryBackup and PowerOutage - if (attackType === "VIRUS") { - return this.protectedBy("ANTIVIRUS") - } else if (attackType === "POWEROUTAGE") { - return this.protectedBy("GENERATOR") - } else if (attackType === "H") { // HACK - return this.protectedBy("FIREWALL") - } + hasNegative (effect) { + return this.negativeEffects.find(e => e === effect) !== undefined } } diff --git a/src/classes/Models/Stack.js b/src/classes/Models/Stack.js index 75319844..5f3a7ed6 100755 --- a/src/classes/Models/Stack.js +++ b/src/classes/Models/Stack.js @@ -1,110 +1,85 @@ /** * @file the card class file - * @author Josh on 2017-03-13. + * @author Josh on 2017-03-13, Steven modified on 2020-05-25 */ const uuidV1 = require('uuid/v1') +// The maximum number of repeats allowed in a stack +const MAX_REPEATS = 2 + + /** - * This is the object representation of a stack of cards. + * An object to represent a stack of instruction cards. */ export default class Stack { - // constructor for the stack object /** - * @constructor Stack + * Constructor for Stack * @param {int} playerId The ID of the player - * @param {boolean} boolSide The side the stack is on */ - constructor (playerId, boolSide) { + constructor (playerId) { this.stackId = uuidV1() this.playerId = playerId - this.boolSide = boolSide this.cards = [] - this.score = 0 } - // function that takes a card as an argument and adds it to the cards array of the stack object + /** - * addCardToStack function to add a card to the stack - * @memberOf Stack - * @param {card} card the card to be added to the stack + * Check if the stack is empty. + * @return {bool} true if the stack has no cards. */ - addCardToStack (card) { - this.cards.push(card) + isEmpty () { + return this.cards.length === 0 } - // function that is meant to calculate the score of an individual stack /** - * calculateStackScore function to calculate the score of the stack - * @memberOf Stack + * Calculates the stack's score. + * @return {int} the stack's total score. */ - calculateStackScore () { - // declare a temporary score - let tempScore = 0 - - // loop through all of the cards in this' card list - // the let "thing" of "this.thing" creates a shallow copy of each object and allows us to - // iterate over the objects and get the attributes of them - for (let card of this.cards) { - // we add the value of the card to the stack if I or G type - if (card.type === 'I' || card.type === 'G') { - tempScore += card.value - // else we multiply - } else { - tempScore *= card.value - } + getScore () { + if (this.isEmpty()) { + return 0 } - // set the value of the stack - this.score = tempScore - // here is a comment, a longer comment, and more + let score = this.getBase().value + for (let i = 1; i < this.cards.length; i++) { + score *= this.cards[i].value + } + return score } - // this function returns a reference to the first (bottom) card of the stack cards array /** - * stackTopCard function to return a reference to the first (bottom) card of the stack cards array - * @memberOf Stack - * @returns {card} + * Returns the base card of the stack, which is an instruction or group card. + * @returns {card} the base of the stack. */ - stackTopCard () { - return this.cards[this.cards.length - 1] + getBase () { + return this.cards[0] } - // this function returns the top card of a stack and then removes it from the stack /** - * popTopCard function to return the top card of a stack and then removes it from the stack - * @memberOf Stack - * @returns {*} + * Returns the top card of the stack. + * @returns {card} the top card of the stack. */ - popTopCard () { - return this.cards.pop() + getTop () { + return this.cards[this.cards.length - 1] } - // this function returns a reference to the last card of the stack cards array /** - * stackBottomCard function returns a reference to the last card of the stack cards array - * @memberOf Stack - * @returns {*} + * Checks if the stack has the maximum allowed number of repeats. + * @return {bool} true if the max repeats has been reached, false otherwise. */ - stackBottomCard () { - return this.cards[0] + hasMaxRepeats () { + let numRepeats = this.cards.reduce((acc, card) => { + return card.type === 'REPEAT' ? acc + 1 : acc + }, 0) + return numRepeats >= MAX_REPEATS } /** - * Checks if the max number of repeats in a certain stack has been reached + * Checks to see if the stack is hackable or not. + * @return {bool} true if the stack can be hacked, false otherwise. */ - maxRepeats () { - let rCount = 0 - for (let i = 0; i < this.cards.length; i++) { - if (this.cards[i].type === 'R') { - rCount++ - } - } - return rCount >= 2 - } - isHackable () { - return this.stackBottom().type !== 'G' + return !this.isEmpty() && this.getBase().type !== 'GROUP' } - } diff --git a/tests/unit/AiLogic.spec.js b/tests/unit/AiLogic.spec.js deleted file mode 100644 index 4df9b0e5..00000000 --- a/tests/unit/AiLogic.spec.js +++ /dev/null @@ -1,215 +0,0 @@ -/* eslint-disable no-trailing-spaces */ -var sinon = require('sinon') -import {store} from '@/store/store' -import Card from '@/classes/Models/Card' -import Player from '@/classes/Models/Player' -import Stack from '@/classes/Models/Stack' -import Handler from '@/classes/AiActions/AiHandler' -import AiMove from '@/classes/AiActions/AiMove' -import AntiVirus from '@/classes/AiActions/AntiVirusStep' -import Firewall from '@/classes/AiActions/FirewallStep' -import Generator from '@/classes/AiActions/GeneratorStep' -import OverClock from '@/classes/AiActions/OverClockStep' -import BatteryBackup from '@/classes/AiActions/BatteryBackupStep' -import Repeat from '@/classes/AiActions/RepeatStep' -import RepeatX from '@/classes/AiActions/RepeatXStep' -import Group from '@/classes/AiActions/GroupStep' -import Instruction from '@/classes/AiActions/InstStep' -import Hack from '@/classes/AiActions/HackStep' -import Variable from '@/classes/AiActions/VarStep' -import Virus from '@/classes/AiActions/VirusStep' -import PowerOutage from '@/classes/AiActions/PowerOutageStep' -import Discard from '@/classes/AiActions/DiscardStep' - -let move = new AiMove() -let boolSide = true - -// INFO: Tests depend on this order -let defaultHand = {cards: [new Card(0, 0, 'V')]} -let hand = move.organizeHand({hand: defaultHand}) -let canGroup = { - cardToPlay: new Card('14', 3, 'G'), - stackToPlay: new Stack(1, true) -} -let player = new Player(0, 'aiTest', hand, 0, true) -let player2 = new Player(1, 'aiTest2', hand, 0, true) -player2.score = 1 -player2.cards = defaultHand.cards -let event = {cards: hand, hand: defaultHand, stack: [new Stack(0, true), new Stack(0, true), new Stack(1, true), new Stack(1, true)], opponents: [player2]} -event.stack[0].cards = [new Card(9, 3, 'I'), new Card(8, 1, 'R')] -event.stack[0].score = 3 -event.stack[1].cards = [new Card(9, 3, 'I')] -event.stack[1].score = 3 -event.stack[2].cards = [new Card(9, 3, 'I')] -event.stack[2].score = 3 -event.stack[3].cards = [new Card(9, 3, 'I')] -event.stack[3].score = 3 -let oPO = player2 -let oV = player2 - -let actionObject = { - avAction: new AntiVirus(hand, boolSide, move, event), - fwAction: new Firewall(hand, boolSide, move, event), - genAction: new Generator(hand, boolSide, move, event), - ocAction: new OverClock(hand, boolSide, move, event), - bbAction: new BatteryBackup(hand, boolSide, move, event), - rAction: new Repeat(hand, boolSide, move, event), - rxAction: new RepeatX(hand, boolSide, move, event), - gAction: new Group(hand, boolSide, move, event, canGroup), - iAction: new Instruction(hand, boolSide, move, event), - hAction: new Hack(hand, boolSide, move, event), - varAction: new Variable(hand, boolSide, move, event), - vAction: new Virus(hand, boolSide, move, event, oV), - poAction: new PowerOutage(hand, boolSide, move, event, oPO), - dAction: new Discard(hand, boolSide, move, event) -} -let avSpy = sinon.spy(actionObject.avAction, 'execute') -let fwSpy = sinon.spy(actionObject.fwAction, 'execute') -let genSpy = sinon.spy(actionObject.genAction, 'execute') -let ocSpy = sinon.spy(actionObject.ocAction, 'execute') -let bbSpy = sinon.spy(actionObject.bbAction, 'execute') -let rSpy = sinon.spy(actionObject.rAction, 'execute') -let rxSpy = sinon.spy(actionObject.rxAction, 'execute') -let gSpy = sinon.spy(actionObject.gAction, 'execute') -let iSpy = sinon.spy(actionObject.iAction, 'execute') -let hSpy = sinon.spy(actionObject.hAction, 'execute') -let varSpy = sinon.spy(actionObject.varAction, 'execute') -let vSpy = sinon.spy(actionObject.vAction, 'execute') -let poSpy = sinon.spy(actionObject.poAction, 'execute') - -let handler = new Handler(oPO, oV, actionObject.avAction, actionObject.fwAction, actionObject.genAction, actionObject.ocAction, actionObject.bbAction, actionObject.gAction, - actionObject.vAction, actionObject.hAction, actionObject.poAction, actionObject.iAction, actionObject.rAction, actionObject.rxAction, actionObject.varAction, actionObject.dAction) - -describe('AILogic', () => { - it('calls execute() correctly', () => { - store.state.activePlayer = 0 - store.state.players = [player, player2] - store.state.coinMsg = true - expect(handler.getOpponentVirus().id).toEqual(oV.id) - expect(handler.getOpponentPO().id).toEqual(oPO.id) - expect(handler.getMove()).toEqual(undefined) - expect(handler.getCard()).toEqual(undefined) - expect(handler.getOpponent()).toEqual(undefined) - expect(handler.getStack()).toEqual(undefined) - }) - - it('Variable logic', () => { - handler.setAi('gambler') - expect(varSpy.calledOnce) - expect(handler.getMove()).toEqual('play') - expect(handler.cardToPlay.type).toEqual('V') - }) - it('RepeatX played', () => { - changeHand([new Card(1, 1, 'R')]) - handler.setAi('gambler') - expect(rxSpy.calledOnce) - expect(handler.getMove()).toEqual('play') - expect(handler.cardToPlay.type).toEqual('R') - expect(handler.cardToPlay.value).toEqual(1) - }) - it('Repeat played third', () => { - changeHand([new Card(1, 2, 'R')]) - handler.setAi('gambler') - expect(rSpy.calledOnce) - expect(handler.getMove()).toEqual('play') - expect(handler.cardToPlay.type).toEqual('R') - expect(handler.cardToPlay.value).toEqual(2) - }) - it('instruction played fourth', () => { - event.stack.push(new Stack(0, true)) - event.stack[event.stack.length - 1].score = 0 - changeHand([new Card(1, 2, 'I')]) - handler.setAi('gambler') - expect(iSpy.calledOnce) - expect(handler.getMove()).toEqual('play') - expect(handler.cardToPlay.type).toEqual('I') - expect(handler.cardToPlay.value).toEqual(2) - }) - it('Hack played fifth', () => { - changeHand([new Card(1, 1, 'H')]) - handler.setAi('gambler') - expect(hSpy.calledOnce) - expect(handler.getMove()).toEqual('hack') - expect(handler.cardToPlay.type).toEqual('H') - expect(handler.cardToPlay.value).toEqual(1) - }) - it('Overclock played sixth', () => { - changeHand([new Card(10, 1, 'OVERCLOCK')]) - handler.setAi('gambler') - expect(ocSpy.calledOnce) - expect(handler.getMove()).toEqual('enhance') - expect(handler.cardToPlay.type).toEqual('OVERCLOCK') - expect(handler.cardToPlay.value).toEqual(1) - }) - it('Power Outage played seventh', () => { - changeHand([new Card(11, 1, 'POWEROUTAGE')]) - handler.setAi('gambler') - expect(poSpy.calledOnce) - expect(handler.getMove()).toEqual('po') - expect(handler.cardToPlay.type).toEqual('POWEROUTAGE') - expect(handler.cardToPlay.value).toEqual(1) - }) - it('virus played eighth', () => { - store.state.firstRound = false - changeHand([new Card(12, 1, 'VIRUS')]) - handler.setAi('gambler') - expect(vSpy.calledOnce) - expect(handler.getMove()).toEqual('virus') - expect(handler.cardToPlay.type).toEqual('VIRUS') - expect(handler.cardToPlay.value).toEqual(1) - }) - it('group played ninth', () => { - changeHand([new Card(14, 3, 'G')]) - handler.setAi('gambler') - expect(gSpy.calledOnce) - expect(handler.getMove()).toEqual('group') - expect(handler.cardToPlay.type).toEqual('G') - expect(handler.cardToPlay.value).toEqual(3) - }) - it('Battery Backup played', () => { - changeHand([new Card(15, 1, 'BATTERYBACKUP')]) - store.state.players[store.state.activePlayer].hasPowerOutage = true - handler.setAi('gambler') - expect(bbSpy.calledOnce) - expect(handler.getMove()).toEqual('enhance') - expect(handler.cardToPlay.type).toEqual('BATTERYBACKUP') - expect(handler.cardToPlay.value).toEqual(1) - }) - it('Firewall played', () => { - changeHand([new Card(16, 1, 'FIREWALL')]) - handler.setAi('gambler') - expect(fwSpy.calledOnce) - expect(handler.getMove()).toEqual('protection') - expect(handler.cardToPlay.type).toEqual('FIREWALL') - expect(handler.cardToPlay.value).toEqual(1) - }) - it('Generator played', () => { - changeHand([new Card(15, 1, 'GENERATOR')]) - handler.setAi('gambler') - expect(genSpy.calledOnce) - expect(handler.getMove()).toEqual('protection') - expect(handler.cardToPlay.type).toEqual('GENERATOR') - expect(handler.cardToPlay.value).toEqual(1) - }) - it('AntiVirus played', () => { - changeHand([new Card(15, 1, 'ANTIVIRUS')]) - handler.setAi('gambler') - expect(avSpy.calledOnce) - expect(handler.getMove()).toEqual('protection') - expect(handler.cardToPlay.type).toEqual('ANTIVIRUS') - expect(handler.cardToPlay.value).toEqual(1) - store.state.coinMsg = false - store.state.firstRound = true - }) - - function changeHand (h) { - defaultHand = {cards: h} - hand = move.organizeHand({hand: defaultHand}) - event.hand = defaultHand - event.cards = hand - for (let action in actionObject) { - actionObject[action].setHand(hand) - actionObject[action].setEvent(event) - } - } -}) diff --git a/tests/unit/Card.spec.js b/tests/unit/Card.spec.js index 6a32a1c3..1a68509b 100644 --- a/tests/unit/Card.spec.js +++ b/tests/unit/Card.spec.js @@ -1,132 +1,12 @@ -//import Vue from 'vue' -import Card from '@/components/SharedComponents/Card' -import CardObj from '@/classes/Models/Card' +import Card from '@/classes/Models/Card' -/* The tests using these functions no longer work. - See the comments above the broken tests for more details. - It is likely that these functions can be moved into the tests - in a better way when mocking and stubbing out vuex related obects - and functions. If they are only used once they can be created in - a spcific test otherwise in a beforeEach block or appropriate testing - function. -function getCssString (Component, propsData) { - const Ctor = Vue.extend(Component) - const vm = new Ctor({propsData}).$mount() - return vm.cardCss -} - -function getTitle (Component, propsData) { - const Ctor = Vue.extend(Component) - const vm = new Ctor({ propsData }).$mount() - return vm.title -} - -function getCardType (Component, propsData) { - const Ctor = Vue.extend(Component) - const vm = new Ctor({ propsData }).$mount() - return vm.cardType -} -function getCardValue (Component, propsData) { - const Ctor = Vue.extend(Component) - const vm = new Ctor({ propsData }).$mount() - return vm.cardValue -} -function getCardGraphics (Component, propsData) { - const Ctor = Vue.extend(Component) - const vm = new Ctor({ propsData }).$mount() - return vm.cardGraphics -} -*/ - -describe('Card.vue', () => { - it('check if name property of component is present', () => { - expect(Card.name).toEqual('Card') - }) - it('check if props are there', () => { - expect(Card.props[0]).toEqual('cardData') - expect(Card.props[1]).toEqual('inStack') - }) - it('test if data field is there', () => { - expect(typeof Card.data).toBe('function') - }) - it('test to see if data field msg field is populated correctly', () => { - const defaultData = Card.data() - expect(defaultData.msg).toEqual('Program Wars') - }) - it('test to see if data field valueCSS is set properly initially', () => { - const defaultData = Card.data() - expect(defaultData.valueCss).toEqual('value') - }) - it('test to see if data field typeCss is set properly initially', () => { - const defaultData = Card.data() - expect(defaultData.typeCss).toEqual('type') - }) - it('test to see if computed field exists', () => { - expect(typeof Card.computed).toEqual('object') - }) - it('testing flipFace function', () => { - let testCard = new CardObj(0, 1, 'I') - testCard.flipCardFace() - expect(testCard.showFace).toEqual(true) - }) - -/* These need to be re-written - The vuex state and store components are undefined without setting them - Explicitly like in some other tests. These need to be stubbed out as the - store state is not relevant to these tests. - To test the rest of the functions and methods of the Card component - Specific objects that they deal with will need to be mocked. - - see https://vue-test-utils.vuejs.org/guides/using-with-vuex.html - for more information on testing with vuex - - - // test if css string is set without selected property - it('test computed property function cardCss()', () => { - let testCard = new CardObj(0, 0, 'I') - expect(getCssString(Card, { cardData: testCard })).toEqual('card') - }) - // test if cssString is set with selected property - it('test cssString on card selected', () => { - let testCard = new CardObj(0, 0, 'I') - testCard.selected = true - expect(getCssString(Card, { cardData: testCard })).toEqual('card selected') - }) - // testing the inStack property - it('testing if the inStack property is set then the cssString should change', () => { - let stackVar = true - let testCard = new CardObj(0, 0, 'I') - expect(getCssString(Card, { inStack: stackVar, cardData: testCard })).toEqual('card stack') - }) - // testing title() function - it('testing if the title is set appropriately', () => { - let testCard = new CardObj(0, 0, 'I') - expect(getTitle(Card, { cardData: testCard })).toEqual('Card') - }) - // testing cardType function with various types - it('testing cardType function with I', () => { - let testCard = new CardObj(0, 0, 'I') - expect(getCardType(Card, { cardData: testCard })).toEqual('I') - }) - // testing cardType with Rx - it('testing cardType function with Rx', () => { - let testCard = new CardObj(0, 1, 'R') - expect(getCardType(Card, { cardData: testCard })).toEqual('Rx') - }) - // testing cardValue with Rx - it('testing cardValue function with Rx', () => { - let testCard = new CardObj(0, 1, 'R') - expect(getCardValue(Card, { cardData: testCard })).toEqual('_') - }) - // testing cardValue with any other value - it('testing cardValue function with anything else', () => { - let testCard = new CardObj(0, 1, 'I') - expect(getCardValue(Card, { cardData: testCard })).toEqual(1) - }) - it('testing cardGraphics', () => { - let testCard = new CardObj(0, 1, 'I', '/static/cardImg/V6.png') - expect(getCardGraphics(Card, {cardData: testCard})).toEqual('/static/cardImg/V6.png') +describe('Card data object', () => { + test('constructor functions properly', () => { + let card = new Card(5, 10, 'VIRUS', 'some/image/path.png') + expect(card.id).toEqual(5) + expect(card.value).toEqual(10) + expect(card.type).toEqual('VIRUS') + expect(card.image).toEqual('some/image/path.png') }) -*/ }) diff --git a/tests/unit/Deck.spec.js b/tests/unit/Deck.spec.js index 1850711e..c7c834ea 100644 --- a/tests/unit/Deck.spec.js +++ b/tests/unit/Deck.spec.js @@ -1,467 +1,144 @@ import Deck from '@/classes/Models/Deck' -// import Card from '@/classes/Card' -describe('Deck.js', () => { - // test initial cards array length - it('test if the initial cards array is empty', () => { - let testDeck = new Deck() - expect(testDeck.cards.length).toEqual(0) - }) +let count = function (cards, type) { + return cards.reduce((acc, card) => { + return card.type === type ? acc + 1 : acc + }, 0) +} + - // test initial discard_cards array length - it('test if the initial discard_cards array is empty', () => { +describe('Deck.js', () => { + it('test if the initial discard array is empty', () => { let testDeck = new Deck() - expect(testDeck.discard_cards.length).toEqual(0) + expect(testDeck.discard.length).toEqual(0) }) - - // test initDeck function 1 player it('test the initDeck function for number of cards', () => { - let testDeck = new Deck() - testDeck.initDeck(1) + let testDeck = new Deck(1) expect(testDeck.cards.length).toEqual(72) }) - - // test initDeck function 3 players it('test the initDeck function for number of cards', () => { - let testDeck = new Deck() - testDeck.initDeck(3) + let testDeck = new Deck(3) expect(testDeck.cards.length).toEqual(219) }) - // test the number of 'I' cards 1 player - it('test that initDeck is putting in the correct number of instruction cards', () => { - let testDeck = new Deck() - testDeck.initDeck(1) - let cardsArray = testDeck.cards - let instructionCounter = 0 - for (let idx of cardsArray) { - if (idx.type === 'I') { - instructionCounter++ - } - } - expect(instructionCounter).toEqual(27) - }) - - // test the number of 'I' cards 3 players - it('test that initDeck is putting in the correct number of instruction cards', () => { - let testDeck = new Deck() - testDeck.initDeck(3) - let cardsArray = testDeck.cards - let instructionCounter = 0 - for (let idx of cardsArray) { - if (idx.type === 'I') { - instructionCounter++ - } - } - expect(instructionCounter).toEqual(81) - }) - - // test the number of R cards 1 player - it('test that the number of R cards is correct', () => { - let testDeck = new Deck() - testDeck.initDeck(1) - let cardsArray = testDeck.cards - let repetitionCounter = 0 - for (let idx of cardsArray) { - if (idx.type === 'R') { - repetitionCounter++ - } - } - expect(repetitionCounter).toEqual(14) - }) - - // test the number of R cards 3 player - it('test that the number of R cards is correct', () => { - let testDeck = new Deck() - testDeck.initDeck(3) - let cardsArray = testDeck.cards - let repetitionCounter = 0 - for (let idx of cardsArray) { - if (idx.type === 'R') { - repetitionCounter++ - } - } - expect(repetitionCounter).toEqual(42) - }) - - // test the number of Rx cards 1 player - it('test the number of Rx cards in the deck', () => { - let testDeck = new Deck() - testDeck.initDeck(1) - let cardsArray = testDeck.cards - let rxCounter = 0 - for (let idx of cardsArray) { - if (idx.type === 'R' && idx.value === 1) { - rxCounter++ - } - } - expect(rxCounter).toEqual(5) - }) - - // test the number of Rx cards 3 players - it('test the number of Rx cards in the deck', () => { - let testDeck = new Deck() - testDeck.initDeck(3) - let cardsArray = testDeck.cards - let rxCounter = 0 - for (let idx of cardsArray) { - if (idx.type === 'R' && idx.value === 1) { - rxCounter++ - } - } - expect(rxCounter).toEqual(15) - }) - - // test the number of variable cards in the deck 1 player - it('test the number of Variable cards in the deck', () => { - let testDeck = new Deck() - testDeck.initDeck(1) - let cardsArray = testDeck.cards - let varCounter = 0 - for (let idx of cardsArray) { - if (idx.type === 'V') { - varCounter++ - } - } - expect(varCounter).toEqual(7) - }) - - // test the number of variable cards in the deck 3 players - it('test the number of Variable cards in the deck', () => { - let testDeck = new Deck() - testDeck.initDeck(3) - let cardsArray = testDeck.cards - let varCounter = 0 - for (let idx of cardsArray) { - if (idx.type === 'V') { - varCounter++ - } - } - expect(varCounter).toEqual(21) - }) - - // test the number of hack cards in the deck 1 player - it('test the number of hack cards in the deck', () => { - let testDeck = new Deck() - testDeck.initDeck(1) - let cardsArray = testDeck.cards - let hackCounter = 0 - for (let idx of cardsArray) { - if (idx.type === 'H') { - hackCounter++ - } - } - expect(hackCounter).toEqual(3) - }) - - // test the number of Virus cards in the deck 1 player - it('test the number of virus cards in the deck', () => { - let testDeck = new Deck() - testDeck.initDeck(1) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'VIRUS') { - counter++ - } - } - expect(counter).toEqual(3) - }) - - // test the number of Power Outage cards in the deck 1 player - it('test the number of power outage cards in the deck', () => { - let testDeck = new Deck() - testDeck.initDeck(1) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'POWEROUTAGE') { - counter++ - } - } - expect(counter).toEqual(3) - }) - - // PROTECTION CARDS - // test the number of AntiVirus cards in the deck 1 player - it('test the number of AntiVirus cards in the deck(1)', () => { - let testDeck = new Deck() - testDeck.initDeck(1) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'ANTIVIRUS') { - counter++ - } - } - expect(counter).toEqual(0) - }) - - // test the number of AntiVirus cards in the deck 2 players - it('test the number of AntiVirus cards in the deck(2)', () => { - let testDeck = new Deck() - testDeck.initDeck(2) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'ANTIVIRUS') { - counter++ - } - } - expect(counter).toEqual(1) - }) - - // test the number of AntiVirus cards in the deck 3 players - it('test the number of AntiVirus cards in the deck(3)', () => { - let testDeck = new Deck() - testDeck.initDeck(3) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'ANTIVIRUS') { - counter++ - } - } - expect(counter).toEqual(1) - }) - - // test the number of AntiVirus cards in the deck 4 players - it('test the number of AntiVirus cards in the deck(4)', () => { - let testDeck = new Deck() - testDeck.initDeck(4) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'ANTIVIRUS') { - counter++ - } - } - expect(counter).toEqual(2) - }) - - // test the number of Generator cards in the deck 1 player - it('test the number of Generator cards in the deck(1)', () => { - let testDeck = new Deck() - testDeck.initDeck(1) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'GENERATOR') { - counter++ - } - } - expect(counter).toEqual(0) - }) - - // test the number of Generator cards in the deck 2 players - it('test the number of Generator cards in the deck(2)', () => { - let testDeck = new Deck() - testDeck.initDeck(2) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'GENERATOR') { - counter++ - } - } - expect(counter).toEqual(1) - }) - - // test the number of Generator cards in the deck 3 players - it('test the number of Generator cards in the deck(3)', () => { - let testDeck = new Deck() - testDeck.initDeck(3) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'GENERATOR') { - counter++ - } - } - expect(counter).toEqual(1) - }) - - // test the number of Generator cards in the deck 4 players - it('test the number of Generator cards in the deck(4)', () => { - let testDeck = new Deck() - testDeck.initDeck(4) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'GENERATOR') { - counter++ - } - } - expect(counter).toEqual(2) - }) - - // test the number of Firewall cards in the deck 1 player - it('test the number of Firewall cards in the deck(1)', () => { - let testDeck = new Deck() - testDeck.initDeck(1) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'FIREWALL') { - counter++ - } - } - expect(counter).toEqual(0) - }) - - // test the number of Firewall cards in the deck 2 players - it('test the number of Firewall cards in the deck(2)', () => { - let testDeck = new Deck() - testDeck.initDeck(2) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'FIREWALL') { - counter++ - } - } - expect(counter).toEqual(1) - }) - - // test the number of Firewall cards in the deck 3 players - it('test the number of Firewall cards in the deck(3)', () => { - let testDeck = new Deck() - testDeck.initDeck(3) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'FIREWALL') { - counter++ - } - } - expect(counter).toEqual(1) - }) - - // test the number of Firewall cards in the deck 4 players - it('test the number of Firewall cards in the deck(4)', () => { - let testDeck = new Deck() - testDeck.initDeck(4) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'FIREWALL') { - counter++ - } - } - expect(counter).toEqual(2) - }) - - // test the number of hack cards in the deck 3 players - it('test the number of hack cards in the deck', () => { - let testDeck = new Deck() - testDeck.initDeck(3) - let cardsArray = testDeck.cards - let hackCounter = 0 - for (let idx of cardsArray) { - if (idx.type === 'H') { - hackCounter++ - } - } - expect(hackCounter).toEqual(9) - }) - - // test the number of Virus cards in the deck 3 player - it('test the number of virus cards in the deck', () => { - let testDeck = new Deck() - testDeck.initDeck(3) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'VIRUS') { - counter++ - } - } - expect(counter).toEqual(9) - }) - - // test the number of Power Outage cards in the deck 3 player - it('test the number of power outage cards in the deck', () => { - let testDeck = new Deck() - testDeck.initDeck(3) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'POWEROUTAGE') { - counter++ - } - } - expect(counter).toEqual(9) - }) - - // PROTECTION CARDS - // test the number of AntiVirus cards in the deck 3 player - it('test the number of AntiVirus cards in the deck', () => { - let testDeck = new Deck() - testDeck.initDeck(3) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'ANTIVIRUS') { - counter++ - } - } - expect(counter).toEqual(1) - }) - - // test the number of Generator cards in the deck 3 player - it('test the number of Generator cards in the deck', () => { - let testDeck = new Deck() - testDeck.initDeck(3) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'GENERATOR') { - counter++ - } - } - expect(counter).toEqual(1) - }) - - // test the number of Firewall cards in the deck 3 player - it('test the number of Firewall cards in the deck', () => { - let testDeck = new Deck() - testDeck.initDeck(3) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'FIREWALL') { - counter++ - } - } - expect(counter).toEqual(1) - }) - - // test to see if the draw function draws the card from the top of the deck - it('test to see if the draw function works properly', () => { - let testDeck = new Deck() - testDeck.initDeck(1) - // let testCard = new Card(0, 1, 'I') - let drawnCard = testDeck.draw() - expect(testDeck.cards.length).toEqual(71) - - expect(typeof drawnCard).toEqual('object') - // The deck shuffles itself when created, no way of know what the top card is - // expect(drawnCard.id).toEqual(testCard.id) - // expect(drawnCard.value).toEqual(testCard.value) - // expect(drawnCard.type).toEqual(testCard.type) - }) - - // test the shuffle function - it('test to see if the shuffle function works', () => { - let testDeck = new Deck() - testDeck.initDeck(1) - let shuffledDeck = testDeck - shuffledDeck.shuffle(testDeck) - let counter = 0 - for (let idx of testDeck.cards) { - expect(idx.id).not.toEqual(shuffledDeck.cards[counter]) - expect(idx.value).not.toEqual(shuffledDeck.cards[counter]) - counter++ - } + describe('correct setup for one player decks', () => { + let deck1 + beforeEach(() => { + deck1 = new Deck(1) + }) + test('correct number of instructions', () => { + expect(count(deck1.cards, 'I')).toEqual(27) + }) + test('correct number of repeats', () => { + expect(count(deck1.cards, 'R')).toEqual(14) + }) + test('correct number of Rx', () => { + let num = deck1.cards.reduce((acc, card) => { + return card.type === 'R' && card.value === 1 ? acc + 1 : acc + }, 0) + expect(num).toEqual(5) + }) + test('correct number of variables', () => { + expect(count(deck1.cards, 'V')).toEqual(7) + }) + it('correct number of hacks', () => { + expect(count(deck1.cards, 'H')).toEqual(3) + }) + it('correct number of viruses', () => { + expect(count(deck1.cards, 'VIRUS')).toEqual(3) + }) + it('correct number of power outages', () => { + expect(count(deck1.cards, 'POWEROUTAGE')).toEqual(3) + }) + it('correct number of anti viruses', () => { + expect(count(deck1.cards, 'ANTIVIRUS')).toEqual(0) + }) + it('correct number of generator cards', () => { + expect(count(deck1.cards, 'GENERATOR')).toEqual(0) + }) + it('correct number of firewall cards', () => { + expect(count(deck1.cards, 'FIREWALL')).toEqual(0) + }) + it('draw function works properly', () => { + // The deck shuffles itself when created, no way of know what the top card is + expect(deck1.draw()).not.toBeUndefined() + expect(deck1.cards.length).toEqual(71) + }) + // deleted shuffle test as it didn't really test anything + // could write a new one to check that shuffle changes order a bit, but this + // is inherently difficult to be sure of + }) + + describe('correct setup for two player decks', () => { + let deck2 + beforeEach(() => { + deck2 = new Deck(2) + }) + test('correct number of anti virus cards', () => { + expect(count(deck2.cards, 'ANTIVIRUS')).toEqual(1) + }) + test('correct number of generator cards', () => { + expect(count(deck2.cards, 'GENERATOR')).toEqual(1) + }) + test('correct number of firewall cards', () => { + expect(count(deck2.cards, 'FIREWALL')).toEqual(1) + }) + }) + + describe('correct setup for three player decks', () => { + let deck3 + beforeEach(() => { + deck3 = new Deck(3) + }) + test('correct number instructions', () => { + expect(count(deck3.cards, 'I')).toEqual(81) + }) + test('correct number of repeats', () => { + expect(count(deck3.cards, 'R')).toEqual(42) + }) + test('correct number of Rx', () => { + let num = deck3.cards.reduce((acc, card) => { + return card.type === 'R' && card.value === 1 ? acc + 1 : acc + }, 0) + expect(num).toEqual(15) + }) + test('correct number of variables', () => { + expect(count(deck3.cards, 'V')).toEqual(21) + }) + it('correct number of hacks', () => { + expect(count(deck3.cards, 'H')).toEqual(9) + }) + it('correct number of viruses', () => { + expect(count(deck3.cards, 'VIRUS')).toEqual(9) + }) + it('correct number of power outages', () => { + expect(count(deck3.cards, 'POWEROUTAGE')).toEqual(9) + }) + it('correct number of anti viruses', () => { + expect(count(deck3.cards, 'ANTIVIRUS')).toEqual(1) + }) + it('correct number of generator cards', () => { + expect(count(deck3.cards, 'GENERATOR')).toEqual(1) + }) + it('correct number of firewall cards', () => { + expect(count(deck3.cards, 'FIREWALL')).toEqual(1) + }) + }) + + + describe('correct setup for four player decks', () => { + let deck4 + beforeEach(() => { + deck4 = new Deck(4) + }) + test('correct number of anti virus cards', () => { + expect(count(deck4.cards, 'ANTIVIRUS')).toEqual(2) + }) + test('correct number of generator cards', () => { + expect(count(deck4.cards, 'GENERATOR')).toEqual(2) + }) + test('correct number of firewall cards', () => { + expect(count(deck4.cards, 'FIREWALL')).toEqual(2) + }) }) }) diff --git a/tests/unit/Gambler.spec.js b/tests/unit/Gambler.spec.js deleted file mode 100644 index 8d173f6a..00000000 --- a/tests/unit/Gambler.spec.js +++ /dev/null @@ -1,95 +0,0 @@ -/* eslint-disable no-trailing-spaces */ -var sinon = require('sinon') -import {store} from '@/store/store' -import Card from '@/classes/Models/Card' -import Player from '@/classes/Models/Player' -import Stack from '@/classes/Models/Stack' -import Handler from '@/classes/AiActions/AiHandler' -import AiMove from '@/classes/AiActions/AiMove' -import AntiVirus from '@/classes/AiActions/AntiVirusStep' -import Firewall from '@/classes/AiActions/FirewallStep' -import Generator from '@/classes/AiActions/GeneratorStep' -import OverClock from '@/classes/AiActions/OverClockStep' -import BatteryBackup from '@/classes/AiActions/BatteryBackupStep' -import Repeat from '@/classes/AiActions/RepeatStep' -import RepeatX from '@/classes/AiActions/RepeatXStep' -import Group from '@/classes/AiActions/GroupStep' -import Instruction from '@/classes/AiActions/InstStep' -import Hack from '@/classes/AiActions/HackStep' -import Variable from '@/classes/AiActions/VarStep' -import Virus from '@/classes/AiActions/VirusStep' -import PowerOutage from '@/classes/AiActions/PowerOutageStep' -import Discard from '@/classes/AiActions/DiscardStep' - -let canGroup = false -let move = new AiMove() -let boolSide = true - -// INFO: Tests depend on this order -let defaultHand = {cards: [new Card(0, 0, 'V'), new Card(1, 0, 'R'), new Card(2, 0, 'R'), new Card(3, 0, 'I'), new Card(4, 0, 'H'), new Card(5, 0, 'VIRUS')]} -let hand = move.organizeHand({hand: defaultHand}) - -let player = new Player(0, 'aiTest', hand, 0, true) -let player2 = new Player(1, 'aiTest2', hand, 0, true) - -let event = {cards: hand, hand: defaultHand, stack: [new Stack(0, true), new Stack(0, true), new Stack(1, true), new Stack(1, true)], opponents: [player2]} - -let oPO = player2 -let oV = player2 - -let actionObject = { - avAction: new AntiVirus(hand, boolSide, move, event), - fwAction: new Firewall(hand, boolSide, move, event), - genAction: new Generator(hand, boolSide, move, event), - ocAction: new OverClock(hand, boolSide, move, event), - bbAction: new BatteryBackup(hand, boolSide, move, event), - rAction: new Repeat(hand, boolSide, move, event), - rxAction: new RepeatX(hand, boolSide, move, event), - gAction: new Group(hand, boolSide, move, event, canGroup), - iAction: new Instruction(hand, boolSide, move, event), - hAction: new Hack(hand, boolSide, move, event), - varAction: new Variable(hand, boolSide, move, event), - vAction: new Virus(hand, boolSide, move, event, oV), - poAction: new PowerOutage(hand, boolSide, move, event, oPO), - dAction: new Discard(hand, boolSide, move, event) -} -let rSpy = sinon.spy(actionObject.rAction, 'execute') -let rxSpy = sinon.spy(actionObject.rxAction, 'execute') -let gSpy = sinon.spy(actionObject.gAction, 'execute') -let iSpy = sinon.spy(actionObject.iAction, 'execute') -let hSpy = sinon.spy(actionObject.hAction, 'execute') -let varSpy = sinon.spy(actionObject.varAction, 'execute') -let vSpy = sinon.spy(actionObject.vAction, 'execute') -let poSpy = sinon.spy(actionObject.poAction, 'execute') -let dSpy = sinon.spy(actionObject.dAction, 'execute') - -let handler = new Handler(oPO, oV, actionObject.avAction, actionObject.fwAction, actionObject.genAction, actionObject.ocAction, actionObject.bbAction, actionObject.gAction, - actionObject.vAction, actionObject.hAction, actionObject.poAction, actionObject.iAction, actionObject.rAction, actionObject.rxAction, actionObject.varAction, actionObject.dAction) - -describe('Gambler', () => { - it('calls execute() correctly', () => { - store.state.activePlayer = 0 - store.state.players = [player, player2] - store.state.players[0].hasPowerOutage = true - expect(handler.getOpponentVirus().id).toEqual(oV.id) - expect(handler.getOpponentPO().id).toEqual(oPO.id) - expect(handler.getMove()).toEqual(undefined) - expect(handler.getCard()).toEqual(undefined) - expect(handler.getOpponent()).toEqual(undefined) - expect(handler.getStack()).toEqual(undefined) - }) - - it('The ordering of cards is correct', () => { - handler.setAi('gambler') - expect(varSpy.calledBefore(rxSpy)) - expect(rxSpy.calledBefore(rSpy)) - expect(rSpy.calledBefore(iSpy)) - expect(iSpy.calledBefore(hSpy)) - expect(hSpy.calledBefore(vSpy)) - expect(vSpy.calledBefore(poSpy)) - expect(poSpy.calledBefore(gSpy)) - expect(gSpy.calledBefore(dSpy)) - expect(dSpy.calledOnce) - expect(handler.getCard().type).toEqual(defaultHand.cards[0].type) - }) -}) diff --git a/tests/unit/Getters.spec.js b/tests/unit/Getters.spec.js deleted file mode 100644 index 9bac1bac..00000000 --- a/tests/unit/Getters.spec.js +++ /dev/null @@ -1,125 +0,0 @@ -/* eslint-disable no-trailing-spaces */ -import {store} from '@/store/store' -import Card from '@/classes/Models/Card' - -let card = new Card(55, 3, 'I', 'f') -let card2 = new Card(34, 2, 'R', 'v') -describe('test store.js getters', () => { - it('test the store getCurrentPlayerId function', () => { - store.state.activePlayer = 0 - expect(store.getters.getCurrentPlayerId).toEqual(0) - }) - it('test the store maxPlayers function maxPlayers', () => { - store.state.players = [] - expect(store.getters.maxplayers).toEqual(0) - }) - it('test the store currentPlayerName function', () => { - expect(store.getters.currentPlayerName).toEqual('') - }) - it('test the store getCurrentPlayerHand function', () => { - expect(JSON.stringify(store.getters.getCurrentPlayerHand) === JSON.stringify({})).toEqual(true) - }) - it('test the store getCurrentPlayerStacks function', () => { - expect(store.getters.getCurrentPlayerStacks).toEqual(undefined) - }) - it('test the store getActivePlayer function', () => { - expect(store.getters.getActivePlayer).toEqual(0) - }) - it('test the store getActiveCard function', () => { - expect(store.getters.getActiveCard).toEqual(undefined) - }) - it('test the store getStacks function', () => { - expect(Array.isArray(store.getters.getStacks)).toEqual(true) - }) - it('test the store getPlayers function', () => { - expect(Array.isArray(store.getters.getPlayers)).toEqual(true) - }) - it('test the store getIsDiscard function', () => { - expect(store.getters.getIsDiscard).toEqual(false) - }) - it('test the store getIsHack function', () => { - expect(store.getters.getIsHack).toEqual(false) - }) - it('test the store getAiTurn function', () => { - expect(store.getters.getAiTurn).toEqual(false) - }) - it('test the store getHackedPlayer function', () => { - expect(store.getters.getHackedPlayer).toEqual('') - }) - it('test the store getCoinFlip function', () => { - expect(store.getters.getCoinFlip).toEqual(0) - }) - it('test the store getHasPlayed function', () => { - expect(store.getters.getHasPlayed).toEqual(false) - }) - it('test the store getgameState function', () => { - expect(store.getters.getgameState).toEqual('newGame') - }) - it('test the store getSelectedStacks function', () => { - expect(Array.isArray(store.getters.getSelectedStacks)).toEqual(true) - }) - it('test the store getSelectedStacksBoolean function', () => { - expect(store.getters.getSelectedStacksBoolean).toEqual(undefined) - }) - it('test the store getActiveSide function', () => { - expect(store.getters.getActiveSide).toEqual(true) - }) - it('test the store getScoreLimit function', () => { - expect(store.getters.getScoreLimit).toEqual(10) - }) - it('test the store groupStacks function', () => { - expect(store.getters.groupStacks).toEqual(false) - }) - it('test the store trueFalseAnim function', () => { - expect(store.getters.trueFalseAnim).toEqual(false) - }) - it('test the store getWinner function', () => { - expect(store.getters.getWinner).toEqual(false) - }) - it('test the store getWinnerName function', () => { - expect(store.getters.getWinnerName).toEqual('') - }) - it('test the store getWinnerScore function', () => { - expect(store.getters.getWinnerScore).toEqual(0) - }) - it('test the store getTips function', () => { - expect(store.getters.getTips.tutorial).toEqual(true) - }) - it('test the store getPlayerTurn function', () => { - expect(store.getters.getPlayerTurn).toEqual(false) - }) - it('test the store getCurrentPlayer function', () => { - expect(store.getters.getCurrentPlayer).toEqual(undefined) - }) - it('test the store getFirstRound function', () => { - expect(store.getters.getFirstRound).toEqual(true) - }) - it('test the store getCoinMsg function', () => { - expect(store.getters.getCoinMsg).toEqual(false) - }) - it('test the store getTutorialState function', () => { - expect(store.getters.getTutorialState).toEqual(false) - }) - it('test the store getFactIndex function', () => { - expect(store.getters.getFactIndex).toEqual(0) - }) - it('test the store getTutorialStep function', () => { - expect(store.getters.getTutorialStep).toEqual(true) - }) - it('test the store getDiscard function', () => { - expect(Array.isArray(store.getters.getDiscard)).toEqual(true) - }) - it('test the store getAiDependent function', () => { - expect(store.getters.getAiDependent.scoreLimit).toEqual(10) - let pay = {list: [{name: 'joe', isAi: false}, {name: 'lucy', isAi: true}]} - store.commit('addPlayers', pay) - store.state.hands.push({cards: [card], playerId: 0}) - store.state.hands.push({cards: [card2], playerId: 1}) - store.state.activePlayer = 0 - store.commit('addStackToPlayer', {playerId: 0, boolSide: true}) - store.commit('addStackToPlayer', {playerId: 0, boolSide: false}) - store.commit('addStackToPlayer', {playerId: 1, boolSide: true}) - store.commit('addStackToPlayer', {playerId: 1, boolSide: false}) - expect(store.getters.getAiDependent.hand.cards[0].type).toEqual('R') - }) -}) diff --git a/tests/unit/HackModal.spec.js b/tests/unit/HackModal.spec.js deleted file mode 100644 index bff72223..00000000 --- a/tests/unit/HackModal.spec.js +++ /dev/null @@ -1,13 +0,0 @@ -import hackModal from '@/components/Modals/CardModals/HackModal.vue' -// import { bus } from '@/components/Bus.vue' - -describe('HackModal', () => { - it('running the hackCanceled function', () => { - // let call = false - hackModal.methods.hackCanceled() - // bus.$on('hackCanceled', () => { - // call = true - // }) - // expect(call).toEqual(true) - }) -}) diff --git a/tests/unit/Hacker.spec.js b/tests/unit/Hacker.spec.js deleted file mode 100644 index dec45a01..00000000 --- a/tests/unit/Hacker.spec.js +++ /dev/null @@ -1,95 +0,0 @@ -/* eslint-disable no-trailing-spaces */ -var sinon = require('sinon') -import {store} from '@/store/store' -import Card from '@/classes/Models/Card' -import Player from '@/classes/Models/Player' -import Stack from '@/classes/Models/Stack' -import Handler from '@/classes/AiActions/AiHandler' -import AiMove from '@/classes/AiActions/AiMove' -import AntiVirus from '@/classes/AiActions/AntiVirusStep' -import Firewall from '@/classes/AiActions/FirewallStep' -import Generator from '@/classes/AiActions/GeneratorStep' -import OverClock from '@/classes/AiActions/OverClockStep' -import BatteryBackup from '@/classes/AiActions/BatteryBackupStep' -import Repeat from '@/classes/AiActions/RepeatStep' -import RepeatX from '@/classes/AiActions/RepeatXStep' -import Group from '@/classes/AiActions/GroupStep' -import Instruction from '@/classes/AiActions/InstStep' -import Hack from '@/classes/AiActions/HackStep' -import Variable from '@/classes/AiActions/VarStep' -import Virus from '@/classes/AiActions/VirusStep' -import PowerOutage from '@/classes/AiActions/PowerOutageStep' -import Discard from '@/classes/AiActions/DiscardStep' - -let canGroup = false -let move = new AiMove() -let boolSide = true - -// INFO: Tests depend on this order -let defaultHand = {cards: [new Card(0, 0, 'V'), new Card(1, 0, 'R'), new Card(2, 0, 'R'), new Card(3, 0, 'I'), new Card(4, 0, 'H'), new Card(5, 0, 'VIRUS')]} -let hand = move.organizeHand({hand: defaultHand}) - -let player = new Player(0, 'aiTest', hand, 0, true) -let player2 = new Player(1, 'aiTest2', hand, 0, true) - -let event = {cards: hand, hand: defaultHand, stack: [new Stack(0, true), new Stack(0, true), new Stack(1, true), new Stack(1, true)], opponents: [player2]} - -let oPO = player2 -let oV = player2 - -let actionObject = { - avAction: new AntiVirus(hand, boolSide, move, event), - fwAction: new Firewall(hand, boolSide, move, event), - genAction: new Generator(hand, boolSide, move, event), - ocAction: new OverClock(hand, boolSide, move, event), - bbAction: new BatteryBackup(hand, boolSide, move, event), - rAction: new Repeat(hand, boolSide, move, event), - rxAction: new RepeatX(hand, boolSide, move, event), - gAction: new Group(hand, boolSide, move, event, canGroup), - iAction: new Instruction(hand, boolSide, move, event), - hAction: new Hack(hand, boolSide, move, event), - varAction: new Variable(hand, boolSide, move, event), - vAction: new Virus(hand, boolSide, move, event, oV), - poAction: new PowerOutage(hand, boolSide, move, event, oPO), - dAction: new Discard(hand, boolSide, move, event) -} -let rSpy = sinon.spy(actionObject.rAction, 'execute') -let rxSpy = sinon.spy(actionObject.rxAction, 'execute') -let gSpy = sinon.spy(actionObject.gAction, 'execute') -let iSpy = sinon.spy(actionObject.iAction, 'execute') -let hSpy = sinon.spy(actionObject.hAction, 'execute') -let varSpy = sinon.spy(actionObject.varAction, 'execute') -let vSpy = sinon.spy(actionObject.vAction, 'execute') -let poSpy = sinon.spy(actionObject.poAction, 'execute') -let dSpy = sinon.spy(actionObject.dAction, 'execute') - -let handler = new Handler(oPO, oV, actionObject.avAction, actionObject.fwAction, actionObject.genAction, actionObject.ocAction, actionObject.bbAction, actionObject.gAction, - actionObject.vAction, actionObject.hAction, actionObject.poAction, actionObject.iAction, actionObject.rAction, actionObject.rxAction, actionObject.varAction, actionObject.dAction) - -describe('Hacker', () => { - it('calls execute() correctly', () => { - store.state.activePlayer = 0 - store.state.players = [player, player2] - store.state.players[0].hasPowerOutage = true - expect(handler.getOpponentVirus().id).toEqual(oV.id) - expect(handler.getOpponentPO().id).toEqual(oPO.id) - expect(handler.getMove()).toEqual(undefined) - expect(handler.getCard()).toEqual(undefined) - expect(handler.getOpponent()).toEqual(undefined) - expect(handler.getStack()).toEqual(undefined) - }) - - it('The ordering of cards is correct', () => { - handler.setAi('hacker') - expect(hSpy.calledBefore(vSpy)) - expect(vSpy.calledBefore(poSpy)) - expect(poSpy.calledBefore(varSpy)) - expect(varSpy.calledBefore(rxSpy)) - expect(rxSpy.calledBefore(rSpy)) - expect(rSpy.calledBefore(iSpy)) - expect(iSpy.calledBefore(gSpy)) - expect(gSpy.calledBefore(dSpy)) - expect(dSpy.calledOnce) - expect(handler.getCard().type).toEqual(defaultHand.cards[0].type) - }) -}) diff --git a/tests/unit/MainComponent.spec.js b/tests/unit/MainComponent.spec.js deleted file mode 100644 index 5d347e10..00000000 --- a/tests/unit/MainComponent.spec.js +++ /dev/null @@ -1,26 +0,0 @@ -import MainComponent from '@/components/MainGame/MainComponent.vue' - -describe('MainComponent.js', () => { - it('has a created hook', () => { - expect(typeof MainComponent.created).toEqual('function') - }) - - it('sets the correct default data', () => { - expect(typeof MainComponent.data).toEqual('function') - const defaultData = MainComponent.data() - expect(defaultData.idCounter).toEqual(0) - expect(defaultData.dataToggle).toEqual(false) - expect(Array.isArray(defaultData.localPlayers)).toEqual(true) - expect(defaultData.gameStart).toEqual(false) - expect(defaultData.showDismissCards).toEqual(false) - expect(Array.isArray(defaultData.modalCards)).toEqual(true) - expect(defaultData.gameOverWinner).toEqual('') - expect(defaultData.gameOverText).toEqual('') - expect(defaultData.modalId).toEqual('gameOverModal') - expect(defaultData.tipsToggle).toEqual(true) - expect(Array.isArray(defaultData.playerList)).toEqual(true) - expect(defaultData.winner).toEqual('') - expect(defaultData.winnerScore).toEqual(0) - expect(Array.isArray(defaultData.deleteData)).toEqual(true) - }) -}) diff --git a/tests/unit/Mutations.spec.js b/tests/unit/Mutations.spec.js deleted file mode 100644 index 5d2dd6cb..00000000 --- a/tests/unit/Mutations.spec.js +++ /dev/null @@ -1,349 +0,0 @@ -/* eslint-disable no-trailing-spaces */ -import {store} from '@/store/store' -import Card from '@/classes/Models/Card' - -let card = new Card(55, 3, 'I', 'f') -let card2 = new Card(34, 2, 'R', 'v') -describe('test store.js mutations', () => { - it('test the store resetState function', () => { - store.commit('resetState') - expect(store.getters.getWinner).toEqual(false) - }) - - it('test the store addPlayers function', () => { - let pay = {list: [{name: 'joe', isAi: false}, {name: 'lucy', isAi: true}]} - store.commit('addPlayers', pay) - expect(store.getters.getPlayers[0].name).toEqual('joe') - store.state.activePlayer = 0 - expect(store.getters.currentPlayerName).toEqual('joe') - }) - - it('test the initTutorialDeck function', () => { - store.commit('initTutorialDeck') - expect(store.state.tutorialDeck.cards.length).toEqual(66) - }) - - it('test the store changeBonusScore function', () => { - store.commit('changeBonusScore', {id: 0, score: 1}) - expect(store.getters.getPlayers[0].bonus).toEqual(1) - }) - - it('test the store endTurn function', () => { - store.commit('endTurn', 1) - expect(store.getters.getPlayers[0].name).toEqual('joe') - }) - - it('test the store giveFirewall function', () => { - store.state.activeCard = new Card(55, 3, 'I', 'f') - store.commit('giveFirewall', 0) - expect(store.getters.getPlayers[0].hasFirewall).toEqual(true) - }) - - it('test the store giveGenerator function', () => { - store.getters.getPlayers[0].attackedCards = [new Card(22, 0, 'FIREWALL', 't')] - store.commit('giveGenerator', 0) - expect(store.getters.getPlayers[0].hasGenerator).toEqual(true) - }) - - it('test the store giveAntiVirus function', () => { - store.commit('giveAntiVirus', 0) - store.commit('giveFirewall', 0) - store.commit('giveGenerator', 0) - expect(store.getters.getPlayers[0].hasAntiVirus).toEqual(true) - store.getters.getPlayers[0].hasFirewall = false - store.getters.getPlayers[0].hasAntiVirus = false - store.getters.getPlayers[0].attackedCards = [new Card(22, 0, 'VIRUS', 't')] - store.commit('giveAntiVirus', 0) - expect(store.getters.getPlayers[0].hasAntiVirus).toEqual(true) - }) - - it('test the store giveOverclock and giveVirus functions', () => { - store.commit('giveOverclock', 0) - store.commit('giveVirus', 0) - store.commit('giveVirus', 1) - store.commit('giveOverclock', 1) - expect(store.getters.getPlayers[0].hasVirus).toEqual(false) - expect(store.getters.getPlayers[0].hasOverclock).toEqual(false) - expect(store.getters.getPlayers[1].hasVirus).toEqual(false) - expect(store.getters.getPlayers[1].hasOverclock).toEqual(false) - }) - - it('test the store givePowerOutage and giveBatteryBackup functions', () => { - store.commit('givePowerOutage', 0) - expect(store.getters.getPlayers[0].hasPowerOutage).toEqual(true) - store.commit('giveBatteryBackup', 0) - expect(store.getters.getPlayers[0].hasPowerOutage).toEqual(false) - }) - - it('test the store flipTutorialStep function', () => { - store.commit('flipTutorialStep') - expect(store.state.tutorialStep).toEqual(false) - store.commit('giveBatteryBackup', 0) - expect(store.getters.getPlayers[0].hasPowerOutage).toEqual(false) - }) - - it('test the store setFirstRound function', () => { - store.commit('setFirstRound', false) - expect(store.state.firstRound).toEqual(false) - }) - - it('test the store setFirstRound function', () => { - store.commit('setFirstRound', false) - expect(store.state.firstRound).toEqual(false) - }) - it('test the setAiTurn function', () => { - store.commit('setAiTurn', true) - expect(store.state.aiTurn).toEqual(true) - store.commit('setAiTurn', false) - expect(store.state.aiTurn).toEqual(false) - }) - - it('test the increaseFactIndex function', () => { - expect(store.state.factIndex).toEqual(0) - store.commit('increaseFactIndex') - expect(store.state.factIndex).toEqual(1) - }) - - it('test the setPlayfieldColour function', () => { - store.commit('setPlayfieldColour', false) - // expect(store.state.trueSideColour).toEqual('background-color: #80aef7; box-shadow: 0px 3px 15px rgba(0,0,0,0.6)') - // expect(store.state.falseSideColour).toEqual('background-color: #80aef7; box-shadow: 0px 3px 15px rgba(0,0,0,0.6)') - store.state.activeSide = true - store.commit('setPlayfieldColour', true) - expect(store.state.trueSideColour).toEqual('background-color: rgba(14, 183, 99, 0.9); box-shadow: 0 0 15px 10px forestgreen') - expect(store.state.falseSideColour).toEqual('background-color: rgba(242, 0, 0, 0.4)') - store.commit('setActiveSide', false) - store.commit('setPlayfieldColour', true) - expect(store.state.falseSideColour).toEqual('background-color: rgba(14, 183, 99, 0.9); box-shadow: 0 0 15px 10px forestgreen') - expect(store.state.trueSideColour).toEqual('background-color: rgba(242, 0, 0, 0.4)') - }) - - it('test the setCoinFlipAnim function', () => { - expect(store.state.coinFlip).toEqual(0) - store.commit('setCoinFlipAnim', 1) - expect(store.state.coinFlip).toEqual(1) - }) - - it('test the playerModalTrigger function', () => { - expect(store.state.playerTurn).toEqual(false) - store.commit('playerModalTrigger') - expect(store.state.playerTurn).toEqual(true) - }) - - it('test the playerModalHide function', () => { - expect(store.state.playerTurn).toEqual(true) - store.commit('playerModalHide') - expect(store.state.playerTurn).toEqual(false) - }) - - it('test the checkWin function', () => { - expect(store.state.winner).toEqual(false) - store.state.players[1].instructions = 100 - store.state.players[1].isDefensive = true - store.state.players[1].hasHadOverclock = false - store.state.players[1].hasPlayedInstruction = false - store.state.players[1].hasOverclock = true - store.state.players[0].hasVirus = true - store.commit('checkWin') - expect(store.state.winner).toEqual(true) - store.state.winner = false - store.state.players[1].hasOverclock = false - store.state.players[1].hasPlayedInstruction = true - store.state.players[1].isDefensive = false - store.state.players[1].instructions = 0 - store.commit('checkWin') - expect(store.state.winner).toEqual(false) - }) - - it('test the setTips function', () => { - store.commit('setTips', {tutorial: 'isTutorial', fact: 'isFact'}) - expect(store.state.playerTurn).toEqual(false) - }) - - it('test the setTrueFalseAnim function', () => { - store.commit('setTrueFalseAnim', {startAnim: true}) - expect(store.state.playerTurn).toEqual(false) - }) - - it('test the setScoreLimit function', () => { - store.commit('setScoreLimit', {scoreLimit: 10}) - expect(store.state.playerTurn).toEqual(false) - }) - - it('test the setStackSelectedBoolean function', () => { - store.commit('setStackSelectedBoolean', {boolean: false}) - expect(store.state.selectedStackBoolean).toEqual(false) - }) - - it('test the removeAllSelectedStacks function', () => { - store.commit('removeAllSelectedStacks') - expect(Array.isArray(store.state.selectedStacks)).toEqual(true) - }) - - it('test the discardSelectedCard function', () => { - store.state.activeCard = card - store.commit('discardSelectedCard') - store.state.isTutorial = true - store.commit('discardSelectedCard') - expect(store.state.deck.discard_cards[0].id).toEqual(55) - expect(store.state.tutorialDeck.discard_cards[0].id).toEqual(55) - }) - - it('test the removeActiveCardFromHand function', () => { - store.state.activePlayer = 0 - store.state.hands.push({cards: [card], playerId: 0}) - store.state.activeCard = card - store.commit('removeActiveCardFromHand') - expect(store.state.activeCard).toEqual(undefined) - }) - - it('test the setActiveCardUndefined function', () => { - store.state.activeCard = card - store.commit('setActiveCardUndefined') - expect(store.state.activeCard).toEqual(undefined) - }) - - it('test the setActiveCard function', () => { - store.commit('setActiveCard') - expect(store.state.activeCard).toEqual(undefined) - store.commit('setActiveCard', {cardId: 55}) - expect(store.state.activeCard).toEqual(55) - }) - - it('test the addCardToHand function', () => { - store.state.hands = [] - store.state.hands.push({cards: [], playerId: 0}) - store.state.isTutorial = false - store.commit('addCardToHand') - expect(store.state.hands[0].cards.length).toEqual(6) - store.commit('initDeck') - store.commit('addCardToHand') - expect(store.state.hands[0].cards.length).toEqual(6) - store.state.hands.push({cards: [], playerId: 1}) - store.state.isTutorial = true - store.commit('addCardToHand') - expect(store.state.hands[1].cards.length).toEqual(0) - store.state.tutorialDeck.cards = [] - store.state.activePlayer = 1 - store.commit('addCardToHand') - expect(store.state.hands[1].cards.length).toEqual(6) - store.commit('initTutorialDeck') - }) - - it('test the addHandToPlayer function', () => { - store.state.hands = [] - store.state.isTutorial = false - store.commit('addHandToPlayer', 0) - expect(store.state.players[0].hand.length).toEqual(36) - store.state.isTutorial = true - store.commit('addHandToPlayer', 1) - expect(store.state.players[1].hand.length).toEqual(36) - }) - - it('test the selectCard function', () => { - store.state.activePlayer = 0 - store.state.isTutorial = false - store.state.hands[0].cards = [card] - store.state.hands[0].cards[0].selected = true - store.state.hands[0].cards.push(card2) - store.commit('selectCard', card2) - expect(store.state.activeCard.id).toEqual(card2.id) - store.commit('selectCard', card) - store.state.hands[0].cards[0].selected = true - store.commit('selectCard', card) - expect(store.state.hands[0].cards[0].selected).toEqual(false) - store.state.hands[0].cards.push(undefined) - store.commit('selectCard', card) - expect(store.state.hands[0].cards[0].selected).toEqual(true) - }) - - it('test the groupStacks function', () => { - store.commit('groupStacks', {yesOrNo: true}) - expect(store.state.groupStacks).toEqual(true) - }) - - it('test the doGroupStacks function', () => { - store.commit('doGroupStacks', {yesOrNo: false}) - expect(store.state.groupStacks).toEqual(false) - }) - - it('test the setTutorial function', () => { - store.commit('setTutorial', {gameType: true}) - expect(store.state.isTutorial).toEqual(true) - }) - - it('test the initDeck function', () => { - store.commit('initDeck') - expect(store.state.deck.cards.length).toEqual(289) - }) - - it('test the setHasPlayed function', () => { - store.commit('setHasPlayed', {hasPlayed: true}) - expect(store.state.activeHasPlayed).toEqual(true) - }) - - it('test the setGameState function', () => { - store.commit('setGameState', {gameState: 'test'}) - expect(store.state.currentGameState).toEqual('test') - }) - - it('test the addStackToPlayer function', () => { - store.commit('addStackToPlayer', {playerId: 0, boolSide: true}) - store.commit('addStackToPlayer', {playerId: 0, boolSide: false}) - store.commit('addStackToPlayer', {playerId: 1, boolSide: true}) - store.commit('addStackToPlayer', {playerId: 1, boolSide: false}) - expect(store.state.stacks.length).toEqual(4) - store.state.activePlayer = 0 - expect(store.getters.getCurrentPlayerStacks.length).toEqual(2) - }) - - it('test the setPlayerScores function', () => { - store.commit('setPlayerScores') - expect(store.state.players[0].instructions).toEqual(0) - }) - - it('test the addCardToStack function', () => { - store.commit('addCardToStack', {stackId: store.state.stacks[0].stackId, card: card}) - expect(store.state.stacks[0].cards.length).toEqual(1) - }) - - it('test the popCardFromStack function', () => { - store.commit('popCardFromStack', {stackId: store.state.stacks[0].stackId, card: card}) - expect(store.state.stacks[0].cards.length).toEqual(0) - }) - - it('test the removeStack function', () => { - store.commit('removeStack', {stackId: store.state.stacks[3].stackId}) - expect(store.state.stacks.length).toEqual(3) - }) - - it('test the addStackToSelected function', () => { - store.commit('addStackToSelected', {stackId: store.state.stacks[2].stackId}) - expect(store.getters.getSelectedStacks[0].stackId).toEqual(store.state.stacks[2].stackId) - store.commit('addStackToSelected', {stackId: store.state.stacks[2].stackId}) - expect(Array.isArray(store.state.selectedStacks)).toEqual(true) - }) - - it('test the stackDiscard function', () => { - store.state.isTutorial = false - store.commit('stackDiscard', {stackId: store.state.stacks[0].stackId}) - expect(store.state.deck.discard_cards.length).toEqual(1) - store.state.isTutorial = true - store.commit('stackDiscard', {stackId: store.state.stacks[0].stackId}) - expect(store.state.tutorialDeck.discard_cards.length).toEqual(1) - }) - - it('test the getIsLast function', () => { - store.state.activePlayer = 1 - store.commit('getIsLast') - expect(store.state.isLast).toEqual(true) - store.state.activePlayer = 0 - store.commit('getIsLast') - expect(store.state.isLast).toEqual(false) - }) - - it('test the setActiveStack function', () => { - store.commit('setActiveStack', store.state.stacks[0]) - expect(store.state.activeStack.stackId).toEqual(store.state.stacks[0].stackId) - }) -}) diff --git a/tests/unit/Player.spec.js b/tests/unit/Player.spec.js index a3678b8f..57d59608 100644 --- a/tests/unit/Player.spec.js +++ b/tests/unit/Player.spec.js @@ -1,126 +1,20 @@ import Player from '@/classes/Models/Player' -let testPlayer = new Player(1, 'jeff', undefined, 0, true) -let testPlayer2 = new Player(2, 'jose', undefined, 0, false) +let player = new Player(1, 'jeff') describe('Player.js', () => { - it('test the Player constructor id', () => { - expect(testPlayer.id).toEqual(1) - }) - - it('test the Player constructor name', () => { - expect(testPlayer.name).toEqual('jeff') - }) - - it('test the Player constructor hand', () => { - expect(testPlayer.hand).toEqual(undefined) - }) - - it('test the Player constructor true score', () => { - expect(testPlayer.instructions).toEqual(0) - }) - - it('test the Player constructor usedBonusCards', () => { - expect(Array.isArray(testPlayer.usedBonusCards)).toEqual(true) - }) - - it('test the Player constructor attackedCards', () => { - expect(Array.isArray(testPlayer.attackedCards)).toEqual(true) - }) - - it('test the Player constructor hasGenerator', () => { - expect(testPlayer.hasGenerator).toEqual(false) - }) - - it('test the Player constructor hasFirewall', () => { - expect(testPlayer.hasFirewall).toEqual(false) - }) - - it('test the Player constructor hasAntiVirus', () => { - expect(testPlayer.hasAntiVirus).toEqual(false) - }) - - it('test the Player constructor isAi', () => { - expect(testPlayer.isAi).toEqual(true) - }) - it('test the Player2 constructor isAi', () => { - expect(testPlayer2.isAi).toEqual(false) - }) - - it('test the Player constructor hasPowerOutage', () => { - expect(testPlayer.hasPowerOutage).toEqual(false) - }) - - it('test the Player constructor hasOverclock', () => { - expect(testPlayer.hasOverclock).toEqual(false) - }) - - it('test the Player constructor hasVirus', () => { - expect(testPlayer.hasVirus).toEqual(false) - }) - - it('test the Player constructor hasHadOverclock', () => { - expect(testPlayer.hasOverclock).toEqual(false) - }) - - it('test the Player constructor hasPlayedInstruction', () => { - expect(testPlayer.hasPlayedInstruction).toEqual(false) - }) - - it('test the Player constructor instructionBonus', () => { - expect(testPlayer.instructionBonus).toEqual(0) - }) - - it('test the Player constructor completionBonus', () => { - expect(testPlayer.completionBonus).toEqual(0) - }) - - it('test the Player constructor virusBonus', () => { - expect(testPlayer.virusBonus).toEqual(0) - }) - - it('test the Player constructor protectionCardsBonus', () => { - expect(testPlayer.protectionCardsBonus).toEqual(0) - }) - - it('test the Player constructor overClockBonus', () => { - expect(testPlayer.overClockBonus).toEqual(0) - }) - - it('test the Player constructor defensiveBonus', () => { - expect(testPlayer.defensiveBonus).toEqual(0) - }) - - it('test the Player constructor groupingBonus', () => { - expect(testPlayer.groupingBonus).toEqual(0) - }) - - it('test the Player constructor repetitionBonus', () => { - expect(testPlayer.repetitionBonus).toEqual(0) - }) - - it('test the Player constructor variablesBonus', () => { - expect(testPlayer.variablesBonus).toEqual(0) - }) - - it('test the Player constructor overclockIncrease', () => { - expect(testPlayer.overclockIncrease).toEqual(0) - }) - - it('test the Player constructor bonus', () => { - expect(testPlayer.bonus).toEqual(0) - }) - - it('test the Player constructor isDefensive', () => { - expect(testPlayer.isDefensive).toEqual(false) - }) - - it('test the Player constructor isCleanSystem', () => { - expect(testPlayer.isCleanSystem).toEqual(true) - }) - - it('test the Player updateBonus', () => { - testPlayer.updateBonus(5) - expect(testPlayer.bonus).toEqual(5) + test('constructor functions properly', () => { + expect(player.id).toEqual(1) + expect(player.name).toEqual('jeff') + }) + test('hasPositive', () => { + player.positiveEffects.push("BATTERYBACKUP") + expect(player.hasPositive("BATTERYBACKUP")).toBeTruthy() + expect(player.hasPositive("OVERCLOCK")).toBeFalsy() + }) + test('hasNegative', () => { + player.negativeEffects.push("VIRUS") + expect(player.hasNegative("VIRUS")).toBeTruthy() + expect(player.hasNegative("POWEROUTAGE")).toBeFalsy() }) }) diff --git a/tests/unit/PlayerInfoPanel.spec.js b/tests/unit/PlayerInfoPanel.spec.js deleted file mode 100644 index a037d4f0..00000000 --- a/tests/unit/PlayerInfoPanel.spec.js +++ /dev/null @@ -1,25 +0,0 @@ -/** - * PlayerInfoPanel Unit Tests - * By: Austin Ball on: 21/05/19 - */ - -import PlayerInfoPanel from '@/components/MainGame/PlayerInfoPanel.vue' - -describe('PlayerInfoPanel.js', () => { - it('has a created hook', () => { - expect(typeof PlayerInfoPanel.created).toEqual('function') - }) - - it('sets the correct default data', () => { - expect(typeof PlayerInfoPanel.data).toEqual('function') - const defaultData = PlayerInfoPanel.data() - expect(defaultData.title).toEqual('Player Info Panel') - expect(defaultData.idCounter).toEqual(6) - expect(defaultData.modalText).toEqual('') - // expect(defaultData.modalCards).toEqual([]) - expect(defaultData.tipsToggle).toEqual(true) - expect(defaultData.tipsCardSelected).toEqual('Did you know?') - expect(defaultData.tipsInfoText).toEqual('You can toggle on or off this information window by checking the "FUN FACTS" box in the top right corner. ' + - 'You can also turn off the tutorials but keep the fun facts by checking the "TUTORIAL" box.') - }) -}) diff --git a/tests/unit/Protector.spec.js b/tests/unit/Protector.spec.js deleted file mode 100644 index a14e88b0..00000000 --- a/tests/unit/Protector.spec.js +++ /dev/null @@ -1,103 +0,0 @@ -/* eslint-disable no-trailing-spaces */ -var sinon = require('sinon') -import {store} from '@/store/store' -import Card from '@/classes/Models/Card' -import Player from '@/classes/Models/Player' -import Stack from '@/classes/Models/Stack' -import Handler from '@/classes/AiActions/AiHandler' -import AiMove from '@/classes/AiActions/AiMove' -import AntiVirus from '@/classes/AiActions/AntiVirusStep' -import Firewall from '@/classes/AiActions/FirewallStep' -import Generator from '@/classes/AiActions/GeneratorStep' -import OverClock from '@/classes/AiActions/OverClockStep' -import BatteryBackup from '@/classes/AiActions/BatteryBackupStep' -import Repeat from '@/classes/AiActions/RepeatStep' -import RepeatX from '@/classes/AiActions/RepeatXStep' -import Group from '@/classes/AiActions/GroupStep' -import Instruction from '@/classes/AiActions/InstStep' -import Hack from '@/classes/AiActions/HackStep' -import Variable from '@/classes/AiActions/VarStep' -import Virus from '@/classes/AiActions/VirusStep' -import PowerOutage from '@/classes/AiActions/PowerOutageStep' -import Discard from '@/classes/AiActions/DiscardStep' - -let canGroup = false -let move = new AiMove() -let boolSide = true - -// INFO: Tests depend on this order -let defaultHand = {cards: [new Card(0, 0, 'V'), new Card(1, 0, 'R'), new Card(2, 0, 'R'), new Card(3, 0, 'I'), new Card(4, 0, 'H'), new Card(5, 0, 'VIRUS')]} -let hand = move.organizeHand({hand: defaultHand}) - -let player = new Player(0, 'aiTest', hand, 0, true) -let player2 = new Player(1, 'aiTest2', hand, 0, true) - -let event = {cards: hand, hand: defaultHand, stack: [new Stack(0, true), new Stack(0, true), new Stack(1, true), new Stack(1, true)], opponents: [player2]} - -let oPO = player2 -let oV = player2 - -let actionObject = { - avAction: new AntiVirus(hand, boolSide, move, event), - fwAction: new Firewall(hand, boolSide, move, event), - genAction: new Generator(hand, boolSide, move, event), - ocAction: new OverClock(hand, boolSide, move, event), - bbAction: new BatteryBackup(hand, boolSide, move, event), - rAction: new Repeat(hand, boolSide, move, event), - rxAction: new RepeatX(hand, boolSide, move, event), - gAction: new Group(hand, boolSide, move, event, canGroup), - iAction: new Instruction(hand, boolSide, move, event), - hAction: new Hack(hand, boolSide, move, event), - varAction: new Variable(hand, boolSide, move, event), - vAction: new Virus(hand, boolSide, move, event, oV), - poAction: new PowerOutage(hand, boolSide, move, event, oPO), - dAction: new Discard(hand, boolSide, move, event) -} -let rSpy = sinon.spy(actionObject.rAction, 'execute') -let rxSpy = sinon.spy(actionObject.rxAction, 'execute') -let gSpy = sinon.spy(actionObject.gAction, 'execute') -let iSpy = sinon.spy(actionObject.iAction, 'execute') -let hSpy = sinon.spy(actionObject.hAction, 'execute') -let varSpy = sinon.spy(actionObject.varAction, 'execute') -let vSpy = sinon.spy(actionObject.vAction, 'execute') -let poSpy = sinon.spy(actionObject.poAction, 'execute') -let dSpy = sinon.spy(actionObject.dAction, 'execute') - -let handler = new Handler(oPO, oV, actionObject.avAction, actionObject.fwAction, actionObject.genAction, actionObject.ocAction, actionObject.bbAction, actionObject.gAction, - actionObject.vAction, actionObject.hAction, actionObject.poAction, actionObject.iAction, actionObject.rAction, actionObject.rxAction, actionObject.varAction, actionObject.dAction) - -describe('Protector', () => { - it('calls execute() correctly', () => { - store.state.activePlayer = 0 - store.state.players = [player, player2] - store.state.players[0].hasPowerOutage = true - expect(handler.getOpponentVirus().id).toEqual(oV.id) - expect(handler.getOpponentPO().id).toEqual(oPO.id) - expect(handler.getMove()).toEqual(undefined) - expect(handler.getCard()).toEqual(undefined) - expect(handler.getOpponent()).toEqual(undefined) - expect(handler.getStack()).toEqual(undefined) - }) - - // Original tests had VIRUS for last test. - // If handler.getCard().type is inspected after each other check - // The original tests they are all VIRUS and in this test all V. - // This makes me think the test is not really working so I am changing - // It to V for now and it should be re-written to properly test the - // card order in the AI players hand, Or the order they would play - // the cards? whatever the test was supposed to actually check. - // The Safety.spec.js tests might be a better example of how this could work - it('The ordering of cards is correct', () => { - handler.setAi('protector') - expect(gSpy.calledBefore(vSpy)) - expect(vSpy.calledBefore(poSpy)) - expect(poSpy.calledBefore(varSpy)) - expect(varSpy.calledBefore(rSpy)) - expect(rSpy.calledBefore(iSpy)) - expect(iSpy.calledBefore(rxSpy)) - expect(rxSpy.calledBefore(hSpy)) - expect(hSpy.calledBefore(dSpy)) - expect(dSpy.calledOnce) - expect(handler.getCard().type).toEqual('V') - }) -}) diff --git a/tests/unit/Safety.spec.js b/tests/unit/Safety.spec.js deleted file mode 100644 index f27ff7e8..00000000 --- a/tests/unit/Safety.spec.js +++ /dev/null @@ -1,149 +0,0 @@ -/* eslint-disable no-trailing-spaces */ -var sinon = require('sinon') -import {store} from '@/store/store' -import Card from '@/classes/Models/Card' -import Player from '@/classes/Models/Player' -import Stack from '@/classes/Models/Stack' -import Handler from '@/classes/AiActions/AiHandler' -import AiMove from '@/classes/AiActions/AiMove' -import AntiVirus from '@/classes/AiActions/AntiVirusStep' -import Firewall from '@/classes/AiActions/FirewallStep' -import Generator from '@/classes/AiActions/GeneratorStep' -import OverClock from '@/classes/AiActions/OverClockStep' -import BatteryBackup from '@/classes/AiActions/BatteryBackupStep' -import Repeat from '@/classes/AiActions/RepeatStep' -import RepeatX from '@/classes/AiActions/RepeatXStep' -import Group from '@/classes/AiActions/GroupStep' -import Instruction from '@/classes/AiActions/InstStep' -import Hack from '@/classes/AiActions/HackStep' -import Variable from '@/classes/AiActions/VarStep' -import Virus from '@/classes/AiActions/VirusStep' -import PowerOutage from '@/classes/AiActions/PowerOutageStep' -import Discard from '@/classes/AiActions/DiscardStep' - -let canGroup = false -let move = new AiMove() -let boolSide = true - -// INFO: Tests depend on this order -let defaultHand = {cards: [new Card(0, 0, 'FIREWALL'), new Card(1, 0, 'GENERATOR'), new Card(2, 0, 'ANTIVIRUS'), new Card(3, 0, 'OVERCLOCK'), new Card(4, 0, 'BATTERYBACKUP')]} -let hand = move.organizeHand({hand: defaultHand}) - -let event = {cards: hand, stack: [new Stack(0, true), new Stack(0, true), new Stack(1, true), new Stack(1, true)]} - -let player = new Player(0, 'aiTest', hand, 0, true) -let player2 = new Player(1, 'aiTest2', hand, 0, true) - -let oPO = player2 -let oV = player2 - -let avAction = new AntiVirus(hand, boolSide, move, event) -let fwAction = new Firewall(hand, boolSide, move, event) -let genAction = new Generator(hand, boolSide, move, event) -let ocAction = new OverClock(hand, boolSide, move, event) -let bbAction = new BatteryBackup(hand, boolSide, move, event) -let rAction = new Repeat(hand, boolSide, move, event) -let rxAction = new RepeatX(hand, boolSide, move, event) -let gAction = new Group(hand, boolSide, move, event, canGroup) -let iAction = new Instruction(hand, boolSide, move, event) -let hAction = new Hack(hand, boolSide, move, event) -let varAction = new Variable(hand, boolSide, move, event) -let vAction = new Virus(hand, boolSide, move, event, oV) -let poAction = new PowerOutage(hand, boolSide, move, event, oPO) -let dAction = new Discard(hand, boolSide, move, event) - -let avSpy = sinon.spy(avAction, 'execute') -let fwSpy = sinon.spy(fwAction, 'execute') -let genSpy = sinon.spy(genAction, 'execute') -let ocSpy = sinon.spy(ocAction, 'execute') -let bbSpy = sinon.spy(bbAction, 'execute') -let rSpy = sinon.spy(rAction, 'execute') -let rxSpy = sinon.spy(rxAction, 'execute') -let gSpy = sinon.spy(gAction, 'execute') -let iSpy = sinon.spy(iAction, 'execute') -let hSpy = sinon.spy(hAction, 'execute') -let varSpy = sinon.spy(varAction, 'execute') -let vSpy = sinon.spy(vAction, 'execute') -let poSpy = sinon.spy(poAction, 'execute') -let dSpy = sinon.spy(dAction, 'execute') - -let handler = new Handler(oPO, oV, avAction, fwAction, genAction, ocAction, bbAction, gAction, vAction, hAction, poAction, iAction, rAction, rxAction, varAction, dAction) - -describe('Safety cards', () => { - it('calls execute() correctly', () => { - store.state.activePlayer = 0 - store.state.players = [player, player2] - expect(handler.getOpponentVirus().id).toEqual(oV.id) - expect(handler.getOpponentPO().id).toEqual(oPO.id) - expect(handler.getMove()).toEqual(undefined) - expect(handler.getCard()).toEqual(undefined) - expect(handler.getOpponent()).toEqual(undefined) - expect(handler.getStack()).toEqual(undefined) - }) - it('Generator played first', () => { - handler.setAi('') - expect(genSpy.calledOnce) - expect(fwSpy.notCalled) - expect(bbSpy.notCalled) - expect(avSpy.notCalled) - expect(ocSpy.notCalled) - nonSafetyCards() - }) - it('Firewall played second', () => { - changeHand() - handler.setAi('') - expect(genSpy.calledBefore(fwSpy)) - expect(fwSpy.calledOnce) - expect(bbSpy.notCalled) - expect(avSpy.notCalled) - expect(ocSpy.notCalled) - nonSafetyCards() - }) - it('Battery Backup played third', () => { - changeHand() - handler.setAi('') - expect(genSpy.calledBefore(fwSpy)) - expect(fwSpy.calledBefore(bbSpy)) - expect(bbSpy.calledOnce) - expect(avSpy.notCalled) - nonSafetyCards() - }) - it('Antivirus played fourth', () => { - changeHand() - handler.setAi('') - expect(genSpy.calledBefore(fwSpy)) - expect(fwSpy.calledBefore(bbSpy)) - expect(bbSpy.calledBefore(avSpy)) - expect(avSpy.calledOnce) - expect(ocSpy.notCalled) - expect(ocSpy.notCalled) - nonSafetyCards() - }) - it('Overclock played fifth', () => { - changeHand() - handler.setAi('') - expect(genSpy.calledBefore(fwSpy)) - expect(fwSpy.calledBefore(bbSpy)) - expect(bbSpy.calledBefore(avSpy)) - expect(avSpy.calledBefore(ocSpy)) - expect(ocSpy.calledOnce) - nonSafetyCards() - }) - - function nonSafetyCards () { - expect(rSpy.notCalled) - expect(rxSpy.notCalled) - expect(gSpy.notCalled) - expect(iSpy.notCalled) - expect(hSpy.notCalled) - expect(varSpy.notCalled) - expect(vSpy.notCalled) - expect(poSpy.notCalled) - expect(dSpy.notCalled) - } - - function changeHand () { - defaultHand.cards.shift() - hand = move.organizeHand({hand: defaultHand}) - } -}) diff --git a/tests/unit/Sprinter.spec.js b/tests/unit/Sprinter.spec.js deleted file mode 100644 index e73ff7b1..00000000 --- a/tests/unit/Sprinter.spec.js +++ /dev/null @@ -1,103 +0,0 @@ -/* eslint-disable no-trailing-spaces */ -var sinon = require('sinon') -import {store} from '@/store/store' -import Card from '@/classes/Models/Card' -import Player from '@/classes/Models/Player' -import Stack from '@/classes/Models/Stack' -import Handler from '@/classes/AiActions/AiHandler' -import AiMove from '@/classes/AiActions/AiMove' -import AntiVirus from '@/classes/AiActions/AntiVirusStep' -import Firewall from '@/classes/AiActions/FirewallStep' -import Generator from '@/classes/AiActions/GeneratorStep' -import OverClock from '@/classes/AiActions/OverClockStep' -import BatteryBackup from '@/classes/AiActions/BatteryBackupStep' -import Repeat from '@/classes/AiActions/RepeatStep' -import RepeatX from '@/classes/AiActions/RepeatXStep' -import Group from '@/classes/AiActions/GroupStep' -import Instruction from '@/classes/AiActions/InstStep' -import Hack from '@/classes/AiActions/HackStep' -import Variable from '@/classes/AiActions/VarStep' -import Virus from '@/classes/AiActions/VirusStep' -import PowerOutage from '@/classes/AiActions/PowerOutageStep' -import Discard from '@/classes/AiActions/DiscardStep' - -let canGroup = false -let move = new AiMove() -let boolSide = true - -// INFO: Tests depend on this order -let defaultHand = {cards: [new Card(0, 0, 'V'), new Card(1, 0, 'R'), new Card(2, 0, 'R'), new Card(3, 0, 'I'), new Card(4, 0, 'H'), new Card(5, 0, 'VIRUS')]} -let hand = move.organizeHand({hand: defaultHand}) - -let player = new Player(0, 'aiTest', hand, 0, true) -let player2 = new Player(1, 'aiTest2', hand, 0, true) - -let event = {cards: hand, hand: defaultHand, stack: [new Stack(0, true), new Stack(0, true), new Stack(1, true), new Stack(1, true)], opponents: [player2]} - -let oPO = player2 -let oV = player2 - -let actionObject = { - avAction: new AntiVirus(hand, boolSide, move, event), - fwAction: new Firewall(hand, boolSide, move, event), - genAction: new Generator(hand, boolSide, move, event), - ocAction: new OverClock(hand, boolSide, move, event), - bbAction: new BatteryBackup(hand, boolSide, move, event), - rAction: new Repeat(hand, boolSide, move, event), - rxAction: new RepeatX(hand, boolSide, move, event), - gAction: new Group(hand, boolSide, move, event, canGroup), - iAction: new Instruction(hand, boolSide, move, event), - hAction: new Hack(hand, boolSide, move, event), - varAction: new Variable(hand, boolSide, move, event), - vAction: new Virus(hand, boolSide, move, event, oV), - poAction: new PowerOutage(hand, boolSide, move, event, oPO), - dAction: new Discard(hand, boolSide, move, event) -} -let rSpy = sinon.spy(actionObject.rAction, 'execute') -let rxSpy = sinon.spy(actionObject.rxAction, 'execute') -let gSpy = sinon.spy(actionObject.gAction, 'execute') -let iSpy = sinon.spy(actionObject.iAction, 'execute') -let hSpy = sinon.spy(actionObject.hAction, 'execute') -let varSpy = sinon.spy(actionObject.varAction, 'execute') -let vSpy = sinon.spy(actionObject.vAction, 'execute') -let poSpy = sinon.spy(actionObject.poAction, 'execute') -let dSpy = sinon.spy(actionObject.dAction, 'execute') - -let handler = new Handler(oPO, oV, actionObject.avAction, actionObject.fwAction, actionObject.genAction, actionObject.ocAction, actionObject.bbAction, actionObject.gAction, - actionObject.vAction, actionObject.hAction, actionObject.poAction, actionObject.iAction, actionObject.rAction, actionObject.rxAction, actionObject.varAction, actionObject.dAction) - -describe('Sprinter', () => { - it('calls execute() correctly', () => { - store.state.activePlayer = 0 - store.state.players = [player, player2] - store.state.players[0].hasPowerOutage = true - expect(handler.getOpponentVirus().id).toEqual(oV.id) - expect(handler.getOpponentPO().id).toEqual(oPO.id) - expect(handler.getMove()).toEqual(undefined) - expect(handler.getCard()).toEqual(undefined) - expect(handler.getOpponent()).toEqual(undefined) - expect(handler.getStack()).toEqual(undefined) - }) - - // Original tests had VIRUS for last test. - // If handler.getCard().type is inspected after each other check - // The original tests they are all VIRUS and in this test all V. - // This makes me think the test is not really working so I am changing - // It to V for now and it should be re-written to properly test the - // card order in the AI players hand, Or the order they would play - // the cards? whatever the test was supposed to actually check. - // The Safety.spec.js tests might be a better example of how this could work - it('The ordering of cards is correct', () => { - handler.setAi('sprinter') - expect(varSpy.calledBefore(rxSpy)) - expect(rxSpy.calledBefore(rSpy)) - expect(rSpy.calledBefore(iSpy)) - expect(iSpy.calledBefore(hSpy)) - expect(hSpy.calledBefore(vSpy)) - expect(vSpy.calledBefore(poSpy)) - expect(poSpy.calledBefore(gSpy)) - expect(gSpy.calledBefore(dSpy)) - expect(dSpy.calledOnce) - expect(handler.getCard().type).toEqual('V') - }) -}) diff --git a/tests/unit/Stacks.spec.js b/tests/unit/Stacks.spec.js index 92e5080d..104dc7ac 100644 --- a/tests/unit/Stacks.spec.js +++ b/tests/unit/Stacks.spec.js @@ -1,56 +1,62 @@ import Stack from '@/classes/Models/Stack' import Card from '@/classes/Models/Card' -let testStack = new Stack(1, true) -let testCard = new Card(2, 3, 'I') -let testGroup = new Card(3, 3, 'G') -let testRep = new Card(4, 3, 'R') -let testRep2 = new Card(4, 3, 'R') -let testRep3 = new Card(4, 3, 'R') +let stack +let instruction = new Card(2, 75, 'INSTRUCTION') +let group = new Card(3, 150, 'GROUP') +let repeat = new Card(4, 3, 'REPEAT') -describe('Stack.js', () => { - it('test player id in stack', () => { - expect(testStack.playerId).toEqual(1) - }) - - it('test bool side in stack', () => { - expect(testStack.boolSide).toEqual(true) - }) - it('test addCardToStack', () => { - testStack.addCardToStack(testCard) - expect(testStack.cards.length).toEqual(1) - }) - - it('test CalculateStackScore', () => { - testStack.calculateStackScore() - expect(testStack.score).toEqual(3) - testStack.addCardToStack(testGroup) - testStack.calculateStackScore() - expect(testStack.score).toEqual(6) - testStack.addCardToStack(testRep) - testStack.calculateStackScore() - expect(testStack.score).toEqual(18) - }) - - it('test StackTopCard', () => { - expect(testStack.stackTopCard()).toEqual(testRep) - }) - - it('test popTopCard', () => { - testStack.popTopCard() - expect(testStack.cards.length).toEqual(2) - }) - - it('test stackBottomCard', () => { - expect(testStack.stackBottomCard()).toEqual(testCard) - }) - it('test maxRepeats', () => { - testStack.calculateStackScore() - expect(testStack.maxRepeats()).toEqual(false) - testStack.addCardToStack(testRep) - testStack.addCardToStack(testRep2) - testStack.addCardToStack(testRep3) - expect(testStack.maxRepeats()).toEqual(true) +describe('Stack.js', () => { + beforeEach(() => { + stack = new Stack(1) + }) + test('constructor functions properly', () => { + expect(stack.playerId).toEqual(1) + expect(stack.id).not.toBeDefined() // uuid is random so just make sure it is set + }) + test('is empty true and false', () => { + expect(stack.isEmpty()).toBeTruthy() + stack.cards.push(instruction) + expect(stack.isEmpty()).toBeFalsy() + }) + test('get base card', () => { + stack.cards.push(instruction) + expect(stack.getBase()).toEqual(instruction) + }) + test('get top card', () => { + stack.cards.push(instruction) + stack.cards.push(repeat) + expect(stack.getTop()).toEqual(repeat) + }) + test('calculate correct score no repeats', () => { + expect(stack.getScore()).toEqual(0) + stack.cards.push(instruction) + expect(stack.getScore()).toEqual(75) + }) + test('calculate correct score with repeats', () => { + stack.cards.push(group) + stack.cards.push(repeat) + expect(stack.getScore()).toEqual(450) + stack.cards.push(repeat) + expect(stack.getScore()).toEqual(1350) + }) + test('maximum number of repeats (2)', () => { + stack.cards.push(instruction) + stack.cards.push(repeat) + expect(stack.hasMaxRepeats()).toBeFalsy() + stack.cards.push(repeat) + expect(stack.hasMaxRepeats()).toBeTruthy() + stack.cards.push(repeat) + expect(stack.hasMaxRepeats()).toBeTruthy() + }) + test('stack is hackable true', () => { + stack.cards.push(instruction) + expect(stack.isHackable()).toBeTruthy() + }) + test('stack is hackable false', () => { + expect(stack.isHackable()).toBeFalsy() + stack.cards.push(group) + expect(stack.isHackable()).toBeFalsy() }) }) diff --git a/tests/unit/TutorialDeck.spec.js b/tests/unit/TutorialDeck.spec.js deleted file mode 100644 index 9bd9ee02..00000000 --- a/tests/unit/TutorialDeck.spec.js +++ /dev/null @@ -1,321 +0,0 @@ -import TutorialDeck from '@/classes/Models/TutorialDeck' -// import Card from '@/classes/Card' - -describe('TutorialDeck.js', () => { - // test initial cards array length - it('test if the initial cards array is empty', () => { - let testDeck = new TutorialDeck() - expect(testDeck.cards.length).toEqual(0) - }) - - // test initial discard_cards array length - it('test if the initial discard_cards array is empty', () => { - let testDeck = new TutorialDeck() - expect(testDeck.discard_cards.length).toEqual(0) - }) - - // test initDeck function 1 player - it('test the initDeck function for number of cards', () => { - let testDeck = new TutorialDeck() - testDeck.initDeck(1) - expect(testDeck.cards.length).toEqual(33) - }) - - // test initDeck function 3 players - it('test the initDeck function for number of cards', () => { - let testDeck = new TutorialDeck() - testDeck.initDeck(3) - expect(testDeck.cards.length).toEqual(99) - }) - - // test the number of 'I' cards 1 player - it('test that initDeck is putting in the correct number of instruction cards', () => { - let testDeck = new TutorialDeck() - testDeck.initDeck(1) - let cardsArray = testDeck.cards - let instructionCounter = 0 - for (let idx of cardsArray) { - if (idx.type === 'I') { - instructionCounter++ - } - } - expect(instructionCounter).toEqual(12) - }) - - // test the number of 'I' cards 3 players - it('test that initDeck is putting in the correct number of instruction cards', () => { - let testDeck = new TutorialDeck() - testDeck.initDeck(3) - let cardsArray = testDeck.cards - let instructionCounter = 0 - for (let idx of cardsArray) { - if (idx.type === 'I') { - instructionCounter++ - } - } - expect(instructionCounter).toEqual(36) - }) - - // test the number of R cards 1 player - it('test that the number of R cards is correct', () => { - let testDeck = new TutorialDeck() - testDeck.initDeck(1) - let cardsArray = testDeck.cards - let repetitionCounter = 0 - for (let idx of cardsArray) { - if (idx.type === 'R') { - repetitionCounter++ - } - } - expect(repetitionCounter).toEqual(6) - }) - - // test the number of R cards 3 player - it('test that the number of R cards is correct', () => { - let testDeck = new TutorialDeck() - testDeck.initDeck(3) - let cardsArray = testDeck.cards - let repetitionCounter = 0 - for (let idx of cardsArray) { - if (idx.type === 'R') { - repetitionCounter++ - } - } - expect(repetitionCounter).toEqual(18) - }) - - // test the number of Rx cards 1 player - it('test the number of Rx cards in the deck', () => { - let testDeck = new TutorialDeck() - testDeck.initDeck(1) - let cardsArray = testDeck.cards - let rxCounter = 0 - for (let idx of cardsArray) { - if (idx.type === 'R' && idx.value === 1) { - rxCounter++ - } - } - expect(rxCounter).toEqual(1) - }) - - // test the number of Rx cards 3 players - it('test the number of Rx cards in the deck', () => { - let testDeck = new TutorialDeck() - testDeck.initDeck(3) - let cardsArray = testDeck.cards - let rxCounter = 0 - for (let idx of cardsArray) { - if (idx.type === 'R' && idx.value === 1) { - rxCounter++ - } - } - expect(rxCounter).toEqual(3) - }) - - // test the number of variable cards in the deck 1 player - it('test the number of Variable cards in the deck', () => { - let testDeck = new TutorialDeck() - testDeck.initDeck(1) - let cardsArray = testDeck.cards - let varCounter = 0 - for (let idx of cardsArray) { - if (idx.type === 'V') { - varCounter++ - } - } - expect(varCounter).toEqual(6) - }) - - // test the number of variable cards in the deck 3 players - it('test the number of Variable cards in the deck', () => { - let testDeck = new TutorialDeck() - testDeck.initDeck(3) - let cardsArray = testDeck.cards - let varCounter = 0 - for (let idx of cardsArray) { - if (idx.type === 'V') { - varCounter++ - } - } - expect(varCounter).toEqual(18) - }) - - // test the number of hack cards in the deck 1 player - it('test the number of hack cards in the deck', () => { - let testDeck = new TutorialDeck() - testDeck.initDeck(1) - let cardsArray = testDeck.cards - let hackCounter = 0 - for (let idx of cardsArray) { - if (idx.type === 'H') { - hackCounter++ - } - } - expect(hackCounter).toEqual(1) - }) - - // test the number of Virus cards in the deck 1 player - it('test the number of virus cards in the deck', () => { - let testDeck = new TutorialDeck() - testDeck.initDeck(1) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'VIRUS') { - counter++ - } - } - expect(counter).toEqual(1) - }) - - // test the number of Power Outage cards in the deck 1 player - it('test the number of power outage cards in the deck', () => { - let testDeck = new TutorialDeck() - testDeck.initDeck(1) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'POWEROUTAGE') { - counter++ - } - } - expect(counter).toEqual(1) - }) - - // PROTECTION CARDS - // test the number of AntiVirus cards in the deck 1 player - it('test the number of AntiVirus cards in the deck', () => { - let testDeck = new TutorialDeck() - testDeck.initDeck(1) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'ANTIVIRUS') { - counter++ - } - } - expect(counter).toEqual(1) - }) - - // test the number of Generator cards in the deck 1 player - it('test the number of Generator cards in the deck', () => { - let testDeck = new TutorialDeck() - testDeck.initDeck(1) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'GENERATOR') { - counter++ - } - } - expect(counter).toEqual(1) - }) - - // test the number of Firewall cards in the deck 1 player - it('test the number of Firewall cards in the deck', () => { - let testDeck = new TutorialDeck() - testDeck.initDeck(1) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'FIREWALL') { - counter++ - } - } - expect(counter).toEqual(1) - }) - - // test the number of hack cards in the deck 3 players - it('test the number of hack cards in the deck', () => { - let testDeck = new TutorialDeck() - testDeck.initDeck(3) - let cardsArray = testDeck.cards - let hackCounter = 0 - for (let idx of cardsArray) { - if (idx.type === 'H') { - hackCounter++ - } - } - expect(hackCounter).toEqual(3) - }) - - // test the number of Virus cards in the deck 3 player - it('test the number of virus cards in the deck', () => { - let testDeck = new TutorialDeck() - testDeck.initDeck(3) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'VIRUS') { - counter++ - } - } - expect(counter).toEqual(3) - }) - - // test the number of Power Outage cards in the deck 3 player - it('test the number of power outage cards in the deck', () => { - let testDeck = new TutorialDeck() - testDeck.initDeck(3) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'POWEROUTAGE') { - counter++ - } - } - expect(counter).toEqual(3) - }) - - // PROTECTION CARDS - // test the number of AntiVirus cards in the deck 3 player - it('test the number of AntiVirus cards in the deck', () => { - let testDeck = new TutorialDeck() - testDeck.initDeck(3) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'ANTIVIRUS') { - counter++ - } - } - expect(counter).toEqual(3) - }) - - // test the number of Generator cards in the deck 3 player - it('test the number of Generator cards in the deck', () => { - let testDeck = new TutorialDeck() - testDeck.initDeck(3) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'GENERATOR') { - counter++ - } - } - expect(counter).toEqual(3) - }) - - // test the number of Firewall cards in the deck 3 player - it('test the number of Firewall cards in the deck', () => { - let testDeck = new TutorialDeck() - testDeck.initDeck(3) - let cardsArray = testDeck.cards - let counter = 0 - for (let idx of cardsArray) { - if (idx.type === 'FIREWALL') { - counter++ - } - } - expect(counter).toEqual(3) - }) - - // test to see if the draw function draws the card from the top of the deck - it('test to see if the draw function works properly', () => { - let testDeck = new TutorialDeck() - testDeck.initDeck(1) - let drawnCard = testDeck.draw() - expect(testDeck.cards.length).toEqual(32) - expect(typeof drawnCard).toEqual('object') - }) -}) From 6a6cc2281ede3cd05d2fd97dece12d2bc9aecc05 Mon Sep 17 00:00:00 2001 From: strinsberg Date: Tue, 26 May 2020 09:52:22 -0600 Subject: [PATCH 02/92] Changed player effects to use set. Cleaned up vuex store and added new getters for things that neede a little computation only. Wrote tests for the new getters. --- src/classes/Models/Player.js | 16 ++-- src/store/getters.js | 148 ++++++----------------------------- src/store/store.js | 76 +++--------------- tests/unit/Getters.spec.js | 48 ++++++++++++ tests/unit/Player.spec.js | 15 ++-- 5 files changed, 97 insertions(+), 206 deletions(-) create mode 100644 tests/unit/Getters.spec.js diff --git a/src/classes/Models/Player.js b/src/classes/Models/Player.js index a79065a8..10e332c2 100755 --- a/src/classes/Models/Player.js +++ b/src/classes/Models/Player.js @@ -9,28 +9,30 @@ export default class Player { * @constructor Player * @param {int} id The ID of the Player * @param {string} name The name of the Player + * @param {bool} isAi if the player is a computer player */ - constructor (id, name) { + constructor (id, name, isAi) { this.id = id this.name = name - this.positiveEffects = [] - this.negativeEffects = [] + this.positiveEffects = new Set() + this.negativeEffects = new Set() this.cardsPlayed = [] + this.isAi = isAi } /** * Checks to see if the player has a positive effect. * @param {string} effect The effect to check for. */ - hasPositive (effect) { - return this.positiveEffects.find(e => e === effect) !== undefined + helpedBy (effect) { + return this.positiveEffects.has(effect) } /** * Check to see if a player has a negative effect. * @param {string} effect The effect to check for. */ - hasNegative (effect) { - return this.negativeEffects.find(e => e === effect) !== undefined + hurtBy (effect) { + return this.negativeEffects.has(effect) } } diff --git a/src/store/getters.js b/src/store/getters.js index 82358bdf..ba8c4e9c 100755 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -1,138 +1,34 @@ /** - * This file includes all of the getter functions from the store to avoid directly manipulating the store.state + * Includes getters for handy and non-trivial access to state members. + * For access to these members use mapState in components. */ export default { - /* getConditionsList (state) { - return state.conditionsList - }, */ + /** + * Returns the Hand object for the current player. + */ getCurrentPlayerHand (state) { - return Object.assign({}, state.hands.find(hand => hand.playerId === state.activePlayer)) - }, - getCurrentPlayerId (state) { - return state.activePlayer - }, - maxplayers (state) { - return state.players.length - }, - currentPlayerName (state) { - if (state.players.length) { return state.players.find(player => player.id === state.activePlayer).name } else { return '' } + return state.hands[state.activePlayerId] }, - getCurrentPlayerStacks (state) { - if (state.stacks.length) { return state.stacks.filter(st => st.playerId === state.activePlayer) } else { return } - }, - getActivePlayer (state) { - return state.activePlayer - }, - getActiveCard (state) { - return state.activeCard - }, - getStacks (state) { - return state.stacks - }, - getPlayers (state) { - return state.players - }, - getDiscard (state) { - return state.deck.discard_cards - }, - getIsDiscard (state) { - return state.isDiscard - }, - getIsHack (state) { - return state.isHack - }, - getAiTurn (state) { - return state.aiTurn - }, - getHackedPlayer (state) { - return state.hackedPlayer - }, - getCoinFlip (state) { - return state.coinFlip - }, - getHasPlayed (state) { - return state.activeHasPlayed - }, - getgameState (state) { - return state.currentGameState - }, - getSelectedStacks (state) { - let selectedStacks = [] - for (let stackId of state.selectedStacks) { - selectedStacks.push(state.stacks.find(stack => stack.stackId === stackId)) - } - return selectedStacks - }, - getSelectedStacksBoolean (state) { - return state.selectedStackBoolean - }, - getActiveSide (state) { - return state.activeSide - }, - getScoreLimit (state) { - return state.scoreLimit - }, - groupStacks (state) { - return state.groupStacks - }, - trueFalseAnim (state) { - return state.trueFalseAnim - }, - getWinner (state) { - return state.winner - }, - getWinnerName (state) { - return state.winnerName - }, - getWinnerScore (state) { - return state.winnerScore - }, - getTips (state) { - return state.tips - }, - getPlayerTurn (state) { - return state.playerTurn - }, + /** + * Returns the current players object. + */ getCurrentPlayer (state) { - return state.players[state.activePlayer] - }, - getFirstRound (state) { - return state.firstRound - }, - getAiDependent (state) { - let playerHand - let playerStack = [] - let opponentStack = [] - let currentPlayer = state.players[state.activePlayer] - for (let hand of state.hands) { - if (currentPlayer.hand === hand.handId) { - playerHand = hand - } - } - for (let stack of state.stacks) { - if (currentPlayer.id === stack.playerId) { - playerStack.push(stack) - } else { - opponentStack.push(stack) - } - } - return {hand: playerHand, stack: playerStack, opponents: opponentStack, player: currentPlayer, scoreLimit: state.scoreLimit} - }, - getCoinMsg (state) { - return state.coinMsg - }, - getTutorialState (state) { - return state.isTutorial + return state.players[state.activePlayerId] }, - getFactIndex (state) { - return state.factIndex - }, - getTutorialStep (state) { - return state.tutorialStep + + /** + * Return a list of the current player's stacks. + */ + getCurrentPlayerStacks (state) { + return state.stacks.filter(st => st.playerId === state.activePlayerId) }, - getTimerInterval (state) { - return state.timerInterval + + /** + * Get AI handler for the current player. + */ + getCurrentAiHandler (state) { + return state.aiHandlers.find(h => h.playerId === state.activePlayerId) } } diff --git a/src/store/store.js b/src/store/store.js index 4a19ecba..f00ff78d 100755 --- a/src/store/store.js +++ b/src/store/store.js @@ -7,84 +7,28 @@ import actions from './actions.js' import mutations from './mutations.js' import getters from './getters.js' import Deck from '../classes/Models/Deck' -import TutorialDeck from '../classes/Models/TutorialDeck.js' + /** - * The store holds all of the information that vuex will store and use. The functions are seperated into different files. - * @type {Store} + * Holds all game objects and state. */ export const store = new Vuex.Store({ state: { players: [], stacks: [], - deck: new Deck(), - tutorialDeck: new TutorialDeck(), - isTutorial: false, hands: [], - currentGameState: 'newGame', - displayObjModal: false, - activeSide: true, - activePlayer: 0, - activeHasPlayed: false, - currentId: 0, + aiHanlders: [], + objectives: [], + deck: new Deck(), + gameState: 'newGame', + activePlayerId: 0, activeCard: undefined, - selectedStacks: [], - selectedStackBoolean: undefined, - scoreLimit: 10, - groupStacks: false, - trueFalseAnim: false, - winner: false, - winnerName: '', - winnerScore: 0, - isLast: false, - tips: {tutorial: true}, - currentOpponents: [], - coinFlip: 0, - coinMsg: false, - playerTurn: false, - firstRound: true, - aiTurn: false, - trueSideColour: 'background-color: #80aef7; box-shadow: 0px 3px 15px rgba(0,0,0,0.6)', - falseSideColour: 'background-color: #80aef7; box-shadow: 0px 3px 15px rgba(0,0,0,0.6)', - mainBackgroundColour: 'background-color: #ffffff', - pIPBackgroundColour: 'background-color: #cccccc', - pIPTextColour: 'color: #000000; background-color: #cccccc', - mainTextColour: 'color: #000000; background-color: #ffffff', - playfieldTextColour: 'color: #ffffff', - isHack: false, - isVirus: false, - hackedPlayer: '', - isDiscard: false, - pointerEvent: 'pointer-events: none', - factIndex: 0, - tutorialStep: true, - tutorialOver: false, + scoreLimit: 5500, + tips: {tutorial: true, factIndex: 0}, + colorScheme: {}, timerInterval: undefined, - showBackstory: true/* , - conditionsList: [{condIf: '(more than 5 groups)', condThen: '{earn 10 points}', condElse: '{lose 5 points}', completed: false}, - {condIf: '(more than 5 repeats)', condThen: '{earn 10 points}', condElse: '{lose 5 points}', completed: false}, - {condIf: '(more than 3 players hacked)', condThen: '{earn 15 points}', condElse: '{lose 3 points}', completed: false}, - {condIf: '(no virus on PC)', condThen: '{earn 5 points}', condElse: '{lose 10 points}', completed: false}, - {condI: '(all safeties)', condThen: '{earn 50 points}', condElse: '{lose 5 points}', completed: false}] */ }, - originalState: { - players: [], - stacks: [], - deck: new Deck(), - tutorialDeck: new TutorialDeck(), - hands: [], - currentGameState: 'newGame', - activeSide: true, - activePlayer: 0, - activeHasPlayed: false, - currentId: 0, - activeCard: undefined, - selectedStacks: [], - selectedStackBoolean: undefined, - tutorialStep: true, - tutorialOver: false - }, getters, mutations, actions diff --git a/tests/unit/Getters.spec.js b/tests/unit/Getters.spec.js new file mode 100644 index 00000000..d0b773d7 --- /dev/null +++ b/tests/unit/Getters.spec.js @@ -0,0 +1,48 @@ +import getters from '@/store/getters.js' + +describe('vuex getters', () => { + const state = { + activePlayerId: 1, + players: [{id: 0}, {id: 1}], + stacks: [ + {stackId: 25, playerId: 1}, + {stackId: 26, playerId: 0}, + {stackId: 27, playerId: 1}, + {stackId: 28, playerId: 0}, + {stackId: 29, playerId: 1} + ], + hands: [{id: 300, playerId: 0}, {id: 301, playerId: 1}], + aiHandlers: [{id: 1000, playerId: 1}] + } + + test('get the current players hand', () => { + let hand = getters.getCurrentPlayerHand(state) + expect(hand.id).toEqual(301) + expect(hand.playerId).toEqual(1) + }) + test('get the current player', () => { + let player = getters.getCurrentPlayer(state) + expect(player.id).toEqual(1) + }) + test('get the current players stacks', () => { + let stacks = getters.getCurrentPlayerStacks(state) + expect(stacks.length).toEqual(3) + expect(stacks[0].stackId).toEqual(25) + expect(stacks[0].playerId).toEqual(1) + expect(stacks[1].stackId).toEqual(27) + expect(stacks[1].playerId).toEqual(1) + expect(stacks[2].stackId).toEqual(29) + expect(stacks[2].playerId).toEqual(1) + }) + test('get an ai handler associated with the current player', () => { + let handler = getters.getCurrentAiHandler(state) + expect(handler.id).toEqual(1000) + expect(handler.playerId).toEqual(1) + }) + test('get an ai handler when current player is not an AI', () => { + let localState = Object.assign({}, state) + localState.activePlayerId = 0 + let handler = getters.getCurrentAiHandler(localState) + expect(handler).toBeUndefined() + }) +}) diff --git a/tests/unit/Player.spec.js b/tests/unit/Player.spec.js index 57d59608..da6f4bd9 100644 --- a/tests/unit/Player.spec.js +++ b/tests/unit/Player.spec.js @@ -1,20 +1,21 @@ import Player from '@/classes/Models/Player' -let player = new Player(1, 'jeff') +let player = new Player(1, 'jeff', true) describe('Player.js', () => { test('constructor functions properly', () => { expect(player.id).toEqual(1) expect(player.name).toEqual('jeff') + expect(player.isAi).toBeTruthy() }) test('hasPositive', () => { - player.positiveEffects.push("BATTERYBACKUP") - expect(player.hasPositive("BATTERYBACKUP")).toBeTruthy() - expect(player.hasPositive("OVERCLOCK")).toBeFalsy() + player.positiveEffects.add("BATTERYBACKUP") + expect(player.helpedBy("BATTERYBACKUP")).toBeTruthy() + expect(player.helpedBy("OVERCLOCK")).toBeFalsy() }) test('hasNegative', () => { - player.negativeEffects.push("VIRUS") - expect(player.hasNegative("VIRUS")).toBeTruthy() - expect(player.hasNegative("POWEROUTAGE")).toBeFalsy() + player.negativeEffects.add("VIRUS") + expect(player.hurtBy("VIRUS")).toBeTruthy() + expect(player.hurtBy("POWEROUTAGE")).toBeFalsy() }) }) From 732d9e3339e11afdd1351804c57bcd1aedf7da94 Mon Sep 17 00:00:00 2001 From: strinsberg Date: Tue, 26 May 2020 10:54:11 -0600 Subject: [PATCH 03/92] Added getters to vuex and player to test for protection from effects and get all opponents that are attackable. --- src/classes/Models/Player.js | 16 ++++++++++++++++ src/store/getters.js | 10 ++++++++++ tests/unit/Getters.spec.js | 22 +++++++++++++++++++++- tests/unit/Player.spec.js | 29 ++++++++++++++++++++++++++--- 4 files changed, 73 insertions(+), 4 deletions(-) diff --git a/src/classes/Models/Player.js b/src/classes/Models/Player.js index 10e332c2..938c0ee1 100755 --- a/src/classes/Models/Player.js +++ b/src/classes/Models/Player.js @@ -35,4 +35,20 @@ export default class Player { hurtBy (effect) { return this.negativeEffects.has(effect) } + + /** + * Find out if a player is protected from an effect. + * @param {string} effect The effect to check. + * @return true if the player is protected, false otherwise. + */ + isProtectedFrom (effect) { + if (effect === "HACK") { + return this.helpedBy("FIREWALL") + } else if (effect === "POWEROUTAGE") { + return this.helpedBy("BATTERYBACKUP") || this.helpedBy("GENERATOR") + } else if (effect === "VIRUS") { + return this.helpedBy("ANTIVIRUS") + } + return false + } } diff --git a/src/store/getters.js b/src/store/getters.js index ba8c4e9c..d87cb905 100755 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -29,6 +29,16 @@ export default { */ getCurrentAiHandler (state) { return state.aiHandlers.find(h => h.playerId === state.activePlayerId) + }, + + /** + * Get attackable opponents given a card type. + * Not for Hacking. + */ + getAttackableOpponents (state, payload) { + return state.players.filter((p) => { + return p.id !== state.activePlayerId && !p.isProtectedFrom(payload.effect) + }) } } diff --git a/tests/unit/Getters.spec.js b/tests/unit/Getters.spec.js index d0b773d7..612b9a09 100644 --- a/tests/unit/Getters.spec.js +++ b/tests/unit/Getters.spec.js @@ -1,9 +1,19 @@ import getters from '@/store/getters.js' + describe('vuex getters', () => { + // Mock functions for players + const isProtected = jest.fn(e => true) + const isNotProtected = jest.fn(e => false) + + // Mock state const state = { activePlayerId: 1, - players: [{id: 0}, {id: 1}], + players: [ + {id: 0, isProtectedFrom: isProtected}, + {id: 1}, + {id: 2, isProtectedFrom: isNotProtected} + ], stacks: [ {stackId: 25, playerId: 1}, {stackId: 26, playerId: 0}, @@ -15,6 +25,7 @@ describe('vuex getters', () => { aiHandlers: [{id: 1000, playerId: 1}] } + test('get the current players hand', () => { let hand = getters.getCurrentPlayerHand(state) expect(hand.id).toEqual(301) @@ -45,4 +56,13 @@ describe('vuex getters', () => { let handler = getters.getCurrentAiHandler(localState) expect(handler).toBeUndefined() }) + test('get a list of players not that can be attacked with a card type', () => { + let opp = getters.getAttackableOpponents(state, {effect: "VIRUS"}) + expect(opp.length).toEqual(1) + expect(opp[0].id).toEqual(2) + expect(isProtected.mock.calls.length).toEqual(1) + expect(isNotProtected.mock.calls.length).toEqual(1) + expect(isProtected.mock.calls[0][0]).toEqual('VIRUS') + expect(isNotProtected.mock.calls[0][0]).toEqual('VIRUS') + }) }) diff --git a/tests/unit/Player.spec.js b/tests/unit/Player.spec.js index da6f4bd9..e2cdb98c 100644 --- a/tests/unit/Player.spec.js +++ b/tests/unit/Player.spec.js @@ -1,21 +1,44 @@ import Player from '@/classes/Models/Player' -let player = new Player(1, 'jeff', true) describe('Player.js', () => { + let player + beforeEach(() => { + player = new Player(1, 'jeff', true) + }) test('constructor functions properly', () => { expect(player.id).toEqual(1) expect(player.name).toEqual('jeff') expect(player.isAi).toBeTruthy() }) - test('hasPositive', () => { + test('if helped by effect true and false', () => { player.positiveEffects.add("BATTERYBACKUP") expect(player.helpedBy("BATTERYBACKUP")).toBeTruthy() expect(player.helpedBy("OVERCLOCK")).toBeFalsy() }) - test('hasNegative', () => { + test('if hurt by an effect true and false', () => { player.negativeEffects.add("VIRUS") expect(player.hurtBy("VIRUS")).toBeTruthy() expect(player.hurtBy("POWEROUTAGE")).toBeFalsy() }) + test('is protected from hacks true and false', () => { + expect(player.isProtectedFrom("HACK")).toBeFalsy() + player.positiveEffects.add("FIREWALL") + expect(player.isProtectedFrom("HACK")).toBeTruthy() + }) + test('is protected from power outages w/ battery true and false', () => { + expect(player.isProtectedFrom("POWEROUTAGE")).toBeFalsy() + player.positiveEffects.add("BATTERYBACKUP") + expect(player.isProtectedFrom("POWEROUTAGE")).toBeTruthy() + }) + test('is protected from power outages w/ generator true and false', () => { + expect(player.isProtectedFrom("POWEROUTAGE")).toBeFalsy() + player.positiveEffects.add("GENERATOR") + expect(player.isProtectedFrom("POWEROUTAGE")).toBeTruthy() + }) + test('is protected from viruses true and false', () => { + expect(player.isProtectedFrom("VIRUS")).toBeFalsy() + player.positiveEffects.add("ANTIVIRUS") + expect(player.isProtectedFrom("VIRUS")).toBeTruthy() + }) }) From 42381f084ff1a689924fd5f13c49fb42b22de585 Mon Sep 17 00:00:00 2001 From: strinsberg Date: Tue, 26 May 2020 11:13:39 -0600 Subject: [PATCH 04/92] Added getter to find all hackable players and tested it. --- src/store/getters.js | 13 +++++++++++++ tests/unit/Getters.spec.js | 32 ++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/store/getters.js b/src/store/getters.js index d87cb905..9ff1c2db 100755 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -39,6 +39,19 @@ export default { return state.players.filter((p) => { return p.id !== state.activePlayerId && !p.isProtectedFrom(payload.effect) }) + }, + + /** + * Get a list of hackable opponents. + */ + getHackableOpponents (state) { + return state.players.filter((p) => { + if (p.id === state.activePlayerId || p.isProtectedFrom('HACK')) { + return false + } + let stacks = state.stacks.filter(s => s.playerId === p.id && s.isHackable()) + return stacks.length > 0 + }) } } diff --git a/tests/unit/Getters.spec.js b/tests/unit/Getters.spec.js index 612b9a09..49f4f1e1 100644 --- a/tests/unit/Getters.spec.js +++ b/tests/unit/Getters.spec.js @@ -2,9 +2,11 @@ import getters from '@/store/getters.js' describe('vuex getters', () => { - // Mock functions for players + // Mock functions const isProtected = jest.fn(e => true) const isNotProtected = jest.fn(e => false) + const trueFn = jest.fn().mockReturnValue(true) + const falseFn = jest.fn().mockReturnValue(false) // Mock state const state = { @@ -12,14 +14,17 @@ describe('vuex getters', () => { players: [ {id: 0, isProtectedFrom: isProtected}, {id: 1}, - {id: 2, isProtectedFrom: isNotProtected} + {id: 2, isProtectedFrom: isNotProtected}, + {id: 3, isProtectedFrom: isNotProtected} ], stacks: [ - {stackId: 25, playerId: 1}, - {stackId: 26, playerId: 0}, - {stackId: 27, playerId: 1}, - {stackId: 28, playerId: 0}, - {stackId: 29, playerId: 1} + {stackId: 25, playerId: 1, isHackable: trueFn}, + {stackId: 26, playerId: 0, isHackable: trueFn}, + {stackId: 27, playerId: 1, isHackable: falseFn}, + {stackId: 28, playerId: 0, isHackable: falseFn}, + {stackId: 29, playerId: 1, isHackable: falseFn}, + {stackId: 30, playerId: 2, isHackable: falseFn}, + {stackId: 31, playerId: 3, isHackable: trueFn}, ], hands: [{id: 300, playerId: 0}, {id: 301, playerId: 1}], aiHandlers: [{id: 1000, playerId: 1}] @@ -56,13 +61,20 @@ describe('vuex getters', () => { let handler = getters.getCurrentAiHandler(localState) expect(handler).toBeUndefined() }) - test('get a list of players not that can be attacked with a card type', () => { + test('get a list of players that can be attacked with a card type', () => { let opp = getters.getAttackableOpponents(state, {effect: "VIRUS"}) - expect(opp.length).toEqual(1) + expect(opp.length).toEqual(2) expect(opp[0].id).toEqual(2) + expect(opp[1].id).toEqual(3) expect(isProtected.mock.calls.length).toEqual(1) - expect(isNotProtected.mock.calls.length).toEqual(1) + expect(isNotProtected.mock.calls.length).toEqual(2) expect(isProtected.mock.calls[0][0]).toEqual('VIRUS') expect(isNotProtected.mock.calls[0][0]).toEqual('VIRUS') + expect(isNotProtected.mock.calls[1][0]).toEqual('VIRUS') + }) + test('get a list of players that can be hacked', () => { + let opp = getters.getHackableOpponents(state) + expect(opp.length).toEqual(1) + expect(opp[0].id).toEqual(3) }) }) From d7b3ba3fd1ba77eeaf9e7a4415e15dcabe818abd Mon Sep 17 00:00:00 2001 From: strinsberg Date: Tue, 26 May 2020 11:19:32 -0600 Subject: [PATCH 05/92] Added a getter for the current players objectives and a test. --- src/store/getters.js | 7 +++++++ tests/unit/Getters.spec.js | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/store/getters.js b/src/store/getters.js index 9ff1c2db..f02ae7f4 100755 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -52,6 +52,13 @@ export default { let stacks = state.stacks.filter(s => s.playerId === p.id && s.isHackable()) return stacks.length > 0 }) + }, + + /** + * Get current players objectives. + */ + getCurrentPlayerObjectives (state) { + return state.objectives[state.activePlayerId] } } diff --git a/tests/unit/Getters.spec.js b/tests/unit/Getters.spec.js index 49f4f1e1..65e7818a 100644 --- a/tests/unit/Getters.spec.js +++ b/tests/unit/Getters.spec.js @@ -27,7 +27,8 @@ describe('vuex getters', () => { {stackId: 31, playerId: 3, isHackable: trueFn}, ], hands: [{id: 300, playerId: 0}, {id: 301, playerId: 1}], - aiHandlers: [{id: 1000, playerId: 1}] + aiHandlers: [{id: 1000, playerId: 1}], + objectives: [{playerId: 0}, {playerId: 1}] } @@ -77,4 +78,8 @@ describe('vuex getters', () => { expect(opp.length).toEqual(1) expect(opp[0].id).toEqual(3) }) + test('get an objectives obj associated with the current player', () => { + let objectives = getters.getCurrentPlayerObjectives(state) + expect(objectives.playerId).toEqual(1) + }) }) From 499f8d0182823117c805b6f08f1cf5a40ac24b76 Mon Sep 17 00:00:00 2001 From: strinsberg Date: Tue, 26 May 2020 11:43:51 -0600 Subject: [PATCH 06/92] Moved some things around and deleted everything that I know I don't need right now. I saved them somewhere else for reference. Probably a lot more will be removed or substantially changed, but I wanted to keep somethings to build off of. --- src/classes/AiActions/AiChain.js | 45 -- src/classes/AiActions/AiHandler.js | 96 --- src/classes/AiActions/AiMove.js | 198 ------ src/classes/AiActions/AntiVirusStep.js | 13 - src/classes/AiActions/BatteryBackupStep.js | 13 - src/classes/AiActions/DiscardStep.js | 9 - src/classes/AiActions/FirewallStep.js | 13 - src/classes/AiActions/GeneratorStep.js | 13 - src/classes/AiActions/GroupStep.js | 17 - src/classes/AiActions/HackStep.js | 14 - src/classes/AiActions/InstStep.js | 13 - src/classes/AiActions/OverClockStep.js | 13 - src/classes/AiActions/Personality.js | 59 -- src/classes/AiActions/PowerOutageStep.js | 19 - src/classes/AiActions/RepeatStep.js | 14 - src/classes/AiActions/RepeatXStep.js | 14 - src/classes/AiActions/VarStep.js | 14 - src/classes/AiActions/VirusStep.js | 19 - src/classes/Models/TutorialDeck.js | 115 ---- .../Modals/CardModals/HackDiscardMsg.vue | 65 -- .../Modals/CardModals/NoGroupingModal.vue | 32 - src/components/Modals/CoinModal.vue | 40 -- src/components/Modals/NoGroupingModal.vue | 32 - src/components/Modals/TutorialStartModal.vue | 53 -- .../SharedComponents/StatsPanel.vue | 42 -- src/components/Tutorial/TutorialComponent.vue | 455 ------------- .../Tutorial/TutorialPlayerInfoPanel.vue | 637 ------------------ .../{SharedComponents => game}/Card.vue | 0 .../CardWithOverlays.vue | 0 .../Conditionals.vue | 0 .../DisplayUsedCards.vue | 0 .../{MainGame => game}/MainComponent.vue | 0 .../OpponentStack.vue | 0 .../OpponentStacks.vue | 0 .../{MainGame => game}/PlayerInfoPanel.vue | 0 .../PlayerTurnPopUp.vue | 0 .../{SharedComponents => game}/Playfield.vue | 0 .../{SharedComponents => game}/Stack.vue | 0 .../SettingsComponent.vue | 0 .../{Modals => modals}/BackstoryModal.vue | 0 .../{Modals => modals}/CreditsModal.vue | 0 .../CardModals => modals}/HackModal.vue | 0 src/components/{Modals => modals}/Modal.vue | 0 .../{Modals => modals}/RulesModal.vue | 0 .../{Modals => modals}/ThemesModal.vue | 0 .../{Modals => modals}/WinnerModal.vue | 0 .../{SharedComponents => shared}/Bus.js | 0 .../{SharedComponents => shared}/Timer.vue | 0 src/store/actions.js | 95 +-- src/store/mutations.js | 509 +------------- src/store/store.js | 8 +- 51 files changed, 7 insertions(+), 2672 deletions(-) delete mode 100644 src/classes/AiActions/AiChain.js delete mode 100644 src/classes/AiActions/AiHandler.js delete mode 100644 src/classes/AiActions/AiMove.js delete mode 100644 src/classes/AiActions/AntiVirusStep.js delete mode 100644 src/classes/AiActions/BatteryBackupStep.js delete mode 100644 src/classes/AiActions/DiscardStep.js delete mode 100644 src/classes/AiActions/FirewallStep.js delete mode 100644 src/classes/AiActions/GeneratorStep.js delete mode 100644 src/classes/AiActions/GroupStep.js delete mode 100644 src/classes/AiActions/HackStep.js delete mode 100644 src/classes/AiActions/InstStep.js delete mode 100644 src/classes/AiActions/OverClockStep.js delete mode 100644 src/classes/AiActions/Personality.js delete mode 100644 src/classes/AiActions/PowerOutageStep.js delete mode 100644 src/classes/AiActions/RepeatStep.js delete mode 100644 src/classes/AiActions/RepeatXStep.js delete mode 100644 src/classes/AiActions/VarStep.js delete mode 100644 src/classes/AiActions/VirusStep.js delete mode 100644 src/classes/Models/TutorialDeck.js delete mode 100644 src/components/Modals/CardModals/HackDiscardMsg.vue delete mode 100644 src/components/Modals/CardModals/NoGroupingModal.vue delete mode 100644 src/components/Modals/CoinModal.vue delete mode 100644 src/components/Modals/NoGroupingModal.vue delete mode 100644 src/components/Modals/TutorialStartModal.vue delete mode 100644 src/components/SharedComponents/StatsPanel.vue delete mode 100644 src/components/Tutorial/TutorialComponent.vue delete mode 100644 src/components/Tutorial/TutorialPlayerInfoPanel.vue rename src/components/{SharedComponents => game}/Card.vue (100%) rename src/components/{SharedComponents => game}/CardWithOverlays.vue (100%) rename src/components/{SharedComponents => game}/Conditionals.vue (100%) rename src/components/{SharedComponents => game}/DisplayUsedCards.vue (100%) rename src/components/{MainGame => game}/MainComponent.vue (100%) rename src/components/{SharedComponents => game}/OpponentStack.vue (100%) rename src/components/{SharedComponents => game}/OpponentStacks.vue (100%) rename src/components/{MainGame => game}/PlayerInfoPanel.vue (100%) rename src/components/{SharedComponents => game}/PlayerTurnPopUp.vue (100%) rename src/components/{SharedComponents => game}/Playfield.vue (100%) rename src/components/{SharedComponents => game}/Stack.vue (100%) rename src/components/{SharedComponents => landingPage}/SettingsComponent.vue (100%) rename src/components/{Modals => modals}/BackstoryModal.vue (100%) rename src/components/{Modals => modals}/CreditsModal.vue (100%) rename src/components/{Modals/CardModals => modals}/HackModal.vue (100%) rename src/components/{Modals => modals}/Modal.vue (100%) rename src/components/{Modals => modals}/RulesModal.vue (100%) rename src/components/{Modals => modals}/ThemesModal.vue (100%) rename src/components/{Modals => modals}/WinnerModal.vue (100%) rename src/components/{SharedComponents => shared}/Bus.js (100%) rename src/components/{SharedComponents => shared}/Timer.vue (100%) diff --git a/src/classes/AiActions/AiChain.js b/src/classes/AiActions/AiChain.js deleted file mode 100644 index 37e2eb14..00000000 --- a/src/classes/AiActions/AiChain.js +++ /dev/null @@ -1,45 +0,0 @@ -/** - * This is the superclass of all of the Ai's possible moves - */ -export class Turn { - /** - * These assign the shared traits among all steps. - * @param hand - The Ai's hand - * @param boolSide - The current side to be played. - * @param move - the AiMove.js object - * @param event - JSON object to contain a lot of extra information inputted from the Personality.js object - */ - constructor (hand, boolSide, move, event) { - this.cardToPlay = undefined - this.stackToPlay = undefined - this.opponentToAttack = undefined - this.moveType = undefined - this.hand = hand - this.boolSide = boolSide - this.move = move - this.event = event - } - execute () { - // eslint-disable-next-line no-console - console.error('Execute not implemented') - } - getMove () { - return this.moveType - } - getStack () { - return this.stackToPlay - } - getCard () { - return this.cardToPlay - } - getOpponent () { - return this.opponentToAttack - } - setHand (h) { - this.hand = h - } - setEvent (e) { - this.event = e - } -} - diff --git a/src/classes/AiActions/AiHandler.js b/src/classes/AiActions/AiHandler.js deleted file mode 100644 index 10e7e359..00000000 --- a/src/classes/AiActions/AiHandler.js +++ /dev/null @@ -1,96 +0,0 @@ - -/** - * This is the handler for the chain of responsibility pattern. It handles running through all of the steps (or chains) - * that the Ai will execute. - */ -export default class Handler { - constructor (oPO, oV, aV, fW, gen, oC, bB, group, virus, hack, pO, inst, rep, repX, variable, disc) { - this.opponentPO = oPO - this.opponentVirus = oV - this.antiVirus = aV - this.firewall = fW - this.generator = gen - this.overclock = oC - this.batteryBackup = bB - this.group = group - this.virus = virus - this.hack = hack - this.powerOutage = pO - this.instruction = inst - this.repeat = rep - this.repeatX = repX - this.variable = variable - this.discard = disc - this.stackToPlay = undefined - this.cardToPlay = undefined - this.opponentToAttack = undefined - this.moveType = undefined - } - - /** - * This creates the order of operations for the ai steps and executes them until a step has been chosen. - * @param type The type of Ai. - */ - setAi (type) { - // Reversed order of importance to get correct behaviour from unshift - let safetyAndProtectMoves = [this.overclock, this.antiVirus, this.batteryBackup, this.firewall, this.generator] - - let cardPlayed = false - let moveList = [] - // These are the moves taken after the inital steps are taken, these differentiate the personalities - if (type === 'gambler') { - moveList = [this.variable, this.repeatX, this.repeat, this.instruction, this.hack, this.virus, this.powerOutage, this.group] - } else if (type === 'hacker') { - moveList = [this.hack, this.virus, this.powerOutage, this.variable, this.repeatX, this.repeat, this.instruction, this.group] - } else if (type === 'sprinter') { - moveList = [this.variable, this.repeatX, this.repeat, this.instruction, this.hack, this.virus, this.powerOutage, this.group] - } else if (type === 'protector') { - moveList = [this.group, this.virus, this.powerOutage, this.variable, this.repeat, this.instruction, this.repeatX, this.hack] - } - - // Add the saftey & protect moved to the start of the move list - for (let move in safetyAndProtectMoves) { - moveList.unshift(safetyAndProtectMoves[move]) - } - - for (let turn in moveList) { - if (typeof moveList[turn] !== 'undefined' && moveList[turn].execute()) { - this.stackToPlay = moveList[turn].getStack() - this.cardToPlay = moveList[turn].getCard() - this.opponentToAttack = moveList[turn].getOpponent() - this.moveType = moveList[turn].getMove() - cardPlayed = true - break - } - } - if (!cardPlayed && typeof this.discard !== 'undefined') { - this.discard.execute() - this.cardToPlay = this.discard.getCard() - this.moveType = this.discard.getMove() - } - } - - getMove () { - return this.moveType - } - - getStack () { - return this.stackToPlay - } - - getCard () { - return this.cardToPlay - } - - getOpponent () { - return this.opponentToAttack - } - - getOpponentPO () { - return this.opponentPO - } - - getOpponentVirus () { - return this.opponentVirus - } -} diff --git a/src/classes/AiActions/AiMove.js b/src/classes/AiActions/AiMove.js deleted file mode 100644 index 11728085..00000000 --- a/src/classes/AiActions/AiMove.js +++ /dev/null @@ -1,198 +0,0 @@ -import {store} from '../../store/store.js' - -export default class { - - getBoolSide () { - return store.getters.getCoinMsg - } - - organizeHand (event) { - let bestICard - let bestRCard - let rXCard - let hackCard - let bestVCard - let bestGCard = [] - let virusCard - let powerOutageCard - let batteryBackupCard - let overclockCard - let generatorCard - let antiVirusCard - let firewallCard - - for (let card of event.hand.cards) { - if (card.type === 'I') { - bestICard = this.findBestCard(card, bestICard) - } - if (card.type === 'R') { - if (card.value === 1) { - rXCard = card - } else { - bestRCard = this.findBestCard(card, bestRCard) - } - } - if (card.type === 'V') { - bestVCard = this.findBestCard(card, bestVCard) - } - if (card.type === 'G') { - bestGCard.push(card) - } - if (card.type === 'H') { - hackCard = card - } - if (card.type === 'VIRUS') { - virusCard = card - } - if (card.type === 'POWEROUTAGE') { - powerOutageCard = card - } - if (card.type === 'BATTERYBACKUP') { - batteryBackupCard = card - } - if (card.type === 'OVERCLOCK') { - overclockCard = card - } - if (card.type === 'FIREWALL') { - firewallCard = card - } - if (card.type === 'GENERATOR') { - generatorCard = card - } - if (card.type === 'ANTIVIRUS') { - antiVirusCard = card - } - } - return {bestICard, bestRCard, rXCard, hackCard, bestVCard, bestGCard, virusCard, powerOutageCard, batteryBackupCard, overclockCard, firewallCard, generatorCard, antiVirusCard} - } - - /** - * This allows us to find a stack to repeat. It checks if the top of each stack is a ReapeatX and if it is it won't try to repeat it, - * otherwise it will find a stack to repeat under the specified stack value. - * @param e - * @returns {*} - */ - getStackToRepeat (e) { - let stackToRepeat - let aRepeatCard = 'R' - let aRepeatX = 1 - let maxStackValue = 10 - if (e.stack !== undefined) { - for (let curStackValue = 1; curStackValue <= maxStackValue; curStackValue++) { - let tmpStack = e.stack.find(stack => stack.score === curStackValue && !stack.maxRepeats() && (stack.stackTopCard().type !== aRepeatCard || stack.stackTopCard().value !== aRepeatX)) - if (tmpStack !== undefined && tmpStack.boolSide === store.getters.getCoinMsg) { - stackToRepeat = tmpStack - } - } - } - return stackToRepeat - } - - stackToAddVariable (e) { - let stackToRepeat - for (let i = 1; i <= 25; i++) { - let tmpStack = e.stack.find(stack => stack.score === i && stack.stackTopCard().type === 'R' && stack.stackTopCard().value === 1) - - if (tmpStack !== undefined && tmpStack.cards[1].value === 1 && tmpStack.boolSide === store.getters.getCoinMsg) { - stackToRepeat = tmpStack - } - } - - return stackToRepeat - } - - getHackOpponent (event) { - let tmpOpponents = event.opponents.filter(opponents => opponents.score > 0 && opponents.cards[0].type !== 'G' && opponents.hasFirewall !== true) - let tmpScore = 0 - let opponentToAttack - for (let player of tmpOpponents) { - if (player.score > tmpScore && player.cards[0].type !== 'G') { - opponentToAttack = player - tmpScore = player.score - } - } - return opponentToAttack - } - - getOpponentToAttack (event, type) { - let tmpOpponents - if (type === 'POWEROUTAGE') { - tmpOpponents = store.getters.getPlayers.filter(player => player.hasGenerator !== true && player.hasPowerOutage !== true && - store.getters.getCurrentPlayer.id !== player.id) - } else if (type === 'VIRUS') { - tmpOpponents = store.getters.getPlayers.filter(player => player.hasAntiVirus !== true && player.hasVirus !== true && - store.getters.getCurrentPlayer.id !== player.id) - } - - let tmpScore = 0 - let opponentToAttack - if (tmpOpponents !== undefined) { - for (let player of tmpOpponents) { - if (player.instructions >= tmpScore) { - opponentToAttack = player - tmpScore = player.instructions - } - } - } - return opponentToAttack - } - - findBestCard (card, cardToBeat) { - if (cardToBeat !== undefined) { - if (card.value > cardToBeat.value) { - return card - } else { - return cardToBeat - } - } else { - return card - } - } - - compare (a, b) { - if (a.score < b.score || a.value < b.value) { return 1 } - if (a.score > b.score || a.value > b.value) { return -1 } - return 0 - } - - findGroup (stack, groupCard) { - stack = stack.sort(this.compare) - let tmpStack = [] - for (let i of stack) { - if (i.score > 0 && i.score < 6 && i.boolSide === store.getters.getCoinMsg) { - tmpStack.push(i) - } - } - groupCard = groupCard.sort(this.compare) - for (let card of groupCard) { - let lookingForStacks = this.findMatch(card.value, tmpStack) - if (lookingForStacks !== undefined) { - return {cardToPlay: card, stackToPlay: lookingForStacks} - } - } - return undefined - } - - findMatch (groupValue, groupStacks) { - let num = groupStacks.length - for (let j = 0; j < num; j++) { - let newValue = 0 - let tmpStack = [] - for (let i = 0; i < num; i++) { - if (newValue + groupStacks[i].score <= groupValue) { - newValue = newValue + groupStacks[i].score - tmpStack.push(groupStacks[i]) - if (newValue === groupValue) { - if (tmpStack.length === 1 && tmpStack[0].cards[0].type === 'G') { - return undefined - } else { - return tmpStack - } - } - } - } - num-- - } - return undefined - } -} diff --git a/src/classes/AiActions/AntiVirusStep.js b/src/classes/AiActions/AntiVirusStep.js deleted file mode 100644 index 421e3e69..00000000 --- a/src/classes/AiActions/AntiVirusStep.js +++ /dev/null @@ -1,13 +0,0 @@ -import {Turn} from './AiChain' -import {store} from '../../store/store' - -export default class AntiVirus extends Turn { - execute () { - if (this.hand.antiVirusCard !== undefined && !store.getters.getCurrentPlayer.hasAntiVirus) { - this.cardToPlay = this.hand.antiVirusCard - this.moveType = 'protection' - return true - } - } -} - diff --git a/src/classes/AiActions/BatteryBackupStep.js b/src/classes/AiActions/BatteryBackupStep.js deleted file mode 100644 index d40c17be..00000000 --- a/src/classes/AiActions/BatteryBackupStep.js +++ /dev/null @@ -1,13 +0,0 @@ -import {Turn} from './AiChain' -import {store} from '../../store/store' - -export default class BatteryBackup extends Turn { - execute () { - if (this.hand.batteryBackupCard !== undefined && store.getters.getCurrentPlayer.hasPowerOutage && !store.getters.getCurrentPlayer.hasGenerator) { - this.cardToPlay = this.hand.batteryBackupCard - this.moveType = 'enhance' - return true - } - } -} - diff --git a/src/classes/AiActions/DiscardStep.js b/src/classes/AiActions/DiscardStep.js deleted file mode 100644 index 1ece90d0..00000000 --- a/src/classes/AiActions/DiscardStep.js +++ /dev/null @@ -1,9 +0,0 @@ -import {Turn} from './AiChain' - -export default class Discard extends Turn { - execute () { - this.cardToPlay = this.event.hand.cards[0] - this.moveType = 'discard' - return true - } -} diff --git a/src/classes/AiActions/FirewallStep.js b/src/classes/AiActions/FirewallStep.js deleted file mode 100644 index ef9e0158..00000000 --- a/src/classes/AiActions/FirewallStep.js +++ /dev/null @@ -1,13 +0,0 @@ -import {Turn} from './AiChain' -import {store} from '../../store/store' - -export default class Firewall extends Turn { - execute () { - if (this.hand.firewallCard !== undefined && !store.getters.getCurrentPlayer.hasFirewall) { - this.cardToPlay = this.hand.firewallCard - this.moveType = 'protection' - return true - } - return false - } -} diff --git a/src/classes/AiActions/GeneratorStep.js b/src/classes/AiActions/GeneratorStep.js deleted file mode 100644 index 92521c88..00000000 --- a/src/classes/AiActions/GeneratorStep.js +++ /dev/null @@ -1,13 +0,0 @@ -import {Turn} from './AiChain' -import {store} from '../../store/store' - -export default class Generator extends Turn { - execute () { - if (this.hand.generatorCard !== undefined && !store.getters.getCurrentPlayer.hasGenerator) { - this.cardToPlay = this.hand.generatorCard - this.moveType = 'protection' - return true - } - return false - } -} diff --git a/src/classes/AiActions/GroupStep.js b/src/classes/AiActions/GroupStep.js deleted file mode 100644 index d015430b..00000000 --- a/src/classes/AiActions/GroupStep.js +++ /dev/null @@ -1,17 +0,0 @@ -import {Turn} from './AiChain' - -export default class Group extends Turn { - constructor (hand, boolSide, move, event, canGroup) { - super(hand, boolSide, move, event) - this.canGroup = canGroup - } - - execute () { - if (this.hand.bestGCard.length > 0 && this.canGroup !== undefined && this.event.stack.find(stack => stack.boolSide === this.boolSide)) { - this.cardToPlay = this.canGroup.cardToPlay - this.stackToPlay = this.canGroup.stackToPlay - this.moveType = 'group' - return true - } - } -} diff --git a/src/classes/AiActions/HackStep.js b/src/classes/AiActions/HackStep.js deleted file mode 100644 index c3a04310..00000000 --- a/src/classes/AiActions/HackStep.js +++ /dev/null @@ -1,14 +0,0 @@ -import {Turn} from './AiChain' - -export default class Hack extends Turn { - execute () { - if (this.hand.hackCard !== undefined && this.move.getHackOpponent(this.event) !== undefined && this.event.stack.find(stack => stack.boolSide === this.boolSide)) { - this.cardToPlay = this.hand.hackCard - this.opponentToAttack = this.move.getHackOpponent(this.event) - this.moveType = 'hack' - return true - } - return false - } -} - diff --git a/src/classes/AiActions/InstStep.js b/src/classes/AiActions/InstStep.js deleted file mode 100644 index 7a196e32..00000000 --- a/src/classes/AiActions/InstStep.js +++ /dev/null @@ -1,13 +0,0 @@ -import {Turn} from './AiChain' -import {store} from '../../store/store' - -export default class Instruction extends Turn { - execute () { - if (this.hand.bestICard !== undefined && !store.getters.getCurrentPlayer.hasPowerOutage) { - this.cardToPlay = this.hand.bestICard - this.stackToPlay = this.event.stack.find(stack => stack.boolSide === this.boolSide && stack.score === 0) - this.moveType = 'play' - return true - } - } -} diff --git a/src/classes/AiActions/OverClockStep.js b/src/classes/AiActions/OverClockStep.js deleted file mode 100644 index 994c9566..00000000 --- a/src/classes/AiActions/OverClockStep.js +++ /dev/null @@ -1,13 +0,0 @@ -import {Turn} from './AiChain' -import {store} from '../../store/store' - -export default class OverClock extends Turn { - execute () { - if (this.hand.overclockCard !== undefined && !store.getters.getCurrentPlayer.hasOverclock) { - this.cardToPlay = this.hand.overclockCard - this.moveType = 'enhance' - return true - } - } -} - diff --git a/src/classes/AiActions/Personality.js b/src/classes/AiActions/Personality.js deleted file mode 100644 index 48890ac4..00000000 --- a/src/classes/AiActions/Personality.js +++ /dev/null @@ -1,59 +0,0 @@ -import Handler from './AiHandler' -import Discard from './DiscardStep' -import Group from './GroupStep' -import RepeatX from './RepeatXStep' -import OverClock from './OverClockStep' -import Firewall from './FirewallStep' -import Variable from './VarStep' -import Generator from './GeneratorStep' -import Hack from './HackStep' -import AntiVirus from './AntiVirusStep' -import PowerOutage from './PowerOutageStep' -import Repeat from './RepeatStep' -import Virus from './VirusStep' -import BatteryBackup from './BatteryBackupStep' -import Instruction from './InstStep' -import {store} from '../../store/store' -import AiMove from './AiMove' - -/** - * This class picks at random one of the Ai personalities to use. - */ -export default class Personality { - - constructor () { - this.num = Math.floor((Math.random() * 4) + 1) - } - - turnLogic (event) { - let move = new AiMove() - let opponentPO = move.getOpponentToAttack(event, 'POWEROUTAGE') - let opponentVirus = move.getOpponentToAttack(event, 'VIRUS') - let hand = move.organizeHand(event) - let boolSide = store.getters.getCoinMsg - let canGroup = move.findGroup(event.stack, hand.bestGCard) - let antiVirus = new AntiVirus(hand, boolSide, move, event) - let firewall = new Firewall(hand, boolSide, move, event) - let generator = new Generator(hand, boolSide, move, event) - let overclock = new OverClock(hand, boolSide, move, event) - let batteryBackup = new BatteryBackup(hand, boolSide, move, event) - let group = new Group(hand, boolSide, move, event, canGroup) - let virus = new Virus(hand, boolSide, move, event, opponentVirus) - let hack = new Hack(hand, boolSide, move, event) - let powerOutage = new PowerOutage(hand, boolSide, move, event, opponentPO) - let instruction = new Instruction(hand, boolSide, move, event) - let repeat = new Repeat(hand, boolSide, move, event) - let repeatX = new RepeatX(hand, boolSide, move, event) - let variable = new Variable(hand, boolSide, move, event) - let discard = new Discard(hand, boolSide, move, event) - let personality = new Handler(opponentPO, opponentVirus, antiVirus, firewall, generator, overclock, batteryBackup, - group, virus, hack, powerOutage, instruction, repeat, repeatX, variable, discard) - switch (this.num) { - case 1: personality.setAi('sprinter'); break - case 2: personality.setAi('hacker'); break - case 3: personality.setAi('gambler'); break - case 4: personality.setAi('protector'); break - } - return personality - } -} diff --git a/src/classes/AiActions/PowerOutageStep.js b/src/classes/AiActions/PowerOutageStep.js deleted file mode 100644 index d2f66ff5..00000000 --- a/src/classes/AiActions/PowerOutageStep.js +++ /dev/null @@ -1,19 +0,0 @@ -import {Turn} from './AiChain' - -export default class PowerOutage extends Turn { - constructor (hand, boolSide, move, event, opponentPO) { - super(hand, boolSide, move, event) - this.opponentPO = opponentPO - } - - execute () { - if (this.hand.powerOutageCard !== undefined && this.opponentPO !== undefined) { - this.opponentToAttack = this.move.getOpponentToAttack(this.event, 'POWEROUTAGE') - this.cardToPlay = this.hand.powerOutageCard - this.moveType = 'po' - return true - } - return false - } -} - diff --git a/src/classes/AiActions/RepeatStep.js b/src/classes/AiActions/RepeatStep.js deleted file mode 100644 index 83e58eb5..00000000 --- a/src/classes/AiActions/RepeatStep.js +++ /dev/null @@ -1,14 +0,0 @@ -import {Turn} from './AiChain' - -export default class Repeat extends Turn { - execute () { - if (this.hand.bestRCard !== undefined && this.move.getStackToRepeat(this.event) !== undefined && this.event.stack.find(stack => stack.boolSide === this.boolSide)) { - this.cardToPlay = this.hand.bestRCard - this.stackToPlay = this.move.getStackToRepeat(this.event) - this.moveType = 'play' - return true - } - return false - } -} - diff --git a/src/classes/AiActions/RepeatXStep.js b/src/classes/AiActions/RepeatXStep.js deleted file mode 100644 index 063b91d0..00000000 --- a/src/classes/AiActions/RepeatXStep.js +++ /dev/null @@ -1,14 +0,0 @@ -import {Turn} from './AiChain' - -export default class RepeatX extends Turn { - execute () { - if (this.hand.rXCard !== undefined && this.move.getStackToRepeat(this.event) !== undefined && this.event.stack.find(stack => stack.boolSide === this.boolSide)) { - this.cardToPlay = this.hand.rXCard - this.stackToPlay = this.move.getStackToRepeat(this.event) - this.moveType = 'play' - return true - } - return false - } -} - diff --git a/src/classes/AiActions/VarStep.js b/src/classes/AiActions/VarStep.js deleted file mode 100644 index 59442998..00000000 --- a/src/classes/AiActions/VarStep.js +++ /dev/null @@ -1,14 +0,0 @@ -import {Turn} from './AiChain' - -export default class Variable extends Turn { - execute () { - if (this.hand.bestVCard !== undefined && this.move.stackToAddVariable(this.event) !== undefined && this.event.stack.find(stack => stack.boolSide === this.boolSide)) { - this.cardToPlay = this.hand.bestVCard - this.stackToPlay = this.move.stackToAddVariable(this.event) - this.moveType = 'play' - return true - } - return false - } -} - diff --git a/src/classes/AiActions/VirusStep.js b/src/classes/AiActions/VirusStep.js deleted file mode 100644 index 97ba955b..00000000 --- a/src/classes/AiActions/VirusStep.js +++ /dev/null @@ -1,19 +0,0 @@ -import {Turn} from './AiChain' -import {store} from '../../store/store' - -export default class Virus extends Turn { - constructor (hand, boolSide, move, event, opponentVirus) { - super(hand, boolSide, move, event) - this.opponentVirus = opponentVirus - } - - execute () { - if (this.hand.virusCard !== undefined && !store.getters.getFirstRound && this.opponentVirus !== undefined) { - this.opponentToAttack = this.move.getOpponentToAttack(this.event, 'VIRUS') - this.cardToPlay = this.hand.virusCard - this.moveType = 'virus' - return true - } - } -} - diff --git a/src/classes/Models/TutorialDeck.js b/src/classes/Models/TutorialDeck.js deleted file mode 100644 index 1fb94e14..00000000 --- a/src/classes/Models/TutorialDeck.js +++ /dev/null @@ -1,115 +0,0 @@ -/** - * @file TutorialDeck.js file - * @author Jace Riehl on 2018-05-08. - */ -import Card from './Card' - -const instruction1 = 7 -const instruction2 = 7 -const instruction3 = 7 - -const group2 = 1 -const group3 = 2 - -const repetition2 = 4 -const repetition3 = 4 -const repetition4 = 0 -const repetitionX = 5 - -const variable3 = 4 -const variable4 = 3 -const variable5 = 3 -const variable6 = 1 - -const hack = 3 -const malware = 3 -const powerOutage = 3 - -const overClock = 3 - -const antiVirus = 1 -const firewall = 1 -const generator = 1 - -// WARNING: Do not change order of cards. -const cardDeck = [ - {type: 'I', cardValue: 1, imgSrc: '/static/cardImg/Instruction1.png', howMany: instruction1}, - {type: 'I', cardValue: 3, imgSrc: '/static/cardImg/Instruction3.png', howMany: instruction3}, - {type: 'I', cardValue: 2, imgSrc: '/static/cardImg/Instruction2.png', howMany: instruction2}, - {type: 'R', cardValue: 1, imgSrc: '/static/cardImg/RepetitionX.png', howMany: repetitionX}, - {type: 'G', cardValue: 3, imgSrc: '/static/cardImg/Group3.png', howMany: group3}, - - {type: 'V', cardValue: 3, imgSrc: '/static/cardImg/Variable3.png', howMany: variable3}, - {type: 'I', cardValue: 2, imgSrc: '/static/cardImg/Instruction2.png', howMany: instruction2}, - {type: 'I', cardValue: 2, imgSrc: '/static/cardImg/Instruction2.png', howMany: instruction2}, - {type: 'R', cardValue: 2, imgSrc: '/static/cardImg/Repetition2.png', howMany: repetition2}, - {type: 'G', cardValue: 2, imgSrc: '/static/cardImg/Group2.png', howMany: group2}, - - {type: 'V', cardValue: 5, imgSrc: '/static/cardImg/Variable5.png', howMany: variable5}, - {type: 'R', cardValue: 4, imgSrc: '/static/cardImg/Repetition4.png', howMany: repetition4}, - {type: 'I', cardValue: 3, imgSrc: '/static/cardImg/Instruction3.png', howMany: instruction3}, - - {type: 'R', cardValue: 2, imgSrc: '/static/cardImg/Repetition2.png', howMany: repetition2}, - {type: 'R', cardValue: 3, imgSrc: '/static/cardImg/Repetition3.png', howMany: repetition3}, - - {type: 'R', cardValue: 3, imgSrc: '/static/cardImg/Repetition3.png', howMany: repetition3}, - - {type: 'V', cardValue: 4, imgSrc: '/static/cardImg/Variable4.png', howMany: variable4}, - {type: 'V', cardValue: 6, imgSrc: '/static/cardImg/Variable6.png', howMany: variable6}, - - {type: 'OVERCLOCK', cardValue: 0, imgSrc: '/static/cardImg/OverClock.png', howMany: overClock}, - {type: 'I', cardValue: 1, imgSrc: '/static/cardImg/Instruction1.png', howMany: instruction1}, - {type: 'GENERATOR', cardValue: 0, imgSrc: '/static/cardImg/Generator.png', howMany: generator}, - {type: 'I', cardValue: 1, imgSrc: '/static/cardImg/Instruction1.png', howMany: instruction1}, - {type: 'POWEROUTAGE', cardValue: 0, imgSrc: '/static/cardImg/PowerOutage.png', howMany: powerOutage}, - {type: 'I', cardValue: 1, imgSrc: '/static/cardImg/Instruction1.png', howMany: instruction1}, - {type: 'ANTIVIRUS', cardValue: 0, imgSrc: '/static/cardImg/AntiVirus.png', howMany: antiVirus}, - {type: 'I', cardValue: 1, imgSrc: '/static/cardImg/Instruction1.png', howMany: instruction1}, - {type: 'VIRUS', cardValue: 0, imgSrc: '/static/cardImg/Malware.png', howMany: malware}, - {type: 'I', cardValue: 1, imgSrc: '/static/cardImg/Instruction1.png', howMany: instruction1}, - {type: 'FIREWALL', cardValue: 0, imgSrc: '/static/cardImg/Firewall.png', howMany: firewall}, - {type: 'I', cardValue: 1, imgSrc: '/static/cardImg/Instruction1.png', howMany: instruction1}, - {type: 'H', cardValue: 0, imgSrc: '/static/cardImg/Hacker.png', howMany: hack}, - {type: 'V', cardValue: 3, imgSrc: '/static/cardImg/Variable3.png', howMany: variable3}, - {type: 'V', cardValue: 5, imgSrc: '/static/cardImg/Variable5.png', howMany: variable5} -] - -/** - * This is the object repesentaiton of the tutorial's deck - */ -export default class TutorialDeck { - /** - * The constructor for the Deck class - * @constructor Deck - */ - constructor () { - this.cards = [] - this.discard_cards = [] - } - - /** - * initDeck function to initialize the deck with a pre determined number and type of cards - * @memberOf Deck - */ - initDeck (value) { - let cardId = 0 - for (let k = 0; k < value; k++) { - for (let i = 0; i < cardDeck.length; i++) { - this.cards.push(new Card(cardId, cardDeck[i].cardValue, cardDeck[i].type, cardDeck[i].imgSrc)) - cardId++ - } - } - }// end Init game - - /** - * draw function returns the card at the front (top) of the deck and removes it from the deck - * @memberOf Deck - * @returns {Card} - */ - draw () { - let card = this.cards[0]// [0] is the top of the deck - this.cards.shift()// unshift removes the first element. - return card - } - -} diff --git a/src/components/Modals/CardModals/HackDiscardMsg.vue b/src/components/Modals/CardModals/HackDiscardMsg.vue deleted file mode 100644 index bc3faa38..00000000 --- a/src/components/Modals/CardModals/HackDiscardMsg.vue +++ /dev/null @@ -1,65 +0,0 @@ - - - - - diff --git a/src/components/Modals/CardModals/NoGroupingModal.vue b/src/components/Modals/CardModals/NoGroupingModal.vue deleted file mode 100644 index edde534d..00000000 --- a/src/components/Modals/CardModals/NoGroupingModal.vue +++ /dev/null @@ -1,32 +0,0 @@ - - - diff --git a/src/components/Modals/CoinModal.vue b/src/components/Modals/CoinModal.vue deleted file mode 100644 index 97957bc1..00000000 --- a/src/components/Modals/CoinModal.vue +++ /dev/null @@ -1,40 +0,0 @@ - - - - - diff --git a/src/components/Modals/NoGroupingModal.vue b/src/components/Modals/NoGroupingModal.vue deleted file mode 100644 index edde534d..00000000 --- a/src/components/Modals/NoGroupingModal.vue +++ /dev/null @@ -1,32 +0,0 @@ - - - diff --git a/src/components/Modals/TutorialStartModal.vue b/src/components/Modals/TutorialStartModal.vue deleted file mode 100644 index d74d492a..00000000 --- a/src/components/Modals/TutorialStartModal.vue +++ /dev/null @@ -1,53 +0,0 @@ - - - - diff --git a/src/components/SharedComponents/StatsPanel.vue b/src/components/SharedComponents/StatsPanel.vue deleted file mode 100644 index d666fe0b..00000000 --- a/src/components/SharedComponents/StatsPanel.vue +++ /dev/null @@ -1,42 +0,0 @@ - - - - - diff --git a/src/components/Tutorial/TutorialComponent.vue b/src/components/Tutorial/TutorialComponent.vue deleted file mode 100644 index a56ac4a9..00000000 --- a/src/components/Tutorial/TutorialComponent.vue +++ /dev/null @@ -1,455 +0,0 @@ - - - - - - diff --git a/src/components/Tutorial/TutorialPlayerInfoPanel.vue b/src/components/Tutorial/TutorialPlayerInfoPanel.vue deleted file mode 100644 index 0517c3ca..00000000 --- a/src/components/Tutorial/TutorialPlayerInfoPanel.vue +++ /dev/null @@ -1,637 +0,0 @@ - - - - - - diff --git a/src/components/SharedComponents/Card.vue b/src/components/game/Card.vue similarity index 100% rename from src/components/SharedComponents/Card.vue rename to src/components/game/Card.vue diff --git a/src/components/SharedComponents/CardWithOverlays.vue b/src/components/game/CardWithOverlays.vue similarity index 100% rename from src/components/SharedComponents/CardWithOverlays.vue rename to src/components/game/CardWithOverlays.vue diff --git a/src/components/SharedComponents/Conditionals.vue b/src/components/game/Conditionals.vue similarity index 100% rename from src/components/SharedComponents/Conditionals.vue rename to src/components/game/Conditionals.vue diff --git a/src/components/SharedComponents/DisplayUsedCards.vue b/src/components/game/DisplayUsedCards.vue similarity index 100% rename from src/components/SharedComponents/DisplayUsedCards.vue rename to src/components/game/DisplayUsedCards.vue diff --git a/src/components/MainGame/MainComponent.vue b/src/components/game/MainComponent.vue similarity index 100% rename from src/components/MainGame/MainComponent.vue rename to src/components/game/MainComponent.vue diff --git a/src/components/SharedComponents/OpponentStack.vue b/src/components/game/OpponentStack.vue similarity index 100% rename from src/components/SharedComponents/OpponentStack.vue rename to src/components/game/OpponentStack.vue diff --git a/src/components/SharedComponents/OpponentStacks.vue b/src/components/game/OpponentStacks.vue similarity index 100% rename from src/components/SharedComponents/OpponentStacks.vue rename to src/components/game/OpponentStacks.vue diff --git a/src/components/MainGame/PlayerInfoPanel.vue b/src/components/game/PlayerInfoPanel.vue similarity index 100% rename from src/components/MainGame/PlayerInfoPanel.vue rename to src/components/game/PlayerInfoPanel.vue diff --git a/src/components/SharedComponents/PlayerTurnPopUp.vue b/src/components/game/PlayerTurnPopUp.vue similarity index 100% rename from src/components/SharedComponents/PlayerTurnPopUp.vue rename to src/components/game/PlayerTurnPopUp.vue diff --git a/src/components/SharedComponents/Playfield.vue b/src/components/game/Playfield.vue similarity index 100% rename from src/components/SharedComponents/Playfield.vue rename to src/components/game/Playfield.vue diff --git a/src/components/SharedComponents/Stack.vue b/src/components/game/Stack.vue similarity index 100% rename from src/components/SharedComponents/Stack.vue rename to src/components/game/Stack.vue diff --git a/src/components/SharedComponents/SettingsComponent.vue b/src/components/landingPage/SettingsComponent.vue similarity index 100% rename from src/components/SharedComponents/SettingsComponent.vue rename to src/components/landingPage/SettingsComponent.vue diff --git a/src/components/Modals/BackstoryModal.vue b/src/components/modals/BackstoryModal.vue similarity index 100% rename from src/components/Modals/BackstoryModal.vue rename to src/components/modals/BackstoryModal.vue diff --git a/src/components/Modals/CreditsModal.vue b/src/components/modals/CreditsModal.vue similarity index 100% rename from src/components/Modals/CreditsModal.vue rename to src/components/modals/CreditsModal.vue diff --git a/src/components/Modals/CardModals/HackModal.vue b/src/components/modals/HackModal.vue similarity index 100% rename from src/components/Modals/CardModals/HackModal.vue rename to src/components/modals/HackModal.vue diff --git a/src/components/Modals/Modal.vue b/src/components/modals/Modal.vue similarity index 100% rename from src/components/Modals/Modal.vue rename to src/components/modals/Modal.vue diff --git a/src/components/Modals/RulesModal.vue b/src/components/modals/RulesModal.vue similarity index 100% rename from src/components/Modals/RulesModal.vue rename to src/components/modals/RulesModal.vue diff --git a/src/components/Modals/ThemesModal.vue b/src/components/modals/ThemesModal.vue similarity index 100% rename from src/components/Modals/ThemesModal.vue rename to src/components/modals/ThemesModal.vue diff --git a/src/components/Modals/WinnerModal.vue b/src/components/modals/WinnerModal.vue similarity index 100% rename from src/components/Modals/WinnerModal.vue rename to src/components/modals/WinnerModal.vue diff --git a/src/components/SharedComponents/Bus.js b/src/components/shared/Bus.js similarity index 100% rename from src/components/SharedComponents/Bus.js rename to src/components/shared/Bus.js diff --git a/src/components/SharedComponents/Timer.vue b/src/components/shared/Timer.vue similarity index 100% rename from src/components/SharedComponents/Timer.vue rename to src/components/shared/Timer.vue diff --git a/src/store/actions.js b/src/store/actions.js index 75e44411..5fdb56a5 100755 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -1,96 +1,5 @@ -let playerModalTimer = 2// sec -let endTurnTimer = 1.5// sec -let coinTimer = 2// sec -let runTimer = 1// sec +import { bus } from '@/components/SharedComponents/Bus' -export default { - playerTookTurn (context) { - context.commit('removeActiveCardFromHand') - context.commit('setHasPlayed', {hasPlayed: true}) - context.commit('setPlayerScores') - }, - - firstRound (context) { - context.commit('playerModalTrigger') - if (!context.state.isTutorial) { context.dispatch('coinAnimation') } - setTimeout(() => { - context.commit('playerModalHide') - context.state.pointerEvent = '' - }, playerModalTimer * 1000) - setTimeout(() => { - if (context.getters.getCurrentPlayer.isAi) { - context.commit('aiTakeTurn', context.getters.getAiDependent) - } - }, 2500) - }, - coinAnimation (context) { - context.commit('coinModalTrigger') - context.commit('setCoinFlipAnim', 0) - context.commit('setPlayfieldColour', true) - context.state.coinMsg = !!context.state.activeSide - setTimeout(() => { context.commit('setCoinFlipAnim', 1) }, 200) - setTimeout(() => { - $('.coin').modal('handleUpdate') - $('.coin').modal('hide') - }, coinTimer * 600) - }, - - turn (context, payload) { - context.commit('getIsLast') - context.state.pointerEvent = 'pointer-events: none' - switch (payload) { - case true: - if (context.state.isLast) { - setTimeout(() => { - context.commit('setHasPlayed', {hasPlayed: false}) - context.commit('endTurn', context.state.players.length) - context.commit('setGameState', {gameState: 'startPlayerTurn'}) - return '' - }, endTurnTimer * 1000) - } else { - setTimeout(() => { - context.commit('setHasPlayed', {hasPlayed: false}) - context.commit('endTurn', context.state.players.length) - context.commit('setGameState', {gameState: 'startPlayerTurn'}) - /* context.commit('playerModalTrigger') - setTimeout(() => { - context.commit('playerModalHide') - }, playerModalTimer * 1000) */ - }, endTurnTimer * 1000) - setTimeout(() => { - if (context.getters.getCurrentPlayer.isAi) { - context.commit('aiTakeTurn', context.getters.getAiDependent) - } - }, 4000) - } - context.state.pointerEvent = '' - break - case false: - context.commit('checkWin') - if (!context.state.winner) { - context.dispatch('coinAnimation') - } - if (context.state.winner) { - setTimeout(() => { - context.commit('winnerModalTrigger') - return '' - }, coinTimer * 1000 + 350) - } else if (!(context.state.winner)) { - setTimeout(() => { - context.commit('playerModalTrigger') - setTimeout(() => { - context.commit('playerModalHide') - context.state.pointerEvent = '' - }, playerModalTimer * 1000) - }, (coinTimer + runTimer) * 1000 + 350) - setTimeout(() => { - if (context.getters.getCurrentPlayer.isAi) { - context.commit('aiTakeTurn', context.getters.getAiDependent) - } - }, 6000) - } - break - } - } +export default { } diff --git a/src/store/mutations.js b/src/store/mutations.js index e1095a8d..5fdb56a5 100755 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -1,512 +1,5 @@ -/* eslint-disable no-undef */ -import TutorialDeck from '../classes/Models/TutorialDeck' +import { bus } from '@/components/SharedComponents/Bus' -const uuidV1 = require('uuid/v1') - -import { bus } from '../components/SharedComponents/Bus' - -import Stack from '../classes/Models/Stack' -import Player from '../classes/Models/Player' -import Deck from '../classes/Models/Deck' export default { - resetState (state) { - state.players = [] - state.stacks = [] - state.deck = new Deck() - state.tutorialDeck = new TutorialDeck() - state.hands = [] - state.currentGameState = 'newGame' - state.activeSide = true - state.activePlayer = 0 - state.activeHasPlayed = false - state.currentId = 0 - state.activeCard = undefined - state.selectedStacks = [] - state.selectedStackBoolean = undefined - state.winner = false - state.winnerName = '' - state.winnerScore = 0 - state.tips.tutorial = true - state.tips.fact = true - state.firstRound = true - state.aiTurn = false - state.playerTurn = false - state.isTutorial = false - state.factIndex = 0 - state.tutorialStep = true - state.trueSideColour = 'background-color: #80aef7; box-shadow: 0px 3px 15px rgba(0,0,0,0.6)' - state.falseSideColour = 'background-color: #80aef7; box-shadow: 0px 3px 15px rgba(0,0,0,0.6)' - }, - addPlayers (state, payload) { - let id = 0 - for (let p of payload.list) { - let pp = new Player(id, p.name, undefined, 0, p.isAi) - state.players.push(pp) - id++ - } - }, - - endTurn (state, maxplayers) { - state.activePlayer += 1 - state.activePlayer = state.activePlayer % maxplayers - }, - - selectCard (state, c) { - let playerHand = state.hands.find(hand => hand.playerId === state.activePlayer) - bus.$emit('cardHasBeenSelected') - for (let card in playerHand.cards) { - if (playerHand.cards[card] !== undefined) { - if (playerHand.cards[card].id === c.id) { - playerHand.cards[card].selected = !playerHand.cards[card].selected - if (!playerHand.cards[card].selected) { - bus.$emit('cardDeselected') - } else { - state.activeCard = c - } - } else { - playerHand.cards[card].selected = false - } - } - } - }, - addHandToPlayer (state, playerId) { - let hand = { - handId: uuidV1(), - playerId: playerId, - cards: [] - } - let localState = state - let cardsTemp = [] - for (let i = 0; i < 5; i++) { - if (state.isTutorial) { - cardsTemp.push(localState.tutorialDeck.draw()) - } else { - cardsTemp.push(localState.deck.draw()) - } - } - hand.cards = cardsTemp - state.hands.push(hand) - state.players.find(player => player.id === playerId).hand = hand.handId - }, - // eslint-disable-next-line no-unused-vars - reDrawPlayerCards (state, playerId) { - let localState = state - localState.deck.shuffle(localState.deck.cards) - let cardsTemp = [] - for (let i = 0; i < 6; i++) { - if (state.isTutorial) { - cardsTemp.push(localState.tutorialDeck.draw()) - } else { - cardsTemp.push(localState.deck.draw()) - } - } - state.hands.find(hand => hand.playerId === state.activePlayer).cards = cardsTemp - state.activeCard = undefined - }, - addCardToHand (state) { - if (state.isTutorial) { - if (state.tutorialDeck.cards.length <= 1 && state.tutorialDeck.discard_cards.length > 0) { - for (let i = 0; i < state.tutorialDeck.discard_cards.length; i++) { - state.tutorialDeck.cards.push(state.tutorialDeck.discard_cards[i]) - } - state.tutorialDeck.discard_cards = [] - } - if (state.hands.find(hand => hand.playerId === state.activePlayer).cards.length < 6) { - do { - state.hands.find(hand => hand.playerId === state.activePlayer).cards.push(state.tutorialDeck.cards.pop()) - } while (state.hands.find(hand => hand.playerId === state.activePlayer).cards.length < 6) - } - } else { - if (state.deck.cards.length <= 1 && state.deck.discard_cards.length > 0) { - state.deck.shuffle(state.deck.discard_cards) - for (let i = 0; i < state.deck.discard_cards.length; i++) { - state.deck.cards.push(state.deck.discard_cards[i]) - } - state.deck.discard_cards = [] - } - if (state.hands.find(hand => hand.playerId === state.activePlayer).cards.length < 6) { - do { - state.hands.find(hand => hand.playerId === state.activePlayer).cards.push(state.deck.cards.pop()) - } while (state.hands.find(hand => hand.playerId === state.activePlayer).cards.length < 6) - } - } - }, - initDeck (state) { - state.deck.initDeck(state.players.length) - }, - initTutorialDeck (state) { - state.tutorialDeck.initDeck(state.players.length) - }, - setTutorial (state, payload) { - state.isTutorial = payload.gameType - }, - addStackToPlayer (state, payload) { - state.stacks.push(new Stack(payload.playerId, payload.boolSide)) - }, - addCardToStack (state, payload) { - let stackToAdd = state.stacks.find(st => st.stackId === payload.stackId) - payload.card.selected = false - stackToAdd.addCardToStack(payload.card) - stackToAdd.calculateStackScore() - }, - popCardFromStack (state, payload) { - let stackToPop = state.stacks.find(st => st.stackId === payload.stackId) - payload.card.selected = false - stackToPop.popTopCard() - stackToPop.calculateStackScore() - }, - groupStacks (state, payload) { - state.groupStacks = payload.yesOrNo - }, - doGroupStacks (state, payload) { - state.groupStacks = payload.yesOrNo - }, - setActiveCard (state, payload) { - if (payload !== undefined) { - state.activeCard = payload.cardId - } else { - state.activeCard = payload - } - }, - setActiveCardUndefined (state) { - state.activeCard = undefined - }, - removeActiveCardFromHand (state) { - if (state.activeCard !== undefined) { - let playerHand = state.hands.find(hand => hand.playerId === state.activePlayer) - let playerHandUpdated = playerHand.cards.filter(card => card.id !== state.activeCard.id) - playerHand.cards = playerHandUpdated - state.activeCard = undefined - } - }, - stackDiscard (state, payload) { - let card = state.stacks.find(stack => stack.stackId === payload.stackId).popTopCard() - if (state.isTutorial) { - state.tutorialDeck.discard_cards.push(card) - } else { - state.deck.discard_cards.push(card) - } - }, - discardSelectedCard (state) { - let tempActiveCard = state.activeCard - tempActiveCard.selected = false - if (state.isTutorial) { - state.tutorialDeck.discard_cards.push(tempActiveCard) - } else { - state.deck.discard_cards.push(tempActiveCard) - } - }, - setHasPlayed (state, payload) { - state.activeHasPlayed = payload.hasPlayed - }, - setGameState (state, payload) { - state.currentGameState = payload.gameState - }, - addStackToSelected (state, payload) { - let stackIdExists = state.selectedStacks.find(stackId => stackId === payload.stackId) - if (stackIdExists === undefined) { - state.selectedStacks.push(payload.stackId) - } else { - state.selectedStacks = state.selectedStacks.filter(stackId => stackId !== payload.stackId) - } - }, - removeAllSelectedStacks (state) { - state.selectedStacks = [] - }, - setStackSelectedBoolean (state, payload) { - state.selectedStackBoolean = payload.boolean - }, - removeStack (state, payload) { - state.stacks = state.stacks.filter(s => s.stackId !== payload.stackId) - }, - setActiveSide (state, payload) { - state.activeSide = payload.activeSide - }, - setScoreLimit (state, payload) { - state.scoreLimit = payload.scoreLimit - }, - setTrueFalseAnim (state, payload) { - state.trueFalseAnim = payload.startAnim - }, - setPlayerScores (state) { - let players = state.players - let stacks = state.stacks - for (let player of players) { - player.instructions = 0 - for (let stack of stacks) { - if (stack.playerId === player.id) { - player.instructions += stack.score - } - } - } - }, - setTips (state, payload) { - state.tips.tutorial = payload.tutorial - state.tips.fact = payload.fact - }, - checkWin (state) { - let playerList = state.players - let highScore = 0 - for (let player of playerList) { - player.instructionBonus = 0 - player.defensiveBonus = 0 - player.virusBonus = 0 - player.overClockBonus = 0 - player.completionBonus = 0 - player.overclockIncrease = 0 - player.totalScore = 0 - let instructions = 0 - let completionBonus = 10 - let overClockBonus = 10 - let defensiveBonus = 15 - let virusBonus = 10 - instructions = player.instructions - if (player.hasVirus) { - instructions = instructions * 0.75 - } else if (player.hasOverclock) { - instructions = instructions * 1.25 - } - player.totalInstructions = instructions - player.totalScore = instructions - - // Complete Program Bonus - if (instructions >= state.scoreLimit) { - player.completionBonus = completionBonus - } - - // Defensive Programmer Bonus - if (player.isDefensive) { - player.defensiveBonus = defensiveBonus - } - - // Cool System Bonus - if (!player.hasHadOverclock) { - player.overClockBonus = overClockBonus - } - - // Clean System bonus - if (!player.hasVirus) { - player.virusBonus = virusBonus - } - - player.totalScore += player.virusBonus - player.totalScore += player.completionBonus - player.totalScore += player.defensiveBonus - player.totalScore += player.overClockBonus - player.totalScore += player.protectionCardsBonus - player.totalScore += player.groupingBonus - player.totalScore += player.repetitionBonus - player.totalScore += player.variablesBonus - - // Check if game won - if (player.totalInstructions >= state.scoreLimit) { - state.winner = true - if ((player.totalScore > highScore)) { - highScore = player.totalScore - state.winnerName = player.name - state.winnerScore = highScore - } - } - } - }, - getIsLast (state) { - if ((state.activePlayer + 1) % state.players.length === 0) { - state.isLast = true - } else { - state.isLast = false - } - return state.isLast - }, - winnerModalTrigger () { - $('.winner').modal('show') - $('#playerTurn').modal('handleUpdate') - }, - playerModalTrigger (state) { - state.playerTurn = true - }, - playerModalHide (state) { - state.playerTurn = false - }, - coinModalTrigger () { - $('.coin').modal('handleUpdate') - $('.coin').modal('show') - }, - setCoinFlipAnim (state, payload) { - state.coinFlip = payload - }, - setPlayfieldColour (state, payload) { - if (payload) { - if (state.activeSide) { - state.trueSideColour = 'background-color: rgba(14, 183, 99, 0.9); box-shadow: 0 0 15px 10px forestgreen' - state.falseSideColour = 'background-color: rgba(242, 0, 0, 0.4)' - } else { - state.falseSideColour = 'background-color: rgba(14, 183, 99, 0.9); box-shadow: 0 0 15px 10px forestgreen' - state.trueSideColour = 'background-color: rgba(242, 0, 0, 0.4)' - } - } else { - state.trueSideColour = 'background-color: #80aef7; box-shadow: 0px 3px 15px rgb(0,0,0)' - state.falseSideColour = 'background-color: #80aef7; box-shadow: 0px 3px 15px rgb(0,0,0)' - } - }, - aiTakeTurn (state, payload) { - state.aiTurn = true - let aiMove = state.players[state.activePlayer].type.turnLogic(payload) - let cardToPlay = aiMove.getCard() - let stackToPlay = aiMove.getStack() - let stackToHack = aiMove.getOpponent() - let moveType = aiMove.getMove() - let opponentPO = aiMove.getOpponentPO() - let opponentVirus = aiMove.getOpponentVirus() - state.activeCard = cardToPlay - if (moveType === 'play') { - bus.$emit('aiAddToStack', stackToPlay) - } else if (moveType === 'discard') { - bus.$emit('aiDiscard') - } else if (moveType === 'hack') { - bus.$emit('aiHack', stackToHack) - } else if (moveType === 'group') { - for (let id of stackToPlay) { - state.selectedStacks.push(id.stackId) - } - state.selectedStackBoolean = stackToPlay[0].boolSide - state.groupStacks = false - bus.$emit('aiGroup', stackToPlay[0].boolSide, state.players[state.activePlayer].id) - } else if (moveType === 'po') { - bus.$emit('aiAttack', opponentPO) - } else if (moveType === 'virus') { - bus.$emit('aiAttack', opponentVirus) - } else if (moveType === 'protection') { - bus.$emit('aiProtection') - } else if (moveType === 'enhance') { - bus.$emit('aiEnhance') - } - }, - increaseFactIndex (state) { - state.factIndex++ - }, - giveVirus (state, payload) { - if (state.players[payload].hasOverclock) { - state.players[payload].hasOverclock = false - state.players[payload].usedBonusCards = state.players[payload].usedBonusCards.filter((obj) => { - return obj.type !== 'OVERCLOCK' - }) - } else { - state.players[payload].hasVirus = true - state.activeCard.showFace = true - state.players[payload].attackedCards.push(state.activeCard) - } - state.players[payload].hadVirus = true - }, - givePowerOutage (state, payload) { - if (state.players[payload].hasBatteryBackup) { - state.players[payload].hasBatteryBackup = false - state.players[payload].usedBonusCards = state.players[payload].usedBonusCards.filter((obj) => { - return obj.type !== 'BATTERYBACKUP' - }) - } else { - state.players[payload].hasPowerOutage = true - state.activeCard.showFace = true - state.players[payload].attackedCards.push(state.activeCard) - } - }, - giveBatteryBackup (state, payload) { - if (state.players[payload].hasPowerOutage) { - state.players[payload].hasPowerOutage = false - state.activeCard.showFace = true - state.players[payload].attackedCards = state.players[payload].attackedCards.filter((obj) => { - return obj.type !== 'POWEROUTAGE' - }) - } else { - state.players[payload].hasBatteryBackup = true - state.activeCard.showFace = true - state.players[payload].usedBonusCards.push(state.activeCard) - } - }, - giveOverclock (state, payload) { - if (state.players[payload].hasVirus) { - state.players[payload].hasVirus = false - state.activeCard.showFace = true - state.players[payload].attackedCards = state.players[payload].attackedCards.filter((obj) => { - return obj.type !== 'VIRUS' - }) - } else { - state.players[payload].hasOverclock = true - state.activeCard.showFace = true - state.players[payload].usedBonusCards.push(state.activeCard) - state.players[payload].hasHadOverclock = true - } - }, - giveFirewall (state, payload) { - let bonus = 5 - state.players[payload].hasFirewall = true - state.players[payload].hasPowerOutage = false - state.activeCard.showFace = true - state.players[payload].usedBonusCards.push(state.activeCard) - state.players[payload].updateBonus(bonus, bonus) - state.players[payload].protectionCardsBonus += bonus - if (state.players[payload].hasFirewall && state.players[payload].hasAntiVirus && state.players[payload].hasGenerator) { - state.players[payload].isDefensive = true - } - }, - giveGenerator (state, payload) { - let bonus = 5 - state.players[payload].hasGenerator = true - state.players[payload].hasPowerOutage = false - state.players[payload].attackedCards = state.players[payload].attackedCards.filter((obj) => { - return obj.type !== 'POWEROUTAGE' - }) - state.players[payload].usedBonusCards = state.players[payload].usedBonusCards.filter((obj) => { - return obj.type !== 'BATTERYBACKUP' - }) - state.activeCard.showFace = true - state.players[payload].usedBonusCards.push(state.activeCard) - state.players[payload].updateBonus(bonus, bonus) - state.players[payload].protectionCardsBonus += bonus - if (state.players[payload].hasFirewall && state.players[payload].hasAntiVirus && state.players[payload].hasGenerator) { - state.players[payload].isDefensive = true - } - }, - giveAntiVirus (state, payload) { - let bonus = 5 - state.players[payload].hasAntiVirus = true - state.players[payload].hasVirus = false - state.players[payload].attackedCards = state.players[payload].attackedCards.filter((obj) => { - return obj.type !== 'VIRUS' - }) - state.activeCard.showFace = true - state.players[payload].usedBonusCards.push(state.activeCard) - state.players[payload].updateBonus(bonus, bonus) - state.players[payload].protectionCardsBonus += bonus - if (state.players[payload].hasFirewall && state.players[payload].hasAntiVirus && state.players[payload].hasGenerator) { - state.players[payload].isDefensive = true - } - }, - changeBonusScore (state, payload) { - state.players[payload.id].bonus += payload.score - }, - flipTutorialStep (state) { - state.tutorialStep = !state.tutorialStep - }, - setFirstRound (state, payload) { - state.firstRound = payload - }, - setAiTurn (state, payload) { - state.aiTurn = payload - }, - setActiveStack (state, payload) { - state.activeStack = payload - }, - setTimerInterval (state, payload) { - state.timerInterval = payload - }, - stopTimer (state) { - state.timerInterval.stop() - }, - updateTheme (state, payload) { - state.mainBackgroundColour = payload.mainBC - state.mainTextColour = payload.mainTC - state.pIPBackgroundColour = payload.playfieldBC - state.pIPTextColour = payload.playfieldTC - } } diff --git a/src/store/store.js b/src/store/store.js index f00ff78d..d1189714 100755 --- a/src/store/store.js +++ b/src/store/store.js @@ -3,10 +3,10 @@ import Vuex from 'vuex' Vue.use(Vuex) -import actions from './actions.js' -import mutations from './mutations.js' -import getters from './getters.js' -import Deck from '../classes/Models/Deck' +import actions from './actions' +import mutations from './mutations' +import getters from './getters' +import Deck from '@/classes/Models/Deck' /** From dc7510492f8b6dd786ec0e3d020ddce254979d70 Mon Sep 17 00:00:00 2001 From: strinsberg Date: Tue, 26 May 2020 12:05:27 -0600 Subject: [PATCH 07/92] Adding empty templates for the components that will be needed for the two different pages. --- src/components/game/Game.vue | 35 ++ src/components/game/StacksArea.vue | 19 + src/components/game/TurnArea.vue | 18 + src/components/landingPage/LandingPage.vue | 27 ++ .../landingPage/SettingsComponent.vue | 437 +----------------- src/components/shared/SideMenu.vue | 11 + 6 files changed, 113 insertions(+), 434 deletions(-) create mode 100644 src/components/game/Game.vue create mode 100644 src/components/game/StacksArea.vue create mode 100644 src/components/game/TurnArea.vue create mode 100644 src/components/landingPage/LandingPage.vue create mode 100644 src/components/shared/SideMenu.vue diff --git a/src/components/game/Game.vue b/src/components/game/Game.vue new file mode 100644 index 00000000..e4f71285 --- /dev/null +++ b/src/components/game/Game.vue @@ -0,0 +1,35 @@ + + + + + + diff --git a/src/components/game/StacksArea.vue b/src/components/game/StacksArea.vue new file mode 100644 index 00000000..c282835e --- /dev/null +++ b/src/components/game/StacksArea.vue @@ -0,0 +1,19 @@ + + + + + + + diff --git a/src/components/game/TurnArea.vue b/src/components/game/TurnArea.vue new file mode 100644 index 00000000..8aedae12 --- /dev/null +++ b/src/components/game/TurnArea.vue @@ -0,0 +1,18 @@ + + + + + + diff --git a/src/components/landingPage/LandingPage.vue b/src/components/landingPage/LandingPage.vue new file mode 100644 index 00000000..1f59563c --- /dev/null +++ b/src/components/landingPage/LandingPage.vue @@ -0,0 +1,27 @@ + + + + + diff --git a/src/components/landingPage/SettingsComponent.vue b/src/components/landingPage/SettingsComponent.vue index 9bd34434..1dd0bf4c 100755 --- a/src/components/landingPage/SettingsComponent.vue +++ b/src/components/landingPage/SettingsComponent.vue @@ -1,442 +1,11 @@ - - diff --git a/src/components/shared/SideMenu.vue b/src/components/shared/SideMenu.vue new file mode 100644 index 00000000..3cc2a5b5 --- /dev/null +++ b/src/components/shared/SideMenu.vue @@ -0,0 +1,11 @@ + + + + From e3fe0bd4adb9ae9aa3a7bda392d0d0821d1bef55 Mon Sep 17 00:00:00 2001 From: strinsberg Date: Tue, 26 May 2020 12:52:49 -0600 Subject: [PATCH 08/92] Deleted the rest of the files. Still have them elsewhere for reference. Project will serve on localhost with some very very simple pages to get started. Now content can be added back/created in a good way. --- src/components/game/Card.vue | 219 ------ src/components/game/CardWithOverlays.vue | 170 ----- src/components/game/Conditionals.vue | 224 ------ src/components/game/DisplayUsedCards.vue | 158 ----- src/components/game/Game.vue | 10 +- src/components/game/MainComponent.vue | 440 ------------ src/components/game/OpponentStack.vue | 255 ------- src/components/game/OpponentStacks.vue | 70 -- src/components/game/PlayerInfoPanel.vue | 641 ------------------ src/components/game/PlayerTurnPopUp.vue | 81 --- src/components/game/Playfield.vue | 181 ----- src/components/game/Stack.vue | 547 --------------- src/components/game/StacksArea.vue | 19 - src/components/game/TurnArea.vue | 18 - src/components/landingPage/LandingPage.vue | 10 +- .../landingPage/SettingsComponent.vue | 11 - src/components/modals/BackstoryModal.vue | 39 -- src/components/modals/CreditsModal.vue | 34 - src/components/modals/HackModal.vue | 111 --- src/components/modals/Modal.vue | 96 --- src/components/modals/RulesModal.vue | 349 ---------- src/components/modals/ThemesModal.vue | 118 ---- src/components/modals/WinnerModal.vue | 163 ----- src/components/shared/Timer.vue | 46 -- src/router/index.js | 8 +- src/store/actions.js | 2 +- src/store/mutations.js | 2 +- 27 files changed, 22 insertions(+), 4000 deletions(-) delete mode 100755 src/components/game/Card.vue delete mode 100644 src/components/game/CardWithOverlays.vue delete mode 100644 src/components/game/Conditionals.vue delete mode 100644 src/components/game/DisplayUsedCards.vue delete mode 100755 src/components/game/MainComponent.vue delete mode 100755 src/components/game/OpponentStack.vue delete mode 100755 src/components/game/OpponentStacks.vue delete mode 100755 src/components/game/PlayerInfoPanel.vue delete mode 100644 src/components/game/PlayerTurnPopUp.vue delete mode 100755 src/components/game/Playfield.vue delete mode 100755 src/components/game/Stack.vue delete mode 100644 src/components/game/StacksArea.vue delete mode 100644 src/components/game/TurnArea.vue delete mode 100755 src/components/landingPage/SettingsComponent.vue delete mode 100644 src/components/modals/BackstoryModal.vue delete mode 100644 src/components/modals/CreditsModal.vue delete mode 100644 src/components/modals/HackModal.vue delete mode 100644 src/components/modals/Modal.vue delete mode 100644 src/components/modals/RulesModal.vue delete mode 100644 src/components/modals/ThemesModal.vue delete mode 100644 src/components/modals/WinnerModal.vue delete mode 100644 src/components/shared/Timer.vue diff --git a/src/components/game/Card.vue b/src/components/game/Card.vue deleted file mode 100755 index e2840de6..00000000 --- a/src/components/game/Card.vue +++ /dev/null @@ -1,219 +0,0 @@ - - - - - - diff --git a/src/components/game/CardWithOverlays.vue b/src/components/game/CardWithOverlays.vue deleted file mode 100644 index 9c309cc1..00000000 --- a/src/components/game/CardWithOverlays.vue +++ /dev/null @@ -1,170 +0,0 @@ - - - - - - - diff --git a/src/components/game/Conditionals.vue b/src/components/game/Conditionals.vue deleted file mode 100644 index d3a38e07..00000000 --- a/src/components/game/Conditionals.vue +++ /dev/null @@ -1,224 +0,0 @@ - - - - - diff --git a/src/components/game/DisplayUsedCards.vue b/src/components/game/DisplayUsedCards.vue deleted file mode 100644 index 532ce87e..00000000 --- a/src/components/game/DisplayUsedCards.vue +++ /dev/null @@ -1,158 +0,0 @@ - - - - - diff --git a/src/components/game/Game.vue b/src/components/game/Game.vue index e4f71285..ad38d8f4 100644 --- a/src/components/game/Game.vue +++ b/src/components/game/Game.vue @@ -20,7 +20,8 @@ track of more than just these if statements -->
- +

Game Page

+
@@ -28,7 +29,12 @@ diff --git a/src/components/game/MainComponent.vue b/src/components/game/MainComponent.vue deleted file mode 100755 index 1c940866..00000000 --- a/src/components/game/MainComponent.vue +++ /dev/null @@ -1,440 +0,0 @@ - - - - - - diff --git a/src/components/game/OpponentStack.vue b/src/components/game/OpponentStack.vue deleted file mode 100755 index a21fa4c1..00000000 --- a/src/components/game/OpponentStack.vue +++ /dev/null @@ -1,255 +0,0 @@ - - - - - - diff --git a/src/components/game/OpponentStacks.vue b/src/components/game/OpponentStacks.vue deleted file mode 100755 index 5c4d044f..00000000 --- a/src/components/game/OpponentStacks.vue +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - diff --git a/src/components/game/PlayerInfoPanel.vue b/src/components/game/PlayerInfoPanel.vue deleted file mode 100755 index a47d0571..00000000 --- a/src/components/game/PlayerInfoPanel.vue +++ /dev/null @@ -1,641 +0,0 @@ - - - - - - diff --git a/src/components/game/PlayerTurnPopUp.vue b/src/components/game/PlayerTurnPopUp.vue deleted file mode 100644 index 442ed6a0..00000000 --- a/src/components/game/PlayerTurnPopUp.vue +++ /dev/null @@ -1,81 +0,0 @@ - - - - - diff --git a/src/components/game/Playfield.vue b/src/components/game/Playfield.vue deleted file mode 100755 index 983e3b16..00000000 --- a/src/components/game/Playfield.vue +++ /dev/null @@ -1,181 +0,0 @@ - - - - - - diff --git a/src/components/game/Stack.vue b/src/components/game/Stack.vue deleted file mode 100755 index 5d246050..00000000 --- a/src/components/game/Stack.vue +++ /dev/null @@ -1,547 +0,0 @@ - - - - - - diff --git a/src/components/game/StacksArea.vue b/src/components/game/StacksArea.vue deleted file mode 100644 index c282835e..00000000 --- a/src/components/game/StacksArea.vue +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - diff --git a/src/components/game/TurnArea.vue b/src/components/game/TurnArea.vue deleted file mode 100644 index 8aedae12..00000000 --- a/src/components/game/TurnArea.vue +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - diff --git a/src/components/landingPage/LandingPage.vue b/src/components/landingPage/LandingPage.vue index 1f59563c..3352ec03 100644 --- a/src/components/landingPage/LandingPage.vue +++ b/src/components/landingPage/LandingPage.vue @@ -13,7 +13,8 @@ able to hold all of the stuff it need or be broken up into smaller components. -->
- +

Landing Page

+
@@ -21,7 +22,12 @@ diff --git a/src/components/landingPage/SettingsComponent.vue b/src/components/landingPage/SettingsComponent.vue deleted file mode 100755 index 1dd0bf4c..00000000 --- a/src/components/landingPage/SettingsComponent.vue +++ /dev/null @@ -1,11 +0,0 @@ - - - - diff --git a/src/components/modals/BackstoryModal.vue b/src/components/modals/BackstoryModal.vue deleted file mode 100644 index 4d83844c..00000000 --- a/src/components/modals/BackstoryModal.vue +++ /dev/null @@ -1,39 +0,0 @@ - - - diff --git a/src/components/modals/CreditsModal.vue b/src/components/modals/CreditsModal.vue deleted file mode 100644 index 4a87ab32..00000000 --- a/src/components/modals/CreditsModal.vue +++ /dev/null @@ -1,34 +0,0 @@ - - - diff --git a/src/components/modals/HackModal.vue b/src/components/modals/HackModal.vue deleted file mode 100644 index bd1a3996..00000000 --- a/src/components/modals/HackModal.vue +++ /dev/null @@ -1,111 +0,0 @@ - - - - - diff --git a/src/components/modals/Modal.vue b/src/components/modals/Modal.vue deleted file mode 100644 index 2d20c864..00000000 --- a/src/components/modals/Modal.vue +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Created by shauncullen on 2017-03-28. - */ - - - - - - - diff --git a/src/components/modals/RulesModal.vue b/src/components/modals/RulesModal.vue deleted file mode 100644 index 5c5d5a47..00000000 --- a/src/components/modals/RulesModal.vue +++ /dev/null @@ -1,349 +0,0 @@ - - - - - diff --git a/src/components/modals/ThemesModal.vue b/src/components/modals/ThemesModal.vue deleted file mode 100644 index 4cef850e..00000000 --- a/src/components/modals/ThemesModal.vue +++ /dev/null @@ -1,118 +0,0 @@ - - - - - diff --git a/src/components/modals/WinnerModal.vue b/src/components/modals/WinnerModal.vue deleted file mode 100644 index c4ff1513..00000000 --- a/src/components/modals/WinnerModal.vue +++ /dev/null @@ -1,163 +0,0 @@ - - - - - diff --git a/src/components/shared/Timer.vue b/src/components/shared/Timer.vue deleted file mode 100644 index 0dca4db5..00000000 --- a/src/components/shared/Timer.vue +++ /dev/null @@ -1,46 +0,0 @@ - - - - - diff --git a/src/router/index.js b/src/router/index.js index 50fcc951..943971e7 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,7 +1,7 @@ import Vue from 'vue' import VueRouter from 'vue-router' -import SettingsComponent from '../components/SharedComponents/SettingsComponent.vue' -import MainComponent from '../components/MainGame/MainComponent.vue' +import LandingPage from '@/components/landingPage/LandingPage' +import Game from '@/components/game/Game' Vue.use(VueRouter) @@ -10,13 +10,13 @@ const routes = [ path: '/', name: 'Home', canReuse: false, - component: SettingsComponent + component: LandingPage }, { path: '/game', name: 'Game', canReuse: false, - component: MainComponent + component: Game }, { path: '*', diff --git a/src/store/actions.js b/src/store/actions.js index 5fdb56a5..1a7b6733 100755 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -1,4 +1,4 @@ -import { bus } from '@/components/SharedComponents/Bus' +//import { bus } from '@/components/SharedComponents/Bus' export default { diff --git a/src/store/mutations.js b/src/store/mutations.js index 5fdb56a5..1a7b6733 100755 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -1,4 +1,4 @@ -import { bus } from '@/components/SharedComponents/Bus' +//import { bus } from '@/components/SharedComponents/Bus' export default { From b2a3d2ad7cafba93925b1042d17da51e52861013 Mon Sep 17 00:00:00 2001 From: strinsberg Date: Tue, 26 May 2020 13:52:53 -0600 Subject: [PATCH 09/92] Added back a couple of modals needed for the side menu. Created a new side-menu component to hold the menu. It is missing having different targets based on game state, but it is functioning as expected and previously. Should probably use it as a nice easy start to vue component testing once it is ready. --- src/components/game/Game.vue | 12 +- src/components/landingPage/LandingPage.vue | 12 +- src/components/modals/BackstoryModal.vue | 39 +++ src/components/modals/CreditsModal.vue | 34 ++ src/components/modals/RulesModal.vue | 349 +++++++++++++++++++++ src/components/shared/SideMenu.vue | 91 +++++- src/store/actions.js | 32 ++ src/store/mutations.js | 7 + src/store/store.js | 2 +- 9 files changed, 573 insertions(+), 5 deletions(-) create mode 100644 src/components/modals/BackstoryModal.vue create mode 100644 src/components/modals/CreditsModal.vue create mode 100644 src/components/modals/RulesModal.vue diff --git a/src/components/game/Game.vue b/src/components/game/Game.vue index ad38d8f4..028c92e5 100644 --- a/src/components/game/Game.vue +++ b/src/components/game/Game.vue @@ -22,17 +22,27 @@

Game Page

+
diff --git a/src/components/modals/CreditsModal.vue b/src/components/modals/CreditsModal.vue new file mode 100644 index 00000000..4a87ab32 --- /dev/null +++ b/src/components/modals/CreditsModal.vue @@ -0,0 +1,34 @@ + + + diff --git a/src/components/modals/RulesModal.vue b/src/components/modals/RulesModal.vue new file mode 100644 index 00000000..5c5d5a47 --- /dev/null +++ b/src/components/modals/RulesModal.vue @@ -0,0 +1,349 @@ + + + + + diff --git a/src/components/shared/SideMenu.vue b/src/components/shared/SideMenu.vue index 3cc2a5b5..80f99508 100644 --- a/src/components/shared/SideMenu.vue +++ b/src/components/shared/SideMenu.vue @@ -1,11 +1,98 @@ + diff --git a/src/store/actions.js b/src/store/actions.js index 1a7b6733..186c0a52 100755 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -1,5 +1,37 @@ //import { bus } from '@/components/SharedComponents/Bus' +import router from '@/router' export default { + /** + * Starts a new game. + * Fully initializes a new state and navigates to the game page. + * Payload needs field players wich is a list of objects + * of the form {name: 'name', ai: bool} + */ + newGame (context, payload) { + context.commit('changeGameState', {newState: 'game'}) + // use player info in payload and setup a new game + // need to mutate to defaults or new game + // some changes can be put in a mutation some will have to + // be in mutation in here + router.push('game') + console.log(payload) + console.log(context.state.gameState) + }, + + /** + * Leaves the current game and navigates back to home. + * Any current game state may be lost. + * Will reset any state information for starting a new game. + */ + leaveGame (context, payload) { + // For now it just changes state, but later it may need to cleanup or + // setup the state for the home page? + // from the game before heading to the home page + context.commit('changeGameState', {newState: 'home'}) + router.push('home') + console.log(payload) + console.log(context.state.gameState) + } } diff --git a/src/store/mutations.js b/src/store/mutations.js index 1a7b6733..04ac6c51 100755 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -2,4 +2,11 @@ export default { + /** + * Change the game state to a given new state. + * Payload needs field -> newState: 'state' + */ + changeGameState(state, payload) { + state.gameState = payload.newState + } } diff --git a/src/store/store.js b/src/store/store.js index d1189714..6ab5e7c3 100755 --- a/src/store/store.js +++ b/src/store/store.js @@ -20,7 +20,7 @@ export const store = new Vuex.Store({ aiHanlders: [], objectives: [], deck: new Deck(), - gameState: 'newGame', + gameState: 'home', activePlayerId: 0, activeCard: undefined, scoreLimit: 5500, From fb1cded41439d1844e39aeb656bb3eaf2570591e Mon Sep 17 00:00:00 2001 From: strinsberg Date: Tue, 26 May 2020 14:53:01 -0600 Subject: [PATCH 10/92] cleaned up the menu modals a bit. The rules modal is long and a bit gnarly so it is probably still in need of some help. --- src/components/modals/BackstoryModal.vue | 47 +- src/components/modals/CreditsModal.vue | 48 +- src/components/modals/RulesModal.vue | 619 ++++++++++++----------- 3 files changed, 390 insertions(+), 324 deletions(-) diff --git a/src/components/modals/BackstoryModal.vue b/src/components/modals/BackstoryModal.vue index 4d83844c..76d3e504 100644 --- a/src/components/modals/BackstoryModal.vue +++ b/src/components/modals/BackstoryModal.vue @@ -1,39 +1,46 @@ diff --git a/src/components/modals/CreditsModal.vue b/src/components/modals/CreditsModal.vue index 4a87ab32..aaa100d5 100644 --- a/src/components/modals/CreditsModal.vue +++ b/src/components/modals/CreditsModal.vue @@ -2,33 +2,53 @@
diff --git a/src/components/modals/RulesModal.vue b/src/components/modals/RulesModal.vue index 5c5d5a47..5704e8ac 100644 --- a/src/components/modals/RulesModal.vue +++ b/src/components/modals/RulesModal.vue @@ -1,317 +1,356 @@ - + diff --git a/src/components/landingPage/LandingPage.vue b/src/components/landingPage/LandingPage.vue index 7c262997..78abb12c 100644 --- a/src/components/landingPage/LandingPage.vue +++ b/src/components/landingPage/LandingPage.vue @@ -12,23 +12,23 @@ Can also use a settings component for the setup. That component may be able to hold all of the stuff it need or be broken up into smaller components. --> -
+
+

Landing Page

-
+ diff --git a/src/components/shared/PageHeader.vue b/src/components/shared/PageHeader.vue new file mode 100644 index 00000000..eb4eb36a --- /dev/null +++ b/src/components/shared/PageHeader.vue @@ -0,0 +1,99 @@ + + + + + + + diff --git a/src/components/shared/SideMenu.vue b/src/components/shared/SideMenu.vue index 80f99508..4a8ed4a9 100644 --- a/src/components/shared/SideMenu.vue +++ b/src/components/shared/SideMenu.vue @@ -1,32 +1,32 @@ + + diff --git a/src/store/actions.js b/src/store/actions.js index 186c0a52..09358770 100755 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -30,6 +30,7 @@ export default { // setup the state for the home page? // from the game before heading to the home page context.commit('changeGameState', {newState: 'home'}) + context.commit('stopTimer') router.push('home') console.log(payload) console.log(context.state.gameState) diff --git a/src/store/mutations.js b/src/store/mutations.js index 04ac6c51..67ca5316 100755 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -8,5 +8,30 @@ export default { */ changeGameState(state, payload) { state.gameState = payload.newState + }, + + /** + * Toggle tips on and off. + */ + toggleTips (state) { + state.tips.showTips = !state.tips.showTips + console.log(state.tips.showTips) + }, + + /** + * Set a new timer. + */ + setTimer (state, payload) { + state.timer = payload.timer + }, + + /** + * Stop the current timer. + */ + stopTimer (state) { + if (state.timer) { + state.timer.stop() + } + console.log("stopping timer") } } diff --git a/src/store/store.js b/src/store/store.js index 6ab5e7c3..a27d527b 100755 --- a/src/store/store.js +++ b/src/store/store.js @@ -24,9 +24,9 @@ export const store = new Vuex.Store({ activePlayerId: 0, activeCard: undefined, scoreLimit: 5500, - tips: {tutorial: true, factIndex: 0}, + tips: {showTips: true, factIndex: 0}, colorScheme: {}, - timerInterval: undefined, + timer: undefined, }, getters, From d62719971b29077e1a0f8f8780d4704910d55ff4 Mon Sep 17 00:00:00 2001 From: strinsberg Date: Tue, 26 May 2020 16:54:38 -0600 Subject: [PATCH 12/92] Removed the timer component and moved the things it was actually doing to actions. Moved the div with the time and the css for it into the header class directly. --- src/components/shared/PageHeader.vue | 17 +++++++--- src/components/shared/Timer.vue | 47 ---------------------------- src/store/actions.js | 7 ++--- src/store/mutations.js | 14 ++++++--- 4 files changed, 25 insertions(+), 60 deletions(-) delete mode 100644 src/components/shared/Timer.vue diff --git a/src/components/shared/PageHeader.vue b/src/components/shared/PageHeader.vue index eb4eb36a..b62a138f 100644 --- a/src/components/shared/PageHeader.vue +++ b/src/components/shared/PageHeader.vue @@ -12,7 +12,11 @@ Game Tips - + +
+ 00:00:00 +
@@ -23,7 +27,6 @@ - - diff --git a/src/store/actions.js b/src/store/actions.js index 09358770..30115117 100755 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -10,14 +10,14 @@ export default { * of the form {name: 'name', ai: bool} */ newGame (context, payload) { + payload context.commit('changeGameState', {newState: 'game'}) + context.commit('newTimer') // use player info in payload and setup a new game // need to mutate to defaults or new game // some changes can be put in a mutation some will have to // be in mutation in here router.push('game') - console.log(payload) - console.log(context.state.gameState) }, /** @@ -26,13 +26,12 @@ export default { * Will reset any state information for starting a new game. */ leaveGame (context, payload) { + payload // For now it just changes state, but later it may need to cleanup or // setup the state for the home page? // from the game before heading to the home page context.commit('changeGameState', {newState: 'home'}) context.commit('stopTimer') router.push('home') - console.log(payload) - console.log(context.state.gameState) } } diff --git a/src/store/mutations.js b/src/store/mutations.js index 67ca5316..cd983b80 100755 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -1,4 +1,5 @@ //import { bus } from '@/components/SharedComponents/Bus' +import Timer from 'easytimer' export default { @@ -15,14 +16,18 @@ export default { */ toggleTips (state) { state.tips.showTips = !state.tips.showTips - console.log(state.tips.showTips) }, /** - * Set a new timer. + * Setup a new timer. */ - setTimer (state, payload) { - state.timer = payload.timer + newTimer (state) { + state.timer = new Timer() + state.timer.start() + // eslint-disable-next-line no-unused-vars + state.timer.addEventListener('secondsUpdated', function (e) { + $('#basicUsage').html(state.timer.getTimeValues().toString()) + }) }, /** @@ -32,6 +37,5 @@ export default { if (state.timer) { state.timer.stop() } - console.log("stopping timer") } } From 033cf88f779a16b13e458a6982e85a1665bc8f53 Mon Sep 17 00:00:00 2001 From: strinsberg Date: Tue, 26 May 2020 18:42:23 -0600 Subject: [PATCH 13/92] moved the isGame function into getters as I was using it in two places. Updated the side menu to show newGame when you are in game, but not at landing page. Removed the button to get back to the landing page. --- src/components/game/Game.vue | 10 ---------- src/components/shared/PageHeader.vue | 9 ++++----- src/components/shared/SideMenu.vue | 23 ++++++++++++++++------- src/store/getters.js | 7 +++++++ 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/components/game/Game.vue b/src/components/game/Game.vue index c9ff7f5e..cdbfb23d 100644 --- a/src/components/game/Game.vue +++ b/src/components/game/Game.vue @@ -22,7 +22,6 @@

Game Page

-
@@ -30,21 +29,12 @@ diff --git a/src/components/shared/PageHeader.vue b/src/components/shared/PageHeader.vue index b62a138f..2a3f906b 100644 --- a/src/components/shared/PageHeader.vue +++ b/src/components/shared/PageHeader.vue @@ -27,7 +27,7 @@ diff --git a/src/store/actions.js b/src/store/actions.js index 30115117..a69232ad 100755 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -10,13 +10,9 @@ export default { * of the form {name: 'name', ai: bool} */ newGame (context, payload) { - payload - context.commit('changeGameState', {newState: 'game'}) + context.commit('resetStateForGame') context.commit('newTimer') - // use player info in payload and setup a new game - // need to mutate to defaults or new game - // some changes can be put in a mutation some will have to - // be in mutation in here + context.commit('addPlayers', payload) router.push('game') }, @@ -25,11 +21,7 @@ export default { * Any current game state may be lost. * Will reset any state information for starting a new game. */ - leaveGame (context, payload) { - payload - // For now it just changes state, but later it may need to cleanup or - // setup the state for the home page? - // from the game before heading to the home page + leaveGame (context) { context.commit('changeGameState', {newState: 'home'}) context.commit('stopTimer') router.push('home') diff --git a/src/store/mutations.js b/src/store/mutations.js index cd983b80..4e43438c 100755 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -1,13 +1,34 @@ //import { bus } from '@/components/SharedComponents/Bus' import Timer from 'easytimer' +import Player from '@/classes/Models/Player' +import Deck from '@/classes/Models/Deck' export default { + /** + * Resets all game related items in the state for a fresh game. + * Sets gameState to 'game'. + * Should not affect non-game related settings. + */ + resetStateForGame (state) { + state.players = [] + state.stacks = [] + state.hands = [] + state.aiHanlders = [] + state.objectives = [] + state.deck = new Deck() + state.gameState = 'game' + state.activePlayerId = 0 + state.activeCard = undefined + state.scoreLimit = 5500 + state.tips = {showTips: true, factIndex: 0} + }, + /** * Change the game state to a given new state. * Payload needs field -> newState: 'state' */ - changeGameState(state, payload) { + changeGameState (state, payload) { state.gameState = payload.newState }, @@ -37,5 +58,16 @@ export default { if (state.timer) { state.timer.stop() } + }, + + /** + * Uses a list of player information to create and add new players. + */ + addPlayers(state, payload) { + let playerInfo = payload.players + for (let i = 0; i < playerInfo.length; i++) { + let player = new Player(i, playerInfo[i].name, playerInfo[i].ai) + state.players.push(player) + } } } From 77bc179136b23014d10596ebcc12bcacdbf21310 Mon Sep 17 00:00:00 2001 From: strinsberg Date: Tue, 26 May 2020 20:24:24 -0600 Subject: [PATCH 16/92] Added a player info area component. Created 2 of them on the game page in the right areas. They are moslty empty for now. --- src/components/game/Game.vue | 38 +++++++++++++++++++--- src/components/game/PlayerInfo.vue | 38 ++++++++++++++++++++++ src/components/landingPage/LandingPage.vue | 2 +- 3 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 src/components/game/PlayerInfo.vue diff --git a/src/components/game/Game.vue b/src/components/game/Game.vue index cfeabbdd..dffae25f 100644 --- a/src/components/game/Game.vue +++ b/src/components/game/Game.vue @@ -25,7 +25,13 @@
-

This is the play area

+
+ +
+ +
+ +
@@ -39,18 +45,28 @@ + + + diff --git a/src/components/landingPage/LandingPage.vue b/src/components/landingPage/LandingPage.vue index 82279bfb..b030e7e5 100644 --- a/src/components/landingPage/LandingPage.vue +++ b/src/components/landingPage/LandingPage.vue @@ -37,7 +37,7 @@ export default { 'newGame' ]), game () { - this.newGame({players: [{name: 'steven', ai: false}, {name: 'noob_bot', ai: true}]}) + this.newGame({players: [{name: 'Steven', ai: false}, {name: 'n00b_bot mk1.', ai: true}]}) } } } From bef9ac4981e427bc94ef5c5c87436e3c849ec605 Mon Sep 17 00:00:00 2001 From: strinsberg Date: Tue, 26 May 2020 20:39:53 -0600 Subject: [PATCH 17/92] Added a component for the main card area and set it up with the game component. --- src/components/game/CardArea.vue | 37 ++++++++++++++++++++++++ src/components/game/Game.vue | 46 ++++++++++++------------------ src/components/game/PlayerInfo.vue | 10 +++++-- 3 files changed, 63 insertions(+), 30 deletions(-) create mode 100644 src/components/game/CardArea.vue diff --git a/src/components/game/CardArea.vue b/src/components/game/CardArea.vue new file mode 100644 index 00000000..1eade96a --- /dev/null +++ b/src/components/game/CardArea.vue @@ -0,0 +1,37 @@ + + + + + + + + diff --git a/src/components/game/Game.vue b/src/components/game/Game.vue index dffae25f..af686887 100644 --- a/src/components/game/Game.vue +++ b/src/components/game/Game.vue @@ -1,37 +1,21 @@