private static List <int[]> GetAttackCoordinates(Heigan monster, string input) { List <int[]> AttackCoordinates = new List <int[]>(); int row = int.Parse(input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Skip(1).First()); int col = int.Parse(input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Skip(2).First()); for (int colIndex = col - 1; colIndex <= col + 1; colIndex++) { if (IsInTheMatrix(row - 1, colIndex)) { var cell = new int[] { row - 1, colIndex }; AttackCoordinates.Add(cell); } if (IsInTheMatrix(row, colIndex)) { var cell = new int[] { row, colIndex }; AttackCoordinates.Add(cell); } if (IsInTheMatrix(row + 1, colIndex)) { var cell = new int[] { row + 1, colIndex }; AttackCoordinates.Add(cell); } } return(AttackCoordinates); }
private static void MovePlayerToNewPosition(Player player, Heigan monster, string typeOfAttack) { int[] positionUp = { player.Coordinates[0] - 1, player.Coordinates[1] }; int[] positionRight = { player.Coordinates[0], player.Coordinates[1] + 1 }; int[] positionDown = { player.Coordinates[0] + 1, player.Coordinates[1] }; int[] positionLeft = { player.Coordinates[0], player.Coordinates[1] - 1 }; List <int[]> AttackCoordinates = typeOfAttack == "Cloud" ? monster.PlagueCloudCoordinates : monster.EruptionCoordinates; if (!AttackCoordinates.Any(c => c[0] == positionUp[0] && c[1] == positionUp[1]) && IsInTheMatrix(positionUp[0], positionUp[1])) { player.Coordinates = positionUp; } else if (!AttackCoordinates.Any(c => c[0] == positionRight[0] && c[1] == positionRight[1]) && IsInTheMatrix(positionRight[0], positionRight[1])) { player.Coordinates = positionRight; } else if (!AttackCoordinates.Any(c => c[0] == positionDown[0] && c[1] == positionDown[1]) && IsInTheMatrix(positionDown[0], positionDown[1])) { player.Coordinates = positionDown; } else if (!AttackCoordinates.Any(c => c[0] == positionLeft[0] && c[1] == positionLeft[1]) && IsInTheMatrix(positionLeft[0], positionLeft[1])) { player.Coordinates = positionLeft; } }
static void Main(string[] args) { Player player = new Player(); Heigan heigan = new Heigan(); while (heigan.hitPoints > 0 && player.hitPoints > 0) { player.Attack(heigan); player.TakeDamage("first"); if (heigan.hitPoints < 0 || player.hitPoints < 0) { break; } heigan.Attack(player); player.TakeDamage("second"); } ShowStats(player, heigan); }
static void ShowStats(Player player, Heigan heigan) { if (heigan.hitPoints < 0) { Console.WriteLine("Heigan: Defeated!"); } else { Console.WriteLine("Heigan: {0:F2}", heigan.hitPoints); } if (player.hitPoints < 0) { Console.WriteLine($"Player: Killed by {player.killedBy}"); } else { Console.WriteLine($"Player: {player.hitPoints}"); } Console.WriteLine($"Final position: {player.row}, {player.col}"); }
public void Attack(Heigan heigan) { heigan.hitPoints -= strength; }
static void Main() { Player player = CreateNewPlayer(); Heigan monster = new Heigan(); bool isPlayerDead = false; bool isMonsterDead = false; bool isCloudActive = false; while (true) { // Player hits first player.HitMonster(monster); if (monster.Health <= 0) { isMonsterDead = true; } // Aplly DOT if active if (isCloudActive) { monster.PlagueCloud(player); if (player.Health <= 0) { isPlayerDead = true; player.CauseOfDeath = "Plague Cloud"; } isCloudActive = false; } if (isMonsterDead || isPlayerDead) { break; } // Monster attacks string input = Console.ReadLine(); string typeOfAttack = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).First(); // Cloud attack if (typeOfAttack == "Cloud") { // Check Cloud attack coordinates monster.PlagueCloudCoordinates = GetAttackCoordinates(monster, input); if (monster.PlagueCloudCoordinates.Any(c => c[0] == player.Coordinates[0] && c[1] == player.Coordinates[1])) { int[] currentPlayerPosition = new int[] { player.Coordinates[0], player.Coordinates[1] }; MovePlayerToNewPosition(player, monster, typeOfAttack); if (player.Coordinates[0] == currentPlayerPosition[0] && player.Coordinates[1] == currentPlayerPosition[1]) { // Successful attack monster.PlagueCloud(player); isCloudActive = true; if (player.Health <= 0) { isPlayerDead = true; player.CauseOfDeath = "Plague Cloud"; break; } } monster.PlagueCloudCoordinates.Clear(); } } // Eruption attack if (typeOfAttack == "Eruption") { // Check Eruption attack coordinates monster.EruptionCoordinates = GetAttackCoordinates(monster, input); if (monster.EruptionCoordinates.Any(c => c[0] == player.Coordinates[0] && c[1] == player.Coordinates[1])) { int[] currentPlayerPosition = new int[] { player.Coordinates[0], player.Coordinates[1] }; MovePlayerToNewPosition(player, monster, typeOfAttack); if (player.Coordinates[0] == currentPlayerPosition[0] && player.Coordinates[1] == currentPlayerPosition[1]) { // Successful attack on player monster.Eruption(player); if (player.Health <= 0) { isPlayerDead = true; player.CauseOfDeath = "Eruption"; break; } } monster.EruptionCoordinates.Clear(); } } } if (isMonsterDead) { Console.WriteLine("Heigan: Defeated!"); } else { Console.WriteLine($"Heigan: {monster.Health:f2}"); } if (isPlayerDead) { Console.WriteLine($"Player: Killed by {player.CauseOfDeath}"); } else { Console.WriteLine($"Player: {player.Health}"); } Console.WriteLine($"Final position: {player.Coordinates[0]}, {player.Coordinates[1]}"); }
public void HitMonster(Heigan monster) { monster.Health -= this.Damage; }
public static void Main(string[] args) { var player = new Player(); var heigan = new Heigan(double.Parse(ReadLine())); playField = new int[15, 15]; var lastUsedSpell = ""; //While the player and heigan are both alive while (!player.IsDead && !heigan.IsDead) { var inputData = ReadLine().Split(' ').Where(i => i != "").ToArray(); var spell = inputData[0]; var castPosition = new int[] { int.Parse(inputData[1]), int.Parse(inputData[2]) }; //In every move heigan gets his default amount of damage heigan.Damage(); //Damage the area if (!heigan.IsDead) { ManipulateField(castPosition, true); } //If the player has active Plague Cloud from the previous curse, drop player's health once more if (player.ActiveCloud > 0) { player.Health -= heigan.PerformSpell("Cloud"); // Plague Cloud does not overlap cuz... logic player.ActiveCloud = 0; } //Then check if the somebody died if (player.IsDead || heigan.IsDead) { break; } //If everybody is ok perform the curent damage to the player if he stands on a damaged cell and can't move away from it if (playField[player.Position[0], player.Position[1]] == 1 && !PlayerMoved(player)) { player.Damage(heigan.PerformSpell(spell), spell); } lastUsedSpell = spell; //After all mmodifications, if player had died, the program will stop in order to skip any further modifications of the field // which takes time. if (player.IsDead) { break; } //Clean the area for the next damaging ManipulateField(castPosition, false); } if (heigan.IsDead) { WriteLine($"Heigan: Defeated!"); } else { WriteLine($"Heigan: {heigan.Health:F2}"); } if (player.IsDead) { WriteLine($"Player: Killed by {(lastUsedSpell == "Eruption" ? lastUsedSpell : "Plague Cloud")}"); } else { WriteLine($"Player: {player.Health}"); } WriteLine($"Final position: {player.Position[0]}, {player.Position[1]}"); }