/// <summary> /// Has the enemy battle the player. /// </summary> /// <param name="newEnemy">Enemy joining combat</param> public static void EnemyJoin(Character newEnemy) { if (enemy != null && !enemy.Alive) { enemy = null; } else if (enemy == null) { enemy = newEnemy; } }
/// <summary> /// Moves a character down a floor if it exists, otherwise create a new floor. /// </summary> /// <param name="player">The character to move down a floor.</param> public void MovePlayerDownFloor(Character player) { currentFloor--; Floor floorTravelingTo; if (currentFloor < 0) { floorTravelingTo = new Floor(this, viewport, 50 + floorsVisited, 50 + floorsVisited); floors.Insert(0,floorTravelingTo); floorsVisited++; currentFloor = 0; } else { floorTravelingTo = floors[currentFloor]; } MovePlayerToFloor(floorTravelingTo.StairsUpLocation, floorTravelingTo, player); }
/// <summary> /// Performs a round of combat based on player and enemy inputs. /// </summary> /// <param name="userInput">Player's input</param> /// <param name="enemyInput">Enemy's input</param> /// <param name="player">Player</param> /// <param name="enemy">Enemy</param> /// <returns></returns> public string Battle(EInput userInput, EInput enemyInput, Character player, Character enemy) { output = ""; if (combat == true) { BattleAction(userInput, enemyInput, player, enemy); } if ((player.Health > 0) == true && (enemy.Health > 0) == false) { player.Health += roll.Next(1, 11); output = output + "\nYou win!"; } else if ((player.Health > 0) == false) output = output + "\n You have died!"; return output; }
/// <summary> /// Removes the chracter from the floor. /// </summary> /// <param name="character">The chracter to remove.</param> public void RemoveCharacter(Character character) { for (int x = 0; x < characters.GetLength(0); x++) { for (int y = 0; y < characters.GetLength(1); y++) { if (characters[x, y] == character) { characters[x, y] = null; return; } } } }
/// <summary> /// Adds the character to the floor at its given corinates if the space is empty. /// </summary> /// <param name="character">The character to add to the floor.</param> public void AddChracter(Character character) { int characterPositionX = (int)(character.PositionX); int characterPositionY = (int)(character.PositionY); if (characters[characterPositionX, characterPositionY] == null) { characters[characterPositionX, characterPositionY] = character; } }
public int Combat(EInput input, Character defender) { int output = 0; switch (input) { case EInput.Attack: output = Attack(); if (defender.Defense < output) { defender.Defense = 0; defender.Health -= Math.Max((output - defender.Defense), 0); } else defender.Defense -= output; break; case EInput.Defend: output = Defend(); break; case EInput.Magic: output = Magic(); if (defender.Defense < output) { defender.Defense = 0; defender.Health -= Math.Max((output - defender.Defense), 0); } else defender.Defense -= output; break; case EInput.Potion: output = Potion(); break; } return output; }
public FinalCombat() { InitializeComponent(); dungeon = new Dungeon(map); player = new Warrior(dungeon.GetFloor(0).StairsDownLocation.X, dungeon.GetFloor(0).StairsDownLocation.Y+1, 10, 0, 0, 0, 0, 0, Brushes.PowderBlue); }
/// <summary> /// Checks to see if the player is currently in combat. /// </summary> private void CombatVisCheck() { if (enemy != null && player.Health > 0 && enemy.Health > 0) { CombatVisibility(true); FIGHT.Combat = true; } else { CombatVisibility(false); if (player.Health > 0 && enemy != null) { enemy = null; FIGHT.Combat = false; MessageBox.Show("You have won the combat!", "Victory", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (enemy != null && enemy.Health > 0) { MessageBox.Show("You have died!", "Defeat", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } } }
/// <summary> /// Moves a chracter up a floor, if it exists, otherwise create a new /// floor. /// </summary> /// <param name="player">The chracter to move up the floor.</param> public void MovePlayerUpFloor(Character player) { currentFloor++; Floor floorTravelingTo; if (currentFloor >= floors.Count) { floorTravelingTo = new Floor(this, viewport, 50 + floorsVisited, 50 + floorsVisited); floors.Add(floorTravelingTo); floorsVisited++; } else { floorTravelingTo = floors[currentFloor]; } MovePlayerToFloor(floorTravelingTo.StairsDownLocation, floorTravelingTo, player); }
/// <summary> /// Handles addeing the chracter to the new floor, and sets the positon of the character to the /// location of the stairs. /// </summary> /// <param name="stairsLocation">The location of the stairs where the player will end up at.</param> /// <param name="floorTravelingTo">The new floor the chracter will be on.</param> /// <param name="player">The character to move to the new floor.</param> private void MovePlayerToFloor(Point stairsLocation, Floor floorTravelingTo, Character player) { floorTravelingTo.AddChracter(player); player.PositionX = stairsLocation.X; player.PositionY = stairsLocation.Y + 1; RenderDungeon((int)player.PositionX, (int)player.PositionY); }
/// <summary> /// Executes player and enemy actions. /// </summary> /// <param name="firstInput">Player action</param> /// <param name="secondInput">Enemy action</param> /// <param name="first">Player</param> /// <param name="second">Enemy</param> /// <returns></returns> public string BattleAction(EInput firstInput, EInput secondInput, Character first, Character second) { string whoFirst = "You "; string whoSecond = "They "; Console.WriteLine(first.Dexterity + "\n" + second.Dexterity); if (first.Dexterity > second.Dexterity) { whoFirst = "They "; Console.WriteLine("swap"); whoSecond = "You "; } if (first.Health > 0) { int firstOut = first.Combat(firstInput, second); if (firstInput == EInput.Potion) output = output + "\n" + whoFirst + "heal for " + firstOut + "."; else if (firstInput == EInput.Defend) output = output + "\n" + whoFirst + "defend for " + firstOut + "."; else output = output + "\n" + whoFirst + "deal " + firstOut + " damage."; } else combat = false; if (second.Health > 0) { int secondOut = second.Combat(secondInput, first); if (secondInput == EInput.Potion) output = output + "\n" + whoSecond + "heal for " + secondOut + "."; else if (secondInput == EInput.Defend) output = output + "\n" + whoSecond + "defend for " + secondOut + "."; else output = output + "\n" + whoSecond + "deal " + secondOut + " damage."; } else combat = false; return output; }