/// <summary> /// Loads all the content needed for the game stage /// </summary> public static void LoadContent() { //Link togther the LevelContainer and InputMenu class throug events //Level Events LevelContainer.Instance.RunCompleteFailed += m => InputMenu.Instance.ShowResultsForRoundFailed(m); LevelContainer.Instance.RunCompleteSuccess += li => InputMenu.Instance.ShowResultsForRoundSuccess(li); LevelContainer.Instance.AllLevelsComplete += lr => InputMenu.Instance.ShowResultsAllLevelsComplete(lr); //Command events InputMenu.Instance.CommandReadingStarting += () => LevelContainer.Instance.ReStartLevel(); InputMenu.Instance.CommandReadingComplete += q => LevelContainer.Instance.LoadCommands(q); LevelContainer.Instance.ExecutingNextCommand += () => InputMenu.Instance.ShowNextCommand(); //Collectable events LevelContainer.Instance.KeysAndGemsCounted += (nk, ng) => InputMenu.Instance.SetNumKeys(nk, ng); LevelContainer.Instance.playerKeyCollected += nk => InputMenu.Instance.UpdateNumCollectedKeys(nk); LevelContainer.Instance.playerGemCollected += ng => InputMenu.Instance.UpdateNumCollectedGems(ng); //leaving the game stage InputMenu.Instance.PlayerReadyToExistMainGame += s => AllLevelsComplete.Invoke(s); InputMenu.Instance.QuitGame += () => BackToMenu.Invoke(); //Load content for LevelContainer and InputMenu foreach (ISection section in sections) { section.LoadContent(); } //Load the legend image legend = Helper.LoadImage("Images/command legend ethan"); }
/// <summary> /// Updates all the gameobjects in the level /// </summary> public void Update() { //If the game is paused dont update anything if (GamePaused) { return; } //If all the objects are standing still and there is more commands left, run them if (!commands.IsEmpty && gameObjects.All(g => g.IsStandingStill())) { //give player the next command and notify Game that the next command is being excecuted player.LoadNextCommand(commands.Dequeue()); ExecutingNextCommand.Invoke(); //If the command just loaded is the last command check if the player won if (commands.IsEmpty) { //pause the game GamePaused = true; //check if the player has reached the flag check if they collected all the gems if (player.Box.Location == flagPos) { //if they did not collect all the gems then inform Game they failed the level for that reason if (player.GemCount != numGems) { RunCompleteFailed.Invoke("You did not collect all the gems : press ENTER to try again."); } //the player won else { //stop the timer timer.Stop(); //Save the results for this level and update the final results finalResult.LevelResults[curLevel - 1] = new LevelResult(timer.Elapsed.Milliseconds + numCommands * 100, timer.Elapsed.Seconds); finalResult.TotalTime += finalResult.LevelResults[curLevel - 1].Time; finalResult.TotalScore += finalResult.LevelResults[curLevel - 1].Score; //check if that was the last level if (curLevel == NUM_LEVELS) { //inform Game all levels complete and send it final reslts AllLevelsComplete.Invoke(finalResult); } else { //inform Game that the level has been complete and send the correct level results RunCompleteSuccess.Invoke(finalResult.LevelResults[curLevel - 1]); //go to the next level and indicate that a new level is starting ++curLevel; startingNewLevel = true; } } } //the player did not reach the goal else { //Inform Game that the level did not reach the goal RunCompleteFailed.Invoke("A'w Shuc'ks Buddy ol Pal! Failed to reach goal : press ENTER to try again."); } } } //Update all the gameobjects gameObjects.ForEach(g => g.Update()); //Try to move all the gameobjects (while taking collision into account) MoveGameObjects(); }