in progress: gold chip functionality
This commit is contained in:
2110
package-lock.json
generated
2110
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -10,18 +10,22 @@
|
|||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"react": "^18.2.0",
|
"react": "^16.14.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^16.14.0",
|
||||||
"react-router-dom": "^6.3.0",
|
"react-router-dom": "^6.3.0",
|
||||||
"scss": "^0.2.4",
|
"scss": "^0.2.4",
|
||||||
"uuid": "^8.3.2"
|
"uuid": "^8.3.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@testing-library/react": "^13.3.0",
|
"@testing-library/react": "^13.3.0",
|
||||||
|
"@types/enzyme": "^3.10.12",
|
||||||
|
"@types/enzyme-adapter-react-16": "^1.0.6",
|
||||||
"@types/react": "^18.0.15",
|
"@types/react": "^18.0.15",
|
||||||
"@types/react-dom": "^18.0.6",
|
"@types/react-dom": "^18.0.6",
|
||||||
"@types/uuid": "^8.3.4",
|
"@types/uuid": "^8.3.4",
|
||||||
"@vitejs/plugin-react": "^2.0.0",
|
"@vitejs/plugin-react": "^2.0.0",
|
||||||
|
"enzyme": "^3.11.0",
|
||||||
|
"enzyme-adapter-react-16": "^1.15.6",
|
||||||
"jsdom": "^20.0.0",
|
"jsdom": "^20.0.0",
|
||||||
"typescript": "^4.6.4",
|
"typescript": "^4.6.4",
|
||||||
"vite": "^3.0.0",
|
"vite": "^3.0.0",
|
||||||
|
|||||||
@@ -11,21 +11,23 @@ export const tooExpensive = (card: CardData, state: AppState): boolean => {
|
|||||||
if (!currentPlayer) return true;
|
if (!currentPlayer) return true;
|
||||||
|
|
||||||
let availableGold = currentPlayer.inventory.gold || 0;
|
let availableGold = currentPlayer.inventory.gold || 0;
|
||||||
for (let [cardGemType, cardCost] of Object.entries(card.resourceCost)) {
|
|
||||||
|
// iterate through resource costs on card
|
||||||
|
for (let [cardResource, cardQuantity] of Object.entries(card.resourceCost)) {
|
||||||
let totalBuyingPower = getTotalBuyingPower(currentPlayer);
|
let totalBuyingPower = getTotalBuyingPower(currentPlayer);
|
||||||
for (let [heldResource, quantity] of Object.entries(totalBuyingPower)) {
|
// iterate through each section of player's total buying power
|
||||||
if (cardGemType === heldResource && quantity < cardCost) {
|
for (let [heldResource, heldQuantity] of Object.entries(totalBuyingPower)) {
|
||||||
let adjustedQuantity = quantity;
|
// match card resource to held quantity
|
||||||
while (availableGold > 0) {
|
if (cardResource === heldResource) {
|
||||||
|
let adjustedQuantity = heldQuantity;
|
||||||
|
// enter while loop if adjustedQuantity does not cover cost
|
||||||
|
while (adjustedQuantity < cardQuantity) {
|
||||||
|
// if there is no gold available to modify cost, card is too expensive
|
||||||
|
if (!availableGold) return true;
|
||||||
|
// else, add to the insufficient quantity and decrement available gold
|
||||||
adjustedQuantity++;
|
adjustedQuantity++;
|
||||||
availableGold--;
|
availableGold--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (adjustedQuantity > cardCost) {
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,88 +0,0 @@
|
|||||||
import { describe, expect, test } from "vitest"
|
|
||||||
import { initialState } from "../../../../hooks/stateSetters"
|
|
||||||
import { mockPlayerTwo } from "../../../../util/testUtils"
|
|
||||||
import { AppState, CardData, PlayerData } from "../../../../util/types"
|
|
||||||
import { tooExpensive } from "../buyCardActions"
|
|
||||||
|
|
||||||
describe("buy card methods", () => {
|
|
||||||
test("tooExpensive", () => {
|
|
||||||
const card: CardData = {
|
|
||||||
gemValue: 'ruby',
|
|
||||||
tier: 3,
|
|
||||||
points: 0,
|
|
||||||
resourceCost: {
|
|
||||||
ruby: 0,
|
|
||||||
sapphire: 0,
|
|
||||||
emerald: 0,
|
|
||||||
diamond: 0,
|
|
||||||
onyx: 3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const testPlayer: PlayerData = {
|
|
||||||
name: "Test Player",
|
|
||||||
id: 1,
|
|
||||||
starter: true,
|
|
||||||
turnActive: true,
|
|
||||||
points: 0,
|
|
||||||
cards: [],
|
|
||||||
nobles: [],
|
|
||||||
inventory: {
|
|
||||||
ruby: 1,
|
|
||||||
sapphire: 1,
|
|
||||||
emerald: 1,
|
|
||||||
diamond: 1,
|
|
||||||
onyx: 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const sampleState: AppState = {
|
|
||||||
...initialState,
|
|
||||||
players: [testPlayer, mockPlayerTwo]
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(tooExpensive(card, sampleState)).toBeTruthy();
|
|
||||||
})
|
|
||||||
|
|
||||||
test('tooExpensive accounts for gold chips', () => {
|
|
||||||
const card: CardData = {
|
|
||||||
gemValue: 'ruby',
|
|
||||||
tier: 3,
|
|
||||||
points: 0,
|
|
||||||
resourceCost: {
|
|
||||||
ruby: 0,
|
|
||||||
sapphire: 0,
|
|
||||||
emerald: 0,
|
|
||||||
diamond: 0,
|
|
||||||
onyx: 3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const testPlayer: PlayerData = {
|
|
||||||
name: "Test Player",
|
|
||||||
id: 1,
|
|
||||||
starter: true,
|
|
||||||
turnActive: true,
|
|
||||||
points: 0,
|
|
||||||
cards: [],
|
|
||||||
nobles: [],
|
|
||||||
inventory: {
|
|
||||||
ruby: 1,
|
|
||||||
sapphire: 1,
|
|
||||||
emerald: 1,
|
|
||||||
diamond: 1,
|
|
||||||
onyx: 2,
|
|
||||||
gold: 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const sampleState: AppState = {
|
|
||||||
...initialState,
|
|
||||||
players: [testPlayer, mockPlayerTwo]
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(tooExpensive(card, sampleState)).toBeFalsy();
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
export default {}
|
|
||||||
122
src/components/Player/ActionMethods/tests/buyCard.test.tsx
Normal file
122
src/components/Player/ActionMethods/tests/buyCard.test.tsx
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
import { describe, expect, it, test, vi } from "vitest"
|
||||||
|
import Adapter from 'enzyme-adapter-react-16';
|
||||||
|
import { shallow } from "enzyme"
|
||||||
|
import { initialState } from "../../../../hooks/stateSetters"
|
||||||
|
import { mockCardRows, mockPlayerOne, mockPlayerTwo, sampleTierOneCard } from "../../../../util/testUtils"
|
||||||
|
import { AppState, PlayerData, setStateType } from "../../../../util/types"
|
||||||
|
import { buyCard, tooExpensive } from "../buyCardActions"
|
||||||
|
import { configure } from "enzyme";
|
||||||
|
import Player from "../../Player"
|
||||||
|
import Gameboard from "../../../Gameboard/Gameboard";
|
||||||
|
import initializeBoard from "../../../../util/initializeBoard";
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
|
configure({ adapter: new Adapter() });
|
||||||
|
|
||||||
|
const testPlayer: PlayerData = {
|
||||||
|
name: "Test Player",
|
||||||
|
id: 1,
|
||||||
|
starter: true,
|
||||||
|
turnActive: true,
|
||||||
|
points: 0,
|
||||||
|
cards: [],
|
||||||
|
nobles: [],
|
||||||
|
inventory: {
|
||||||
|
ruby: 1,
|
||||||
|
sapphire: 1,
|
||||||
|
emerald: 1,
|
||||||
|
diamond: 1,
|
||||||
|
onyx: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("buy card methods", () => {
|
||||||
|
describe("tooExpensive", () => {
|
||||||
|
it('detects unaffordable cards', () => {
|
||||||
|
const sampleState: AppState = {
|
||||||
|
...initialState,
|
||||||
|
players: [testPlayer, mockPlayerTwo]
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(tooExpensive(sampleTierOneCard, sampleState)).toBeTruthy();
|
||||||
|
})
|
||||||
|
|
||||||
|
it('accounts for gold chips', () => {
|
||||||
|
const goldPlayer: PlayerData = {
|
||||||
|
...testPlayer,
|
||||||
|
inventory: {
|
||||||
|
ruby: 1,
|
||||||
|
sapphire: 1,
|
||||||
|
emerald: 1,
|
||||||
|
diamond: 1,
|
||||||
|
onyx: 2,
|
||||||
|
gold: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const sampleState: AppState = {
|
||||||
|
...initialState,
|
||||||
|
players: [goldPlayer, mockPlayerTwo],
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(tooExpensive(sampleTierOneCard, sampleState)).toBeFalsy();
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('buyCard', () => {
|
||||||
|
const setState: setStateType = vi.fn();
|
||||||
|
|
||||||
|
test('renders Player component', () => {
|
||||||
|
const wrapper = shallow(<Player player={testPlayer} state={initialState} setState={setState} />)
|
||||||
|
const name = wrapper.contains("Test Player");
|
||||||
|
expect(name).toBeTruthy();
|
||||||
|
})
|
||||||
|
|
||||||
|
it('updates player inventory', () => {
|
||||||
|
// const updatedPlayerOne: PlayerData = {
|
||||||
|
// ...mockPlayerOne,
|
||||||
|
// inventory: {
|
||||||
|
// ...mockPlayerOne.inventory,
|
||||||
|
// onyx: 3
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const currentState: AppState = {
|
||||||
|
// ...initialState,
|
||||||
|
// players: [updatedPlayerOne, mockPlayerTwo],
|
||||||
|
// gameboard: {
|
||||||
|
// ...initialState.gameboard,
|
||||||
|
// cardRows: mockCardRows
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // shallow renders a new gameboard component which encapsulates current players
|
||||||
|
// const wrapper = shallow(<Gameboard state={currentState} setState={setState} />)
|
||||||
|
// initializeBoard(currentState, setState);
|
||||||
|
|
||||||
|
// expect(currentState.gameboard.cardRows.tierOne).toHaveLength(4);
|
||||||
|
// expect(currentState.gameboard.cardRows.tierOne).toContain(sampleTierOneCard);
|
||||||
|
|
||||||
|
// const playerUI = shallow((<Player player={updatedPlayerOne} state={currentState} setState={setState}></Player>))
|
||||||
|
// expect(playerUI.children()).toContain("Name: Player One");
|
||||||
|
})
|
||||||
|
|
||||||
|
it('spends a player\'s gold when necessary', () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
it('updates gameboard resources', () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
it('triggers player to pick up first possible noble', () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
it('only allows one noble to be acquired at a time', () => {
|
||||||
|
expect(1).toBe(0);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
export default {}
|
||||||
@@ -75,8 +75,4 @@ describe('get chips', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('getChips', () => {
|
|
||||||
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
@@ -43,7 +43,7 @@ export default function Player({ player, state, setState }: PlayerProps) {
|
|||||||
{
|
{
|
||||||
dynamic.reservedCards?.map((data: CardData) => {
|
dynamic.reservedCards?.map((data: CardData) => {
|
||||||
return (
|
return (
|
||||||
<div key={v4()} className="mini-card" style={{backgroundColor: 'white'}}>
|
<div key={v4()} className="mini-card" id={`${dynamic.name}-player-ui`} style={{backgroundColor: 'white'}}>
|
||||||
<p>{data.gemValue} cards</p>
|
<p>{data.gemValue} cards</p>
|
||||||
<p>{data.points + " points" || null}</p>
|
<p>{data.points + " points" || null}</p>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { initialState } from "../hooks/stateSetters"
|
import { initialState } from "../hooks/stateSetters"
|
||||||
import { AppState, CardData, NobleData, PlayerData } from "./types"
|
import { AppState, CardData, NobleData, PlayerData } from "./types"
|
||||||
|
import Cards from '../data/cards.json';
|
||||||
|
|
||||||
// mock data for early game
|
// mock data for early game
|
||||||
export const mockPlayerOne: PlayerData = {
|
export const mockPlayerOne: PlayerData = {
|
||||||
@@ -43,6 +44,40 @@ export const mockState: AppState = {
|
|||||||
players: [mockPlayerOne, mockPlayerTwo]
|
players: [mockPlayerOne, mockPlayerTwo]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const sampleTierOneCard: CardData = {
|
||||||
|
gemValue: 'ruby',
|
||||||
|
tier: 3,
|
||||||
|
points: 0,
|
||||||
|
resourceCost: {
|
||||||
|
ruby: 0,
|
||||||
|
sapphire: 0,
|
||||||
|
emerald: 0,
|
||||||
|
diamond: 0,
|
||||||
|
onyx: 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const mockCardRows = {
|
||||||
|
tierOne: [
|
||||||
|
Cards.tierOne[0],
|
||||||
|
Cards.tierOne[1],
|
||||||
|
Cards.tierOne[2],
|
||||||
|
sampleTierOneCard,
|
||||||
|
],
|
||||||
|
tierTwo: [
|
||||||
|
Cards.tierTwo[0],
|
||||||
|
Cards.tierTwo[1],
|
||||||
|
Cards.tierTwo[2],
|
||||||
|
Cards.tierTwo[3],
|
||||||
|
],
|
||||||
|
tierThree: [
|
||||||
|
Cards.tierThree[0],
|
||||||
|
Cards.tierThree[1],
|
||||||
|
Cards.tierThree[2],
|
||||||
|
Cards.tierThree[3],
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
// mock data for midgame
|
// mock data for midgame
|
||||||
// playerOneMidGame buys high diamond cost card
|
// playerOneMidGame buys high diamond cost card
|
||||||
export const playerOneMidGame = {
|
export const playerOneMidGame = {
|
||||||
|
|||||||
Reference in New Issue
Block a user