Example #1
0
        static void Main(string[] args)
        {
            //Prepare Operating-system independent environment and initialize some variables
            _winner = Winner.undetermined;
            if (PlatformID.Win32NT == Environment.OSVersion.Platform) 
            {
                Console.WindowWidth = 100;
            } 
            else
            {
                Console.WriteLine("Please make sure that your Terminal Window is at least 100 characters wide");
                Console.WriteLine("Press any key to cotinue when ready...");
                Console.ReadKey();
            }
	        Console.ForegroundColor = ConsoleColor.Gray;
            
            //Create and initialize playing grids in which each player can see their own ships
            HomeGrid playerHomeGrid = new HomeGrid(Playertype.Human);
            HomeGrid aiHomeGrid = new HomeGrid(Playertype.AI);

            //Create and initialize radar Grids in which each player can 
            EnemyGrid playerEnemyGrid = new EnemyGrid(Playertype.Human);
            EnemyGrid AIEnemyGrid = new EnemyGrid(Playertype.AI);

            //fleet deployment (currently automatic)
			Fleet playerFleet = new Fleet();
            Fleet aiFleet = new Fleet();
            playerHomeGrid.DeployFleet(playerFleet);
            aiHomeGrid.DeployFleet(aiFleet);
            bool forfeit=false;

            // subscribe to fire-exchange events
            playerEnemyGrid.AimFireEvent += aiHomeGrid.ReceiveShot;
            AIEnemyGrid.AimFireEvent += playerHomeGrid.ReceiveShot;

            //Main game phase
            do
            {
                forfeit = playerEnemyGrid.AimAndFire();  
                if (Winner == Winner.undetermined && !forfeit) AI.Turn(AIEnemyGrid);
  
            } while (Winner == Winner.undetermined && !forfeit);

            //End of the game
            Console.SetCursorPosition(0, 23);

            if (forfeit)
            {
                
                Console.WriteLine("AI has won by player forfeiture");
            }
            else
            {
               
                Console.WriteLine("Game ends. {0} victorious!", _winner.ToString());
            }
            Console.ReadLine();
			
        }
Example #2
0
        /// <summary>
        /// Automatically deploys a fleet of ships
        /// </summary>
        /// <param name="ships">the fleet of ships to deploy</param>
        public void DeployFleet(Fleet Fleet)
        {   //currently implemented as random and stupid
            Random rnd = new Random(DateTime.Now.Ticks.GetHashCode());
            bool[] used = new bool[10];
            foreach (var ship in Fleet.Ships)
            {
                Coord coord = new Coord();              //freien platz finden
                coord.Col = rnd.Next(9 - ship.Size);

                do // dont put two ships in the same row
                {
                    coord.Row = rnd.Next(10);
                } while (used[coord.Row]);
                used[coord.Row] = true;

                Coord[] coords = ship.Move(coord, false);
                this.RefreshTiles(coords, TileContent.ship);
            }
            
            this.fleet = Fleet;
            this.Redraw();
        }
Example #3
0
 internal void DeployFleetManual(Fleet fleet)
 {
     throw new NotImplementedException();
 }