add game smart monday

This commit is contained in:
lagaffe 2026-04-19 13:44:45 +02:00
parent 0a95900c55
commit 8f08f96096
7 changed files with 42 additions and 15 deletions

View file

@ -91,7 +91,7 @@ export class Fridge extends Game {
makeDragable(newBottle, (node) => {
this._onBottleDrop(node);
if (this._bottlePlaced >= this._bottleCount) {
console.log("fridge game won");
this._win();
}
});
this.gameContainer.addChild(newBottle);

View file

@ -10,4 +10,10 @@ export class Game {
/* should reset the game to its initial position*/
reset() {}
_win() {
this.win = true;
console.log("game won");
// we probably want to call a callback here
}
}

View file

@ -1,2 +1,3 @@
export { Fridge } from "./fridge.js";
export { Opinator } from "./opinator.js";
export { SmartMonday } from "./smartMonday.js";

View file

@ -51,13 +51,13 @@ export class Opinator extends Game {
this._pixelGoalScore,
);
if (this._pixelGoalScore < this._currentScore) {
console.log("game won");
this.won = true;
this._win();
}
} //else ignore, not enough move to get some distance
}
});
backgroundSprite.layout = backgroundLayout;
backgroundSprite.layout = { objectFit: "contain" };
this.gameContainer.layout = { width: "100%", height: "100%" };
this.gameContainer.addChild(backgroundSprite);
}

22
src/games/smartMonday.js Normal file
View file

@ -0,0 +1,22 @@
import { Application, Assets, Container, Sprite, Rectangle } from "pixi.js";
import { Game } from "./game";
import { KeyBoardListener } from "../common";
export class SmartMonday extends Game {
constructor() {
super();
this._goal = 100 * this._difficulty; // number of characters
this._currentString = "";
const handle = KeyBoardListener.onKeyDown((event) => {
this._currentString += event.key;
console.log("current text", this._currentString);
if (this._currentString.length >= this._goal) {
this._win();
}
});
}
reset() {}
}

View file

@ -1,7 +1,7 @@
import "@pixi/layout";
import { Application, Assets, Container, Sprite } from "pixi.js";
import { Fridge, Opinator } from "./games";
import { backgroundLayout } from "./common";
import { Fridge, Opinator, SmartMonday } from "./games";
import { backgroundLayout, KeyBoardListener } from "./common";
const app = new Application();
let root = new Container();
@ -53,6 +53,8 @@ async function preload() {
},
];
await Assets.load(assets);
KeyBoardListener.init();
}
function switchToGame(gameContainer, newGame) {
@ -80,7 +82,10 @@ function switchToGame(gameContainer, newGame) {
};
const opinator = new Opinator();
const fridge = new Fridge();
gameContainter.addChild(fridge.gameContainer);
//gameContainter.addChild(opinator.gameContainer);
const smartMonday = new SmartMonday();
//gameContainter.addChild(fridge.gameContainer);
gameContainter.addChild(opinator.gameContainer);
gameContainter.addChild(smartMonday.gameContainer);
root.addChild(gameContainter);
})();

7
src/package-lock.json generated
View file

@ -9,7 +9,6 @@
"version": "0.0.0",
"dependencies": {
"@pixi/layout": "^3.2.0",
"@pixi/math": "^7.4.3",
"pixi.js": "^8.0.0"
},
"devDependencies": {
@ -102,12 +101,6 @@
"yoga-layout": "^3"
}
},
"node_modules/@pixi/math": {
"version": "7.4.3",
"resolved": "https://registry.npmjs.org/@pixi/math/-/math-7.4.3.tgz",
"integrity": "sha512-/uJOVhR2DOZ+zgdI6Bs/CwcXT4bNRKsS+TqX3ekRIxPCwaLra+Qdm7aDxT5cTToDzdxbKL5+rwiLu3Y1egILDw==",
"license": "MIT"
},
"node_modules/@pixi/react": {
"version": "8.0.5",
"resolved": "https://registry.npmjs.org/@pixi/react/-/react-8.0.5.tgz",