Full typescript and mvvm implementation #3
@ -21,14 +21,22 @@ export class CpuRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getRandomCpu() {
|
getRandomCpu() {
|
||||||
let randomIndex = this.#getRandomInt(0, this.#cpuList.length);
|
let randomIndex: number;
|
||||||
|
do {
|
||||||
|
randomIndex = this.#getRandomInt(0, this.#cpuList.length);
|
||||||
|
} while (this.#cpuList[randomIndex]["value"] == null || this.#cpuList[randomIndex]["type"] == null)
|
||||||
this.#cpuList[randomIndex]["name"] = this.#cpuList[randomIndex]["name"].split('@')[0];
|
this.#cpuList[randomIndex]["name"] = this.#cpuList[randomIndex]["name"].split('@')[0];
|
||||||
return this.#cpuList[randomIndex];
|
return this.#cpuList[randomIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
#getRandomInt(min, max) {
|
#getRandomInt(min, max): number {
|
||||||
min = Math.ceil(min);
|
min = Math.ceil(min);
|
||||||
max = Math.floor(max);
|
max = Math.floor(max);
|
||||||
return Math.floor(Math.random() * (max - min) + min); // The maximum is exclusive and the minimum is inclusive
|
return Math.floor(Math.random() * (max - min) + min); // The maximum is exclusive and the minimum is inclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nextRound(): void {
|
||||||
|
this.#currentCPU = this.#nextCPU
|
||||||
|
this.#nextCPU = this.getRandomCpu();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user