// When the Reset Passwors Button is clicked
        private void ResetPasswordButton_Click(object sender, EventArgs e)
        {
            // Validation
            if (PasswordETF.Text.Equals("")) // If no username has been entered
            {
                MessageBox.Show("Please enter a Password"); // Show a message box describing the error
                return; // Stop this method
            }
            else if (ReEnterPasswordETF.Text.Equals("")) // If no username has been entered
            {
                MessageBox.Show("Please Reenter the Password"); // Show a message box describing the error
                return; // Stop this method
            }
            if (!PasswordETF.Text.Equals(ReEnterPasswordETF.Text))
            { // If the passwords entered do not match
                MessageBox.Show("Passwords to not match. Please try again."); // Show a messagebox displaying the error message
                return; // Stop the method
            }

            UserDatabase userDB = new UserDatabase(); // Create a new instance of a User Database. This can be read from and written to a file

            userDB.ChangeUserPassword(username, PasswordETF.Text); // Change the User's password (Details have been verified in the 'Start Display')
            userDB.SaveDatabase(); // Save the Database to a file
            this.Close(); // Close this form now that the password has been reset
        }
Esempio n. 2
0
        int secondsPassed = 0; // Used to monitor the number of seconds that have passed since the gamee started

        #endregion Fields

        #region Constructors

        // When an instance of this GameForm is created
        public GameForm(LoginForm parentForm, string usernameArg)
        {
            InitializeComponent(); // Initialize this Form component
            loginForm = parentForm; // Store the parent LoginForm
            username = usernameArg; // Record the Username that the player logged in with using the supplied username
            SettingsQuestionEntryBox.SetUsername(usernameArg); // Set the username stored by the SettingsQuestionEntryBox
            DropGrid.SetGridRange(7, 21, 21, 0); // Manually set the range of the DropGrid
            DropGrid.AllowDrop = true; // Ensure that the DropGrid allows dropping
            DropGrid.SetGridVisibility(false); // Set the Grid in the drop grid to invisible
            DropGrid.AddOccupyingPB(SoldierPictureBox); // Add the picture of the soldier to the list of PictureBoxes that cannot be dropped ontop of
            DropGrid.DragDrop += new DragEventHandler(objectPlaced); // Add a DragDrop listener to the DropGrid to call the objectPlaced method when triggered
            BeginPanel.BringToFront(); // Ensure that the BeginPanel is at the front of theform
            ShopFlowLayoutPanel.HorizontalScroll.Visible = false; // Prevent the Shop FlowLayoutPanel from scrolling horizontally
            FormClosed += new FormClosedEventHandler(formClosed); // Add a FormClosed listener to call the formClosed method when this form is closed
            PointsLabel.Text = "Points: " + points; // Update the text of the PointsLabel to display the current points of the user

            UserDatabase userDB = new UserDatabase(); // Create a new instance of a UserDatabase. This is done for reading purposes
            QuestionButtonState buttonState = userDB.getQuestionButtonState(username); // Read and store the button state that has been saved for this user
            SetBiologyButtonsState(buttonState.biologyButtonEnabled); // Set the state of the Biology Buttons to the saved values
            OtherSubjectTextBox.Text = buttonState.otherButtonLabel; // Update the name of the Other subjcet to the saved value
            SetOtherButtonState(buttonState.otherButtonEnabled); // Set the state of the Other Subject Buttons to the saved values

            PlantDispenser.stock = 3; // Manually set the stock for each dispenser in the shop.
            TapDispenser.stock = 4;
            FoodMachineDispenser.stock = 1;
            TorchDispenser.stock = 1;
        }
Esempio n. 3
0
        public Game(Login parentForm, string usernameArg)
        {
            InitializeComponent();
            loginForm = parentForm;
            username = usernameArg;
            questionEntryBox1.SetUsername(usernameArg);
            dropGrid.SetGridRange(7, 21, 21, 0);
            dropGrid.AllowDrop = true;
            dropGrid.SetGridVisibility(false);
            dropGrid.AddOccupyingPB(pictureBox2);
            dropGrid.DragDrop += new DragEventHandler(objectPlaced);
            BeginPanel.BringToFront();
            flowLayoutPanel1.HorizontalScroll.Visible = false;
            FormClosed += new FormClosedEventHandler(formClosed);
            PointsLabel.Text = "Points: " + points;

            UserDatabase userDB = new UserDatabase();
            QuestionButtonState buttonState = userDB.getQuestionButtonState(username);
            SetBiologyButtonsState(buttonState.biologyButtonEnabled);
            OtherSubjectTextBox.Text = buttonState.otherButtonLabel;
            SetOtherButtonState(buttonState.otherButtonEnabled);

            PlantDispenser.stock = 3;
            TapDispenser.stock = 4;
            FoodMachineDispenser.stock = 1;
            TorchDispenser.stock = 1;
        }
 private void ResetPasswordButton_Click(object sender, EventArgs e)
 {
     if(!PasswordETF.Text.Equals(ReEnterPasswordETF.Text)){
         MessageBox.Show("Passwords to not match. Please try again.");
         return;
     }
     UserDatabase userDB = new UserDatabase();
     userDB.ChangeUserPassword(username, PasswordETF.Text);
     userDB.SaveDatabase();
 }
 private void SubmitUsernameButton_Click(object sender, EventArgs e)
 {
     UserDatabase userDB = new UserDatabase();
     string[] forgotPasswordDetails = userDB.getForgotPassword(UsernameETF.Text);
     QuestionLabel.Text = forgotPasswordDetails[0];
     QuestionLabel.Visible = true;
     AnswerETF.Visible = true;
     SubmitAnswerButton.Visible = true;
     expectedAnswer = forgotPasswordDetails[1];
     username = UsernameETF.Text;
 }
Esempio n. 6
0
        public void ChangeQuestion(string set)
        {
            UserQuestions userQuestions = new UserDatabase().getUserQuestions(username);
            Console.WriteLine(set);
            List<string[]> questions = userQuestions.getQuestions(set);
            Random random = new Random();
            int questionIndex = -1;

            do{
            questionIndex = random.Next(questions.Count);
            }while(questions.Count > 1 && questions[questionIndex][0].Equals(QuestionLabel.Text));

            QuestionLabel.Text = questions[questionIndex][0];
            int button1TextIndex, button2TextIndex, button3TextIndex;
            button1TextIndex = random.Next(3) + 1;

            do
            {
                button2TextIndex = random.Next(3) + 1;
            } while (button2TextIndex == button1TextIndex);
            do
            {
                button3TextIndex = random.Next(3) + 1;
            } while (button3TextIndex == button1TextIndex || button3TextIndex == button2TextIndex);

            if (button1TextIndex == 1)
            {
                correctAnswerButton = "Answer1";
            }
            else if (button2TextIndex == 1)
            {
                correctAnswerButton = "Answer2";
            }
            else if (button3TextIndex == 1)
            {
                correctAnswerButton = "Answer3";
            }

            Answer1Button.BackColor = Color.Gainsboro;
            Answer2Button.BackColor = Color.Gainsboro;
            Answer3Button.BackColor = Color.Gainsboro;

            Answer1Button.Text = questions[questionIndex][button1TextIndex];
            Answer2Button.Text = questions[questionIndex][button2TextIndex];
            Answer3Button.Text = questions[questionIndex][button3TextIndex];
        }
Esempio n. 7
0
        // Used to change the question that the player is answering using a subject / tier
        public void ChangeQuestion(string set)
        {
            UserQuestions userQuestions = new UserDatabase().getUserQuestions(username); // Create a new UserDatabase and extract and store the User Questions of the active user
            List<string[]> questions = userQuestions.getQuestions(set); // Save the questions from the appropriate set in a list
            Random random = new Random(); // Create a new Random number generator
            int questionIndex = -1; // Default the question index to -1

            do
            { // keep trying to find a new question
                questionIndex = random.Next(questions.Count); // Find a random index to check
            } while (questions.Count > 1 && questions[questionIndex][0].Equals(QuestionLabel.Text)); // Check the index

            QuestionLabel.Text = questions[questionIndex][0]; // Set the text of the question label to our newly found question
            int[] buttonTextIndexes = { 1, 2, 3 }; // Create integers to store the index of the text that will be displayed by each button

            // Shuffle the indexes of the text to be displayed on the buttons

            for (int i = 0; i < 3; i++) // For each button text index
            {
                int changeIndex = random.Next(i, 3); // Find another index to be swapped with our current one (that is higher than our current one)
                int tempIndex = buttonTextIndexes[i]; // Temporarily store the first value which is to be overwritten in the swap
                buttonTextIndexes[i] = buttonTextIndexes[changeIndex]; // Overwrite the first value
                buttonTextIndexes[changeIndex] = tempIndex; // Overwrite the second value
            }

            if (buttonTextIndexes[0] == 1) // If button1 has the index of the correct answer
            {
                correctAnswerButton = "Answer1"; // Save the answer which is the correct one
            }
            else if (buttonTextIndexes[1] == 1) // If button2 has the index of the correct answer
            {
                correctAnswerButton = "Answer2"; // Save the answer which is the correct one
            }
            else if (buttonTextIndexes[2] == 1) // If button3 has the index of the correct answer
            {
                correctAnswerButton = "Answer3"; // Save the answer which is the correct one
            }

            Answer1Button.BackColor = Color.Gainsboro; // Reset the colour of all buttons (They become red when the player makes a mistake)
            Answer2Button.BackColor = Color.Gainsboro;
            Answer3Button.BackColor = Color.Gainsboro;

            Answer1Button.Text = questions[questionIndex][buttonTextIndexes[0]]; //Assign the text of the buttons to their randomly chosen answers
            Answer2Button.Text = questions[questionIndex][buttonTextIndexes[1]];
            Answer3Button.Text = questions[questionIndex][buttonTextIndexes[2]];
        }
Esempio n. 8
0
        List<string> resolvedProblemQuestions = new List<string>(); // Used to store the problematic Questions for the pupil we are currently viewing

        #endregion Fields

        #region Constructors

        // When a new instance of a Teacher Form is created
        public TeacherForm()
        {
            InitializeComponent(); // Initialize the component
            UserDatabase userDB = new UserDatabase(); // Create a new instance of a userDatabase for reading purposes
            List<string> usernames = userDB.getUsernames(); // Extract usernames for all pupils from the database
            RadioButton[] pupilRadioButtons = new RadioButton[usernames.Count]; // Prepare an array of RadioButtons which is the size of the number of usernames
            for (int i = 0; i < usernames.Count; i++) // For each username in the list that has been read
            {
                if (usernames[i] == "Teacher") // If the current username is "Teacher"
                {
                    continue; // Skip this username
                }
                pupilRadioButtons[i] = new RadioButton(); // Create a new RadioButton for this username
                pupilRadioButtons[i].Text = usernames[i]; // Set the text of the RadioButton to the current username
                pupilRadioButtons[i].Size = OverviewRadioButton.Size; // Set the size of the RadioButton to the same as the Size of the Overview button
                pupilRadioButtons[i].Font = new Font("Microsoft Sans Serif", 14); // Set the font of the RadioButton
                pupilRadioButtons[i].Click += new EventHandler(RadioButtonClicked); // Add a Click listener to the radio button that calls RadioButtonClicked when clicked
                PupilFlowLayoutPanel.Controls.Add(pupilRadioButtons[i]); // Add the RadioButton to the FlowLayoutPanel
            }
        }
Esempio n. 9
0
        private void CompleteRegistrationButton_Click(object sender, EventArgs e)
        {
            if (UsernameETF.Text.Equals(""))
            {
                MessageBox.Show("Please enter a Username");
                return;
            }
            else if (PasswordETF.Text.Equals(""))
            {
                MessageBox.Show("Please enter a Password");
                return;
            }
            else if (ReenterPasswordETF.Text.Equals(""))
            {
                MessageBox.Show("Please enter a Reentered Password");
                return;
            }

            if (!PasswordETF.Text.Equals(ReenterPasswordETF.Text))
            {
                MessageBox.Show("Passwords do not match");
                return;
            }

            UserDatabase userDB = new UserDatabase();

            try
            {
                userDB.AddUser(UsernameETF.Text, PasswordETF.Text);
                userDB.setUserForgotPassword(UsernameETF.Text, ForgotPasswordQuestionETF.Text, ForgotPasswordAnswerETF.Text);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
                return;
            }

            userDB.OutputDatabaseContents();
            userDB.SaveDatabase();
            ClearTextFields();
        }
        // Used to change to another display that is stored by this component
        public void ChangeDisplay(string newDisplayID)
        {
            NextQuestionBox.Visible = true; // Show the "Next" boxes at the bottom of the table
            NextCorrectAnswerBox.Visible = true;
            NextWrongAnswer1Box.Visible = true;
            NextWrongAnswer2Box.Visible = true;

            StoreDisplay(); // Store this display in preparation for switching

            if (storedDetails.ContainsKey(username) && storedDetails[username].ContainsKey(newDisplayID)) // If this display already exists
            {
                questions = new List<TextBox>(storedDetails[username][newDisplayID].questions); // Show all details from the found display
                correctAnswers = new List<TextBox>(storedDetails[username][newDisplayID].correctAnswers);
                wrongAnswers1 = new List<TextBox>(storedDetails[username][newDisplayID].wrongAnswers1);
                wrongAnswers2 = new List<TextBox>(storedDetails[username][newDisplayID].wrongAnswers2);
                UpdateDisplay();
            }
            else // If the display does not already exist
            {
                questions = new List<TextBox>(); // Clear all columns
                correctAnswers = new List<TextBox>();
                wrongAnswers1 = new List<TextBox>();
                wrongAnswers2 = new List<TextBox>();

                UserDatabase userDB = new UserDatabase(); // Initialise a new UserDatabase for reading purposes
                UserQuestions userQuestions = userDB.getUserQuestions(username); // Read the current user's questions
                List<string[]> details = userQuestions.getQuestions(newDisplayID); // Extract the questions for this set
                for (int i = 0; i < details.Count; i++) // for each question
                {
                    questions.Add(new TextBox()); // Add a new cell for the question
                    questions[i].BorderStyle = BorderStyle.FixedSingle; // Update the border
                    questions[i].Click += new EventHandler(BoxClicked); // Add an event handler so that when the cell is clicked the Enter Value panel appears
                    questions[i].Text = details[i][0]; // Fill the cell with the question

                    correctAnswers.Add(new TextBox()); // Add a new cell for the Correct Answer
                    correctAnswers[i].BorderStyle = BorderStyle.FixedSingle;
                    correctAnswers[i].Click += new EventHandler(BoxClicked);
                    correctAnswers[i].Text = details[i][1];

                    wrongAnswers1.Add(new TextBox()); // Add a new cell for the wrong answer 1
                    wrongAnswers1[i].BorderStyle = BorderStyle.FixedSingle;
                    wrongAnswers1[i].Click += new EventHandler(BoxClicked);
                    wrongAnswers1[i].Text = details[i][2];

                    wrongAnswers2.Add(new TextBox()); // Add a new cell for the wrong answer 2
                    wrongAnswers2[i].BorderStyle = BorderStyle.FixedSingle;
                    wrongAnswers2[i].Click += new EventHandler(BoxClicked);
                    wrongAnswers2[i].Text = details[i][3];
                }
                UpdateDisplay(); // Update the display to show the columns to the user
            }
            currentID = newDisplayID; // Update the currentID tracking variable to track the current ID
        }
 public void SaveSetForAllPupils(string pupilUsername)
 {
     StoreDisplay();
     Dictionary<string, TempStoredDisplay> detailsToSave = storedDetails[pupilUsername];
     string[] usernames = new UserDatabase().getUsernames().ToArray<string>();
     storedDetails = new Dictionary<string, Dictionary<string, TempStoredDisplay>>();
     foreach (string currentUsername in usernames)
     {
         storedDetails.Add(currentUsername, detailsToSave);
     }
     SaveAllQuestions();
 }
        public void SaveOnePupilQuestions(string pupilUsername)
        {
            StoreDisplay(); // Store the current display

            UserDatabase userDB = new UserDatabase(); // Create a new instance of a UserDatabase. This can be read from and written to

            List<TempStoredDisplay> storedDetailsValues = storedDetails[pupilUsername].Values.ToList<TempStoredDisplay>(); // List all of the TempStoredDisplays in the storedDetials Dictionary

            for (int j = 0; j < storedDetailsValues.Count; j++) // For each display that needs to be saved
            {
                TempStoredDisplay tempStoredDisplay = storedDetailsValues[j]; // get the current display that we are saving
                if (tempStoredDisplay.questions.Count == 0) // If there are no questions in this display
                {
                    continue; // Skip this display
                }

                string[][] questionDetails = new string[4][]; // Create a multi-dimensional array to format the display

                questionDetails[0] = new string[tempStoredDisplay.questions.Count]; // Set the size of each array in the multi-dimensional array to the number of questions
                questionDetails[1] = new string[tempStoredDisplay.questions.Count];
                questionDetails[2] = new string[tempStoredDisplay.questions.Count];
                questionDetails[3] = new string[tempStoredDisplay.questions.Count];

                for (int i = 0; i < tempStoredDisplay.questions.Count; i++) // For each question in this display
                {
                    questionDetails[0][i] = tempStoredDisplay.questions[i].Text; // Add the question to the stored details
                    questionDetails[1][i] = tempStoredDisplay.correctAnswers[i].Text; // Add the correct answer to the stored details
                    questionDetails[2][i] = tempStoredDisplay.wrongAnswers1[i].Text; // Add the wrong answer 1 to the stored details
                    questionDetails[3][i] = tempStoredDisplay.wrongAnswers2[i].Text; // Add the wrong answer 2 to the stored details

                }

                userDB.ClearQuestionSet(pupilUsername, storedDetails[pupilUsername].Keys.ToList<string>()[j]); // Clear the question set that we are about to fill
                userDB.FillQuestionSet(pupilUsername, storedDetails[pupilUsername].Keys.ToList<string>()[j], questionDetails[0], questionDetails[1], questionDetails[2], questionDetails[3]); // Fill the question set with our formatted details

            }

            userDB.SaveDatabase(); // Save the database as a file
        }
Esempio n. 13
0
        // When the Save Settings button has been clicked
        private void SettingsSave_Click(object sender, EventArgs e)
        {
            SettingsQuestionEntryBox.SaveAllQuestions(); // Save all questions held by the SettingsQuestionEntryBox

            UserDatabase userDB = new UserDatabase(); // Create a new instance of a User Database to save the buttons state
            userDB.SetUserQuestionButtonState(username, SettingsBiologyT1.Enabled, SettingsOtherSubjectT1.Enabled, SettingsOtherSubjectT1.Text.Substring(0, SettingsOtherSubjectT1.Text.Length - 7)); // Update the button state in the new User Database
            userDB.SaveDatabase(); // Save the Database

            OtherSubjectT1Button.Text = SettingsOtherSubjectT1.Text; // Update the text of the Other Subject buttons to contain the chosen subject name
            OtherSubjectT2Button.Text = SettingsOtherSubjectT2.Text;
            OtherSubjectT3Button.Text = SettingsOtherSubjectT3.Text;

            SettingsReturnButton_Click(sender, e); // Return from the settings view by calling the functions used when the user clicks on the return button on the settings page
        }
Esempio n. 14
0
        // When the Login button has been clicked
        private void LoginButton_Click(object sender, EventArgs e)
        {
            UserDatabase userDB = new UserDatabase(); // Create a new instance of a User Database. This allows reading and writing of the database

            // Verification
            if (UsernameETF.Text.Equals("")) // If no username has been entered
            {
                MessageBox.Show("Please enter a Username"); // Show a message box describing the error
                return; // Stop this method
            }
            else if (PasswordETF.Text.Equals("")) // If no password has been entered
            {
                MessageBox.Show("Please enter a Password");
                return;
            }
            else if (!userDB.ContainsUsername(UsernameETF.Text)) // If the database does not contain this username
            {
                MessageBox.Show("Username not recognised"); // Display a message box describing the error
                return; // Stop this method
            }
            else if (!userDB.ContainsPassword(UsernameETF.Text, PasswordETF.Text)) // If the user has not entered the correct password for this username
            {
                MessageBox.Show("Password is incorrect for this Username");
                return;
            }

            // Start the game

            if (UsernameETF.Text.Equals("Teacher"))
            {
                TeacherForm teacherForm = new TeacherForm();
                teacherForm.Visible = true;
                UsernameETF.Text = ""; // Clear the username text box
                PasswordETF.Text = ""; // Clear the password text box
                return;
            }
            GameForm gameForm = new GameForm(this, UsernameETF.Text); // Create a new instance of a GameForm
            gameForm.Visible = true; // Make the GameForm Visible
            this.Visible = false; // Hide the current Form
            UsernameETF.Text = ""; // Clear the username text box
            PasswordETF.Text = ""; // Clear the password text box
        }
Esempio n. 15
0
        // When the Complete Registration Button has been clicked
        private void CompleteRegistrationButton_Click(object sender, EventArgs e)
        {
            // Validation

            if (UsernameETF.Text.Equals("")) // If no username has been entered
            {
                MessageBox.Show("Please enter a Username"); // Show a message box describing the error
                return; // Stop this method
            }
            else if (PasswordETF.Text.Equals("")) // If no password has been entered
            {
                MessageBox.Show("Please enter a Password");
                return;
            }
            else if (ReenterPasswordETF.Text.Equals("")) // If the password has not been reentered
            {
                MessageBox.Show("Please reenter a Password");
                return;
            }
            else if (ForgotPasswordQuestionETF.Text.Equals("")) // If the Forgot Password Question has not been entered
            {
                MessageBox.Show("Please enter a Question that will be asked when you have forgotten your password.");
                return;
            }
            else if (ForgotPasswordAnswerETF.Text.Equals("")) // If the Forgot Password Question answer has not been entered
            {
                MessageBox.Show("Please enter the answer to your Forgot Password Question.");
                return;
            }

            if (!PasswordETF.Text.Equals(ReenterPasswordETF.Text)) // If the password and the Reentered Password do not match
            {
                MessageBox.Show("Passwords do not match, please try re-entering them");
                return;
            }

            //Begin Registering the new user

            UserDatabase userDB = new UserDatabase(); // Create a new instance of the User Database. This allows reading and writing of the database

            try
            {
                userDB.AddUser(UsernameETF.Text, PasswordETF.Text); // Attempt to add the new user to the database. Duplicate usernames will be detected here
                userDB.setUserForgotPassword(UsernameETF.Text, ForgotPasswordQuestionETF.Text, ForgotPasswordAnswerETF.Text.ToLower()); // Attempt to give the user a 'Forgot Password Question' and answer
            }
            catch (Exception exception) // Catch any exception, and perform the following
            {
                MessageBox.Show(exception.Message + ""); // Display a message box describing the error
                return; // Stop this method
            }

            SwitchToLoginView();
            RegistrationCompletedLabel.Visible = true;

            userDB.SaveDatabase(); // Save the database to a file
            ClearTextFields(); // Clear all of the TextBoxes
        }
Esempio n. 16
0
        private void SettingsSave_Click(object sender, EventArgs e)
        {
            questionEntryBox1.SaveAllQuestions();

            UserDatabase userDB = new UserDatabase();
            userDB.SetUserQuestionButtonState(username, SettingsBiologyT1.Enabled, SettingsOtherSubjectT1.Enabled, SettingsOtherSubjectT1.Text.Substring(0, SettingsOtherSubjectT1.Text.Length - 7));
            userDB.SaveDatabase();

            SettingsReturnButton_Click(sender, e);
        }
Esempio n. 17
0
 // Used to update the button states of Biology and the Custom Subject
 private void UpdateButtonStates()
 {
     UserDatabase userDB = new UserDatabase(); // Create a new instance of a UserDatabase
     QuestionButtonState buttonState = userDB.getQuestionButtonState(activePupilUsername); // Extract the button state for the active username and store it
     SetBiologyEnabled(buttonState.biologyButtonEnabled); // Set Biology to enabled or disabled depending on the extracted value
     SetOtherSubjectEnabled(buttonState.otherButtonEnabled, buttonState.otherButtonLabel); // Set the Custom Subject to enabled or disabled depending on the extracted value
 }
Esempio n. 18
0
 private void SavePupilButton_Click(object sender, EventArgs e)
 {
     PupilSettingsQuestionEntryBox.SaveOnePupilQuestions(activePupilUsername);
     UserDatabase userDB = new UserDatabase(); // Create a new instance of a User Database to save the buttons state
     userDB.SetUserQuestionButtonState(activePupilUsername, SettingsBiologyT1Button.Enabled, SettingsOtherSubjectT1Button.Enabled, SettingsOtherSubjectT1Button.Text.Substring(0, SettingsOtherSubjectT1Button.Text.Length - 7)); // Update the button state in the new User Database
     userDB.SaveDatabase(); // Save the Database
     MessageBox.Show("Details saved for this pupil");
 }
Esempio n. 19
0
 private void SaveAllPupilsButton_Click(object sender, EventArgs e)
 {
     PupilSettingsQuestionEntryBox.SaveSetForAllPupils(activePupilUsername);
     UserDatabase userDB = new UserDatabase(); // Create a new instance of a User Database to save the buttons state
     List<string> usernames = userDB.getUsernames();
     foreach (string name in usernames) {
         userDB.SetUserQuestionButtonState(name, SettingsBiologyT1Button.Enabled, SettingsOtherSubjectT1Button.Enabled, SettingsOtherSubjectT1Button.Text.Substring(0, SettingsOtherSubjectT1Button.Text.Length - 7)); // Update the button state in the new User Database
     }
     userDB.SaveDatabase();
     MessageBox.Show("Details Saved for all pupils");
 }
Esempio n. 20
0
        // When a radio button is clicked
        private void RadioButtonClicked(object sender, EventArgs e)
        {
            RadioButton clickedRadioButton = sender as RadioButton; // Store the RadioButton that was clicked
            activePupilUsername = clickedRadioButton.Text; // Set the active Set to the text of the RadioButton
            PupilSettingsQuestionEntryBox.ChangeUsername(activePupilUsername); // Change the username of the SettingsEntryBox in the PupilSettingsPanel
            SetSettingsEnabled(true); // Enable the Pupil Settings components
            UpdateButtonStates(); // Update the button states (whether Biology/Custom Subject are enabled or disabled for the newly active user)
            SettingsOtherSubjectEnableButton.Enabled = true; // Make sure that the OtherSubjectEnableButton is enabled
            SettingsOtherSubjectTextBox.Enabled = true; // Make sure that the OtherSubjectTextBox is enabled
            SettingsBiologyEnableButton.Enabled = true; // Make sure that theBiologytEnableButton is enabled
            PlayerNameLabel.Text = "Player Name: " + clickedRadioButton.Text; // Update the text of the Player Name Label to show the newly active player's username
            ViewProblemsButton.Enabled = true; // Make sure that the ViewProblemsButton is enabled
            ViewResolvedProblemsButton.Enabled = true; // Make sure that the ViewResolvedProblemsButton is enabled

            UserDatabase userDB = new UserDatabase(); // Create a new instance of a UserDatabase
            UserDatabase.GameCompletedDetails gameCompletedDetails = userDB.GetGameCompletedDetails(activePupilUsername); // Extract the GameCompletedDetails about the active user from the database
            if (gameCompletedDetails.timeInSeconds < 0) // If the pupil did not complete the game
            {
                GameCompletedLabel.Text = "Game Completed?: No"; // Update the game completed label to tell the teacher that the pupil did not complete the game
                GameTimeLabel.Text = "Game Time: N/A"; // Update the game time label to be unavailable
            }
            else // If the pupil did complete the game
            {
                GameCompletedLabel.Text = "Game Completed?: Yes";
                GameTimeLabel.Text = "Game Time: " + gameCompletedDetails.timeInSeconds + " Seconds";
            }
            NumCorrectAnswersLabel.Text = "Number of Correct Answers:\n    " + gameCompletedDetails.numCorrectAnswers[0] + "\n    " + gameCompletedDetails.numCorrectAnswers[1] + "\n    " + gameCompletedDetails.numCorrectAnswers[2];
            NumMistakesLabel.Text = "Number of Correct Answers:\n    " + gameCompletedDetails.numMistakes[0] + "\n    " + gameCompletedDetails.numMistakes[1] + "\n    " + gameCompletedDetails.numMistakes[2];
            NumProblemQuestionsLabel.Text = "Number of Problem Questions:\n     " + gameCompletedDetails.problemQuestions.Count;
            NumResolvedProblemsLabel.Text = "Number of Resolved Problems:\n     " + gameCompletedDetails.resolvedQuestions.Count;
            problemQuestions = gameCompletedDetails.problemQuestions;
            resolvedProblemQuestions = gameCompletedDetails.resolvedQuestions;
        }
Esempio n. 21
0
        private void OverviewButton_Click(object sender, EventArgs e)
        {
            SetSettingsEnabled(false);
            ViewProblemsButton.Enabled = false;
            ViewResolvedProblemsButton.Enabled = false;
            PlayerNameLabel.Text = "Player Name: N/A";
            GameCompletedLabel.Text = "Game Completed?: N/A";
            int averageTime = 0, averageT1Correct = 0, averageT2Correct = 0, averageT3Correct = 0,
                averageT1Mistakes = 0, averageT2Mistakes = 0, averageT3Mistakes = 0,
                averageProblems = 0, averageResolvedProblems = 0;
            UserDatabase userDB = new UserDatabase();
            int numberValues = userDB.getUsernames().Count;
            foreach (string username in userDB.getUsernames())
            {
                UserDatabase.GameCompletedDetails gameCompletedDetails = userDB.GetGameCompletedDetails(username);
                if (gameCompletedDetails.timeInSeconds > 0)
                {
                    averageTime += gameCompletedDetails.timeInSeconds;
                }
                else
                {
                    numberValues--;
                    continue;
                }
                averageT1Correct += gameCompletedDetails.numCorrectAnswers[0];
                averageT2Correct += gameCompletedDetails.numCorrectAnswers[1];
                averageT3Correct += gameCompletedDetails.numCorrectAnswers[2];
                averageT1Mistakes += gameCompletedDetails.numMistakes[0];
                averageT2Mistakes += gameCompletedDetails.numMistakes[1];
                averageT3Mistakes += gameCompletedDetails.numMistakes[2];
                averageProblems += gameCompletedDetails.problemQuestions.Count;
                averageResolvedProblems += gameCompletedDetails.resolvedQuestions.Count;
            }
            averageTime = averageTime / numberValues;
            averageT1Correct = averageT1Correct / numberValues;
            averageT2Correct = averageT2Correct / numberValues;
            averageT3Correct = averageT3Correct / numberValues;
            averageT1Mistakes = averageT1Mistakes / numberValues;
            averageT2Mistakes = averageT2Mistakes / numberValues;
            averageT3Mistakes = averageT3Mistakes / numberValues;
            averageProblems = averageProblems / numberValues;
            averageResolvedProblems = averageResolvedProblems / numberValues;

            GameTimeLabel.Text = "Game Time: " + averageTime + " Seconds";
            NumCorrectAnswersLabel.Text = "Number of Correct Answers:\n    " + averageT1Correct + "\n    " + averageT2Correct + "\n    " + averageT3Correct;
            NumMistakesLabel.Text = "Number of Correct Answers:\n    " + averageT1Mistakes + "\n    " + averageT2Mistakes + "\n    " + averageT3Mistakes;
            NumProblemQuestionsLabel.Text = "Number of Problem Questions:\n     " + averageProblems;
            NumResolvedProblemsLabel.Text = "Number of Resolved Problems:\n     " + averageResolvedProblems;
        }
Esempio n. 22
0
        // Used to complete the game
        public void CompleteGame()
        {
            AirTimer.Stop(); // Stop all timers
            WaterTimer.Stop();
            FoodTimer.Stop();
            SecondTimer.Stop();
            GameCompletedForm gameCompletedForm = new GameCompletedForm(); // Create a new instance of a GameCompletedForm
            gameCompletedForm.Visible = true; // Make this new instance visible
            this.Visible = false; // Hide the current Form
            gameCompletedForm.SetTimeLabel(secondsPassed); // Set the time label on the new form
            gameCompletedForm.SetQuestionLists(problemQuestions, resolvedProblemQuestions); // Set the values of the question lists on the new form
            gameCompletedForm.SetTotalCorrectAnswers(answersCorrect[0], answersCorrect[1], answersCorrect[2]); // Set the value for total correct answers on the new form
            gameCompletedForm.SetTotalNumMistakes(answersIncorrect[0], answersIncorrect[1], answersIncorrect[2]); // Set the value for the total number of mistakes on the new form
            gameCompletedForm.SetProblemQuestionsLabel(problemQuestions.Count); // Set the data for the Problem Questions on the new form
            gameCompletedForm.SetResolvedQuestionsLabel(resolvedProblemQuestions.Count); // Set the data for the Resolved Questions on the new form

            UserDatabase userDB = new UserDatabase();
            UserDatabase.GameCompletedDetails gameCompletedDetails = new UserDatabase.GameCompletedDetails();
            gameCompletedDetails.timeInSeconds = secondsPassed;
            gameCompletedDetails.numCorrectAnswers = answersCorrect;
            gameCompletedDetails.numMistakes = answersIncorrect;
            gameCompletedDetails.problemQuestions = problemQuestions;
            gameCompletedDetails.resolvedQuestions = resolvedProblemQuestions;
            userDB.AddGameCompletedDetails(username, gameCompletedDetails);
            userDB.SaveDatabase();
        }
 // When the Submit Username Button is clicked
 private void SubmitUsernameButton_Click(object sender, EventArgs e)
 {
     if (UsernameETF.Text.Equals("")) // If no username has been entered
     {
         MessageBox.Show("Please enter a Username"); // Show a message box describing the error
         return; // Stop this method
     }
     UserDatabase userDB = new UserDatabase(); // Create a new instance of the User Database. This can be read from and written to a file
     try
     {
         string[] forgotPasswordDetails = userDB.getForgotPassword(UsernameETF.Text); // Exctract and store the ForgotPasswordDetails about the username entered in the Username Expanding Text Field
         QuestionLabel.Text = forgotPasswordDetails[0]; // Update the QuestionLabel's Text to display the Username's saved Forgot Password Question
         QuestionLabel.Visible = true; // Make sure that the Question Label is visible (It starts off invisible)
         AnswerETF.Visible = true; // Make sure that the Answer Expanding Text Field is visible (It starts off invisible)
         SubmitAnswerButton.Visible = true; // Make sure that the Sumbit Answer Button is visible (It starts off invisible)
         expectedAnswer = forgotPasswordDetails[1]; // Store the expected Answer as the Forgotten Password Answer which was stored for this username
         username = UsernameETF.Text; // Store the Username about which the Forgot Password Details have been extracted
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message + "");
     }
 }
Esempio n. 24
0
 private void LoginButton_Click(object sender, EventArgs e)
 {
     UserDatabase userDB = new UserDatabase();
     if (!userDB.ContainsUsername(UsernameETF.Text))
     {
         MessageBox.Show("Username not recognised");
         return;
     }
     else if(!userDB.ContainsPassword(UsernameETF.Text, PasswordETF.Text))
     {
         MessageBox.Show("Password is incorrect for this Username");
         return;
     }
     Game gameForm = new Game(this, UsernameETF.Text);
     gameForm.Visible = true;
     this.Visible = false;
 }