Advertisement
Arui

TBFS#2

Jul 23rd, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.20 KB | None | 0 0
  1. namespace WalkaTest
  2. {
  3. class Program
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.         int difficulty;
  8.         PlayerTest character;
  9.  
  10.         character = PlayerTest.generatePlayer();
  11.         while (character.lvl < 10 || character.hp == 0)
  12.         {
  13.  
  14.             difficulty = chooseDifficulty();
  15.             MonsterTest enemy;
  16.             enemy= MonsterTest.generateRandomMonster(difficulty);
  17.             Actor.fighting(character, enemy);
  18.         }
  19.     }
  20.  
  21.     public static int chooseDifficulty()
  22.     {
  23.         int difficulty;
  24.         bool inputCheck = false;
  25.  
  26.         do
  27.         {
  28.             Console.WriteLine("Chose dificulty level from 1 to 9");
  29.             inputCheck = Int32.TryParse(Console.ReadLine(), out difficulty);
  30.         }
  31.         while (inputCheck != true);
  32.         if (difficulty < 1) difficulty = 1;
  33.         if (difficulty > 9) difficulty = 9;
  34.  
  35.         return difficulty;
  36.  
  37.     }
  38.  
  39. }
  40.  
  41. }
  42.  
  43. namespace WalkaTest
  44. {
  45.  
  46. abstract class Actor
  47. {
  48.     protected int maxHp = 0;
  49.     protected int maxMp = 0;
  50.  
  51.     //[0-name/1-manaCost/ 2-DMG, id]              
  52.     protected string[,] magicArray = new string[3, 3] { { "Fire ball [1MP]", "Lightning [2MP]", "Healing Wave[2MP]" },
  53.                                                                            { "1","2","2" },
  54.                                                                            { "5","7","-8"} };
  55.  
  56.     Random random = new Random();
  57.     public int hp { get; protected set; }
  58.  
  59.     public int criticalChance { get; protected set; }
  60.  
  61.     public int atack { get; protected set; }
  62.  
  63.     public int def { get; protected set; }
  64.  
  65.     public string Name { get; protected set; }
  66.  
  67.     public int speed { get; protected set; }
  68.  
  69.     public int mp { get; protected set; }
  70.  
  71.     public void hpChange(int amount)
  72.     {
  73.         hp -= amount;
  74.         if (hp > maxHp) hp = maxHp;
  75.     }
  76.  
  77.     public void mpChange(int amount)
  78.     {
  79.         mp -= amount;
  80.         if (mp > maxMp) mp = maxMp;
  81.     }
  82.  
  83.     public void attackTarget(Actor target)
  84.     {
  85.         int critHit = random.Next(1, 100);
  86.         bool ifCritHit = false;
  87.  
  88.  
  89.         int dmg = atack - target.def;
  90.         if (critHit > (100 - criticalChance))
  91.         {
  92.             dmg *= 2;
  93.             ifCritHit = true;
  94.         }
  95.         if (dmg <= 0) dmg = 1;
  96.         target.hpChange(dmg);
  97.         if (ifCritHit == true) Console.WriteLine("{0} hit critically {1} for {2} damage.", Name, target.Name, dmg);
  98.         else Console.WriteLine("{0} hit {1} for {2} damage.", Name, target.Name, dmg);
  99.         Console.WriteLine("{0} got {1} HP left.", target.Name, target.hp);
  100.         if (target.hp <= 0)
  101.         {
  102.             giveExp((target.maxHp * 10) / maxHp);
  103.         }
  104.     }
  105.     public virtual void giveExp(int amount) { }
  106.  
  107.     public static void showFightMenu(Actor a1, Actor a2)
  108.     {
  109.         int fightOption;
  110.         bool inputCheck = false;
  111.  
  112.         do
  113.         {
  114.             Console.WriteLine();
  115.             Console.WriteLine("1. Atack 2. Magic");
  116.             inputCheck = Int32.TryParse(Console.ReadLine(), out fightOption);
  117.         }
  118.         while (inputCheck != true && fightOption >= 1 && fightOption <= 2);
  119.         if (fightOption == 1)
  120.         {
  121.             a1.attackTarget(a2);
  122.         }
  123.         else if (fightOption == 2 && a1.mp > 0)
  124.         {
  125.             a1.useMagic(a2);
  126.         }
  127.         else
  128.         {
  129.             Console.WriteLine("Sorry you dont have any mana points left.");
  130.             Console.WriteLine();
  131.             a1.attackTarget(a2);
  132.  
  133.         }
  134.     }
  135.     public static void fighting(Actor a1, Actor a2)
  136.     {
  137.  
  138.         while (a1.hp > 0 || a2.hp > 0)
  139.         {
  140.             if (a1.speed >= a2.speed)
  141.             {
  142.                 showFightMenu(a1, a2);
  143.                 if (a2.hp <= 0) break;
  144.                 a2.attackTarget(a1);
  145.             }
  146.             else
  147.             {
  148.                 a2.attackTarget(a1);
  149.                 if (a1.hp <= 0) break;
  150.                 showFightMenu(a1, a2);
  151.             }
  152.         }
  153.     }
  154.  
  155.  
  156.     public void useMagic(Actor target)
  157.     {
  158.         int chosenSpellID, spellManaCost, spellDmg, spellAtack;
  159.         bool inputCheck = false;
  160.  
  161.         for (int i = 0; i < magicArray.GetLength(1); i++)
  162.         {
  163.             Console.WriteLine((i + 1) + ". " + magicArray[0, i]);
  164.         }
  165.         do
  166.         {
  167.             Console.WriteLine("Chose your spell: ");
  168.             inputCheck = Int32.TryParse(Console.ReadLine(), out chosenSpellID);
  169.         }
  170.         while (inputCheck != true);
  171.  
  172.         spellManaCost = Convert.ToInt32(magicArray[1, chosenSpellID - 1]);
  173.         spellAtack = Convert.ToInt32(magicArray[2, chosenSpellID - 1]);
  174.         if (mp >= spellManaCost)
  175.         {
  176.             mpChange(spellManaCost);
  177.             if (spellAtack >= 0)
  178.             {
  179.                 spellDmg = target.def - spellAtack;
  180.                 if (spellDmg <= 0) spellDmg = 1;
  181.                 target.hp -= spellDmg;
  182.                 Console.WriteLine("You used {0} and hitted for {1}", magicArray[0, chosenSpellID - 1], spellDmg);
  183.                 Console.WriteLine("You got " + hp + "HP");
  184.                 Console.WriteLine("You got " + mp + "MP");
  185.                 Console.WriteLine("{0} got {1}HP left", target.Name, target.hp);
  186.             }
  187.             else
  188.             {
  189.                 hpChange(spellAtack);
  190.                 Console.WriteLine("You healed for: " + (-1 * spellAtack));
  191.                 Console.WriteLine("You got " + hp + "HP");
  192.                 Console.WriteLine("You got " + mp + "MP");
  193.                 Console.WriteLine();
  194.  
  195.             }
  196.         }
  197.  
  198.     }
  199.  
  200. }
  201.  
  202. class PlayerTest: Actor
  203. {
  204.     public int exp = 0;
  205.     public int[] expNeeded = new int[10] { 10, 30, 70, 110, 160, 220, 290, 370, 460, 560 };
  206.  
  207.     public int lvl = 1;
  208.  
  209.     public PlayerTest(int hp, int atack, int def, int speed, int criticalChance, int mp, string name = "Player")
  210.     {
  211.         this.hp = hp;
  212.         this.atack = atack;
  213.         this.def = def;
  214.         this.Name = name;
  215.         this.speed = speed;
  216.         this.criticalChance = criticalChance;
  217.         this.mp = mp;
  218.         maxMp = mp;
  219.         maxHp = hp;
  220.     }
  221.  
  222.     public override void giveExp(int exp)
  223.     {
  224.         this.exp += exp;
  225.         Console.WriteLine("You got: " + exp + "exp");
  226.         if (this.exp >= expNeeded[lvl - 1])
  227.         {
  228.             this.lvl += this.exp / (10 * lvl);
  229.             lvlingUp();
  230.           }
  231.         Console.WriteLine("You got: " + this.exp + "/" + expNeeded[lvl - 1]);
  232.     }
  233.  
  234.     public void lvlingUp()
  235.     {
  236.         maxHp++;
  237.         maxMp++;
  238.         atack++;
  239.         def++;
  240.         speed++;
  241.         criticalChance++;
  242.         mpChange((maxMp - mp) * (-1));
  243.         hpChange((maxHp - hp) * (-1));
  244.         Console.WriteLine("You leveled up to: " + lvl + "lvl");
  245.  
  246.     }
  247.     public static PlayerTest generatePlayer()
  248.     {
  249.         Console.WriteLine("Choose your name: ");
  250.         string nick = Console.ReadLine();
  251.  
  252.         PlayerTest character = new PlayerTest(hp: 10, atack: 5, def: 5, speed: 5, criticalChance: 5, mp: 10, name: nick);
  253.         return character;
  254.     }
  255. }
  256.  
  257. class MonsterTest: Actor
  258. {
  259.     public MonsterTest(int hp, int atack, int def, int speed, int criticalChance, string name = "Monster")
  260.     {
  261.         this.hp = hp;
  262.         this.atack = atack;
  263.         this.def = def;
  264.         this.Name = name;
  265.         this.maxHp = hp;
  266.         this.speed = speed;
  267.         this.criticalChance = criticalChance;
  268.     }
  269.  
  270.     public override void giveExp(int amount)
  271.     {
  272.         Console.WriteLine("You lost!");
  273.         Console.ReadKey();
  274.         Environment.Exit(1);
  275.     }
  276.  
  277.     public static MonsterTest generateRandomMonster(int difficulty)
  278.     {
  279.         var random = new Random();
  280.         int monsterHealth, monsterAtack, monsterDefense, monsterSpeed, monsterCritical;
  281.  
  282.         monsterAtack = random.Next(1, 5) * difficulty;
  283.         monsterDefense = random.Next(1, 5) * difficulty;
  284.         monsterHealth = random.Next(1, 5) * difficulty * 2;
  285.         monsterSpeed = random.Next(1, 5) * difficulty;
  286.         monsterCritical = random.Next(1, 5) * difficulty;
  287.         MonsterTest enemy = new MonsterTest(monsterHealth, monsterAtack, monsterDefense, monsterSpeed, monsterCritical);
  288.  
  289.         return enemy;
  290.  
  291.     }
  292. }
  293. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement