mazegame
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { MazeObject } from "./MazeObject";
|
||||
|
||||
class MazeQuizGame {
|
||||
constructor(engine, context, questions) {
|
||||
let def = this.generate(questions);
|
||||
console.log(def)
|
||||
this.mazeObject = new MazeObject(engine, def)
|
||||
}
|
||||
|
||||
async load(){
|
||||
await this.mazeObject.load();
|
||||
this.object = this.mazeObject.object;
|
||||
return this.object;
|
||||
}
|
||||
|
||||
generate(questions, idx = 0){
|
||||
let cq = questions[idx]
|
||||
if (!cq) return {};
|
||||
let len = Math.round(Math.random()*4) + 2;
|
||||
let lr = Math.round(Math.random()*4) + 2;
|
||||
let lrv = Math.random() > 0.5;
|
||||
return {
|
||||
len,
|
||||
objects:[
|
||||
{
|
||||
type: 'text', text: cq.s, position:[0,.4,len], rotation:[0,Math.PI, 0]
|
||||
}
|
||||
],
|
||||
[lrv?'r':'l']:{
|
||||
len: 10 - lr,
|
||||
[lrv?'l':'r']: {
|
||||
len: lr,
|
||||
objects:[
|
||||
{
|
||||
type: 'text', text: cq.h, position:[0,.4,lr], rotation:[0,Math.PI, 0]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
[lrv?'l':'r']:{
|
||||
len: lr,
|
||||
[lrv?'r':'l']: this.generate(questions, idx + 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
export {MazeQuizGame}
|
||||
Reference in New Issue
Block a user