示例#1
0
 /// <summary>
 /// Starts water flow.
 /// </summary>
 /// <param name="navigator">The square map navigator to use for water flow.</param>
 /// <param name="achievement">The current game achievement to count achievements for.</param>
 public void Go(ISquareMapNavigatorElement navigator, IAchievementElement achievement)
 {
     if (navigator != null)
     {
         /* start our flow thread */
         AsyncFlow flow = new AsyncFlow(this.Flow);
         flow.BeginInvoke(navigator, achievement, new AsyncCallback(this.FlowComplete), flow);
     }
 }
示例#2
0
        /* note on this flow strategy:
         * it's vital to know that here the complete water flow mechanism is being executed in a
         * separate thread. this enables ui and game logic thread to continue while water is flowing.
         * player may continue to build its pipeline while water is flowing.
         *
         * it's also important to know that basically the commanding for flow and pipe flood are
         * asyncronous, which makes it a little bit harder to handle it here. see Pipe.Flood implementation
         * on how this is being solved by synchronizing it on game logic layer.
         * */
        private void Flow(ISquareMapNavigatorElement navigator, IAchievementElement achievement)
        {
            /* we can flow only through pipes */
            IPipeElement pipe = navigator.Current.Square as IPipeElement;

            /* we start with water source first */
            IWaterSourceElement waterSource = pipe as IWaterSourceElement;

            /* we need water to get some flow */
            IWater water = null;

            if (waterSource != null)
            {
                /* trigger water source */
                water = waterSource.Whoosh();
            }

            /* got water ? */
            if (water != null)
            {
                /* flood pipe with water */
                while ((pipe != null) && (pipe.Flood(water)))
                {
                    /* flooded, grant achievement */
                    achievement.Grant(pipe);

                    /* flooded, navigate to next potential pipe */
                    navigator = navigator.Go(water.Direction);

                    /* got navigator ? */
                    if (navigator != null)
                    {
                        /* try next square as pipe */
                        pipe = navigator.Current.Square as IPipeElement;
                    }
                    else
                    {
                        /* nogo */
                        pipe = null;
                    }
                }
            }
        }
示例#3
0
文件: Game.cs 项目: ilkerde/pipemania
        /* advance to next level */
        private bool NextLevel()
        {
            ILevelService levels = this.GetLevelService();

            if (levels != null)
            {
                if (levels.MoveNext())
                {
                    /* set current level */
                    this.currentLevel = levels.Current;

                    /* get new achievement for level */
                    IElementService elements = this.GetElementService();

                    if (elements != null)
                    {
                        this.currentAchievement = elements.CreateAchievement();

                        /* reset achievement, tells ui to update points/pipes */
                        this.currentAchievement.Reset();
                    }
                    else
                    {
                        this.currentAchievement = null;
                    }
                }
                else
                {
                    this.currentLevel = null;
                    this.currentAchievement = null;
                }
            }

            if ((this.currentLevel != null) && (this.currentAchievement != null))
            {
                /* apply level to game */
                this.countDown.FromDefinition(this.currentLevel.CountDown);
                this.pipeQueue.FromDefinition(this.currentLevel.PipeQueue);
                this.squareMap.FromDefinition(this.currentLevel.SquareMap);

                /* send level number */
                this.ExecuteCommand(PresentationCommands.Game.ChangeLevel, new PresentLevelParameter(this.Id, this.currentLevel.Number));
            }

            return (this.currentLevel != null) && (this.currentAchievement != null);
        }