This commit is contained in:
2024-05-01 19:13:01 +08:00
parent cf008327aa
commit 80a32d9b1b
150 changed files with 8561 additions and 5045 deletions

View File

@@ -1,7 +1,7 @@
import { Vec2 } from 'cc'
export default class RandomUtil {
//随机minNum到maxNum的数字 包含maxNum
// 随机minNum到maxNum的数字 包含maxNum
public static nextInt(minNum: number, maxNum: number) {
return Math.floor(Math.random() * (maxNum - minNum + 1) + minNum)
}
@@ -11,27 +11,24 @@ export default class RandomUtil {
}
public static nextSign() {
let temp = Math.random()
if (temp < 0.5) {
return 1
}
const temp = Math.random()
if (temp < 0.5) return 1
return -1
}
public static nextBoolean() {
let temp = Math.random()
return temp < 0.5;
const temp = Math.random()
return temp < 0.5
}
public static randomArr(nowArr: Array<any>, needNum: number) {
let tempArr: Array<any> = nowArr.concat()
let resultArr: Array<any> = []
const tempArr: Array<any> = nowArr.concat()
const resultArr: Array<any> = []
for (let index = 0; index < needNum; index++) {
if (tempArr.length <= 0) {
break
}
let randomIndex: number = RandomUtil.nextInt(0, tempArr.length - 1)
if (tempArr.length <= 0) break
const randomIndex: number = RandomUtil.nextInt(0, tempArr.length - 1)
resultArr.push(tempArr.splice(randomIndex, 1)[0])
}
return resultArr
@@ -42,8 +39,8 @@ export default class RandomUtil {
}
public static randomP(left: number, right: number, up: number, down: number) {
let randomX: number = RandomUtil.nextNumber(left, right)
let randomY: number = RandomUtil.nextNumber(up, down)
const randomX: number = RandomUtil.nextNumber(left, right)
const randomY: number = RandomUtil.nextNumber(up, down)
return new Vec2(randomX, randomY)
}
}