Beispiel #1
0
 // add a life pack to the list
 public void AddLifePack(System.Drawing.Point lifePackPosition, int lifePackLifeTime)
 {
     LifePack life = new LifePack();
     life.X = lifePackPosition.X;
     life.Y = lifePackPosition.Y;
     life.LifeTime = lifePackLifeTime;
     life.DisappearTime = (int)Global.GameTime.TotalGameTime.TotalMilliseconds + life.LifeTime;
     lifePacks.Add(life);
 }
Beispiel #2
0
    /// <summary>
    ///     FORMAT = [L:x,y:lt#]
    /// </summary>
    /// <param name="command">Command.</param>
    private void LifepackSpawnExec(string command)
    {
        try {
            var lifes    = command.Substring(2).Split(':');
            var location = lifes [0].Split(',');
            var lifePack = new LifePack(int.Parse(location [0]), int.Parse(location [1]), int.Parse(lifes [1]));
            lifepacks.Add(lifePack);

            // Generate Life Packs
            GenerateGameObjects.GetInstance().GenerateLifePacks(lifePack);
        } catch (Exception ex) {
            Debug.LogException(ex);
        }
    }
Beispiel #3
0
 private void decodeLifePack(string[] tokens)
 {
     LifePack lifePack = new LifePack(decodeXY(tokens[1])[0], int.Parse(tokens[2].TrimEnd(new char[] { '#' })) / 1000, size);
     mainscn.LifePacks.Add(lifePack);
 }
Beispiel #4
0
 // remove selected life pack  from the list
 public void RemoveLifePack(LifePack lifePack)
 {
     lifePacks.Remove(lifePack);
 }
        void lifePackDisappearTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (this.nextLifePackToDisappear != null)
            {
                Monitor.Enter(gameEng.DisappearLifePackList);
                Monitor.Enter(gameEng.AvailableLifePackList);
                LifePack lifePackNextInLine = null;
                int      currentIndex       = gameEng.DisappearLifePackList.IndexOf(this.nextLifePackToDisappear);

                if (gameEng.AvailableLifePackList.Contains(this.nextLifePackToDisappear))
                {
                    Console.WriteLine("Life Pack @ " + this.nextLifePackToDisappear.Position + " VANISHED");
                    gui.RemoveMapItem(this.nextLifePackToDisappear.Position.X, this.nextLifePackToDisappear.Position.Y);
                    gameEng.AvailableLifePackList.Remove(this.nextLifePackToDisappear);
                }

                if (currentIndex < gameEng.DisappearLifePackList.Count - 2)
                {
                    lifePackNextInLine = gameEng.DisappearLifePackList[currentIndex + 1];
                    int updateTimeSpan = lifePackNextInLine.DisappearTime -
                                         this.nextLifePackToDisappear.DisappearTime;
                    if (updateTimeSpan > 0)
                    {
                        this.lifePackDisappearTimer.Interval = updateTimeSpan;
                    }
                    else
                    {
                        this.lifePackDisappearTimer.Interval = 500;
                    }
                    this.nextLifePackToDisappear = lifePackNextInLine;
                }
                else
                {
                    int updateTimeSpan = gameEng.DisappearLifePackList[gameEng.DisappearLifePackList.Count - 1].DisappearTime
                                         - gameEng.DisappearLifePackList[gameEng.DisappearLifePackList.Count - 2].DisappearTime;
                    if (updateTimeSpan != 0)
                    {
                        this.lifePackDisappearTimer.Interval = updateTimeSpan;
                    }
                    else
                    {
                        this.lifePackDisappearTimer.Interval = 500;
                    }
                    this.nextLifePackToDisappear = null;
                }
                Monitor.Exit(gameEng.AvailableLifePackList);
                Monitor.Exit(gameEng.DisappearLifePackList);
            }
            else
            {
                if (gameEng.AvailableLifePackList.Contains(gameEng.DisappearLifePackList[gameEng.DisappearLifePackList.Count - 1]))
                {
                    Monitor.Enter(gameEng.DisappearLifePackList);
                    Monitor.Enter(gameEng.AvailableLifePackList);
                    Console.WriteLine("LifePack @ " +
                                      gameEng.DisappearLifePackList[gameEng.DisappearLifePackList.Count - 1].Position + " VANISHED");
                    gui.RemoveMapItem(gameEng.DisappearLifePackList[gameEng.DisappearLifePackList.Count - 1].Position.X, gameEng.DisappearLifePackList[gameEng.DisappearLifePackList.Count - 1].Position.Y);
                    gameEng.AvailableLifePackList.Remove(this.nextLifePackToDisappear);
                    Monitor.Exit(gameEng.AvailableLifePackList);
                    Monitor.Exit(gameEng.DisappearLifePackList);
                    //No need to call game finish here since the lifepacks have no impact on the endgame conditions
                }
            }
        }
        /// <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();
        }
    public void GenerateLifePacks(LifePack lifePack)
    {
        var obj = UpdateGameObject(lifePack.ToString(), LifePack, new Vector3(lifePack.x * xFactor, lifePack.y * yFactor, zPos), originalRot);

        Destroy(obj, ((float)lifePack.lifetime) / 1000);
    }