Пример #1
0
    public void ClockTick()
    {
        if (ClockTickActive != null)
        {
            ClockTickActive.Invoke(this, new EventArgs());
        }
        print("Inside CT adds next");
        while (UnitNumber == 0)
        {
            TurnIsActive = false;
            Units.ForEach(c => { c.AddCT(); });                    //Ct gets added to each unit
            UnitOrderCT = Units.FindAll(c => c.ChargeTime >= 100); //Makes a list of units with full CT
            UnitNumber  = UnitOrderCT.Count();
        }

        //Sorting done to determine order of characters that have their CT 100
        Unit swap;

        print("Inside Sorter next");
        if (UnitNumber > 1)
        {
            print("Inside Sorter");
            //checks if there is more then one character getting a turn, if so sorts
            for (int c = 0; c < (UnitNumber - 1); c++)             //bubble sorting, overkill for the sample size, but I prefer having it for sorting the order of characters based on their CT (not much testing yet)
            {
                for (int d = 0; d < UnitNumber - c - 1; d++)       //aka it sorts the characters in the order of how much ct they had
                {
                    if (UnitOrderCT[d].ChargeTime > UnitOrderCT[d + 1].ChargeTime)
                    {
                        swap               = UnitOrderCT[d];
                        UnitOrderCT[d]     = UnitOrderCT[d + 1];
                        UnitOrderCT[d + 1] = swap;
                    }
                }                 //end CT sort
            }
            print("Did Sorter1");
            //this sorts units with equal CT in order of their UnitID
            for (int c = 0; c < (UnitNumber - 1); c++)             //bubble sorting, overkill for the sample size, but I prefer having it for sorting the order of characters based on their CT (not much testing yet)
            {
                for (int d = 0; d < UnitNumber - c - 1; d++)       //aka it sorts the characters in the order of how much ct they had
                {
                    if (UnitOrderCT[d].ChargeTime == UnitOrderCT[d + 1].ChargeTime && UnitOrderCT[d].UnitID > UnitOrderCT[d + 1].UnitID)
                    {
                        swap               = UnitOrderCT[d];
                        UnitOrderCT[d]     = UnitOrderCT[d + 1];
                        UnitOrderCT[d + 1] = swap;
                    }
                }         //end ID sort
            }             //end of sorting
            print("Did Sorter2 and leaving sort");
        }
        Unit AT = UnitOrderCT[0];

        ///Active Turn
        ActiveTurn(AT);
    }
Пример #2
0
    /// <summary>
    /// Method makes turn transitions. It is called by player at the end of his turn.
    /// </summary>
    public void EndTurn()
    {
        /*
         * if (Units.Select(u => u.PlayerNumber).Distinct().Count() == 1)
         * {
         * return;
         * }
         */
        CellGridState = new CellGridStateTurnChanging(this);

        Units.FindAll(u => u.PlayerNumber.Equals(CurrentPlayerNumber)).ForEach(u => { u.OnTurnEnd(); });

        /*
         * CurrentPlayerNumber = (CurrentPlayerNumber + 1) % NumberOfPlayers;
         * while (Units.FindAll(u => u.PlayerNumber.Equals(CurrentPlayerNumber)).Count == 0)
         * {
         *  CurrentPlayerNumber = (CurrentPlayerNumber + 1)%NumberOfPlayers;
         * }//Skipping players that are defeated.
         */
        if (TurnEnded != null)
        {
            modelAnim.SetBool("walk", false);
            TurnEnded.Invoke(this, new EventArgs());
        }

        CurrentUnit.ChargeTime = 0;
        if (CurrentUnit.ActionPoints != 0)
        {
            CurrentUnit.ChargeTime += 20;
        }
        if (CurrentUnit.MovementPoints != 0)
        {
            CurrentUnit.ChargeTime += 20;
        }

        UnitOrderCT = Units.FindAll(c => c.ChargeTime >= 100);         //Makes a list of units with full CT
        UnitNumber  = UnitOrderCT.Count();
        ClockTick();


        //Needs to be commented, otherwise sudden team attack ;D
        //Units.FindAll(u => u.PlayerNumber.Equals(CurrentPlayerNumber)).ForEach(u => { u.OnTurnStart(); });
        //Players.Find(p => p.PlayerNumber.Equals(CurrentPlayerNumber)).Play(this);
    }