public override void Activity(bool firstTimeCalled) { base.Activity(firstTimeCalled); removeDeadSprites(); removeDeadText(); undoColourOperationsOnFadedInTiles(); if (model.GameState == CoreModel.GameStates.GameOver) { if (InputManager.Mouse.ButtonPushed(Mouse.MouseButtons.LeftButton)) { this.FadeOutComplete += new FadeEventDelegate(CoreGameScreen_MoveToMainMenuFadeOutComplete); this.FadeOut(); } } else if (model.GameState == CoreModel.GameStates.GameComplete) { if (InputManager.Mouse.ButtonPushed(Mouse.MouseButtons.LeftButton)) { this.FadeOut(); } } else { if (this._tutorialPanelShowing == false) { Tile t = findTileMouseIsOver(); if (InputManager.Mouse.ButtonPushed(Mouse.MouseButtons.LeftButton)) { // Left mouse button pushed - down this frame, not down last frame. if (t != null && t.IsEmpty()) { t.Atom = model.NextAtom; model.PickNextAtom(); this.drawTile(t); AudioManager.Instance.PlaySound(CoreModel.SOUND_FILE_PATH + "atom-placed.mp3"); this.drawNextAtom(); this.updateAtomsLeftOrPointsCounter(); BackgroundWorker reactionComputingThread = new BackgroundWorker(); reactionComputingThread.DoWork += new DoWorkEventHandler(reactionComputingThread_DoWork); reactionComputingThread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(reactionComputingThread_RunWorkerCompleted); reactionComputingThread.RunWorkerAsync(t); } } else { if (t != null && !t.IsEmpty()) { if (this._startHoverTime == DateTime.MinValue) { this._startHoverTime = DateTime.Now; } else { TimeSpan time = (DateTime.Now - this._startHoverTime); if (time.TotalMilliseconds >= 500) { infoPanel.Show(t.Atom); } } } else if (InputManager.Mouse.IsOn3D(this._nextAtom, false)) { infoPanel.Show(model.NextAtom); } else { infoPanel.Hide(); this._startHoverTime = DateTime.MinValue; } } if (model.IsLevelOver()) { if (model.CurrentLevel != CoreModel.AVALANCHE_LEVEL && model.CurrentLevel != CoreModel.TRICKLE_LEVEL) { this.FadeOutHalf(); } else { // Show random "good work" message, and add 1000 points string message = this._greatWorkMessages[model.RandomGenerator.Next() % this._greatWorkMessages.Length] + " (+1000 points)"; model.Points += 1000; this.updateAtomsLeftOrPointsCounter(); AudioManager.Instance.PlaySound(CoreModel.SOUND_FILE_PATH + "ulimited-mode-atoms-cleared.mp3"); TowerText messageText = new TowerText(this.AddText(message)); messageText.YVelocity = 15; messageText.AlphaRate = -0.05f; messageText.Scale = 48; messageText.AddShadow(); messageText.Colour(255, 225, 64); this._reactionText.Add(messageText.BaseText); this._reactionText.Add(messageText.EffectText); // Generate 40 tiles on the board. int numGenerated = 0; while (numGenerated < 40) { IList<Tile> tiles = model.SpewOutAtomsFromMachine(); numGenerated += tiles.Count; foreach (Tile tile in tiles) { drawTile(tile); fadeTileIn(tile); } } } } } } }
void model_GameOver() { if (model.CurrentLevel != CoreModel.AVALANCHE_LEVEL && model.CurrentLevel != CoreModel.TRICKLE_LEVEL) { this.FadeOutComplete -= CoreGameScreen_LevelCompleteBlackOutComplete; } this.FadeInComplete += new FadeEventDelegate(CoreGameScreen_ReturnToMainMenuFadeInComplete); this.FadeOutHalf(); TowerText t = new TowerText(this.AddText("Game Over!")); t.AddShadow(); t.Scale = 72; // Go on TOP of the shadow. t.Z = this.GetTopZValueAndMoveFadeToTop() + 1; string returnToMainMenuText = ""; if (model.CurrentLevel == CoreModel.AVALANCHE_LEVEL || model.CurrentLevel == CoreModel.TRICKLE_LEVEL) { returnToMainMenuText += "(You scored " + model.Points + " points.) "; if (model.Points >= 25000) { model.FeatManager.GrantFeat(@"z00KSNDLsTvhZ1oK-8WjmdcEWRE2fF6zKCiARZp_1laXXOXd_Q1IQq_STqr4VwAe_TzKaivRDOhQdyoxiwo_HPtOOuIg9gdW79F6wy6CWjDg9tE-o7ntFhVXw_K-MgU6"); } } returnToMainMenuText += "Click to return to the main menu."; TowerText t2 = new TowerText(this.AddText(returnToMainMenuText)); t2.AddShadow(); t2.Y = t2.Y - (t.Scale / 2) - 8; // Below the above text. Pad 8px. t2.Scale = 24; t2.Z = t.Z; this.ManageForGarbageCollection(t); this.ManageForGarbageCollection(t2); }
void reactionComputingThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (!e.Cancelled) { // Don't let multiple threads eat atoms. Nor let two check for two reactions at // the same time with an overlapping atom. lock (CoreModel.Instance) { IList<Tile> tilesInReaction = e.Result as IList<Tile>; // Final check if someone ate our atoms in-between and unbalanced us. if (tilesInReaction != null && tilesInReaction.Count > 0 && tilesInReaction.Sum(t => t.Atom.IonCharge) == 0) { // Add points. Not displayed outside of Avalanche and Trickle, oh well. model.Points += tilesInReaction.Sum(t => t.Atom.Points); this.updateAtomsLeftOrPointsCounter(); StringBuilder equation = new StringBuilder(); tilesInReaction = tilesInReaction.OrderBy(tile => tile, this._orderTilesByAtomNameComparer).ToList(); String previousElement = tilesInReaction[0].Atom.Element; String currentElement = ""; int quantity = 0; Tile finalTile = tilesInReaction[tilesInReaction.Count - 1]; // Equations only on non-Avalanche and non-Trickle mode. foreach (Tile reactionTile in tilesInReaction) { // For some reason, these appear at high levels in large chains. // HACK: don't display it. if (reactionTile.IsEmpty()) { continue; } reactionTile.AtomSprite.ColorOperation = ColorOperation.Add; reactionTile.AtomSprite.RedRate = 3f; reactionTile.AtomSprite.GreenRate = 3f; reactionTile.AtomSprite.BlueRate = 3f; this._reactingTiles.Add(reactionTile); // Print out something nice, like 2Fl + H + Li. // Or, in Avalanche/Trickle, 1 + 16 + 9. if (model.CurrentLevel != CoreModel.AVALANCHE_LEVEL && model.CurrentLevel != CoreModel.TRICKLE_LEVEL) { currentElement = reactionTile.Atom.Element; if (previousElement == currentElement) { quantity++; } else if (previousElement != currentElement) { // Print nothing if quantity = 1, i.e. we like to // see "H + Cl" not "1H + 1Cl" equation.Append(string.Format("{0}{1} + ", (quantity > 1 ? quantity.ToString() : ""), previousElement)); // 1, not 0, because we won't do this elsewhere; fixes bug where // Fl-Fl-H-H becomes 2Fl + H. quantity = 1; } previousElement = reactionTile.Atom.Element; } else { equation.Append(string.Format("{0} + ", reactionTile.Atom.Points)); } reactionTile.Empty(); // Prevent quick clickers from chaining } // Dump of last element if (model.CurrentLevel != CoreModel.AVALANCHE_LEVEL && model.CurrentLevel != CoreModel.TRICKLE_LEVEL) { equation.Append(string.Format("{0}{1} + ", (quantity > 1 ? quantity.ToString() : ""), previousElement)); } if (equation.Length >= 3) { // Trickle mode bug? equation.Remove(equation.Length - 3, 3); // trailing " + " } TowerText equationText = new TowerText(this.AddText(equation.ToString())); equationText.YVelocity = 15; equationText.AlphaRate = -0.1f; equationText.Scale = 24; equationText.AddShadow(); equationText.InsertNewLines(SpriteManager.Camera.Width); AudioManager.Instance.PlaySound(CoreModel.SOUND_FILE_PATH + "reaction.mp3"); this._reactionText.Add(equationText.BaseText); this._reactionText.Add(equationText.EffectText); } if (model.CurrentLevel >= CoreModel.FIRST_PUZZLE_LEVEL && model.CurrentLevel <= CoreModel.LAST_PUZZLE_LEVEL && model.NextAtom == Atom.NONE && !model.IsLevelOver()) { // Puzzle mode, out of atoms; game over. model.SignalGameOver(); } } } }
void CoreGameScreen_LevelCompleteBlackOutComplete(TowerScreen.FadeOutMode mode) { TowerText levelUp = new TowerText(this.AddText(string.Format("Level complete! on to level {0} ...", model.CurrentLevel + 1))); levelUp.AddShadow(); levelUp.AlphaRate = -0.25f; levelUp.Scale = 44; this._reactionText.Add(levelUp.BaseText); this._reactionText.Add(levelUp.EffectText); // Detect game completion if (model.CurrentLevel == CoreModel.FIRST_PUZZLE_LEVEL - 1 && model.GameState != CoreModel.GameStates.GameComplete) { // Completed normal mode. Woohoo! AudioManager.Instance.PlaySound(CoreModel.SOUND_FILE_PATH + "machine-powers-down.mp3"); this.FadeInComplete -= CoreGameScreen_LevelCompleteBlackOutComplete; this.FadeOutComplete += new FadeEventDelegate(CoreGameScreen_MoveToMainMenuFadeOutComplete); _gameComplete = this.AddSprite("Content/Story/story-mode-complete.jpg"); _gameComplete.Z = this.GetTopZValueAndMoveFadeToTop() + 1; model.SetGameStateToGameComplete(); model.FeatManager.GrantFeat(@"mrv9c_D9NCZXnKzNUMCIXP-cqZI4ZzWld6CXZjHLeEZAKLKnvoBxsxxuUJ98xtzenJJTB8nLzXF3nwTMTMXnetEQxDDu_H53A_AB1SzZaEp8v6cc4fPfSqYUnCJ4u1T6"); } if (model.CurrentLevel == CoreModel.LAST_PUZZLE_LEVEL && model.GameState != CoreModel.GameStates.GameComplete) { // Completed puzzle mode. Woohoo! AudioManager.Instance.PlaySound(CoreModel.SOUND_FILE_PATH + "machine-powers-down.mp3"); this.FadeInComplete -= CoreGameScreen_LevelCompleteBlackOutComplete; this.FadeOutComplete += new FadeEventDelegate(CoreGameScreen_MoveToMainMenuFadeOutComplete); _gameComplete = this.AddSprite("Content/Story/game-complete.jpg"); _gameComplete.Z = this.GetTopZValueAndMoveFadeToTop() + 1; model.FeatManager.GrantFeat(@"nS9N7CWfMXA3GNRjT8Wf868wqK6MT_s7k5iS7h8txeeLl6TRTOvKcRAuobehkekHGLWXafTNAgcstbvcPamDnRHiKpBuG0H2YXANVGCE6GsajGep4tJ2SONyeVWGNLCa"); model.SetGameStateToGameComplete(); } else { // Regular mode. Not Avalanche or Trickle. model.MoveToNextLevel(); performPerLevelPreSetup(); performPerLevelPostSetup(); this.FadeIn(); } model.SaveLevelReached(); }