here's my code:
public class DoomMain {
public static void main(String[] args)
{
DoomControl runner = new DoomControl( );
runner.doomRunner( );
}
}
import java.util.Random;
import java.util.Scanner;
import static java.lang.System.*;
public class DoomGame {
public void battleSequence()
{
DoomControl game = new DoomControl();
game.doomGameOutput();
}
}
//DoomControl is my brain for the whole program.
import static java.lang.System.*;
import java.util.Scanner;
import java.util.Random;
public class DoomControl {
private int health, inihealth, inimonsterhealth, monsterhealth, attack, iniattack, monsterattack, option,
randomattack, exp, experience, givehealth, level, nextlevel;
DoomInput input = new DoomInput();
DoomOutput output = new DoomOutput();
DoomGame doom = new DoomGame();
public DoomControl()
{
health = 10;
inihealth = 10;
monsterhealth = 0;
inimonsterhealth = 0;
attack = 5;
iniattack = 5;
monsterattack = 0;
experience = 0;
exp = 0;
givehealth = 0;
randomattack = 0;
level = 1;
}
//reads in the difficulty selected and gets ready to send out to Output
public void doomDiffReader()
{
input.doomDifficulty();
input.getDiffChoice();
out.println("You have chosen the difficulty level " + input.getDiffChoice() + ".");
switch (input.getDiffChoice())
{
case 1:
{
monsterhealth = 10;
inimonsterhealth = 10;
monsterattack = 2;
break;
}
case 2:
{
monsterhealth = 25;
inimonsterhealth = 25;
monsterattack = 6;
break;
}
case 3:
{
monsterhealth = 40;
inimonsterhealth = 40;
monsterattack = 10;
break;
}
}
out.println("The monster's health will start at " + monsterhealth + ".");
out.println("The monster's attack will start at " + monsterattack + ".");
}
//reads in the main battle and sends it to output from here
public void doomBattleReader()
{
Random generator = new Random();
input.doomBattle();
input.getBattleChoice();
while (input.getBattleChoice() == 2)
{
//you attack the monster
randomattack = generator.nextInt(2);
if(randomattack == 1)
{
monsterhealth = monsterhealth - attack;
}
//the monster attacks you
randomattack = generator.nextInt(2);
if(randomattack == 1)
{
health = health - monsterattack;
}
//if the monster dies, do this
if(monsterhealth <= 0)
{
out.println("You win the battle!");
out.println("You still have " + health + " health left.");
input.doomBattle();
input.getBattleChoice();
}
//if you die, game ends, end of line lolz
if(health <= 0)
{
out.println("You have died. Game Over. End of Line");
break;
}
}
}
public void doomGameOutput()
{
output.doomGameO();
}
//helps keep the whole game running unless you opt to quit
public void doomRunner()
{
out.println("What do you want to do?");
out.println("Go to the Store, Battle, or Quit? (1 = Store, 2 = Battle, 3 = Quit)");
Scanner scanner = new Scanner(in);
option = scanner.nextInt( );
while (option == 1 || option == 2)
{
//you go to the store(for now, nothing really happens)
if (option == 1)
{
out.println("Now what do you want to do?");
out.println("Go to the Store, Battle, or Quit? (1 = Store, 2 = Battle, 3 = Quit)");
option = scanner.nextInt( );
}
//the battle will commence if you press 2
if (option == 2)
{
doom.battleSequence();
//if the player dies in battle, whole game stops
if (health <= 0)
{
break;
}
out.println("Now what do you want to do?");
out.println("Go to the Store, Battle, or Quit? (1 = Store, 2 = Battle, 3 = Quit)");
option = scanner.nextInt( );
}
}
}
}
import static java.lang.System.*;
import java.util.Scanner;
public class DoomInput {
private int difficulty, battle;
//the next two methods cover selecting and returning the value for difficulty
public void doomDifficulty()
{
Scanner scanner = new Scanner(in);
out.println("Choose your difficulty: 1, 2, or 3");
difficulty = scanner.nextInt();
}
public int getDiffChoice()
{
return difficulty;
}
//these two methods cover selecting and returning the choice to battle
public void doomBattle()
{
Scanner scanner = new Scanner(in);
out.println("You must press 2 to battle.");
battle = scanner.nextInt();
}
public int getBattleChoice()
{
return battle;
}
//for monsters that will be added later
public void doomMonsters( )
{
}
}
import static java.lang.System.*;
public class DoomOutput {
//simply prints out everything from the input in DoomController
public void doomGameO()
{
DoomControl outtie = new DoomControl();
outtie.doomDiffReader();
outtie.doomBattleReader();
}
}
ok that's all of it now.
But yes, how can i keep health from going back to ten and staying what it was before exiting out of DoomControl's while loop for the main battle?

New Topic/Question
Reply



MultiQuote




|