示例#1
0
        public void SaveSettings(GolGameSettings settings)
        {
            IFormatter formatter = new BinaryFormatter();
            Stream     stream    = new FileStream("settings.bin", FileMode.Create, FileAccess.Write, FileShare.None);

            /*formatter.Serialize(stream, new SerializableGolSettings(new List<byte[]>()) {
             *  new byte[] { settings.AliveColor.Color.R, settings.AliveColor.Color.G }
             * });*/
            var settingsToPersist = new SerializableGolSettings(new List <byte[]>()
            {
                new byte[]
                {
                    settings.AliveColor.Color.R,
                    settings.AliveColor.Color.G,
                    settings.AliveColor.Color.B,
                    settings.AliveColor.Color.A
                },
                new byte[]
                {
                    settings.DeadColor.Color.R,
                    settings.DeadColor.Color.G,
                    settings.DeadColor.Color.B,
                    settings.DeadColor.Color.A
                }
            });

            formatter.Serialize(stream, settingsToPersist);
            stream.Close();
        }
示例#2
0
        public GolGameSettings GetSettings()
        {
            IFormatter formatter           = new BinaryFormatter();
            Stream     stream              = null;
            SerializableGolSettings result = null;

            try
            {
                stream = new FileStream("settings.bin", FileMode.Open, FileAccess.Read);
                result = (SerializableGolSettings)formatter.Deserialize(stream);
            }
            catch (FileNotFoundException e)
            {
                #if DEBUG
                //throw e;
#endif
                return(null);
            }
            var aliveRGBA = result.Colors[0];
            var deadRGBA  = result.Colors[1];

            var settings = new GolGameSettings()
            {
                AliveColor = new SolidColorBrush(Color.FromArgb(aliveRGBA[3], aliveRGBA[0], aliveRGBA[1], aliveRGBA[2])),
                DeadColor  = new SolidColorBrush(Color.FromArgb(deadRGBA[3], deadRGBA[0], deadRGBA[1], deadRGBA[2]))
            };
            stream.Close();
            return(settings);
        }
示例#3
0
 public CellularSystem(int width, int height, GolGameSettings settings)
 {
     this.width    = width;
     this.heigth   = height;
     this.settings = settings;
     AllCellsDead();
 }
示例#4
0
        public GameOfLifeGame(int width, int height)
        {
            repository = new Repository();
            settings   = repository.GetSettings();
            if (settings == null)
            {
                settings = new GolGameSettings();
            }
            cellularSys = new CellularSystem(width, height, settings);

            updateLoop          = new DispatcherTimer();
            updateLoop.Interval = new TimeSpan(0, 0, 0, 0, 300);
            updateLoop.Tick    += UpdateLoop_Tick;
        }
示例#5
0
 public CellColorPicker(GolGameSettings settings)
 {
     InitializeComponent();
     this.settings = settings;
 }