private void initMap forint i = 0; i level; i++ arrayi 4 = i + 1; arrayi 4 + 1 = i + 1; arrayi 4 + 2 = i + 1; arrayi 4 + 3 = i + 1;
This code initializes a 2D array called "map" with random values based on the input variable "level".
The first for loop assigns values to a 1D array called "array". Each block of four values in "array" contains the same number, which increases by 1 for each iteration of the loop.
The "random" method is then called on "array", which shuffles its values randomly.
The second for loop assigns values from "array" to each block in "map", with each row containing 17 values and each column containing 10 values.
Overall, the code generates a randomized 2D array that can be used as a game map
原文地址: https://www.cveoy.top/t/topic/fcVh 著作权归作者所有。请勿转载和采集!