Example #1
0
    private void CheckVictory(Cell.CellTicTacToeType cellType, Cell[][] currentGrid)
    {
        if (CheckHorizontalRows(cellType, currentGrid) ||
            CheckVerticalRows(cellType, currentGrid) ||
            CheckDiagonal(cellType, currentGrid))
        {
            gameIsOver = true;
        }

        //Check match null
        int count = 0;

        for (int i = 0; i < 3; ++i)
        {
            for (int j = 0; j < 3; ++j)
            {
                if (!GridIsEmpty(new Vector3(i, .5f, j), grid.grid))
                {
                    ++count;
                }
            }
        }

        if (count == 9)
        {
            //Debug.Log("Match nul !!! Bande de nullos hihihih");
            gameIsOver = true;
        }
    }
Example #2
0
    public bool Place(GameObject prefabSign, Vector3 position, Material team, Cell.CellTicTacToeType cellType)
    {
        if (GridIsEmpty(position, grid.grid))
        {
            // Change Player Turn
            //_isPlayer1Turn = !_isPlayer1Turn;

            int x = (int)position.x;
            int z = (int)position.z;
            // Instantiate Team GameObject
            GameObject sign = Instantiate(prefabSign, position, transform.rotation * Quaternion.Euler(90f, 0f, 0f));
            sign.transform.SetParent(this.transform);

            // Change Grid Material
            grid.grid[x][z].cellObject.GetComponent <MeshRenderer>().material = team;

            // Set Cell State
            grid.grid[x][z].cellTicTacToeType = cellType;

            //Debug.Log("Set State : " + grid.grid[x][z].state);
            CheckVictory(cellType, grid.grid);

            return(true);
        }
        return(false);
    }
Example #3
0
    public bool CheckDiagonal(Cell.CellTicTacToeType cellType, Cell[][] currentGrid)
    {
        bool isVictory = currentGrid[0][0].cellTicTacToeType == cellType &&
                         currentGrid[1][1].cellTicTacToeType == cellType &&
                         currentGrid[2][2].cellTicTacToeType == cellType ||
                         currentGrid[0][2].cellTicTacToeType == cellType &&
                         currentGrid[1][1].cellTicTacToeType == cellType &&
                         currentGrid[2][0].cellTicTacToeType == cellType;

        if (isVictory)
        {
            //Debug.Log("Partie gagnée sur une diagonale par " + cellType);
        }
        return(isVictory);
    }
    private Cell[][] ApplyIntentToGrid(Intent intent, Cell[][] grid, CellType type)
    {
        switch (intent)
        {
        case Intent.Tile0:
            grid[0][2].cellTicTacToeType = type;
            break;

        case Intent.Tile1:
            grid[1][2].cellTicTacToeType = type;
            break;

        case Intent.Tile2:
            grid[2][2].cellTicTacToeType = type;
            break;

        case Intent.Tile3:
            grid[0][1].cellTicTacToeType = type;
            break;

        case Intent.Tile4:
            grid[1][1].cellTicTacToeType = type;
            break;

        case Intent.Tile5:
            grid[2][1].cellTicTacToeType = type;
            break;

        case Intent.Tile6:
            grid[0][0].cellTicTacToeType = type;
            break;

        case Intent.Tile7:
            grid[1][0].cellTicTacToeType = type;
            break;

        case Intent.Tile8:
            grid[2][0].cellTicTacToeType = type;
            break;
        }

        return(grid);
    }
Example #5
0
    public bool CheckHorizontalRows(Cell.CellTicTacToeType cellType, Cell[][] currentGrid)
    {
        bool isVictory = false;

        for (int x = 0; x < grid.gridWidth; x++)
        {
            if (currentGrid[0][x].cellTicTacToeType == cellType &&
                currentGrid[1][x].cellTicTacToeType == cellType &&
                currentGrid[2][x].cellTicTacToeType == cellType)
            {
                isVictory = true;
            }
        }

        if (isVictory)
        {
            //Debug.Log("Partie gagnée sur ligne horizontale par " + cellType);
        }
        return(isVictory);
    }
Example #6
0
    public bool CheckVerticalRows(Cell.CellTicTacToeType cellType, Cell[][] currentGrid)
    {
        bool isVictory = false;

        for (int x = 0; x < grid.gridHeight; x++)
        {
            if (currentGrid[x][0].cellTicTacToeType == cellType &&
                currentGrid[x][1].cellTicTacToeType == cellType &&
                currentGrid[x][2].cellTicTacToeType == cellType)
            {
                isVictory = true;
            }
        }

        if (isVictory)
        {
            //Debug.Log("Partie gagnée sur ligne verticale par " + cellType);
        }

        return(isVictory);
    }