Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Etimo/diamonds2 into wip/deno
Browse files Browse the repository at this point in the history
  • Loading branch information
morgan-cromell committed Nov 15, 2024
2 parents 6b3be8f + 4cbe434 commit 678e5ba
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CD
name: Deploy

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ export class BotProvider extends AbstractGameObjectProvider<BotProviderConfig> {
super(config);
}

override onBotJoined(bot: IBot, board: Board) {
// Add game object to board
onBotJoined(bot: IBot, board: Board) {
const base = board.getEmptyPosition();
const botGameObject = this.getInitializedBot(bot, base, board);
board.addGameObjects([botGameObject]);
Expand Down
19 changes: 8 additions & 11 deletions packages/backend/src/gameengine/gameobjects/bot/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ export class BotGameObject extends AbstractGameObject {

override onGameObjectEntered(gameObject: AbstractGameObject) {
if (gameObject instanceof BotGameObject) {
const otherBot = gameObject as BotGameObject;

// Return if the entering bot is not allowed to tackle (should not happen)
if (!otherBot.canTackle) {
if (!gameObject.canTackle) {
return;
}

Expand All @@ -68,23 +66,22 @@ export class BotGameObject extends AbstractGameObject {
// Also they steal some diamonds from me
const canSteal = Math.min(
this.diamonds,
otherBot.inventorySize - otherBot.diamonds,
gameObject.inventorySize - gameObject.diamonds,
);
this.diamonds = Math.max(this.diamonds - canSteal, 0);
otherBot.diamonds += canSteal;
gameObject.diamonds += canSteal;
}
}
override canGameObjectEnter(gameObject: AbstractGameObject): boolean {
if (gameObject instanceof BotGameObject) {
const otherBot = gameObject as BotGameObject;

if (otherBot.canTackle) {
canGameObjectEnter(gameObject: AbstractGameObject): boolean {
if (gameObject instanceof BotGameObject) {
if (gameObject.canTackle) {
return true;
}

if (
otherBot.base.x === this.position.x &&
otherBot.base.y === this.position.y
gameObject.base.x === this.position.x &&
gameObject.base.y === this.position.y
) {
this.position = this.base;
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export class DiamondButtonProvider extends AbstractGameObjectProvider {
* Listen for when game objects are removed and generate new button when needed.
*/
onGameObjectsRemoved(board: Board, gameObjects: AbstractGameObject[]) {
// Check number of diamonds on the board
const existingButtons = board.getGameObjectsByType(DiamondButtonGameObject);
/* istanbul ignore else */
if (existingButtons.length == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { Board } from "../../board.ts";
import { AbstractGameObjectProvider } from "../abstract-game-object-providers.ts";
import { DiamondGameObject } from "./diamond.ts";

export class DiamondProvider
extends AbstractGameObjectProvider<DiamondProviderConfig> {
export class DiamondProvider extends AbstractGameObjectProvider<DiamondProviderConfig> {
constructor(config: DiamondProviderConfig) {
super(config);
}
Expand All @@ -15,8 +14,6 @@ export class DiamondProvider

override onGameObjectsRemoved(board: Board, other: any) {
const diamonds = board.getGameObjectsByType(DiamondGameObject);
const minLimit = board.width * board.height *
this.config.minRatioForGeneration;
if (diamonds.length == 0) {
this.generateDiamonds(board);
}
Expand Down
11 changes: 7 additions & 4 deletions packages/backend/src/gameengine/gameobjects/diamond/diamond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { Board } from "../../board.ts";
import { AbstractGameObject } from "../abstract-game-object.ts";
import { BotGameObject } from "../bot/bot.ts";
export class DiamondGameObject extends AbstractGameObject {
constructor(position: Position, public points: number) {
constructor(
position: Position,
public points: number,
) {
super(position);
}

Expand All @@ -12,15 +15,15 @@ export class DiamondGameObject extends AbstractGameObject {
points: this.points,
};
}

/**
* Remove the diamond when a bot enters and put it in the bot's inventory.
*/
onGameObjectEntered(gameObject: AbstractGameObject, board: Board) {
/* istanbul ignore else */
if (gameObject instanceof BotGameObject) {
const bot = gameObject as BotGameObject;
if (bot.diamonds + this.points <= bot.inventorySize) {
bot.diamonds += this.points;
if (gameObject.diamonds + this.points <= gameObject.inventorySize) {
gameObject.diamonds += this.points;
board.removeGameObject(this);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/services/board.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ export class BoardsService {
const sessionLength = boardConfig.sessionLength;
const minimumDelayBetweenMoves = boardConfig.minimumDelayBetweenMoves;
const extraFactor = 1.5;
const maxMoves = (1000 / minimumDelayBetweenMoves) * sessionLength *
extraFactor;
const maxMoves =
(1000 / minimumDelayBetweenMoves) * sessionLength * extraFactor;
this.recordingsService.setup(
numberOfBoards + numEphemeralBoards,
maxMoves,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import { SparklesComponent } from "./SparklesComponent.tsx";
export const DiamondComponent: FC<DiamondGameObjectProperties> = memo(
({ points }) => {
const characterImg = points === 2 ? diamondRed : diamond;
const imageClassName = "diamond";
return (
<>
<CommonGameObject
characterImg={characterImg}
imageClassName={imageClassName}
imageClassName="diamond"
/>
<SparklesComponent />
</>
Expand Down

0 comments on commit 678e5ba

Please sign in to comment.