Example #1
0
        public void Start()
        {
            GameSetup GameSetup = new GameSetup(gm);

            GameSetup.Setup();

            do
            {
                GameSetup.SetBoard();
                FireShotResponse shotresponse;
                do
                {
                    ControlOutput.ResetScreen(new Player[] { gm.Player1, gm.Player2 });
                    ControlOutput.ShowWhoseTurn(gm.IsPlayer1 ? gm.Player2 : gm.Player1);
                    ControlOutput.DrawHistory(gm.IsPlayer1 ? gm.Player2 : gm.Player1, gm.IsPlayer1 ? 2 : 1);
                    Coordinate ShotPoint = new Coordinate(1, 1);
                    shotresponse = Shot(gm.IsPlayer1 ? gm.Player2 : gm.Player1, gm.IsPlayer1 ? gm.Player1 : gm.Player2, out ShotPoint);

                    ControlOutput.ResetScreen(new Player[] { gm.Player1, gm.Player2 });
                    ControlOutput.ShowWhoseTurn(gm.IsPlayer1 ? gm.Player2 : gm.Player1);
                    ControlOutput.DrawHistory(gm.IsPlayer1 ? gm.Player2 : gm.Player1, gm.IsPlayer1 ? 2 : 1);
                    ControlOutput.ShowShotResult(shotresponse, ShotPoint, gm.IsPlayer1 ? gm.Player1.Name : gm.Player2.Name);
                    if (shotresponse.ShotStatus != ShipHitCheck.Victory)
                    {
                        Console.WriteLine("Press any key to continue to switch to " + (gm.IsPlayer1 ? gm.Player1.Name : gm.Player2.Name));
                        gm.IsPlayer1 = !gm.IsPlayer1;
                        Console.ReadKey();
                    }
                } while (shotresponse.ShotStatus != ShipHitCheck.Victory);
            } while (ControlInput.CheckQuit());
        }
Example #2
0
        private FireShotResponse Shot(Player victim, Player Shoter, out Coordinate ShotPoint)
        {
            FireShotResponse fire; Coordinate WhereToShot;

            do
            {
                WhereToShot = ControlInput.GetShotLocationFromUser();
                fire        = victim.PlayerBoard.FireShot(WhereToShot);
                if (fire.ShotStatus == ShotStatus.Invalid || fire.ShotStatus == ShotStatus.Duplicate)
                {
                    ControlOutput.ShowShotResult(fire, WhereToShot, "");
                }


                if (fire.ShotStatus == ShotStatus.Victory)
                {
                    if (gm.IsPlayer1)
                    {
                        gm.Player1.Win += 1;
                    }
                    else
                    {
                        gm.Player2.Win += 1;
                    }
                }
            } while (fire.ShotStatus == ShotStatus.Duplicate || fire.ShotStatus == ShotStatus.Invalid);
            ShotPoint = WhereToShot;
            return(fire);
        }