Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace RPG___Vddicted
  8. {
  9. /**********************************************
  10. * Script de Batalha *
  11. * Criado e desenvolvido por Jeferson Carvalho*
  12. * 01/04/2014 *
  13. * **** ATUALIZAR SCRIPT DE BATALHA *
  14. **********************************************/
  15.  
  16. class Battle
  17. {
  18. string userChoice;
  19. string monsterChoice;
  20.  
  21. int damage;
  22. int defese;
  23.  
  24. Random rand;
  25.  
  26. public Battle(Hero hero, Character monster)
  27. {
  28. Console.WriteLine("{0} Está enfrentando um {1}.", hero.Identifier, monster.Identifier);
  29. BattleLoop(hero, monster);
  30. }
  31.  
  32. public void BattleLoop(Hero hero, Character monster)
  33. {
  34. do
  35. {
  36. PrintStatus(hero, monster);//Mostra o status dos personagens da batalha.
  37. userChoice = PrintChoice();//Executa e recebe o valor retornado da decisão de ação
  38. Console.WriteLine();
  39. ProcessChoice(userChoice, hero, monster);//faz a checagem de escolha
  40. monster.isAlive = CheckHealth(monster.CurrentHealth);//checa se o monstro esta vivo
  41. hero.isAlive = CheckHealth(hero.CurrentHealth);//checa se o heroi esta vivo
  42. if (monster.isAlive == true)//se o monstro esta vivo, apos a ação do personagem o monstro toma uma ação
  43. {
  44. monsterChoice = monster.AI();//função de escolha do monstro é acionada
  45. ProcessChoice(monsterChoice, monster, hero);
  46. }
  47. if (monster.isAlive == false)//se o monstro foi morto, o heroi ganha Experiencia + Gold
  48. {
  49. hero.Gold++;
  50. hero.Leveling(500, hero);
  51. }
  52. Console.ReadLine();
  53. Console.Clear();
  54. }
  55. while (hero.isAlive == true && monster.isAlive == true);//enquanto o monstro e o heroi estao vivos a batalha continua
  56. }
  57.  
  58. void PrintStatus(Hero hero, Character monster)//Mostra o status dos personagens da batalha
  59. {
  60. Console.Clear();
  61. Console.Write(@"
  62. **********************************************
  63. HP/MaxHP MP/MaxMP
  64. {0}: {1}/{2}hp {3}/{4}mp
  65. {5}: {6}/{7}hp {8}/{9}mp
  66. **********************************************
  67. ", hero.Identifier, hero.CurrentHealth, hero.MaxHealth, hero.CurrentMagic, hero.MaxMagic,
  68. monster.Identifier, monster.CurrentHealth, monster.MaxHealth, monster.CurrentMagic, monster.MaxMagic);
  69. }
  70.  
  71. string PrintChoice()//retorna a escolha do player para a variavel
  72. {
  73. string choice;
  74. Console.WriteLine();
  75. Console.Write(@"
  76. ___________________________
  77. Por favor escolha uma ação:
  78. (A)tacar:
  79. (D)efender:
  80. (F)ugir:
  81. ___________________________");
  82. Console.WriteLine();
  83. choice = Console.ReadLine();
  84. return choice;
  85. }
  86.  
  87. void ProcessChoice(string choice, Character attacker, Character defender)//checa se a escolha é valida
  88. {
  89. switch (choice)
  90. {
  91. case "A":
  92. case "a":
  93. Console.WriteLine();
  94. Console.WriteLine("{0} Ataca!", attacker.Identifier);//se o Player escolher atacar, a função
  95. DealDamage(attacker, defender);//DealDamage é acionada
  96. defender.CurrentHealth -= damage;
  97. if (attacker.criticalHit == true)
  98. {
  99. Console.WriteLine("DANO CRITICO!! {0} Acerta o {1} por {2}hp de dano"
  100. , attacker.Identifier, defender.Identifier, damage);
  101. }else{
  102. Console.WriteLine("{0} Acerta o {1} por {2}hp de dano"
  103. , attacker.Identifier, defender.Identifier, damage);
  104. }
  105. break;
  106. case "D":
  107. case "d":
  108. Console.WriteLine();//Desenvolver DEFESA
  109. Console.WriteLine("{0} defende!", attacker.Identifier);
  110. break;
  111. case "F":
  112. case "f":
  113. Console.WriteLine();//Trabalhar a fuga
  114. Console.WriteLine("{0} foge!", attacker.Identifier);
  115. break;
  116. default:
  117. Console.WriteLine("Me desculpe eu nao entendi este comando!.");//enquanto a escolha não for valida o codigo é repetido
  118. Console.WriteLine();
  119. choice = PrintChoice();
  120. Console.WriteLine();
  121. ProcessChoice(choice, attacker, defender);
  122. break;
  123. }
  124. }
  125.  
  126. public static void CheckDefence(string choice, Character attacker) {
  127.  
  128. if (choice == "D" || choice == "d")
  129. {
  130. attacker.defeding = true;
  131. }
  132. else
  133. {
  134. attacker.defeding = false;
  135. }
  136.  
  137. }
  138.  
  139. /*
  140. *
  141. * Desenvolver Critical Hit
  142. * */
  143. int DealDamage(Character attacker, Character defender)//função que gera o valor do dano do atacante
  144. {
  145. int max;
  146. int min;
  147. int criticalChance;
  148.  
  149. rand = new Random();
  150. defese = defender.Def;
  151.  
  152. attacker.AttackDamage = (attacker.Str / 2) * attacker.Level;//ataque é = a Força do atacante dividida por 2 vezes o level do atacante
  153.  
  154. max = attacker.AttackDamage - defender.Defense;
  155. if (max <= 0)
  156. {
  157. max = 1;
  158. }
  159. min = (int)(attacker.AttackDamage * .8) - defender.Defense;
  160. if (min <= 0)
  161. {
  162. min = 1;
  163. }
  164. damage = rand.Next(min, max);
  165. if (attacker.criticalHit == true)
  166. {
  167. damage = (int)(damage * 1.5);
  168. }
  169. return damage;
  170. }
  171.  
  172. bool CheckHealth(int health)//checa se o player/monstro esta vivo
  173. {
  174. bool alive;
  175. if (health <= 0)
  176. {
  177. alive = false;
  178. }
  179. else
  180. {
  181. alive = true; ;
  182. }
  183. return alive;
  184. }
  185. }
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement