/// <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. } } } }
// Update is called once per frame void Update() { //for testing rotation, todo: remove if (Input.GetKey(KeyCode.Q)) { battleRenderer.RotateLeft(); } if (Input.GetKey(KeyCode.W)) { battleRenderer.RotateRight(); } //map user input to state actions. //there is a 1-1 mapping between actions and keys. //states themselves should have no knowledge of physical inputs. //note: this assumes keyboard controls only. //e.g. If there's mouse controls states will need to handle these as well. currentAction = ACTION_NONE; if (Input.GetKeyUp(KeyCode.A)) { currentAction = ACTION_AGREE; } if (Input.GetKeyUp(KeyCode.B) || Input.GetKeyUp(KeyCode.Z)) { currentAction = ACTION_BACK; } if (Input.GetKeyUp(KeyCode.LeftArrow)) { currentAction = ACTION_LEFT; } if (Input.GetKeyUp(KeyCode.RightArrow)) { currentAction = ACTION_RIGHT; } if (Input.GetKeyUp(KeyCode.UpArrow)) { currentAction = ACTION_UP; } if (Input.GetKeyUp(KeyCode.DownArrow)) { currentAction = ACTION_DOWN; } //most states don't change without input, so can skip the check most of the time. if (currentAction != ACTION_NONE || CurrentState == sFinaliseCharacter || CurrentState == sRenderBattle) { CurrentState.CheckForStateAndChange(this, currentAction); CurrentState.Logic(currentAction); } battleRenderer.Render(this);//TODO: replace this with a proper renderer and remove from main loop }