Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Create a battle program with several methods
- *
- * @neomattlac
- * @version 2, 11/18/2010
- */
- import java.util.*;
- public class TextBasedBattle2
- {
- public void menu(){
- System.out.println();
- System.out.println("*** Menu ***");
- System.out.println("1: Basic attack.");
- System.out.println("-Uses 1 stamina. Inflicts between 1 and 10 damage.");
- System.out.println("---");
- System.out.println("2: Strong attack.");
- System.out.println("-Uses 5 stamina. Inflicts between 25 and 35 damage.");
- System.out.println("---");
- System.out.println("3: Magic attack.");
- System.out.println("-Uses 10 mana. Inflicts between 10 and 35 damage. Has 50% of skipping the monster's turn.");
- System.out.println("---");
- System.out.println("4: Combination attack.");
- System.out.println("-Uses 5 mana and 5 stamina. Inflicts between 30 and 50 damage");
- System.out.println("---");
- System.out.println("5: Heal");
- System.out.println("-Uses 5 mana. Recovers 10-40 health points.");
- System.out.println("---");
- System.out.println("6: Flee");
- System.out.println("-Uses 20 mana and 20 stamina. 33% chance of fleeing");
- System.out.println("---");
- System.out.println("Any other choice results in a forfeited turn");
- System.out.println();
- }
- public void attackCompute(int attackChoice, int monsterHealth, int selfHealth, int selfAttack, int mana, int stamina, int fleeChance);
- Scanner input = new Scanner(System.in);
- Random rgen = new Random();
- System.out.println("Choose your attack");
- System.out.println("--------------------");
- attackChoice=input.nextInt();
- //Take in the user's info and store it as attackChoice
- switch(attackChoice){
- case 1: stamina--;
- //Subtract 1 stamina
- selfAttack=rgen.nextInt(10)+1;
- //Generate a random number between 1 and 10 and store as selfAttack
- System.out.println("You attacked with a basic attack.");
- System.out.println("You dealt " + selfAttack + " damage");
- monsterHealth-=selfAttack;
- //Deal damage to monster
- System.out.println("The monster has " + monsterHealth + " health left.");
- break;
- case 2: stamina-=5;
- //Subtract one stamina
- selfAttack=rgen.nextInt(11)+25;
- //Generate a random number between 25 and 35 and store as selfAttack
- System.out.println("You attacked with a strong attack!");
- System.out.println("You dealt " + selfAttack + " damage");
- monsterHealth-=selfAttack;
- System.out.println("The monster has " + monsterHealth + " health left.");
- break;
- case 3: mana-=10;
- //Subtract 10 mana
- selfAttack=rgen.nextInt(26)+10;
- //Generate a random number between 10 and 35 and store as selfAttack
- System.out.println("You attacked with a magic attack!");
- System.out.println("You dealt " + selfAttack + " damage");
- monsterHealth-=selfAttack;
- System.out.println("The monster has " + monsterHealth + " health left.");
- skipChance=rgen.nextInt(2);
- break;
- case 4: mana-=5; stamina-=5;
- //Subtract 5 mana and 5 stamina
- selfAttack=rgen.nextInt(21)+31;
- //Generate a random number between 30 and 50 and store as selfAttack
- System.out.println("You attacked with a combination attack!");
- System.out.println("You dealt " + selfAttack + " damage");
- monsterHealth-=selfAttack;
- System.out.println("The monster has " + monsterHealth + " health left!");
- break;
- case 5: mana-=5;
- //Subtract 5 mana
- System.out.println("You chose to heal");
- selfHeal=rgen.nextInt(31)+11;
- //Generate a random number between 10 and 40 and store as selfHeal
- System.out.println("You recovered " + selfHeal + " health!");
- break;
- case 6:
- mana-=20; stamina-=20;
- //Subtract 20 mana and 20 stamina
- fleeChance=rgen.nextInt(3);
- //Generate a random number between 0 and 2 and store as fleeChance
- break;
- default: System.out.println("You forfeited your turn!"); break;
- }
- public void stats(int monsterHealth, int selfHealth, int mana, int stamina){
- Scanner input = new Scanner(System.in);
- Random rgen = new Random();
- while(monsterHealth>0||selfHealth>0){
- System.out.println("Stats: " + selfHealth + " health.");
- System.out.println(" " + stamina + "stamina.");
- System.out.println(" " + mana + "mana.");
- System.out.println("------------------");
- }
- }
- public static void main(String args[]){
- Scanner input = new Scanner(System.in);
- TextBasedBattle2 call = new TextBasedBattle2();
- int selfHealth=1000;
- int numBattle=0;
- string battleChoice;
- System.out.println("Would you like to battle");
- battleChoice=input.nextLine();
- if(battleChoice=="yes"||battleChoice=="Yes"&&selfHealth>0){
- int fleeChance=0;
- int attackChoice=0;
- int mana=100;
- int stamina=200;
- int selfHeal=0;
- int selfAttack=0;
- int monsterHeal=0;
- int monsterAttack=0;
- System.out.println("The battle begins!");
- System.out.println("*******************");
- call.Menu();
- call.AttackCompute(attackChoice, monsterHealth, selfHealth, selfAttack, mana, stamina, fleeChance);
- while(fleeChance!=2){
- call.Stats(monsterHealth, selfHealth, mana, stamina);
- if(skipChance!=0){
- monsterAttack=rgen.nextInt(101);
- System.out.println("The monster attacked for " + monsterAttack + " damage!");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement