Beispiel #1
0
        public void removeCoinsFromMap(CoinPile coin)
        {
            //this needs to be called when a timer expires
            CoinPile value;

            Map.getMap.CoinList.TryRemove(coin.Coordinate, out value);
            //Console.WriteLine("coinpile removed.value: "+coin.Value);
        }
 public static void LoadEmotionScene(string sceneToLoad)
 {
     CoinPile.ResetCoinPileSize();
     if (CityInitializer.City != null)
     {
         CityInitializer.City.SetActive(true);
         PlayAudioUnBlockable(CityInitializer.City.GetComponent <AudioSource>());
     }
     LoadScene(sceneToLoad);
 }
        /// <summary>
        /// What needs to be done when a CoinPile disappears
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void CoinPileDisappearTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (this.nextCoinPileToDisappear != null)
            {
                Monitor.Enter(gameEng.DisappearCoinPileList);
                Monitor.Enter(gameEng.AvailableCoinPileList);
                CoinPile CoinPileNextInLine = null;
                int      currentIndex       = gameEng.DisappearCoinPileList.IndexOf(this.nextCoinPileToDisappear);

                if (gameEng.AvailableCoinPileList.Contains(this.nextCoinPileToDisappear))
                {
                    Console.WriteLine("CoinPile @ " + this.nextCoinPileToDisappear.Position + " VANISHED");
                    gui.RemoveMapItem(this.nextCoinPileToDisappear.Position.X, this.nextCoinPileToDisappear.Position.Y);
                    gameEng.AvailableCoinPileList.Remove(this.nextCoinPileToDisappear);
                }
                if (currentIndex < gameEng.DisappearCoinPileList.Count - 2)
                {
                    CoinPileNextInLine = gameEng.DisappearCoinPileList[currentIndex + 1];
                    int updateTimeSpan = CoinPileNextInLine.DisappearTime -
                                         this.nextCoinPileToDisappear.DisappearTime;
                    if (updateTimeSpan > 0)
                    {
                        this.CoinPileDisappearTimer.Interval = updateTimeSpan;
                    }
                    else
                    {
                        this.CoinPileDisappearTimer.Interval = 500;
                    }
                    this.nextCoinPileToDisappear = CoinPileNextInLine;
                }
                else
                {
                    int updateTimeSpan = gameEng.DisappearCoinPileList[gameEng.DisappearCoinPileList.Count - 1].DisappearTime
                                         - gameEng.DisappearCoinPileList[gameEng.DisappearCoinPileList.Count - 2].DisappearTime;
                    if (updateTimeSpan != 0)
                    {
                        this.CoinPileDisappearTimer.Interval = updateTimeSpan;
                    }
                    else
                    {
                        this.CoinPileDisappearTimer.Interval = 500;
                    }
                    this.nextCoinPileToDisappear = null;
                }
                Monitor.Exit(gameEng.AvailableCoinPileList);
                Monitor.Exit(gameEng.DisappearCoinPileList);
            }
            else
            {
                if (gameEng.AvailableCoinPileList.Contains(gameEng.DisappearCoinPileList[gameEng.DisappearCoinPileList.Count - 1]))
                {
                    Monitor.Enter(gameEng.DisappearCoinPileList);
                    Monitor.Enter(gameEng.AvailableCoinPileList);
                    Console.WriteLine("CoinPile @ " +
                                      gameEng.DisappearCoinPileList[gameEng.DisappearCoinPileList.Count - 1].Position + " VANISHED");
                    gui.RemoveMapItem(gameEng.DisappearCoinPileList[gameEng.DisappearCoinPileList.Count - 1].Position.X, gameEng.DisappearCoinPileList[gameEng.DisappearCoinPileList.Count - 1].Position.Y);
                    gameEng.AvailableCoinPileList.Remove(this.nextCoinPileToDisappear);
                    Monitor.Exit(gameEng.AvailableCoinPileList);
                    Monitor.Exit(gameEng.DisappearCoinPileList);
                    gameFinisherThread.RunWorkerAsync();
                }
            }
        }
        /// <summary>
        /// Initializing the timers
        /// </summary>
        private void InitializeTimers()
        {
            this.updateCoinPileTimer           = new System.Timers.Timer();
            this.playerUpdateTimer             = new System.Timers.Timer();
            this.lifeTimer                     = new System.Timers.Timer();
            this.CoinPileDisappearTimer        = new System.Timers.Timer();
            this.updateLifePackTimer           = new System.Timers.Timer();
            this.lifePackDisappearTimer        = new System.Timers.Timer();
            this.plunderCoinPileDisappearTimer = new System.Timers.Timer();


            this.updateCoinPileTimer.Elapsed           += new ElapsedEventHandler(updateCoinPileTimer_Elapsed);
            this.playerUpdateTimer.Elapsed             += new ElapsedEventHandler(playerUpdateTimer_Elapsed);
            this.lifeTimer.Elapsed                     += new ElapsedEventHandler(lifeTimer_Elapsed);
            this.CoinPileDisappearTimer.Elapsed        += new ElapsedEventHandler(CoinPileDisappearTimer_Elapsed);
            this.updateLifePackTimer.Elapsed           += new ElapsedEventHandler(updateLifePackTimer_Elapsed);
            this.lifePackDisappearTimer.Elapsed        += new ElapsedEventHandler(lifePackDisappearTimer_Elapsed);
            this.plunderCoinPileDisappearTimer.Elapsed += new ElapsedEventHandler(plunderCoinPileDisappearTimer_Elapsed);

            this.playerUpdateTimer.Enabled = true;
            this.lifeTimer.Enabled         = true;

            this.updateCoinPileTimer.Enabled    = true;
            this.CoinPileDisappearTimer.Enabled = true;

            this.updateLifePackTimer.Enabled    = true;
            this.lifePackDisappearTimer.Enabled = true;

            this.plunderCoinPileDisappearTimer.Enabled = true;

            this.playerUpdateTimer.Interval = Constant.UPDATE_PERIOD;
            this.lifeTimer.Interval         = Constant.LIFE_TIME;

            this.plunderCoinPileDisappearTimer.Interval = 1;

            if (gameEng.CoinPileList.Count > 0)
            {
                gameEng.NextCoinPileSend             = gameEng.CoinPileList[gameEng.CoinPilesToDisclose - 1].AppearTime;
                this.updateCoinPileTimer.Interval    = gameEng.NextCoinPileSend;
                this.CoinPileDisappearTimer.Interval = gameEng.DisappearCoinPileList[0].DisappearTime;
                this.nextCoinPileToDisappear         = gameEng.DisappearCoinPileList[0];
            }
            else
            {
                this.CoinPileDisappearTimer.Interval       = Constant.LIFE_TIME;
                this.nextCoinPileToDisappear               = new CoinPile(-1, -1);
                this.nextCoinPileToDisappear.AppearTime    = Constant.LIFE_TIME;
                this.nextCoinPileToDisappear.DisappearTime = Constant.LIFE_TIME;
            }

            if (gameEng.LifePackList.Count > 0)
            {
                gameEng.NextLifePackSend             = gameEng.LifePackList[gameEng.LifePacksToDisclose - 1].AppearTime;
                this.updateLifePackTimer.Interval    = gameEng.NextLifePackSend;
                this.lifePackDisappearTimer.Interval = gameEng.DisappearLifePackList[0].DisappearTime;
                this.nextLifePackToDisappear         = gameEng.DisappearLifePackList[0];
            }
            else
            {
                this.lifePackDisappearTimer.Interval       = Constant.LIFE_TIME;
                this.nextLifePackToDisappear               = new LifePack(-1, -1);
                this.nextLifePackToDisappear.AppearTime    = Constant.LIFE_TIME;
                this.nextLifePackToDisappear.DisappearTime = Constant.LIFE_TIME;
            }

            this.updateCoinPileTimer.Stop();
            this.CoinPileDisappearTimer.Stop();

            this.updateLifePackTimer.Stop();
            this.lifePackDisappearTimer.Stop();

            this.playerUpdateTimer.Stop();
            this.lifeTimer.Stop();
        }