Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

javascript - 此(“ board [y] [x] .cell”)方法意味着什么?(What this (“board[y][x].cell”) method means?)

This is the website of a JavaScript tutorial I'm trying to learn ( Snake In JavaScript )(这是我要学习的JavaScript教程的网站( Snake In JavaScript ))

It's a snake game with JavaScript but there are some things I don't understand:(这是一个使用JavaScript的蛇游戏,但是有些事情我不明白:)

  1. What is board[][] ?(什么是board[][] ?)
  2. Why do they add a .snake custom method after the above one ???(为什么他们在上述一个after之后添加.snake自定义方法?) Why is its value equal to 1?(为什么它的值等于1?)
  3. How does the snake move?(蛇如何移动?) (In other words, how does the loop work for the array to add cells in y and x axis according to key press?)((换句话说,该循环如何使数组根据按键在y和x轴上添加单元格?))

These are some obstacles in my understanding.(这些是我理解的障碍。)

  ask by Anmol Kashyap translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

So answer in question 1 by 1:(因此,以1回答问题1:)

  1. Board[][] mean multi-dimension array (2 in this case) - in the case of the snake game it represent the board where each row is array and the first column is array of arrays(Board[][]表示多维数组(在这种情况下为2)-在蛇形游戏中,它表示每个行都是数组而第一列是数组数组的棋盘)
  2. The .snake is not a method but an Boolean variable in the cell object which indicate if the snake is present in that specific cell - it has value of one if the snake is there and 0 otherwise.(.snake不是方法,而是单元格对象中的布尔变量,它指示该特定单元格中是否存在蛇-如果蛇存在,则值为1,否则为0。) This var used where we display the board on screen.(此变量用于在屏幕上显示板的位置。)
  3. The enterKey function is called whenever key is stroke.(每当击键时都会调用enterKey函数。) Then by the key we specify the snake direction and change the head coordinate accordingly.(然后通过键指定蛇的方向并相应地更改头部坐标。)

As for your question in the title: the .cell is a object that is the base object of the board - each element in the 2-dimensional array is a dictionary name cell .(至于标题中的问题: .cell是一个对象,它是电路板的基础对象-二维数组中的每个元素都是一个字典名称cell 。)

I hope this make it little but clearer(我希望这可以使它变得更清晰)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...