What snake does this code?

I am sure that someone there can answer this in a few seconds ...
All that interests me is that this piece of code is read from bottom to top? The comments say that the snake initially moves east, then heads the NORTH, and when I launch it, this statement is true. But the coordinates go from 7.7 to 6.7, then 5.7, and so on ... Isn't this a snake connected to the west? or is the code read from bottom to top?
Here is a snippet of code.

private void initNewGame() {
    mSnakeTrail.clear();
    mAppleList.clear();

    // For now we're just going to load up a short default eastbound snake
    // that just turned north


    mSnakeTrail.add(new Coordinate(7, 7));
    mSnakeTrail.add(new Coordinate(6, 7));
    mSnakeTrail.add(new Coordinate(5, 7));
    mSnakeTrail.add(new Coordinate(4, 7));
    mSnakeTrail.add(new Coordinate(3, 7));
    mSnakeTrail.add(new Coordinate(2, 7));
    mNextDirection = NORTH;
+3
source share
3 answers

Code is never read from the bottom up, at least in Java. This means that the snake is added from head to tail, and not vice versa. Also, three or more, use for :)

+3

, , . , .

+1

No, procedures / methods in Java (and most other languages ​​as far as I know) are read from top to bottom. So, the first thing that is done as you type InitNewGame()is mSnakeTrail.clear(), then mAppleList.clear(), etc.

0
source

Source: https://habr.com/ru/post/1785350/


All Articles