I attempted to run the code, and when I used the "moveUp()" function, the outcomes didn't match my expectations. Consequently, I made some adjustments to my code in an attempt to address the issue correctly. However, even after applying the provided example to solve the problem, the results still didn't align with what I had anticipated. Furthermore, I noticed that the changes made to the two-dimensional array after calling "moveUp" didn't follow the "rotateClockwise()" method as expected, which left me feeling somewhat puzzled. Regrettably, due to space constraints, I'm unable to share my code here. If it's possible, could you please reach out to me via email? I would greatly appreciate any guidance or assistance you can provide. My email address is: moryforcola@outlook.com Thank you very much for your help. This is my code:
package com.codegym.games.game2048;

import com.codegym.engine.cell.*;

public class Game2048 extends Game {
    private static final int SIDE = 4;
    private int[][] gameField = new int[SIDE][SIDE];
    private boolean isGameStopped = false;
    private int score = 0;

    @Override
    public void onKeyPress(Key key){
        if(!canUserMove()){
            gameOver();
            return;
        }
        if(!isGameStopped){
            if (key == Key.LEFT) {
                moveLeft();// Move LEFT
            }else if (key == Key.RIGHT){
                moveRight();// Move RIGHT
            }else if (key == Key.UP){
                moveUp();// Move UP
            }else if (key == Key.DOWN){
                moveDown();// Move DOWN
            }
        }else if (key == key.SPACE){
            createGame();
            isGameStopped = false;
        }else{
            return;
        }
        drawScene();
    }

    @Override
    public void initialize() {
        setScreenSize(SIDE, SIDE);
        createGame();
        drawScene();
    }

    // 初始化游戏
    private void createGame() {
        gameField = new int[SIDE][SIDE];//创建新的游戏矩阵
        score = 0;
        setScore(score);
        createNewNumber();
        createNewNumber();
    }

    // 生成新的随机数字(2或4)
    private void createNewNumber() {
        if(getMaxTileValue() >= 2048){
            win();
            return;
        }
        boolean isCreated = false;
        do {
            int x = getRandomNumber(SIDE);
            int y = getRandomNumber(SIDE);
            if (gameField[y][x] == 0) {
                gameField[y][x] = getRandomNumber(10) < 9 ? 2 : 4;
                isCreated = true;
            }
        } while (!isCreated);
    }

    // 根据值设置单元格颜色和显示文本
    private void setCellColoredNumber(int x, int y, int value) {
        Color color = getColorByValue(value);
        String str = value > 0 ? "" + value : "";
        setCellValueEx(x, y, color, str);
    }

    // 根据值获取颜色
    private Color getColorByValue(int value) {
        switch (value) {
            case 0:
                return Color.WHITE;
            case 2:
                return Color.PLUM;
            case 4:
                return Color.SLATEBLUE;
            case 8:
                return Color.DODGERBLUE;
            case 16:
                return Color.DARKTURQUOISE;
            case 32:
                return Color.MEDIUMSEAGREEN;
            case 64:
                return Color.LIMEGREEN;
            case 128:
                return Color.DARKORANGE;
            case 256:
                return Color.SALMON;
            case 512:
                return Color.ORANGERED;
            case 1024:
                return Color.DEEPPINK;
            case 2048:
                return Color.MEDIUMVIOLETRED;
            default:
                return Color.NONE;
        }
    }

    // 压缩行,将非零元素向左移动,零元素向右移动
    private boolean compressRow(int[] row) {
        int insertPosition = 0;
        boolean result = false;
        for (int x = 0; x < SIDE; x++) {
            if (row[x] > 0) {
                if (x != insertPosition) {
                    row[insertPosition] = row[x];
                    row[x] = 0;
                    result = true;
                }
                insertPosition++;
            }
        }
        return result;
    }

    // 合并行,将相邻相同的元素合并
    private boolean mergeRow(int[] row) {
        boolean result = false;
        for (int i = 0; i < SIDE-1; i++) {
            if (row[i] != 0 && row[i] == row[i+1]) {
                row[i] += row[i+1];
                row[i+1] = 0;
                score += row[i];//得分增加
                setScore(score);
                result = true;
            }
        }
        return result;
    }

    // 绘制游戏场景
    private void drawScene() {
        for (int y = 0; y < SIDE; y++) {
            for (int x = 0; x < SIDE; x++) {
                setCellColoredNumber(x, y, gameField[y][x]);
            }
        }
    }

    private void rotateClockwise(int frequency){
        int[][] rotateClock = new int[SIDE][SIDE];
        for(int i = 0;i < frequency; i++){
            for(int y = 0;y < SIDE;y++){
                for(int x = 0;x < SIDE; x++){
                    rotateClock[x][SIDE-1-y] = gameField[y][x];
                }
            }
            gameField = rotateClock;
        }
    }

    private void move(){
        int moveOrMergeCount = 0;
        for(int i = 0;i < SIDE;i++){
            if(compressRow(gameField[i])){
                mergeRow(gameField[i]);
                compressRow(gameField[i]);
                moveOrMergeCount++;
            }else if(mergeRow(gameField[i])){
                compressRow(gameField[i]);
                moveOrMergeCount++;
            }
        }
        if(moveOrMergeCount != 0){
            createNewNumber();
        }
    }

    //键盘控制 ↑ ↓ ← →
    private void moveLeft(){
        move();
    }

    private void moveRight(){
        rotateClockwise(2);
        move();
        rotateClockwise(2);
    }

    private void moveUp(){
        rotateClockwise(3);
        move();
        rotateClockwise(1);
    }

    private void moveDown(){
        rotateClockwise(1);
        move();
        rotateClockwise(3);
    }


    private int getMaxTileValue(){
        int maxValue = 0;
        for(int y = 0; y < SIDE; y++){
            for(int x = 0; x < SIDE; x++){
                if(gameField[y][x] > maxValue){
                    maxValue = gameField[y][x];
                }
            }
        }
        return maxValue;
    }

    private void win(){
        showMessageDialog (Color.BLUE,"哇塞!2048拿下,大西瓜非你莫属!",Color.RED,18);
        isGameStopped = true;
    }

    private boolean canUserMove(){
        int count  = 0;
        for(int y = 0;y < SIDE; y++){
            for(int x = 0; x < SIDE; x++){
                if(gameField[y][x] == 0){
                    count++;
                }
            }
        }
        if(count > 0){
            return true;
        }else{
            return isMerge();
        }
    }

    private boolean isMerge(){
        for(int count = 0; count < 2; count++){
            if(count == 1){
                rotateClockwise(1);//旋转一次矩阵,检查Y轴是否还有可以合并元素
            }
            for(int y = 0; y < SIDE; y++){
                for(int x = 0; x < SIDE-1; x++){
                    if(gameField[y][x] == gameField[y][x+1]){
                        return true;
                    }
                }
            }
        }
        return false;
    }

    private void gameOver(){
        isGameStopped = true;
        showMessageDialog (Color.YELLOW,"结束咯!",Color.WHITE,18);
    }
}