Skip to content

Commit

Permalink
Correct the cost deductions reported when buying upgrades now that th…
Browse files Browse the repository at this point in the history
…e prices change with each purchase. This suffices to complete "step 7" as defined by the school assignment for which purpose this fork is maintained. (Strictly speaking, the previous commit would also have sufficed, if I wanted to be an insufferable smartass about it, but I don't especially.)
  • Loading branch information
blujai831 committed Oct 11, 2024
1 parent 46ce9a3 commit e6963bd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/GameState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,21 @@ export class GameState implements IGameState {
let upgrade: IGameUpgrade = upgrades[what];
if (upgrade.canPurchase(this)) {
upgrade.doPostPurchase(this);
if (upgrade.purchaseAckMessage !== undefined) {
this._notice(upgrade.purchaseAckMessage(this));
}
let qty: number | undefined = this._upgradeAmounts[what];
if (qty === undefined) {
qty = 0;
}
qty += 1;
this._upgradeAmounts[what] = qty;
if (upgrade.purchaseAckMessage !== undefined) {
this._notice(upgrade.purchaseAckMessage);
}
this._playerSpeedNeedsRecalc = true;
this._showInventoryList();
return true;
} else {
if (upgrade.purchaseNakMessage !== undefined) {
this._notice(upgrade.purchaseNakMessage);
this._notice(upgrade.purchaseNakMessage(this));
}
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/GameUpgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export class GameUpgrade implements IGameUpgrade {
/**
* See IGameUpgrade.purchaseAckMessage.
*/
public purchaseAckMessage?: string;
public purchaseAckMessage?: (gameState: IGameState) => string;
/**
* See IGameUpgrade.purchaseNakMessage.
*/
public purchaseNakMessage?: string;
public purchaseNakMessage?: (gameState: IGameState) => string;
/**
* Callback to be invoked to implement doPostPurchase.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/IGameUpgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ export interface IGameUpgrade {
* If this property exists, it should be used as the message for a notice
* to be displayed when the player successfully purchases this upgrade.
*/
purchaseAckMessage?: string;
purchaseAckMessage?: (gameState: IGameState) => string;
/**
* If this property exists, it should be used as the message for a notice
* to be displayed when the player tries and fails to purchase
* this upgrade.
*/
purchaseNakMessage?: string;
purchaseNakMessage?: (gameState: IGameState) => string;
/**
* Does any modifications to the game state consistent with purchasing
* this upgrade, other than increasing the player's possessed quantity
Expand Down
26 changes: 16 additions & 10 deletions src/upgrades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ export const upgrades: {[upgradeName: string]: IGameUpgrade} = {
purchaseCondition: (gameState: IGameState): boolean =>
gameState.playerPlaceCounter >=
getPrice('beabnsies', gameState, 10),
purchaseAckMessage: "backtracked 10 blocks to find a beabnsy",
purchaseNakMessage:
purchaseAckMessage: (gameState: IGameState): string =>
"backtracked " +
`${getPrice('beabnsies', gameState, 10)} ` +
"blocks to find a beabnsy",
purchaseNakMessage: (_dontCare: IGameState): string =>
"you aren't far enough to backtrack enough " +
"to find a beabnsy",
postPurchaseEffect: (gameState: IGameState): void => {
Expand All @@ -33,10 +36,12 @@ export const upgrades: {[upgradeName: string]: IGameUpgrade} = {
purchaseCondition: (gameState: IGameState): boolean =>
gameState.playerPlaceCounter >=
getPrice('roket', gameState, 100),
purchaseAckMessage:
"picked up tarsh for the past 100 blocks " +
"to build a roket",
purchaseNakMessage: "ther not enough trarsh to built an raocket",
purchaseAckMessage: (gameState: IGameState): string =>
"picked up tarsh for the past " +
`${getPrice('roket', gameState, 100)} ` +
"bloks to build a roket",
purchaseNakMessage: (_dontCare: IGameState): string =>
"ther not enough trarsh to built an raocket",
postPurchaseEffect: (gameState: IGameState): void => {
gameState.playerPlaceCounter -=
getPrice('roket', gameState, 100);
Expand All @@ -48,10 +53,11 @@ export const upgrades: {[upgradeName: string]: IGameUpgrade} = {
purchaseCondition: (gameState: IGameState): boolean =>
gameState.playerPlaceCounter >=
getPrice('bigrkt', gameState, 1000),
purchaseAckMessage:
"pikkocked oup tfarsh for the apst 1000 bloks " +
"too bfilt an BIGRKT WOA WOA",
purchaseNakMessage:
purchaseAckMessage: (gameState: IGameState): string =>
"pikkocked oup tfarsh for the apst " +
`${getPrice('bigrkt', gameState, 1000)} ` +
"blks too bfilt an BIGRKT WOA WOA",
purchaseNakMessage: (_dontCare: IGameState): string =>
"got go frther " +
"theres not ef trarash bakc ther yet",
postPurchaseEffect: (gameState: IGameState): void => {
Expand Down

0 comments on commit e6963bd

Please sign in to comment.