get random cpu
This commit is contained in:
parent
58b0686b44
commit
ce740885c7
19
game.js
19
game.js
@ -1,15 +1,28 @@
|
||||
var cpuList;
|
||||
var currentCpu;
|
||||
var nextCpu;
|
||||
|
||||
async function main() {
|
||||
var cpuList;
|
||||
await fetch('./data.json')
|
||||
.then((response) => response.json())
|
||||
.then((json) => cpuList = json);
|
||||
|
||||
|
||||
currentCpu = getRandomCpu();
|
||||
nextCpu = getRandomCpu();
|
||||
}
|
||||
|
||||
function getRandomCpu() {
|
||||
|
||||
let randomIndex = getRandomInt(0, cpuList.length)
|
||||
return {
|
||||
name: cpuList[randomIndex]["name"].split('@')[0],
|
||||
score: cpuList[randomIndex]["cpuScore"]
|
||||
}
|
||||
}
|
||||
|
||||
function getRandomInt(min, max) {
|
||||
min = Math.ceil(min);
|
||||
max = Math.floor(max);
|
||||
return Math.floor(Math.random() * (max - min) + min); // The maximum is exclusive and the minimum is inclusive
|
||||
}
|
||||
|
||||
main();
|
Loading…
Reference in New Issue
Block a user