Пример #1
0
        void ReleaseDesignerOutlets()
        {
            if (LabelEndGamePoints != null)
            {
                LabelEndGamePoints.Dispose();
                LabelEndGamePoints = null;
            }

            if (LabelWinnerText != null)
            {
                LabelWinnerText.Dispose();
                LabelWinnerText = null;
            }

            if (ButtonMainMenu != null)
            {
                ButtonMainMenu.Dispose();
                ButtonMainMenu = null;
            }

            if (ButtonPlayAgain != null)
            {
                ButtonPlayAgain.Dispose();
                ButtonPlayAgain = null;
            }
        }
Пример #2
0
 // pass in the instance of the game form so that you can access its variables
 public LearnForm(Game game, GameForm gameForm)
 {
     InitializeComponent();
     // hide the play again button until a new question is submitted
     ButtonPlayAgain.Hide();
     _gameForm = gameForm;
     _game = game;
     // if this is the root node, we want to format the print list differently
     if(_game.listIndex == 0)
     {
         _game.listIndex = 1;
     }
 }
Пример #3
0
        private void ButtonNewQuestion_Click(object sender, EventArgs e)
        {
            // build a new question node
            Question newQuestion = new Question(NewClue.Text);
            if (_game.nodeFlag == "Yes")
            {
                newQuestion.noNode = _game.temp.yesNode;
                newQuestion.yesNode =  new Question("Is your pet a " + NewObject.Text + "?");
                _game.current.yesNode = newQuestion;
            }
            else if (_game.nodeFlag == "No")
            {
                newQuestion.yesNode = new Question("Is your pet a " + NewObject.Text + "?");
                newQuestion.noNode = _game.temp.noNode;
                _game.temp.noNode = newQuestion;
            }          
            _game.current = _game.temp;
            // add node to list for printing after increasing count
            _game.listIndex++;
            if(_game.listIndex != 1)
            {
                _game.treeList.Add($"Node{_game.listIndex}: ", newQuestion);
            }
            // check the tree structure - if it is unbalanced, then rebalance
            // TODO

            // save the tree to a file 
            try
            {
                using (StreamWriter stream = File.AppendText(@"c:\repos\twenty-questions\questions.txt"))
                {
                    string prefixParent = "\t\t";
                    string prefixChild = "\t\t\t";
                    stream.WriteLine(prefixParent + newQuestion.question);
                    stream.WriteLine(prefixChild + newQuestion.yesNode.question);
                    stream.WriteLine(prefixChild + newQuestion.noNode.question);
                    stream.Close();
                    prefixParent = prefixParent + "\t";
                    prefixChild = prefixChild + "\t";
                }
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show("File not found");
            }
           
            // make the play again button visible
            ButtonPlayAgain.Show();
        }