Ejemplo n.º 1
0
        public void TakeShot(Board board)
        {
            Point shot = null;

            switch (actionState)
            {
            case ActionState.FindingShip:
                shot = GetShotForFindingShip(board);
                break;

            case ActionState.FindingOrientation:
                shot = GetShotForFindingOrientation(board, shot);     //shot refers to last shot taken
                break;

            case ActionState.SinkingShip:
                break;
            }


            Board.ShotResult shotResult = board.TakeShot(shot);

            switch (actionState)
            {
            case ActionState.FindingShip:
                AfterShotForFindingShip(shot, shotResult);
                break;

            case ActionState.FindingOrientation:
                AfterShotForFindingOrientation(shot, shotResult);
                break;

            case ActionState.SinkingShip:
                break;
            }
            //functions for each



            // if our last shot hit, do something

            // else do something else



            //if (!board.ShotAlreadyTakenAt(shot))
            //{
            //    lastShotStatus = board.TakeShot(shot, out string shipStatus);
            //    lastShot = shot;
            //}

            //if (lastShotStatus)
            //{
            //    //hit and ship not sunk logic
            //}

            //else
            //{

            //}
        }
Ejemplo n.º 2
0
        public void TakeShot(Board board)
        {
            Point shot = PromptShot();

            while (!IsValidShot(board, shot))
            {
                Console.WriteLine("Invalid shot! Please Fire Inbounds!");
                shot = PromptShot();
            }
            board.TakeShot(shot, out string aiShipStatus);
            Console.WriteLine(aiShipStatus);
        }
Ejemplo n.º 3
0
        static void GameStart(Board playerBoard, Board aiBoard)
        {
            string lastShotStatus = "Miss.";
            Point  lastShot;
            Random rnd = new Random();

            playerBoard.PrintBoard(true); //playerboard and aiboard
            aiBoard.PrintBoard(false);

            for (int i = 0; i < 60; i++)
            {
                if (lastShotStatus == "Hit")
                {
                }
                else
                {
                    Point currentShot = new Point(rnd.Next(0, 5), rnd.Next(0, 5));
                    playerBoard.TakeShot(currentShot, out string playerShipStatus); //takeshot on playerboard logic
                    lastShotStatus = playerShipStatus;
                    lastShot       = currentShot;
                    Console.WriteLine(playerShipStatus);
                }



                aiBoard.PrintBoard(false);                            // add argument that toggles display of ships
                if (aiBoard.IsGameOver() || playerBoard.IsGameOver()) //update so that game ends when one board reaches end state
                {
                    Console.WriteLine("Game Over!");
                    break;
                }
            }

            Console.WriteLine("Press any key to exit. . .");

            Console.ReadKey();
        }