Oleo

FighterGame

Jan 24th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.38 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Scanner;
  3.  
  4. public class FightGame {
  5.     public static void main(String[] args) {
  6.         healthReset();
  7.     }
  8.  
  9.     public static void healthReset() {
  10.         int hpu = 100;
  11.         int hpo = 100;
  12.         yourTurn(hpu, hpo);
  13.     }
  14.  
  15.     public static void yourTurn(int hpu, int hpo) {
  16.         // define starting stats
  17.         Scanner scanner = new Scanner(System.in);
  18.         Random rand = new Random();
  19.         Fighter You = new Fighter();
  20.         Fighter Opponent = new Fighter();
  21.         System.out.println("Choose your fighter!");
  22.         System.out.println("1 for Red, 2 for Blue, 3 for Green, 4 for Yellow, 5 for Purple, 6 for Orange, 7 for Pink, 8 for Black, 9 for Random, 0 for RandomStats");
  23.         int fighterChoice = scanner.nextInt();
  24.         if (fighterChoice == 0)
  25.         {
  26.         fighterChoice = rand.nextInt(8) + 1;
  27.         }
  28.         switch (fighterChoice) {
  29.         // attack, heal, defense, hp       
  30.             case 1: You.setStats(15, 3, 5, 110);
  31.             case 2: You.setStats(8, 7, 7, 120);
  32.             case 3: You.setStats(10, 10, 2, 125);
  33.             case 4: You.setStats(40, 5, 5, 80);
  34.             case 5: You.setStats(20, 1, 20, 150);
  35.             case 6: You.setStats(11, 4, 4, 180);
  36.             case 7: You.setStats(5, 25, 10, 115);
  37.             case 8: You.setStats(50, 0, 0, 100);
  38.             case 9: You.setStats(rand.nextInt(30)+1 , rand.nextInt(30)+1, rand.nextInt(30)+1, rand.nextInt(200)+50);
  39.         }
  40.            
  41.  
  42.         int adu = 10;
  43.         int ado = 10;
  44.         int heu = 5;
  45.         int heo = 5;
  46.         int deu = 9;
  47.         int deo = 9;
  48.         int actionu;
  49.         while (hpu > 0 || hpo >= 0) {
  50.             System.out.println("1 to Attack, 0 to Heal, 2 to Defend, 3 for Info");
  51.             System.out.println(hpu + " " + hpo);
  52.             // WinLose conditions start
  53.             if (hpu > 0 & hpo <= 0) {
  54.                 System.out.println("You Win!");
  55.                 playAgain();
  56.             }
  57.             if (hpo > 0 & hpu <= 0) {
  58.                 System.out.println("You Lose!");
  59.                 playAgain();
  60.             }
  61.             if (hpo <= 0 & hpu <= 0) {
  62.                 System.out.println("You Tied!?! How did you do that?");
  63.                 playAgain();
  64.             }
  65.             // WinLose conditions end
  66.             Random rand = new Random();
  67.             int actiono = rand.nextInt(3);
  68.             // Your action start  
  69.             actionu = scanner.nextInt();
  70.             switch (actionu) {
  71.             case 3:
  72.                 System.out.println("1-Attack: Deal damage equal to your attack stat to your opponent.");
  73.                 System.out.println("0-Heal: Recover HP equal to your heal stat");
  74.                 System.out.println("2-Defend: Only take damage equal to your opponents attack minus your defense if they attack. Reflects excess blocked damage.");
  75.                 System.out.println("3-Info: Display these help lines.");
  76.                 System.out.println("Any other input will skip your turn.");
  77.                 yourTurn(hpu, hpo);
  78.             case 1:
  79.                 System.out.println("You Attack");
  80.                 switch (actiono) {
  81.                 case 2:
  82.                     if (adu >= deo)
  83.                     {
  84.                     hpo -= adu - deo;
  85.                     }
  86.                     else {
  87.                     hpu -= deo - adu;
  88.                     }
  89.                 System.out.println("Opponent Defends");
  90.                 yourTurn(hpu, hpo);
  91.                 default:
  92.                     break;
  93.                 }
  94.                 hpo -= adu;
  95.                 opponentTurn(hpu, hpo, actionu, actiono);
  96.             case 0:
  97.                 System.out.println("You Heal");
  98.                 hpu += heu;
  99.                 opponentTurn(hpu, hpo, actionu, actiono);
  100.             case 2:
  101.                 defend(adu, ado, hpu, hpo, deu, deo, heu, heo, actionu, actiono);
  102.             default:
  103.                 System.out.println("Invalid Action");
  104.                 opponentTurn(hpu, hpo, actionu, actiono);
  105.                 // Your action end
  106.             }
  107.         }
  108.     }
  109.  
  110.     public static void opponentTurn(int hpu, int hpo, int actionu, int actiono) {
  111.         int adu = 10;
  112.         int ado = 10;
  113.         int heu = 5;
  114.         int heo = 5;
  115.         int deu = 9;
  116.         int deo = 9;
  117.         switch (actiono) {
  118.         case 1:
  119.             System.out.println("Opponent Attacks");
  120.             hpu -= ado;
  121.             yourTurn(hpu, hpo);
  122.         case 0:
  123.             System.out.println("Opponent Heals");
  124.             hpo += heo;
  125.             yourTurn(hpu, hpo);
  126.         case 2:
  127.             defend(ado, adu, hpu, hpo, deu, deo, heu, heo, actionu, actiono);
  128.         default:
  129.             System.out.println("At Default, Invalid Action");
  130.             yourTurn(hpu, hpo);
  131.         }
  132.     }
  133.  
  134.     public static void defend(int ado, int adu, int hpu, int hpo, int deu, int deo, int heu, int heo, int actionu, int actiono) {
  135.         switch (actiono) {
  136.         case 1:
  137.             System.out.println("You Defend");
  138.             System.out.println("Opponent Attacks");
  139.             if (adu >= deo)
  140.             {
  141.             hpo -= adu - deo;
  142.             }
  143.             else {
  144.             hpu -= deo - adu;
  145.             }
  146.             yourTurn(hpu, hpo);
  147.         case 0:
  148.             System.out.println("You Defend");
  149.             System.out.println("Opponent Heals");
  150.             hpo += heo;
  151.             yourTurn(hpu, hpo);
  152.         case 2:
  153.             switch (actionu) {
  154.             case 2:
  155.                 System.out.println("You Defend");
  156.                 System.out.println("Opponent Defends");
  157.                 yourTurn(hpu, hpo);
  158.             default:
  159.                 System.out.println("Opponent Defends");
  160.                 yourTurn(hpu, hpo);
  161.             }
  162.         default:
  163.             System.out.println("At Default, Invalid Action");
  164.             yourTurn(hpu, hpo);
  165.         }
  166.         switch (actionu) {
  167.         case 0:
  168.             System.out.println("You Heal");
  169.             System.out.println("Opponent Defends");
  170.             hpu += heu;
  171.             yourTurn(hpu, hpo);
  172.         case 2:
  173.             switch (actiono) {
  174.             case 2:
  175.                 System.out.println("You Defend");
  176.                 System.out.println("Opponent Defends");
  177.                 yourTurn(hpu, hpo);
  178.             default:
  179.             }
  180.         default:
  181.             System.out.println("At Default, Invalid Action");
  182.             yourTurn(hpu, hpo);
  183.         }
  184.     }
  185.  
  186.     public static void playAgain() {
  187.         System.out.println("Would you like to play again?");
  188.         System.out.println("1 to play again, 0 to quit");
  189.         Scanner scanner = new Scanner(System.in);
  190.         int playagain = scanner.nextInt();
  191.         switch (playagain) {
  192.         case 1:
  193.             healthReset();
  194.         case 0:
  195.             System.exit(0);
  196.         default:
  197.             playAgain();
  198.  
  199.         }
  200.     }
  201.  
  202. }
  203. /////////////////////////////////////////nextcode
  204.  
  205. public class Fighter
  206. {
  207.     private int attackDamage;
  208.     private int healAmount;
  209.     private int defenseStrength;
  210.     private int startingHealth;
  211.  
  212.  
  213. public void setStats(int adf, int haf, int dsf, int shf)
  214. {
  215.     attackDamage = adf;
  216.     healAmount = haf;
  217.     defenseStrength = dsf;
  218.     startingHealth = shf;
  219. }
  220.  
  221. public int getAttackDamage()
  222. {
  223.     return attackDamage;
  224. }
  225.  
  226. public int getHealAmount()
  227. {
  228.     return healAmount;
  229. }
  230.  
  231. public int getDefenseStrength()
  232. {
  233.     return defenseStrength;
  234. }
  235.  
  236. public int getStartingHealth()
  237. {
  238.     return startingHealth;
  239. }
  240. }
Advertisement
Add Comment
Please, Sign In to add comment