Esempio n. 1
0
    public void ExecuteTurn() // function that drives the turn after receiving all players' turn data (Intended tile (x,y) and intended direction (up/down/left/right)) OR turn timer runs out
    {
        bool done = false;

        while (done == false)
        {
            List <Movement> Showdowns = new List <Movement>();
            bool            matched   = false;
            for (int i = 0; i < moves.Count && !matched; i++)
            {
                //TODO: something about multiplayer rng
                for (int j = i + 1; j < moves.Count && !matched; j++)
                {
                    if (moves[i].coordinates == moves[j].coordinates)
                    {
                        Showdowns.Add(moves[i]); Showdowns.Add(moves[j]);
                        matched = true;
                        Debug.Log("Added move by player " + moves[i].index);
                        Debug.Log("Added move by player " + moves[j].index);
                        //move i and j go to the showdown
                        for (int k = j + 1; k < moves.Count; k++)
                        {
                            if (moves[i].coordinates == moves[k].coordinates)
                            {
                                Showdowns.Add(moves[k]);
                                Debug.Log("Added move by player " + moves[k].index);
                            }
                        }
                    }
                }
            }

            int winnerIndex = -1; int tempMax = -1;

            foreach (Movement i in Showdowns)
            {
                i.roll = Random.Range(1, 6) + CharacterList[i.index].GetAttack() - 3;
                Debug.Log("Player " + i.index + " rolled a " + i.roll + "!");
                if (i.roll > tempMax)
                {
                    tempMax     = i.roll;
                    winnerIndex = i.index;
                }
            }

            if (winnerIndex != -1)
            {
                Debug.Log("Player " + winnerIndex + "Wins!");
            }

            List <Movement> toRemove = new List <Movement>();
            foreach (Movement i in Showdowns)
            {
                if (i.index != winnerIndex)
                {
                    CharacterList[i.index].ModifyHealth(-99999);
                    playShowdown.Play();
                    toRemove.Add(i);
                }
            }
            foreach (Movement i in toRemove)
            {
                moves.Remove(i);
            }
            done = true;
            //Debug.Log("done is true");
            for (int i = 0; i < moves.Count; i++)
            {
                for (int j = i + 1; j < moves.Count; j++)
                {
                    if (moves[i].coordinates == moves[j].coordinates)
                    {
                        done = false;
                    }
                }
            }
        }

        PercolateItems(waveDirection);


        foreach (Movement move in moves)
        {
            MovePlayer(move.index, move.coordinates.x, move.coordinates.y, move.direction);
        }
        foreach (Movement move in moves)
        {
            List <Item> toRemove = new List <Item>();
            foreach (Item item in items)
            {
                if (CharacterList[move.index].GetPosition() == item.GetPosition())
                {
                    item.Activate(this);
                    itemController.Activated(item.GetPosition());
                    toRemove.Add(item);
                }
            }
            foreach (Item item in toRemove)
            {
                items.Remove(item);
            }
        }
        SpawnItemWave();
        // item wave spawns and all items move as turn executes, (to land on item you must aim where it is going to go rather than where it is when you click)
        // movement anime
        // wait for next turn, generate which direction (up/down/left/right) the next wave of items comes from
    }