//If the tyle has been hit it will be o, otherwise x.
        //then, if there's a ship reference in that tile it will displace that character by a certain amount.
        public void ExportGame(string file)
        {
            string       path  = dir + "/Games/" + file + ".txt";
            StreamWriter write = new StreamWriter(path, true);
            string       line  = "";
            char         shipType;

            foreach (Player player in new List <Player> {
                battleship.Player1, battleship.Player2
            })
            {
                TileProperty[,] grid = battleship.PlayerGrids[player].GridLayout;
                for (int x = 0; x < grid.GetLength(0); ++x)
                {
                    for (int y = 0; y < grid.GetLength(1); ++y)
                    {
                        TileProperty cell = grid[x, y];
                        shipType = (char)0;
                        if (cell.HasShip != null)
                        {
                            shipType = (char)(battleship.PlayerGrids[player].ShipList.First(ship => ship.Value == cell.HasShip).Key);
                        }
                        line += (char)((cell.HasChecked ? 'o' : 'x') - shipType);
                    }
                    line += "\r\n";
                }
            }

            write.WriteLine(line);
            write.Write("player1:[Name:{0},TotalWins:{1},TotalLosses:{2},Type:{3}]", battleship.Player1.Name, battleship.Player1.TotalWins, battleship.Player1.TotalLosses, battleship.Player1.GetType() == typeof(AI) ? "Computer" : "Human");
            write.Write("player2:[Name:{0},TotalWins:{1},TotalLosses:{2},Type:{3}]", battleship.Player2.Name, battleship.Player2.TotalWins, battleship.Player2.TotalLosses, battleship.Player2.GetType() == typeof(AI) ? "Computer" : "Human");
            write.Write("currentPlayer:[Name:{0}]", battleship.Player1.Name);
            write.Close();
            Console.WriteLine("Export to {0} Successful!", path);
        }
Ejemplo n.º 2
0
 public void GenerateGrid()
 {
     for (int i = 0; i < 10; i++)
     {
         for (int b = 0; b < 10; b++)
         {
             GridLayout[i, b] = new TileProperty();
         }
     }
 }
Ejemplo n.º 3
0
 public Grid()
 {
     GridLayout = new TileProperty[10, 10];
     ShipList   = new Dictionary <ShipType, Ship>()
     {
         { ShipType.Aircraft, new Ship("Aircraft Carrier", 5) },
         { ShipType.Battleship, new Ship("Battleship", 4) },
         { ShipType.Submarine, new Ship("Submarine", 3) },
         { ShipType.Destroyer, new Ship("Destroyer", 3) },
         { ShipType.Patrol, new Ship("Patrol Boat", 2) }
     };
     GenerateGrid();
 }