Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace RPG___Vddicted
- {
- /**********************************************
- * Script de Batalha *
- * Criado e desenvolvido por Jeferson Carvalho*
- * 01/04/2014 *
- * **** ATUALIZAR SCRIPT DE BATALHA *
- **********************************************/
- class Battle
- {
- string userChoice;
- string monsterChoice;
- int damage;
- int defese;
- Random rand;
- public Battle(Hero hero, Character monster)
- {
- Console.WriteLine("{0} Está enfrentando um {1}.", hero.Identifier, monster.Identifier);
- BattleLoop(hero, monster);
- }
- public void BattleLoop(Hero hero, Character monster)
- {
- do
- {
- PrintStatus(hero, monster);//Mostra o status dos personagens da batalha.
- userChoice = PrintChoice();//Executa e recebe o valor retornado da decisão de ação
- Console.WriteLine();
- ProcessChoice(userChoice, hero, monster);//faz a checagem de escolha
- monster.isAlive = CheckHealth(monster.CurrentHealth);//checa se o monstro esta vivo
- hero.isAlive = CheckHealth(hero.CurrentHealth);//checa se o heroi esta vivo
- if (monster.isAlive == true)//se o monstro esta vivo, apos a ação do personagem o monstro toma uma ação
- {
- monsterChoice = monster.AI();//função de escolha do monstro é acionada
- ProcessChoice(monsterChoice, monster, hero);
- }
- if (monster.isAlive == false)//se o monstro foi morto, o heroi ganha Experiencia + Gold
- {
- hero.Gold++;
- hero.Leveling(500, hero);
- }
- Console.ReadLine();
- Console.Clear();
- }
- while (hero.isAlive == true && monster.isAlive == true);//enquanto o monstro e o heroi estao vivos a batalha continua
- }
- void PrintStatus(Hero hero, Character monster)//Mostra o status dos personagens da batalha
- {
- Console.Clear();
- Console.Write(@"
- **********************************************
- HP/MaxHP MP/MaxMP
- {0}: {1}/{2}hp {3}/{4}mp
- {5}: {6}/{7}hp {8}/{9}mp
- **********************************************
- ", hero.Identifier, hero.CurrentHealth, hero.MaxHealth, hero.CurrentMagic, hero.MaxMagic,
- monster.Identifier, monster.CurrentHealth, monster.MaxHealth, monster.CurrentMagic, monster.MaxMagic);
- }
- string PrintChoice()//retorna a escolha do player para a variavel
- {
- string choice;
- Console.WriteLine();
- Console.Write(@"
- ___________________________
- Por favor escolha uma ação:
- (A)tacar:
- (D)efender:
- (F)ugir:
- ___________________________");
- Console.WriteLine();
- choice = Console.ReadLine();
- return choice;
- }
- void ProcessChoice(string choice, Character attacker, Character defender)//checa se a escolha é valida
- {
- switch (choice)
- {
- case "A":
- case "a":
- Console.WriteLine();
- Console.WriteLine("{0} Ataca!", attacker.Identifier);//se o Player escolher atacar, a função
- DealDamage(attacker, defender);//DealDamage é acionada
- defender.CurrentHealth -= damage;
- if (attacker.criticalHit == true)
- {
- Console.WriteLine("DANO CRITICO!! {0} Acerta o {1} por {2}hp de dano"
- , attacker.Identifier, defender.Identifier, damage);
- }else{
- Console.WriteLine("{0} Acerta o {1} por {2}hp de dano"
- , attacker.Identifier, defender.Identifier, damage);
- }
- break;
- case "D":
- case "d":
- Console.WriteLine();//Desenvolver DEFESA
- Console.WriteLine("{0} defende!", attacker.Identifier);
- break;
- case "F":
- case "f":
- Console.WriteLine();//Trabalhar a fuga
- Console.WriteLine("{0} foge!", attacker.Identifier);
- break;
- default:
- Console.WriteLine("Me desculpe eu nao entendi este comando!.");//enquanto a escolha não for valida o codigo é repetido
- Console.WriteLine();
- choice = PrintChoice();
- Console.WriteLine();
- ProcessChoice(choice, attacker, defender);
- break;
- }
- }
- public static void CheckDefence(string choice, Character attacker) {
- if (choice == "D" || choice == "d")
- {
- attacker.defeding = true;
- }
- else
- {
- attacker.defeding = false;
- }
- }
- /*
- *
- * Desenvolver Critical Hit
- * */
- int DealDamage(Character attacker, Character defender)//função que gera o valor do dano do atacante
- {
- int max;
- int min;
- int criticalChance;
- rand = new Random();
- defese = defender.Def;
- attacker.AttackDamage = (attacker.Str / 2) * attacker.Level;//ataque é = a Força do atacante dividida por 2 vezes o level do atacante
- max = attacker.AttackDamage - defender.Defense;
- if (max <= 0)
- {
- max = 1;
- }
- min = (int)(attacker.AttackDamage * .8) - defender.Defense;
- if (min <= 0)
- {
- min = 1;
- }
- damage = rand.Next(min, max);
- if (attacker.criticalHit == true)
- {
- damage = (int)(damage * 1.5);
- }
- return damage;
- }
- bool CheckHealth(int health)//checa se o player/monstro esta vivo
- {
- bool alive;
- if (health <= 0)
- {
- alive = false;
- }
- else
- {
- alive = true; ;
- }
- return alive;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement