Пример #1
0
        public TicTacTardCell(TicTacTardCell cell, bool updateDisplay)
        {
            position = cell.position;
            CellType = cell.CellType;
            token    = cell.token;
            playerId = cell.playerId;

            if (updateDisplay)
            {
                gameObject = cell.GetCellGameObject();
            }
        }
        // return true if intent is correct
        public static TicTacTardState PlayAction(TicTacTardState state, TicTacTardPlayer player, Intent intent, bool updateDisplay)
        {
            Vector2Int       vector2Int = new Vector2Int(0, 0);
            bool             endGame    = false;
            List <Direction> directions = new List <Direction>();

            switch (intent)
            {
            case Intent.BotCenter:
                vector2Int.x = 1;
                vector2Int.y = 0;

                directions.Add(Direction.Line1);
                directions.Add(Direction.Column2);
                break;

            case Intent.BotLeft:
                vector2Int.x = 0;
                vector2Int.y = 0;
                directions.Add(Direction.Line1);
                directions.Add(Direction.Column1);
                directions.Add(Direction.Diagonal1);
                break;

            case Intent.BotRight:
                vector2Int.x = 2;
                vector2Int.y = 0;
                directions.Add(Direction.Line1);
                directions.Add(Direction.Column3);
                directions.Add(Direction.Diagonal2);
                break;

            case Intent.MidCenter:
                vector2Int.x = 1;
                vector2Int.y = 1;
                directions.Add(Direction.Line2);
                directions.Add(Direction.Column2);
                directions.Add(Direction.Diagonal1);
                directions.Add(Direction.Diagonal2);
                break;

            case Intent.MidLeft:
                vector2Int.x = 0;
                vector2Int.y = 1;
                directions.Add(Direction.Line2);
                directions.Add(Direction.Column1);
                break;

            case Intent.MidRight:
                vector2Int.x = 2;
                vector2Int.y = 1;
                directions.Add(Direction.Line2);
                directions.Add(Direction.Column3);
                break;

            case Intent.TopCenter:
                vector2Int.x = 1;
                vector2Int.y = 2;
                directions.Add(Direction.Line3);
                directions.Add(Direction.Column2);
                break;

            case Intent.TopLeft:
                vector2Int.x = 0;
                vector2Int.y = 2;
                directions.Add(Direction.Line3);
                directions.Add(Direction.Column1);
                directions.Add(Direction.Diagonal2);
                break;

            case Intent.TopRight:
                vector2Int.x = 2;
                vector2Int.y = 2;
                directions.Add(Direction.Line3);
                directions.Add(Direction.Column3);
                directions.Add(Direction.Diagonal1);
                break;
            }

            TicTacTardCell currentCell = state.Grid[vector2Int.x][vector2Int.y] as TicTacTardCell;

            if (currentCell?.token == "-1")
            {
                TicTacTardState newState = new TicTacTardState(state, vector2Int, player.Token, updateDisplay);
                player.IncrementScore(directions);

                return(newState);
            }
            else
            {
                if (updateDisplay)
                {
                    Debug.Log("Token déjà placé");
                }
            }

            return(null);
        }
        public static bool CanPlayIntent(TicTacTardState state, Intent intent)
        {
            int x = 0;
            int y = 0;

            switch (intent)
            {
            case Intent.BotCenter:
                x = 1;
                y = 0;
                break;

            case Intent.BotLeft:
                x = 0;
                y = 0;
                break;

            case Intent.BotRight:
                x = 2;
                y = 0;
                break;

            case Intent.MidCenter:
                x = 1;
                y = 1;
                break;

            case Intent.MidLeft:
                x = 0;
                y = 1;
                break;

            case Intent.MidRight:
                x = 2;
                y = 1;
                break;

            case Intent.TopCenter:
                x = 1;
                y = 2;
                break;

            case Intent.TopLeft:
                x = 0;
                y = 2;
                break;

            case Intent.TopRight:
                x = 2;
                y = 2;
                break;
            }

            TicTacTardCell currentCell = state.Grid[x][y] as TicTacTardCell;

            if (currentCell?.token == "-1")
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }