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; }
// When the Load timer ticks private void LoadTimer_Tick(object sender, EventArgs e) { loadCounter += 50; // Increment the loadCounter by 50. (50 is used because loadCounter works in centiseconds. The interval of LoadTimer is 500 milliseconds) LoadingBar.Increment((int)((4500000 / loadingBarTime) * Math.Abs(Math.Sin(loadCounter * oneRadian)))); // Add to the loading bar, the Sine of the loadCounter in Radians, multiplied by a constant. (This constant is used to slow the timer when the loadingBar Time needs to be high) if (loadCounter - oneRadian == ((loadingBarTime / 500) * 50) - 50) // 500 ms before the loadingBarTime is up { LoadingBar.Value = LoadingBar.Maximum; // Begin Animation animation to fill loading bar LoadingLabel.Text = "Loading Completed"; // Set the Text of LoadingLabel to "Loading Completed" } else if (loadCounter - oneRadian == 100 + ((loadingBarTime / 500) * 50)) // 1 second after the loadingBarTime is up { LoadTimer.Stop(); // Stop the LoadTimer LoginForm loginForm = new LoginForm(); // Create a new Instance of a LoginForm loginForm.FormClosed += new FormClosedEventHandler(loginFormClosed); // Add a listener to this form, so that when the new form closes, we will close our current form loginForm.Show(); // Show our new LoginForm this.Hide(); // Hide this form } else if ((loadCounter - oneRadian) % 400 == 0 && LoadingLabel.Text != "Loading Completed") // Every 8 seconds { ChangeLoadingLabel(); // Change the Loading Label's text } }