Exemplo n.º 1
0
        /// <summary>
        /// Loads a saved instance of Board from the SavedBoard.bin file
        /// </summary>
        /// <returns>The board instance</returns>
        public Board ReadBoardFromBin()
        {
            const string fileName = "SavedBoard.bin";
            Board        board    = null;

            if (File.Exists(fileName))
            {
                Stream testFileStream = File.OpenRead(fileName);
                var    deserializer   = new BinaryFormatter();
                board = (Board)deserializer.Deserialize(testFileStream);
                testFileStream.Close();

                /*
                 * We need to set the properties on the board that
                 * were owned by the banker originally to be the banker
                 * again when reloading the properties
                 */
                foreach (var property in board.GetProperties())
                {
                    var prop   = (Property)property;
                    var banker = Banker.Access();

                    if (prop.GetOwner().GetName() != "Leeroy Jenkins")
                    {
                        continue;
                    }

                    // If it's attached to leeroy who is the banker then
                    // set that propety to be owned by the actual banker
                    var banksProperty = board.GetProperty(prop.GetName());
                    banksProperty.SetOwner(ref banker);
                }
            }

            return(board);
        }