Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace TheHeiganDance
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- public class TheHeiganDanceEntryPoint
- {
- public static void Main()
- {
- decimal demageDoneToHeiganEachTurn = decimal.Parse(Console.ReadLine());
- Player player = new Player(demageDoneToHeiganEachTurn);
- Heigan heigan = new Heigan();
- while (true)
- {
- if (player.IsKilled || heigan.IsDefeated)
- {
- break;
- }
- string inputLine = Console.ReadLine().Trim().ToLower();
- string[] spellInfo = inputLine.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- string spell = spellInfo[0];
- int row = int.Parse(spellInfo[1]);
- int col = int.Parse(spellInfo[2]);
- // 1. heigan takes demage (done)
- // 2. if heigan is dead we skip the other things (done)
- // 3. the spell is casted (done)
- // 4. the spell hits and radius are checked and placed (done)
- // 5. the player tries to move only if a spell is on his cell
- // 6. if he has nowhere to go he takes demage
- // 7. if he dies we skip other things and print the result
- heigan.TakeDemage(player.DemagePerTurn);
- if (heigan.IsDefeated)
- {
- goto SkipSpellIfHeiganIsDead;
- }
- switch (spell)
- {
- case "cloud":
- Spell plagueCloud = new Spell(2, 3500, "Plague Cloud");
- plagueCloud.SetAreaOfEffect(new Position(row, col));
- player.CheckIfSpellHits(plagueCloud);
- break;
- case "eruption":
- Spell eruption = new Spell(1, 6000, "Eruption");
- eruption.SetAreaOfEffect(new Position(row, col));
- player.CheckIfSpellHits(eruption);
- break;
- default:
- break;
- }
- SkipSpellIfHeiganIsDead:
- player.TakeDamage();
- }
- StringBuilder result = new StringBuilder();
- if (heigan.IsDefeated)
- {
- result.AppendLine("Heigan: Defeated!");
- }
- else
- {
- result.AppendLine($"Heigan: {heigan.Health:f2}");
- }
- if (player.IsKilled)
- {
- result.AppendLine($"Player: Killed by {player.KillerSpell}");
- }
- else
- {
- result.AppendLine($"Player: {player.Health}");
- }
- result.Append($"Final position: {player.Position.Row}, {player.Position.Col}");
- Console.WriteLine(result.ToString());
- }
- }
- public static class Chamber
- {
- public const int minRows = 0;
- public const int maxRows = 15;
- public const int minCols = 0;
- public const int maxCols = 15;
- }
- public class Heigan
- {
- private decimal health;
- private bool isDefeated;
- public Heigan()
- {
- this.health = 3000000m;
- this.isDefeated = false;
- }
- public decimal Health
- {
- get { return this.health; }
- set { this.health = value; }
- }
- public bool IsDefeated
- {
- get { return this.isDefeated; }
- set { this.isDefeated = value; }
- }
- public void TakeDemage(decimal demageHeiganTakes)
- {
- if (this.health - demageHeiganTakes <= 0)
- {
- this.isDefeated = true;
- }
- else
- {
- this.health -= demageHeiganTakes;
- }
- }
- }
- public class Player
- {
- private int health;
- private decimal demagePerTurn;
- private Position position;
- private bool isKilled;
- private List<Spell> activeSpells;
- private string killerSpell;
- public Player(decimal demagePerTurn)
- {
- this.killerSpell = string.Empty;
- this.health = 18500;
- this.demagePerTurn = demagePerTurn;
- this.position = new Position(7, 7);
- this.isKilled = false;
- this.activeSpells = new List<Spell>();
- }
- public int Health
- {
- get { return this.health; }
- }
- public decimal DemagePerTurn
- {
- get { return this.demagePerTurn; }
- }
- public Position Position
- {
- get { return this.position; }
- }
- public bool IsKilled
- {
- get { return this.isKilled; }
- }
- public void AddSpell(Spell toAdd)
- {
- this.activeSpells.Add(toAdd);
- }
- public string KillerSpell
- {
- get { return this.killerSpell; }
- }
- public void CheckIfSpellHits(Spell toCheck)
- {
- bool itHits = false;
- foreach (Position cellItEffects in toCheck.AreaOfEffect)
- {
- if (position.Row == cellItEffects.Row && position.Col == cellItEffects.Col)
- {
- itHits = true;
- break;
- }
- }
- if (!itHits)
- {
- return;
- }
- bool menagedToEscape = CheckIfPlayerCouldEscape(toCheck);
- if (!menagedToEscape)
- {
- AddSpell(toCheck);
- }
- }
- private bool CheckIfPlayerCouldEscape(Spell toCheck)
- {
- bool canEscape = true;
- Position newPlayerPosition = null;
- foreach (Position escapeWay in Position.runawayPathsOfThePlayer)
- {
- newPlayerPosition = new Position(position.Row + escapeWay.Row, position.Col + escapeWay.Col);
- canEscape = true;
- foreach (Position effectedCell in toCheck.AreaOfEffect)
- {
- bool isOnTheEffectedCell = newPlayerPosition.Row == effectedCell.Row && newPlayerPosition.Col == effectedCell.Col;
- bool newPlayerPositionIsNotValid = !Position.PositionIsValid(newPlayerPosition);
- if (isOnTheEffectedCell || newPlayerPositionIsNotValid)
- {
- canEscape = false;
- break;
- }
- }
- if (canEscape)
- {
- break;
- }
- }
- if (canEscape)
- {
- position = newPlayerPosition;
- }
- return canEscape;
- }
- public void TakeDamage()
- {
- activeSpells = activeSpells.OrderByDescending(n => n.Name).ToList();
- for (int currSpell = 0; currSpell < activeSpells.Count; currSpell++)
- {
- Spell spell = activeSpells[currSpell];
- this.health -= spell.Demage;
- spell.ReduceDuration();
- if (this.health <= 0)
- {
- this.isKilled = true;
- this.killerSpell = spell.Name;
- break;
- }
- if (!spell.InEffect)
- {
- activeSpells.Remove(activeSpells[currSpell]);
- currSpell--;
- }
- }
- }
- }
- public class Position
- {
- public static Position[] areaOfEffectOfASpell = new Position[]
- {
- new Position(-1, -1),
- new Position(-1, 0),
- new Position(-1, +1),
- new Position(0, +1),
- new Position(+1, +1),
- new Position(+1, 0),
- new Position(+1, -1),
- new Position(0, -1)
- };
- public static Position[] runawayPathsOfThePlayer = new Position[]
- {
- new Position(-1, 0), //up
- new Position(0, +1), //right
- new Position(+1, 0), //down
- new Position(0, -1) //left
- };
- private int row;
- private int col;
- public Position(int row, int col)
- {
- this.row = row;
- this.col = col;
- }
- public int Row
- {
- get { return this.row; }
- set { this.row = value; }
- }
- public int Col
- {
- get { return this.col; }
- set { this.col = value; }
- }
- public static bool PositionIsValid(Position toCheck)
- {
- bool isValid = true;
- if (toCheck.row < Chamber.minRows ||
- toCheck.row >= Chamber.maxRows ||
- toCheck.col < Chamber.minCols ||
- toCheck.col >= Chamber.maxCols)
- {
- isValid = false;
- }
- return isValid;
- }
- }
- public class Spell
- {
- private string name;
- private int duration;
- private int demage;
- private bool inEffect;
- private List<Position> areaOfEffect;
- public Spell(int duration, int demage, string name)
- {
- this.name = name;
- this.duration = duration;
- this.demage = demage;
- this.inEffect = true;
- this.areaOfEffect = new List<Position>();
- }
- public string Name
- {
- get { return this.name; }
- }
- public int Duration
- {
- get { return this.duration; }
- }
- public int Demage
- {
- get { return this.demage; }
- }
- public bool InEffect
- {
- get { return this.inEffect; }
- }
- public List<Position> AreaOfEffect
- {
- get { return this.areaOfEffect; }
- }
- public void ReduceDuration()
- {
- this.duration--;
- if (duration == 0)
- {
- this.inEffect = false;
- }
- }
- public void SetAreaOfEffect(Position targetCell)
- {
- if (Position.PositionIsValid(targetCell))
- {
- areaOfEffect.Add(targetCell);
- }
- foreach (Position neighbourPosition in Position.areaOfEffectOfASpell)
- {
- Position toAdd = new Position(targetCell.Row + neighbourPosition.Row, targetCell.Col + neighbourPosition.Col);
- if (Position.PositionIsValid(toAdd))
- {
- areaOfEffect.Add(toAdd);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement