REQUIREMENT The markTile(int, int) method must set the isFlag field to true, reduce the number of unused flags by one, draw the FLAG symbol on the field if the current element is not a flag (use the setCellValue(int, int, String) method), and change the cell background on the field (use the setCellColor(int, int, Color) method). For example, to Color.YELLOW.
package com.codegym.games.minesweeper;

import com.codegym.engine.cell.Color;
import com.codegym.engine.cell.Game;

import java.util.ArrayList;
import java.util.List;

public class MinesweeperGame extends Game {
    private static final int SIDE = 9;
    private GameObject[][] gameField = new GameObject[SIDE][SIDE];
    private int countMinesOnField;
    private static final String MINE = "\uD83D\uDCA3";
    private static final String FLAG = "\\uD83D\\uDEA9";
    private int countFlags;

    @Override
    public void initialize() {
        setScreenSize(SIDE, SIDE);
        createGame();
    }
    @Override
    public void onMouseLeftClick(int x, int y){
        openTile(x, y);
    }

    @Override
    public void onMouseRightClick(int x, int y) { markTile(x, y); }

    private void createGame() {
        for (int y = 0; y < SIDE; y++) {
            for (int x = 0; x < SIDE; x++) {
                boolean isMine = getRandomNumber(10) < 1;
                if (isMine) {
                    countMinesOnField++;
                }
                gameField[y][x] = new GameObject(x, y, isMine);
                setCellColor(x, y, Color.GREEN);
            }
        }
        countMineNeighbors();
        countFlags = countMinesOnField;
    }

    private List<GameObject> getNeighbors(GameObject gameObject) {
        List<GameObject> result = new ArrayList<>();
        for (int y = gameObject.y - 1; y <= gameObject.y + 1; y++) {
            for (int x = gameObject.x - 1; x <= gameObject.x + 1; x++) {
                if (y < 0 || y >= SIDE) {
                    continue;
                }
                if (x < 0 || x >= SIDE) {
                    continue;
                }
                if (gameField[y][x] == gameObject) {
                    continue;
                }
                result.add(gameField[y][x]);
            }
        }
        return result;
    }

    private void countMineNeighbors(){
        for (int x = 0; x < SIDE; x++)
            for(int y = 0; y < SIDE; y++)
                if(!gameField[y][x].isMine)
                    for(GameObject g:getNeighbors(gameField[y][x])){
                        if(g.isMine)
                            gameField[y][x].countMineNeighbors++;
                    }
    }

    private void openTile(int x, int y) {
        gameField[y][x].isOpen = true;
        setCellColor(x, y, Color.ORANGE);

        if (!gameField[y][x].isMine && gameField[y][x].countMineNeighbors >= 1)
            setCellNumber(x, y, gameField[y][x].countMineNeighbors);
        else if (gameField[y][x].isMine) {
            setCellValue(x, y, MINE);
        } else if (!gameField[y][x].isMine && gameField[y][x].countMineNeighbors == 0) {
            setCellValue(x, y, "");
            getNeighbors(gameField[y][x]);
            int m = y, n = x;
            if (m - 1 >= 0 && m - 1 < SIDE) {
                if (!gameField[m - 1][n].isOpen)
                    openTile(n, m - 1);
                if (n - 1 >= 0 && !gameField[m - 1][n - 1].isOpen)
                    openTile(n - 1, m - 1);
                if (n + 1 < SIDE && !gameField[m - 1][n + 1].isOpen)
                    openTile(n + 1, m - 1);
            }
            if (m >= 0 && m < SIDE) {
                if (n - 1 >= 0 && !gameField[m][n - 1].isOpen)
                    openTile(n - 1, m);
                if (n + 1 < SIDE && !gameField[m][n + 1].isOpen)
                    openTile(n + 1, m);
            }
            if (m + 1 >= 0 && m + 1 < SIDE) {
                if (!gameField[m + 1][n].isOpen)
                    openTile(n, m + 1);
                if (n - 1 >= 0 && !gameField[m + 1][n - 1].isOpen)
                    openTile(n - 1, m + 1);
                if (n + 1 < SIDE && !gameField[m + 1][n + 1].isOpen)
                    openTile(n + 1, m + 1);
            }
        }
    }

    private void markTile(int x, int y) {
        GameObject gameObject = gameField[y][x];

        if (gameObject.isOpen || (countFlags == 0 && !gameObject.isFlag)) {
            return;
        }

            if (!gameObject.isFlag && countFlags > 0) {
                gameField[y][x].isFlag = true;
                countFlags--;
                setCellValue(x, y, FLAG);
                setCellColor(x, y, Color.YELLOW);
            }

            if (gameObject.isFlag) {
                gameObject.isFlag = false;
                countFlags++;
                setCellValue(x, y, "");
                setCellColor(x, y, Color.GREEN);
            }

        }

    }