Exemple #1
0
        // GET: TicTacToe
        public ActionResult Index()
        {
            Session["CellBoard"] = null;
            var model = new TicTacToeModel(4, 4, 4);

            if (model.IsComputerTurn())
            {
                model.ComputerTurn();
                Session["CellBoard"] = model.CellBoard;
            }
            return(View(model));
        }
Exemple #2
0
        public ActionResult Index(string chosenCell)
        {
            var model = new TicTacToeModel(4, 4, 4);

            if (Session["CellBoard"] != null)
            {
                model.CellBoard = (Cell[][])Session["CellBoard"];
            }

            model.ParseChosenCell(chosenCell);
            if (model.TryPlaceChosenCell())
            {
                if (model.IsGameComplete)
                {
                    Session["CellBoard"] = null;
                    if (model.IsTie)
                    {
                        return(View("Tie"));
                    }
                    return(View("Win"));
                }

                model.ComputerTurn();
                if (model.IsGameComplete)
                {
                    Session["CellBoard"] = null;
                    if (model.IsTie)
                    {
                        return(View("Tie"));
                    }
                    return(View("Lose"));
                }
            }
            Session["CellBoard"] = model.CellBoard;
            return(View(model));
        }