Exemple #1
0
        private void ReadSettings()
        {
            BinaryFormatter formatter = new BinaryFormatter();

            using (Stream fStream = new FileStream("settings.dat", FileMode.Open, FileAccess.Read, FileShare.None))
            {
                serializableSettings = (SerializableSettings)formatter.Deserialize(fStream);
            }
            //Map GameSettings to the saved serializableSettings instance.
            gameSettings.Time         = serializableSettings.time;
            gameSettings.Questions    = serializableSettings.questions;
            gameSettings.MaxOperand   = serializableSettings.maxOperand;
            gameSettings.PlayerName   = serializableSettings.playerName;
            gameSettings.WillAdd      = serializableSettings.add;
            gameSettings.WillSubtract = serializableSettings.subtract;
            gameSettings.WillMultiply = serializableSettings.multiply;
            gameSettings.WillDivide   = serializableSettings.divide;
        }
Exemple #2
0
        public MainWindow()
        {
            InitializeComponent();
            gameSettings = new Settings();

            serializableSettings = new SerializableSettings();
            if (File.Exists("settings.dat"))
            {
                ReadSettings();
            }
            else
            {
                WriteSettings();
            }

            DataContext = gameSettings;

            //Populate Duration ComboBox
            cmbDuration.ItemsSource = new string[] { "10 Seconds", "20 Seconds", "30 Seconds", "40 Seconds", "50 Seconds", "60 Seconds" };
            //Populate MaxOperand ComboBox
            cmbMaxOperand.ItemsSource = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            //Read saved game histories.
            if (File.Exists("History.dat"))
            {
                ReadHistory();
            }
            else
            {
                //create the game history schema
                gameHistory = new DataTable();
                gameHistory.Columns.Add("Player", typeof(string));
                gameHistory.Columns.Add("Time", typeof(DateTime));
                gameHistory.Columns.Add("Tot Qs", typeof(int));
                gameHistory.Columns.Add("Att Qs", typeof(int));
                gameHistory.Columns.Add("Correct", typeof(int));
                gameHistory.Columns.Add("Duration", typeof(int));
                gameHistory.Columns.Add("Score", typeof(string));
            }
        }