コード例 #1
0
    /// <summary>
    /// Runs the battle to completion.
    /// </summary>
    public void Run()
    {
        // Run rounds until the outcome is known.
        while (!IsOver)
        {
            // For each character in each party...
            foreach (Party party in new[] { Heroes, Monsters })
            {
                foreach (Character character in party.Characters)
                {
                    Console.WriteLine(); // Slight separation gap.

                    BattleRenderer.Render(this, character);

                    // Display who's turn it is.
                    Console.WriteLine($"{character.Name} is taking a turn...");

                    // Have the player in charge of the party pick an action for the character, and then run that action.
                    party.Player.ChooseAction(this, character).Run(this, character);

                    if (IsOver)
                    {
                        break;         // If the last action ended the battle, there is no need to go on to other characters.
                    }
                }

                if (IsOver)
                {
                    break;         // If the last action ended the battle, there is no need to go on to other parties.
                }
            }
        }
    }
コード例 #2
0
    // Use this for initialization
    void Start()
    {
        battleRenderer = GameObject.Find("BattleCanvas").GetComponent <BattleRenderer>();
        CurrentState   = sMainMenu;
        //each character needs a unique name.
        //if instantiating multiples of the same unit, assign them a suffix
        var tempCharacters = new List <Character>();
        var tempEnemies    = new List <Character>();

        foreach (var charachter in _characters)
        {
            var ch = Instantiate(charachter);

            if (tempCharacters.Where(x => x.Name == ch.Name).Count() > 0)
            {
                //TODO: replace "startWith" will a proper check, e.g. trim suffix numbers and do equality check
                ch.Name = ch.Name + tempCharacters.Count(x => x.Name.StartsWith(ch.Name));
            }
            tempCharacters.Add(ch);
        }
        foreach (var enemy in _enemies)
        {
            var e = Instantiate(enemy);
            if (tempEnemies.Where(x => x.Name == e.Name).Count() > 0)
            {
                e.Name = e.Name + tempEnemies.Count(x => x.Name.StartsWith(x.Name));
            }
            tempEnemies.Add(e);
        }
        _characters = tempCharacters.ToArray();
        _enemies    = tempEnemies.ToArray();
    }