Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace WalkaTest
- {
- class Program
- {
- static void Main(string[] args)
- {
- int difficulty;
- PlayerTest character;
- character = PlayerTest.generatePlayer();
- while (character.lvl < 10 || character.hp == 0)
- {
- difficulty = chooseDifficulty();
- MonsterTest enemy;
- enemy= MonsterTest.generateRandomMonster(difficulty);
- Actor.fighting(character, enemy);
- }
- }
- public static int chooseDifficulty()
- {
- int difficulty;
- bool inputCheck = false;
- do
- {
- Console.WriteLine("Chose dificulty level from 1 to 9");
- inputCheck = Int32.TryParse(Console.ReadLine(), out difficulty);
- }
- while (inputCheck != true);
- if (difficulty < 1) difficulty = 1;
- if (difficulty > 9) difficulty = 9;
- return difficulty;
- }
- }
- }
- namespace WalkaTest
- {
- abstract class Actor
- {
- protected int maxHp = 0;
- protected int maxMp = 0;
- //[0-name/1-manaCost/ 2-DMG, id]
- protected string[,] magicArray = new string[3, 3] { { "Fire ball [1MP]", "Lightning [2MP]", "Healing Wave[2MP]" },
- { "1","2","2" },
- { "5","7","-8"} };
- Random random = new Random();
- public int hp { get; protected set; }
- public int criticalChance { get; protected set; }
- public int atack { get; protected set; }
- public int def { get; protected set; }
- public string Name { get; protected set; }
- public int speed { get; protected set; }
- public int mp { get; protected set; }
- public void hpChange(int amount)
- {
- hp -= amount;
- if (hp > maxHp) hp = maxHp;
- }
- public void mpChange(int amount)
- {
- mp -= amount;
- if (mp > maxMp) mp = maxMp;
- }
- public void attackTarget(Actor target)
- {
- int critHit = random.Next(1, 100);
- bool ifCritHit = false;
- int dmg = atack - target.def;
- if (critHit > (100 - criticalChance))
- {
- dmg *= 2;
- ifCritHit = true;
- }
- if (dmg <= 0) dmg = 1;
- target.hpChange(dmg);
- if (ifCritHit == true) Console.WriteLine("{0} hit critically {1} for {2} damage.", Name, target.Name, dmg);
- else Console.WriteLine("{0} hit {1} for {2} damage.", Name, target.Name, dmg);
- Console.WriteLine("{0} got {1} HP left.", target.Name, target.hp);
- if (target.hp <= 0)
- {
- giveExp((target.maxHp * 10) / maxHp);
- }
- }
- public virtual void giveExp(int amount) { }
- public static void showFightMenu(Actor a1, Actor a2)
- {
- int fightOption;
- bool inputCheck = false;
- do
- {
- Console.WriteLine();
- Console.WriteLine("1. Atack 2. Magic");
- inputCheck = Int32.TryParse(Console.ReadLine(), out fightOption);
- }
- while (inputCheck != true && fightOption >= 1 && fightOption <= 2);
- if (fightOption == 1)
- {
- a1.attackTarget(a2);
- }
- else if (fightOption == 2 && a1.mp > 0)
- {
- a1.useMagic(a2);
- }
- else
- {
- Console.WriteLine("Sorry you dont have any mana points left.");
- Console.WriteLine();
- a1.attackTarget(a2);
- }
- }
- public static void fighting(Actor a1, Actor a2)
- {
- while (a1.hp > 0 || a2.hp > 0)
- {
- if (a1.speed >= a2.speed)
- {
- showFightMenu(a1, a2);
- if (a2.hp <= 0) break;
- a2.attackTarget(a1);
- }
- else
- {
- a2.attackTarget(a1);
- if (a1.hp <= 0) break;
- showFightMenu(a1, a2);
- }
- }
- }
- public void useMagic(Actor target)
- {
- int chosenSpellID, spellManaCost, spellDmg, spellAtack;
- bool inputCheck = false;
- for (int i = 0; i < magicArray.GetLength(1); i++)
- {
- Console.WriteLine((i + 1) + ". " + magicArray[0, i]);
- }
- do
- {
- Console.WriteLine("Chose your spell: ");
- inputCheck = Int32.TryParse(Console.ReadLine(), out chosenSpellID);
- }
- while (inputCheck != true);
- spellManaCost = Convert.ToInt32(magicArray[1, chosenSpellID - 1]);
- spellAtack = Convert.ToInt32(magicArray[2, chosenSpellID - 1]);
- if (mp >= spellManaCost)
- {
- mpChange(spellManaCost);
- if (spellAtack >= 0)
- {
- spellDmg = target.def - spellAtack;
- if (spellDmg <= 0) spellDmg = 1;
- target.hp -= spellDmg;
- Console.WriteLine("You used {0} and hitted for {1}", magicArray[0, chosenSpellID - 1], spellDmg);
- Console.WriteLine("You got " + hp + "HP");
- Console.WriteLine("You got " + mp + "MP");
- Console.WriteLine("{0} got {1}HP left", target.Name, target.hp);
- }
- else
- {
- hpChange(spellAtack);
- Console.WriteLine("You healed for: " + (-1 * spellAtack));
- Console.WriteLine("You got " + hp + "HP");
- Console.WriteLine("You got " + mp + "MP");
- Console.WriteLine();
- }
- }
- }
- }
- class PlayerTest: Actor
- {
- public int exp = 0;
- public int[] expNeeded = new int[10] { 10, 30, 70, 110, 160, 220, 290, 370, 460, 560 };
- public int lvl = 1;
- public PlayerTest(int hp, int atack, int def, int speed, int criticalChance, int mp, string name = "Player")
- {
- this.hp = hp;
- this.atack = atack;
- this.def = def;
- this.Name = name;
- this.speed = speed;
- this.criticalChance = criticalChance;
- this.mp = mp;
- maxMp = mp;
- maxHp = hp;
- }
- public override void giveExp(int exp)
- {
- this.exp += exp;
- Console.WriteLine("You got: " + exp + "exp");
- if (this.exp >= expNeeded[lvl - 1])
- {
- this.lvl += this.exp / (10 * lvl);
- lvlingUp();
- }
- Console.WriteLine("You got: " + this.exp + "/" + expNeeded[lvl - 1]);
- }
- public void lvlingUp()
- {
- maxHp++;
- maxMp++;
- atack++;
- def++;
- speed++;
- criticalChance++;
- mpChange((maxMp - mp) * (-1));
- hpChange((maxHp - hp) * (-1));
- Console.WriteLine("You leveled up to: " + lvl + "lvl");
- }
- public static PlayerTest generatePlayer()
- {
- Console.WriteLine("Choose your name: ");
- string nick = Console.ReadLine();
- PlayerTest character = new PlayerTest(hp: 10, atack: 5, def: 5, speed: 5, criticalChance: 5, mp: 10, name: nick);
- return character;
- }
- }
- class MonsterTest: Actor
- {
- public MonsterTest(int hp, int atack, int def, int speed, int criticalChance, string name = "Monster")
- {
- this.hp = hp;
- this.atack = atack;
- this.def = def;
- this.Name = name;
- this.maxHp = hp;
- this.speed = speed;
- this.criticalChance = criticalChance;
- }
- public override void giveExp(int amount)
- {
- Console.WriteLine("You lost!");
- Console.ReadKey();
- Environment.Exit(1);
- }
- public static MonsterTest generateRandomMonster(int difficulty)
- {
- var random = new Random();
- int monsterHealth, monsterAtack, monsterDefense, monsterSpeed, monsterCritical;
- monsterAtack = random.Next(1, 5) * difficulty;
- monsterDefense = random.Next(1, 5) * difficulty;
- monsterHealth = random.Next(1, 5) * difficulty * 2;
- monsterSpeed = random.Next(1, 5) * difficulty;
- monsterCritical = random.Next(1, 5) * difficulty;
- MonsterTest enemy = new MonsterTest(monsterHealth, monsterAtack, monsterDefense, monsterSpeed, monsterCritical);
- return enemy;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement