/* * Course: SE1011-011 * Term: Fall 2013 * Assignment: Lab 7 * Author: Anonymous et al. */ import javax.swing.JOptionPane; public class Lab7_051_8_2 { public static void main(String[] args){ // Work in progress converting a sequential program to one that uses helper functions // The helper functions Lab7State051_8_2 state = new Lab7State051_8_2(); 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.playerAttacksEnemyAttacks(); } else{ //enemy defends state.playerAttacksEnemyDefends(); } 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.playerDefendsEnemyAttacks(); } else{ //enemy defends state.playerDefendsEnemyDefends(); } 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!"); } } // end main }