Example #1
0
        internal void WriteBattleshipGuessesToTextFile(AbstractGame _abstractGame)
        {
            string currentDirectory = Directory.GetCurrentDirectory();
            string resultsDirectory = currentDirectory + "\\..\\..\\..\\Results";

            if (!Directory.Exists(resultsDirectory))
            {
                Directory.CreateDirectory(resultsDirectory);
            }
            string gameDirectory = resultsDirectory + "\\" + _abstractGame.NumberOfGuesses;

            if (!Directory.Exists(gameDirectory))
            {
                Directory.CreateDirectory(gameDirectory);
            }
            int    gameNumber = 0;
            string filePath;

            do
            {
                filePath = gameDirectory + "\\gameRecord" + ++gameNumber + ".txt";
            } while (File.Exists(filePath));

            using (StreamWriter sw = new StreamWriter(filePath))
            {
                int[,] board = _abstractGame.Board;
                for (int row = 0; row < board.GetLength(0); ++row)
                {
                    sw.WriteLine(String.Join(",", m.GetRowFrom2DArray(board, row)));
                }
            }
        }
Example #2
0
 internal RandomPositionGuesser(AbstractGame _abstractGame) : base(_abstractGame)
 {
     allPositions = new List <Point>();
     for (int x = 0; x < _abstractGame.Board.GetLength(1); ++x)
     {
         for (int y = 0; y < _abstractGame.Board.GetLength(0); ++y)
         {
             allPositions.Add(new Point(x, y));
         }
     }
 }
Example #3
0
        internal VisualGame(AbstractGame _abstractGame, Rectangle _areaToDrawTo, VisualGameAssets _visualGameAssets)
        {
            abstractGame = _abstractGame;
            areaToDrawTo = _areaToDrawTo;

            UnknownSquare  = _visualGameAssets.UnknownSquare;
            MissOverlay    = _visualGameAssets.MissOverlay;
            HitOverlay     = _visualGameAssets.HitOverlay;
            ShipOverlay    = _visualGameAssets.ShipOverlay;
            ShipHitOverlay = _visualGameAssets.ShipHitOverlay;

            ShowShips = false;
        }
Example #4
0
        internal GameStatsGenerator()
        {
            // Sets up game configurations
            Ship destroyer  = new Ship("Destroyer", 2, 1);
            Ship submarine  = new Ship("Submarine", 3, 1);
            Ship cruiser    = new Ship("Cruiser", 3, 1);
            Ship battleship = new Ship("Battleship", 4, 1);
            Ship carrier    = new Ship("Carrier", 5, 1);

            List <Ship> allShips = new List <Ship>()
            {
                carrier, battleship, cruiser, submarine, destroyer
            };

            abstractGame = new AbstractGame(10, 10, allShips);
            serializer   = new Serializer();

            positionGuesser = new RandomPositionGuesserWithHunting(abstractGame);
            //positionGuesser = new RandomPositionGuesser(abstractGame);
        }
Example #5
0
        internal RandomPositionGuesserWithHunting(AbstractGame _abstractGame) : base(_abstractGame)
        {
            // Assumes sourceHuntPoint and huntDirection will be set in 'MakeGuess' function
            inHuntMode = false;

            allPositions = new List <Point>();
            for (int x = 0; x < _abstractGame.Board.GetLength(1); ++x)
            {
                for (int y = 0; y < _abstractGame.Board.GetLength(0); ++y)
                {
                    allPositions.Add(new Point(x, y));
                }
            }

            allDirections = new List <Direction>()
            {
                Direction.North, Direction.East, Direction.West, Direction.South
            };
            huntStartPoint = new Point();
        }
Example #6
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
            IsMouseVisible = true;

            Ship destroyer  = new Ship("Destroyer", 2, 1);
            Ship submarine  = new Ship("Submarine", 3, 1);
            Ship cruiser    = new Ship("Cruiser", 3, 1);
            Ship battleship = new Ship("Battleship", 4, 1);
            Ship carrier    = new Ship("Carrier", 5, 1);

            List <Ship> allShips = new List <Ship>()
            {
                carrier, battleship, cruiser, submarine, destroyer
            };

            abstractGame = new AbstractGame(10, 10, allShips);
            Rectangle areaToDrawTo = new Rectangle(300, 50, 600, 600);

            visualGame = new VisualGame(abstractGame, areaToDrawTo, assets);
        }
Example #7
0
 internal PositionGuesser(AbstractGame _abstractGame)
 {
     abstractGame = _abstractGame;
 }