Example #1
0
        public ActionResult Save(int index)
        {
            var lines = (List <Save>)Session["SaveLines"];
            var line  = lines[index];
            var Set   = new Settings();

            Set.BoardSize = line.Board_size;
            Set.CanTouch  = line.CanTouch;
            var Gb        = new GameBoard(Set.BoardSize);
            var Rules     = new Rules(Gb, Set);
            var Shown     = new GameBoard(Set.BoardSize);
            var enemyRule = new Rules(new GameBoard(Set.BoardSize), Set);
            var Pt        = new PlayersTurn(enemyRule.gameBoard, Gb, Shown, Set);
            var enemy     = new AI(Gb, Set);

            var simulator   = new GameSimulation();
            var playerShips = line.Player_Board.Substring(0, line.Player_Board.Length - 1).Split('|');
            var aiShips     = line.AI_Board.Substring(0, line.AI_Board.Length - 1).Split('|');

            simulator.PutShips(Rules, playerShips);
            simulator.PutShips(enemyRule, aiShips);
            var moves = line.Moves.Substring(0, line.Moves.Length - 1).Split('|');

            simulator.Simulate(moves, Pt, enemy, Gb, Shown);

            Session["Rules"]    = Rules;
            Session["Set"]      = Set;
            Session["ships"]    = Rules.Ships;
            Session["Enemy"]    = enemyRule.gameBoard;
            Session["Shown"]    = Shown;
            Session["AI"]       = enemy;
            ViewData["message"] = "Your turn";
            return(View("Game"));
        }
Example #2
0
        public ActionResult Replay(int index)
        {
            var lines     = (List <Save>)Session["SaveLines"];
            var line      = lines[index];
            var simulator = new GameSimulation();


            var Set = new Settings();

            Set.BoardSize = line.Board_size;
            Set.CanTouch  = line.CanTouch;
            var Gb        = new GameBoard(Set.BoardSize);
            var Rules     = new Rules(Gb, Set);
            var Shown     = new GameBoard(Set.BoardSize);
            var enemyRule = new Rules(new GameBoard(Set.BoardSize), Set);
            var Pt        = new PlayersTurn(enemyRule.gameBoard, Gb, Shown, Set);
            var enemy     = new AI(Gb, Set);

            var playerShips = line.Player_Board.Substring(0, line.Player_Board.Length - 1).Split('|');
            var aiShips     = line.AI_Board.Substring(0, line.AI_Board.Length - 1).Split('|');

            simulator.PutShips(Rules, playerShips);
            simulator.PutShips(enemyRule, aiShips);

            var moves = line.Moves.Substring(0, line.Moves.Length - 1).Split('|');


            Session["Count"]    = 1;
            Session["Moves"]    = moves;
            Session["Rules"]    = Rules;
            Session["ships"]    = Rules.Ships;
            Session["Enemy"]    = enemy;
            Session["Pt"]       = Pt;
            Session["Shown"]    = Shown;
            ViewData["message"] = "Your turn";
            return(RedirectPermanent("/Home/Show"));
        }