/* * Author: Brett Peavler et al. * Week 8, Day 1 * SE1011-021 * * This program relies on the Die class, which you wrote for Lab7. * See http://msoe.us/taylor/se1011/Lab7 for the UML diagram and specification. */ import javax.swing.JOptionPane; public class Lab7_021_8_1 { public static void main(String[] args){ GameState021_8_1 state = new GameState021_8_1(); JOptionPane.showMessageDialog(null, "Welcome to Shootout, press OK to begin."); JOptionPane.showMessageDialog(null, "RULES:\n" + "Attacking allows for a greater chance to damage the enemy\n" + "(successful hit with attack does 3 additional damage, unsuccessful hit takes 2 additional damage)\n" + "Defending allows for a chance to defend yourself\n" + "(successful hit with defend while opponent is in attack mode does 0 additional damage)\n" + "(unsuccessful defend negates 2 damage from attacker)\n" + "At the end of the turn the entity with the higher roll wins and damage values are added\n" + "Ex: Player defends and gets higher roll, Comp attacks and has lower roll\n" + "-Result---> Player gives 0 damage to Comp for defending + 2 damage for the Comp attacking\n" + "If both are defending the one with the higher roll will do one damage to the other\n" + "If both are attacking and the number is equal, both take 1 damage\n" + "If both are defending and the number is equal, neither take damage\n" + "If one is defending and the number is equal, the attacker takes 1 damage"); while(state.enemy>=1&&state.health>=1){ /* * Attacking allows for a greater chance to damage the enemy * (successful hit with attack does 3 additional damage, unsuccessful hit takes 2 additional damage) * Defending allows for a chance to defend yourself * (successful hit with defend while the opponent is in attack mode does 0 additional damage) * (unsuccessful defend negates 2 damage from attacker) * At the end of the turn the entity with the higher roll wins and damage values are added * Ex: Player defends and gets higher roll, Comp attacks and has lower roll * -Result---> Player gives 0 damage to Comp for defending + 2 damage for the Comp attacking * If both are defending the one with the higher roll will do one damage to the other * If both are attacking and the number is equal, both take 1 damage * If both are defending and the number is equal, neither take damage * If one is defending and the number is equal, the attacker takes 1 damage */ state.input=JOptionPane.showInputDialog(null, "Enter 1 for attack, 2 for defense."); if(Integer.parseInt(state.input)==1){ //player attacks if(state.enemyAI.roll()==1){ //enemy attacks state.enemyAttacksYouAttack(); } else{ //enemy defends state.enemyDefendsYouAttack(); } if(state.enemy<0) state.enemy=0; if(state.health<0) state.health=0; JOptionPane.showMessageDialog(null, "You have " + state.health + " health left and\n" + "the enemy has " + state.enemy + " health left."); } else if(Integer.parseInt(state.input)==2){ //player defends if(state.enemyAI.roll()==1){ //enemy attacks state.enemyAttacksYouDefend(); } else{ //enemy defends state.enemyDefendsYouDefend(); } if(state.enemy<0) state.enemy=0; if(state.health<0) state.health=0; JOptionPane.showMessageDialog(null, "You have " + state.health + " health left and\n" + "the enemy has " + state.enemy + " health left."); } else{ //invalid entry JOptionPane.showMessageDialog(null, "Please input a valid entry!"); } } if(state.enemy<=0&&state.health>0){ //player wins JOptionPane.showMessageDialog(null, "You win!"); } else if(state.enemy>0&&state.health<=0){ //enemy wins JOptionPane.showMessageDialog(null, "You lose!"); } else{ //draw (enemy<=0&&health<=0) JOptionPane.showMessageDialog(null, "It's a draw!"); } } }