Exemplo n.º 1
0
    IEnumerator RandomMoveAlgorithm()
    {
        if (myBases.Count == 0 && otherBases.Count == 0)
        {
            Debug.Log("Where the bases at, chap :P");
        }
        else
        {
            StartCoroutine(dropBombRoutinely());
            while (myBases.Count > 0 && otherBases.Count > 0)
            {
                int selectedPop = 0;
                categorizeBases();
                int randomNumberOfMyBases = DateTime.Now.Second % myBases.Count;
                //random.range(a,b) is a to b inclusive, inclusive
                int            randomOtherBaseIndex = DateTime.Now.Second % otherBases.Count;
                int            randomMyBaseIndex    = 0;
                HashSet <Base> selectedBases        = new HashSet <Base>();

                for (int i = 0; i <= randomNumberOfMyBases; i++)
                {
                    randomMyBaseIndex = DateTime.Now.Second % myBases.Count;
                    selectedBases.Add(myBases[randomMyBaseIndex]);
                    selectedPop += myBases[randomMyBaseIndex].myPopulation() / 2;
                }

                /*
                 * if (selectedBases.Count == 0)
                 * {
                 *  foreach (Base b in myBases)
                 *  {
                 *      selectedPop += b.myPopulation() / 2;
                 *      selectedBases.Add(b);
                 *  }
                 * }*/

                target = otherBases[randomOtherBaseIndex];
                if (target != null && selectedBases.Count != 0 && target.myPopulation() - (selectedPop / 2.0f) < 0)
                {
                    //troop sender does a lot to tie things together
                    TroopSender.main(selectedBases, target, myTeam);
                }
                yield return(new WaitForSeconds(.6f));
            }
            if (myBases.Count == 0)
            {
                Debug.Log("Enemy: I lost ;(");
                EM.EndGame(true);
            }
            else
            {
                Debug.Log("Enemy: Yay I win B)");
                EM.EndGame(false);
            }
        }
    }
Exemplo n.º 2
0
    private void Update()
    {
        //hey its simple to implement and less straining on the players fingers like
        //why not only depend on the mouse being clicked on and then seeing what is moused over
        if (Input.GetMouseButton(0))
        {
            foreach (Base b in bases)
            {
                if (b.HasMouseOverIt())
                {
                    if (!b.isHighlighted())
                    {
                        //you cant enlist units from an enemy team
                        if (b.myTeam().Equals(currenteam))
                        {
                            //add to selected bases and highlight for player feedback
                            selectedBases.Add(b);
                            b.highlight();
                            StartCoroutine(bounceBaseToBeat(b));
                        }
                        else
                        {
                            if (target != null)
                            {
                                target.unhighlight();
                            }
                            target = b;
                            target.highlight();
                        }
                    }
                }
            }
        }
        if (Input.GetMouseButtonUp(0))
        {
            StopAllCoroutines();
            LinkedList <Base> toRemove = new LinkedList <Base>();
            foreach (Base b in selectedBases)
            {
                if (!b.myTeam().Equals(currenteam))
                {
                    b.unhighlight();
                    toRemove.AddFirst(b);
                }
            }
            foreach (Base b in toRemove)
            {
                selectedBases.Remove(b);
            }

            foreach (Base b in selectedBases)
            {
                b.unhighlight();
            }
            if (target != null)
            {
                target.unhighlight();
            }

            //when locking in choice with deselect lets make sure player
            //is mousing over a base, otherwise do nothing
            target = null;
            foreach (Base b in bases)
            {
                if (b.HasMouseOverIt())
                {
                    target = b;
                }
            }
            //Debug.Log(target);
            //target isn't a place for units to come from
            selectedBases.Remove(target);

            //pretty easy neat way to deselect, just dont mouse over anything when let go
            if (target != null && selectedBases.Count != 0)
            {
                //troop sender does a lot to tie things together
                TroopSender.main(selectedBases, target, currenteam);
            }
            //alright clear for next time
            selectedBases.Clear();
        }
    }