如何在Javascript中的两个指定变量之间生成随机整数,例如x = 4并y = 8输出4,5,6,7,8中的任何一个?
对于我用JavaScript创建的第一个(正确的)游戏,我正在制作一个Snake游戏.我在这样的类中存储有关蛇的所有信息:
var snake={
//The width and height of each "segment" of the snake (in pixels)
size : 20,
/*Direction that the snake's moving in
Left=0
Right=1
Up=2
Down=3*/
direction : rand_int_between(0,3),
/*Positions of the snake's "segments" (1 is the snake's head, then 2 (when it's created) will be the next segment of the snake,
then 3 will be the next, and so on*/
positions : {
1 : {
"x" : rand_int_between(0, 35)*snake.size, //There are 36 possible "columns" that the …Run Code Online (Sandbox Code Playgroud)