(JAVA)我必须将一个char放入数组中,然后再移动char(scanner)

时间:2019-05-15 18:54:02

标签: java arrays loops

我必须在数组中放置一个X,然后再移动X(向左,向上,向右,向下)。我想我必须用java.util.Scanner来做。我需要帮助。

我使用Arrays创建了一个字段,Point are字段可以在其中移动我的X(Player)。

规则: 我无法移至R或O

public class Main {

    public static void main(String[] args) {

        final int WIDTH = 18;
        final int HEIGHT = 11;
        final int CHAR_COUNT = 30;
        final int PLAYER = 1;
        final int endgame = 1;
        final int PLAYERCOUNTER = 2;
        final char[] CHARS = {
            'R',
            'O'
        };
        final char[] PLAYERPOINTS = {
            'X',
            '+'
        };
        String player = "X";

        // Create field filled with '.'
        char[][] field = new char[HEIGHT][WIDTH];

        for (int i = 0; i < HEIGHT; i++) {
            Arrays.fill(field[i], '.');


        }

        // the holes and robots (R and O)
        Random random = new Random();
        for (char ch: CHARS) {

            for (int j = 0, x, y; j < CHAR_COUNT; j++) {

                do {
                    x = random.nextInt(WIDTH);

                    y = random.nextInt(HEIGHT);
                } while (field[y][x] != '.');
                field[y][x] = ch;

            }
        }

        //print field
        for (char[] row: field) {
            System.out.println(Arrays.toString(row).replaceAll(",", "") + " ");

        }

        //Player
        Scanner input = new Scanner(System.in);
    }
}

0 个答案:

没有答案