Skip to content

Commit

Permalink
You can now buy cards (#16)
Browse files Browse the repository at this point in the history
* You can now buy cards

* Various bug/display fixes

* Make joker selection buttons invisible for buy card to eliminate visual redundancy

Co-authored-by: Gregory Heskett <[email protected]>
  • Loading branch information
zheskett and gheskett authored Aug 22, 2020
1 parent 6925865 commit c0cd5a3
Show file tree
Hide file tree
Showing 8 changed files with 675 additions and 157 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified phaser/src/assets/images/boardAssets/take_chips.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
457 changes: 380 additions & 77 deletions phaser/src/classes/card.js

Large diffs are not rendered by default.

167 changes: 157 additions & 10 deletions phaser/src/classes/returnChips.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export class returnChips extends Phaser.GameObjects.DOMElement {
* @param {integer} x
* @param {integer} y
* @param {string} cache
* @param {string} use
*/

constructor(scene, x, y, cache) {
Expand All @@ -19,7 +18,7 @@ export class returnChips extends Phaser.GameObjects.DOMElement {
this.setDepth(2);
}

createReturnChips(use) {
createReturnChips(use, cardID = -1) {
const chipReturn = this;
const board = chipReturn.scene;
const chipOrder = new Map([
Expand All @@ -41,11 +40,15 @@ export class returnChips extends Phaser.GameObjects.DOMElement {
this.setVisible(true);
this.removeAllListeners();

if (use === "chip_overflow") {
const chipsNeeded =
chipReturn.sumObj(board.gameState.players[globals.playerID.toString()].player_chips) +
chipReturn.sumArr(board.cachedChips) -
10;
if (use === "chip_overflow" || use === "chip_overflow_2") {
if (use === "chip_overflow") {
var chipsNeeded =
chipReturn.sumObj(board.gameState.players[globals.playerID.toString()].player_chips) +
chipReturn.sumArr(board.cachedChips) -
10;
} else {
var chipsNeeded = 1;
}
chipReturn.getChildByID("return_title").innerHTML = "Too Many Gems!";
chipReturn.getChildByID("return_subtitle").innerHTML = "Please return " + chipsNeeded.toString();
if (chipsNeeded === 1) {
Expand All @@ -70,10 +73,17 @@ export class returnChips extends Phaser.GameObjects.DOMElement {
.getChildByID("chip_container")
.getElementsByClassName("chip_and_num")
.item(i).lastElementChild;
og_chipValues[i] =
board.gameState.players[globals.playerID.toString()].player_chips[chipOrder.get(i)] +
(i < 5 ? board.cachedChips[i] : 0);
if (use === "chip_overflow") {
og_chipValues[i] =
board.gameState.players[globals.playerID.toString()].player_chips[chipOrder.get(i)] +
(i < 5 ? board.cachedChips[i] : 0);
} else {
og_chipValues[i] =
board.gameState.players[globals.playerID.toString()].player_chips[chipOrder.get(i)] +
(i < 5 ? 0 : 1);
}
og_chipNums[i].innerHTML = og_chipValues[i].toString();
og_chipNums[i].style.color = "white";

if (og_chipValues[i] >= 1) {
plusButtons[i] = chipReturn
Expand All @@ -94,6 +104,13 @@ export class returnChips extends Phaser.GameObjects.DOMElement {
.item(i).firstElementChild;
minusButtons[i].disabled = true;

if (i === inverseChipMap["joker"]) {
chipReturn
.getChildByID("plus_minus_container")
.getElementsByClassName("plus_minus")
.item(i).style.opacity = 1;
}

returnNums[i] = chipReturn.getChildByID("num_container").children.item(i);
returnNums[i].innerHTML = returnValues[i].toString();
}
Expand Down Expand Up @@ -161,6 +178,136 @@ export class returnChips extends Phaser.GameObjects.DOMElement {
joker: returnValues[5],
};

board.boardEvents.emit("chips_returned", returnObj);
chipReturn.reset();
} else if (pressedButton.type === "cancel") {
board.boardEvents.off("chips_returned");
chipReturn.reset();
}
});
} else if (use === "buy_card") {
chipReturn.getChildByID("return_title").innerHTML = "Buy Card";
chipReturn.getChildByID("return_subtitle").innerHTML = "Please spend necessary gems";
chipReturn.getChildByID("submit_chips").disabled = false;

const player = board.gameState.players[globals.playerID.toString()];

let og_chipNums = [];
let og_chipValues = [];
let plusButtons = [];
let minusButtons = [];
let returnNums = [];
let returnValues = [];

let returnDict = board.calculateReturn(cardID);
let emptyJokers = player.player_chips["joker"] - returnDict.joker;

for (let i = 0; i < Object.keys(returnDict).length; i++) {
og_chipValues[i] = returnDict[chipOrder.get(i)];
returnValues[i] = returnDict[chipOrder.get(i)];

og_chipNums[i] = chipReturn
.getChildByID("chip_container")
.getElementsByClassName("chip_and_num")
.item(i).lastElementChild;

og_chipNums[i].innerHTML = player.player_chips[chipOrder.get(i)].toString();
if (og_chipValues[i] > player.player_chips[chipOrder.get(i)]) og_chipNums[i].style.color = "yellow";
else og_chipNums[i].style.color = "white";

if (emptyJokers >= 1 && chipOrder.get(i) !== "joker" && og_chipValues[i] > 0) {
minusButtons[i] = chipReturn
.getChildByID("plus_minus_container")
.getElementsByClassName("plus_minus")
.item(i).firstElementChild;
minusButtons[i].disabled = false;
} else {
minusButtons[i] = chipReturn
.getChildByID("plus_minus_container")
.getElementsByClassName("plus_minus")
.item(i).firstElementChild;
minusButtons[i].disabled = true;
}
plusButtons[i] = chipReturn
.getChildByID("plus_minus_container")
.getElementsByClassName("plus_minus")
.item(i).lastElementChild;
plusButtons[i].disabled = true;

if (i === inverseChipMap["joker"]) {
chipReturn
.getChildByID("plus_minus_container")
.getElementsByClassName("plus_minus")
.item(i).style.opacity = 0;
}

returnNums[i] = chipReturn.getChildByID("num_container").children.item(i);
returnNums[i].innerHTML = returnValues[i].toString();
}

chipReturn.addListener("click").on("click", function (event) {
let pressedButton = {type: "", id: -1};
if (event.target.parentNode.className === "plus_minus") {
pressedButton.type = event.target.className;
pressedButton.id = inverseChipMap[event.target.parentNode.id.split("_").pop()];
} else if (event.target.id === "submit_chips") {
pressedButton.type = "submit";
} else if (event.target.id === "cancel_chips") {
pressedButton.type = "cancel";
}

if (pressedButton.type === "plus") {
returnValues[pressedButton.id] += 1;
returnValues[inverseChipMap.joker] -= 1;
emptyJokers += 1;

if (returnValues[pressedButton.id] === og_chipValues[pressedButton.id]) {
og_chipNums[pressedButton.id].style.color = "white";
}

returnNums[pressedButton.id].innerHTML = returnValues[pressedButton.id].toString();
returnNums[inverseChipMap.joker].innerHTML = returnValues[inverseChipMap.joker].toString();

if (
returnValues[pressedButton.id] >= og_chipValues[pressedButton.id] ||
returnValues[pressedButton.id] >= player.player_chips[chipOrder.get(pressedButton.id)]
) {
plusButtons[pressedButton.id].disabled = true;
}

for (let i = 0; i < minusButtons.length; i++)
minusButtons[i].disabled = !(returnValues[i] > 0 && i !== inverseChipMap.joker);
} else if (pressedButton.type === "minus") {
returnValues[pressedButton.id] -= 1;
returnValues[inverseChipMap.joker] += 1;
emptyJokers -= 1;

returnNums[pressedButton.id].innerHTML = returnValues[pressedButton.id].toString();
returnNums[inverseChipMap.joker].innerHTML = returnValues[inverseChipMap.joker].toString();
og_chipNums[pressedButton.id].style.color = "yellow";

if (returnValues[pressedButton.id] <= 0) {
minusButtons[pressedButton.id].disabled = true;
}

plusButtons[pressedButton.id].disabled = false;

for (let i = 0; i < minusButtons.length; i++)
minusButtons[i].disabled = !(
returnValues[i] > 0 &&
emptyJokers >= 1 &&
i !== inverseChipMap.joker
);
} else if (pressedButton.type === "submit") {
const returnObj = {
diamond: returnValues[0],
sapphire: returnValues[1],
emerald: returnValues[2],
ruby: returnValues[3],
onyx: returnValues[4],
joker: returnValues[5],
};

board.boardEvents.emit("chips_returned", returnObj);
chipReturn.reset();
} else if (pressedButton.type === "cancel") {
Expand Down
117 changes: 58 additions & 59 deletions phaser/src/classes/serverManager.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,66 @@
import { card } from "./card";
import {card} from "./card";

export class serverManager {
lookUpCard(database, cardId) {
//TODO: actual numbers
if (cardId == -1) {
return {
"card_id" : 0,
"rank" : 1,
"prestige_points" : 0,
"gem_type" : "diamond",
"diamond" : 0,
"sapphire" : 0,
"emerald" : 0,
"ruby" : 0,
"onyx" : 0
};
}
lookUpCard(database, cardId) {
//TODO: actual numbers
if (cardId == -1) {
return {
card_id: 0,
rank: 1,
prestige_points: 0,
gem_type: "diamond",
diamond: 0,
sapphire: 0,
emerald: 0,
ruby: 0,
onyx: 0,
};
}

let card = database[cardId]
let card = database[cardId];

return {
"card_id" : card.card_id,
"rank" : card.rank,
"prestige_points" : card.prestige_points,
"gem_type" : card.gem_type,
"diamond" : card.diamond,
"sapphire" : card.sapphire,
"emerald" : card.emerald,
"ruby" : card.ruby,
"onyx" : card.onyx
};
}
return {
card_id: card.card_id,
rank: card.rank,
prestige_points: card.prestige_points,
gem_type: card.gem_type,
diamond: card.diamond,
sapphire: card.sapphire,
emerald: card.emerald,
ruby: card.ruby,
onyx: card.onyx,
};
}

lookUpNoble(database, nobleId) {
//TODO: actual numbers
if (nobleId == -1) {
return {
"noble_id" : 0,
"prestige_points" : 0,
"diamond" : 0,
"sapphire" : 0,
"emerald" : 0,
"ruby" : 0,
"onyx" : 0
};
}
lookUpNoble(database, nobleId) {
//TODO: actual numbers
if (nobleId == -1) {
return {
noble_id: 0,
prestige_points: 0,
diamond: 0,
sapphire: 0,
emerald: 0,
ruby: 0,
onyx: 0,
};
}

let noble = database[nobleId]
let noble = database[nobleId];

return {
"noble_id" : noble.noble_id,
"prestige_points" : noble.prestige_points,
"diamond" : noble.diamond,
"sapphire" : noble.sapphire,
"emerald" : noble.emerald,
"ruby" : noble.ruby,
"onyx" : noble.onyx
};
}
return {
noble_id: noble.noble_id,
prestige_points: noble.prestige_points,
diamond: noble.diamond,
sapphire: noble.sapphire,
emerald: noble.emerald,
ruby: noble.ruby,
onyx: noble.onyx,
};
}

lookUpFieldChips(game, chipType) {
if (game == null)
return 0;
return game.field_chips[chipType];
}
}
lookUpFieldChips(game, chipType) {
if (game == null) return 0;
return game.field_chips[chipType];
}
}
Loading

0 comments on commit c0cd5a3

Please sign in to comment.