Beispiel #1
0
        private void SaveSettingsButton_Click(object sender, EventArgs e)
        {
            SettingsModel settingsToSave = new SettingsModel();

            settingsToSave.Difficulty   = Convert.ToInt32(DifficultyBox.Text);
            settingsToSave.Theme        = ThemeBox.Text;
            settingsToSave.UserWord     = PSymbolBox.Text;
            settingsToSave.ComputerWord = CSymbolBox.Text;

            GameTurn turn = GameTurn.Random;

            if (TPlayer.Checked)
            {
                turn = GameTurn.Player;
            }
            if (TRandom.Checked)
            {
                turn = GameTurn.Random;
            }
            if (TComputer.Checked)
            {
                turn = GameTurn.Computer;
            }

            settingsToSave.GameTurn = turn;

            File.WriteAllText("settings.json", JsonConvert.SerializeObject(settingsToSave));

            this.Close();
            MainMenuView.Show();
        }
Beispiel #2
0
        public SettingsView(MainMenuView instance)
        {
            MainMenuView = instance;
            Settings     = JsonConvert.DeserializeObject <SettingsModel>(File.ReadAllText("settings.json"));

            InitializeComponent();

            DifficultyBox.Text = Settings.Difficulty.ToString();
            ThemeBox.Text      = Settings.Theme;
            PSymbolBox.Text    = Settings.UserWord;
            CSymbolBox.Text    = Settings.ComputerWord;


            if (Settings.GameTurn == GameTurn.Player)
            {
                TPlayer.Checked = true;
            }
            if (Settings.GameTurn == GameTurn.Random)
            {
                TRandom.Checked = true;
            }
            if (Settings.GameTurn == GameTurn.Computer)
            {
                TComputer.Checked = true;
            }
        }
Beispiel #3
0
        public GameView(MainMenuView instance)
        {
            MainMenuView = instance;
            InitializeComponent();
            SettingsModel settings = TicTacToeService.Settings = JsonConvert.DeserializeObject <SettingsModel>(File.ReadAllText("settings.json"));

            if (File.Exists("save.json"))
            {
                TicTacToeService.Progress        = JsonConvert.DeserializeObject <List <ProgressModel> >(File.ReadAllText("save.json"));
                TicTacToeService.CurrentProgress = TicTacToeService.Progress.FirstOrDefault(p => p.Difficulty == settings.Difficulty);
            }
            else
            {
                TicTacToeService.CurrentProgress = new ProgressModel()
                {
                    Difficulty = settings.Difficulty
                };
                TicTacToeService.Progress = new List <ProgressModel>();

                TicTacToeService.Progress.Add(new ProgressModel()
                {
                    Difficulty = 1
                });
                TicTacToeService.Progress.Add(new ProgressModel()
                {
                    Difficulty = 2
                });
                TicTacToeService.Progress.Add(new ProgressModel()
                {
                    Difficulty = 3
                });

                File.WriteAllText("save.json", JsonConvert.SerializeObject(TicTacToeService.Progress));
            }

            TicTacToeService.InitializePlayGround(PlayGroundDisplay, Wins, Loses);
            switch (TicTacToeService.CurrentProgress.Difficulty)
            {
            case 1:
                DifficultyLabel.ForeColor = Color.Green;
                Loses.ForeColor           = Color.Green;
                Wins.ForeColor            = Color.Green;
                break;

            case 2:
                DifficultyLabel.ForeColor = Color.Orange;
                Loses.ForeColor           = Color.Orange;
                Wins.ForeColor            = Color.Orange;
                break;

            case 3:
                DifficultyLabel.ForeColor = Color.Violet;
                Loses.ForeColor           = Color.Violet;
                Wins.ForeColor            = Color.Violet;
                break;
            }
            DifficultyLabel.Text = "Difficulty : " + TicTacToeService.CurrentProgress.Difficulty.ToString();
            TicTacToeService.StartGame();
        }
 /// <summary>
 ///  Clean up any resources being used.
 /// </summary>
 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
 protected override void Dispose(bool disposing)
 {
     MainMenuView.Show();
     if (disposing && (components != null))
     {
         components.Dispose();
     }
     base.Dispose(disposing);
 }
Beispiel #5
0
 private void CancelSettingsButton_Click(object sender, EventArgs e)
 {
     this.Close();
     MainMenuView.Show();
 }