Пример #1
0
        //saves all necessary data to a text file of given name
        public void SaveGame(Player player1, Player player2)
        {
            string saveName = "";

            while (saveName == "")
            {
                Console.WriteLine("\nPlease enter a name for the Save File.\n");
                saveName = Console.ReadLine();
            }

            using (StreamWriter writer = new StreamWriter(saveName + ".txt", false))
            {
                writer.WriteLine(player1.PlayerName + " vs. " + player2.PlayerName);

                writer.WriteLine("PlayerBoards");
                writer.WriteLine(player1.SavePlayerBoard());
                writer.WriteLine(player2.SavePlayerBoard());

                writer.WriteLine("HitCounts");
                writer.WriteLine(player1.HitCount);
                writer.WriteLine(player2.HitCount);

                writer.WriteLine("MovesTaken");
                foreach (string moveTaken in player1.MovesTaken)
                {
                    writer.Write(moveTaken + " ");
                }

                writer.WriteLine(" ");

                foreach (string moveTaken in player2.MovesTaken)
                {
                    writer.Write(moveTaken + " ");
                }

                writer.WriteLine(" ");

                writer.WriteLine(player1.PlayerName);
                writer.WriteLine(player2.PlayerName);

                writer.WriteLine(log);
            }
        }