Friday, 1 March 2013

Battle System

I have finally after a few weeks of testing and iteration come out with a working battle system for the project.

if(UserInput.equals("BATTLE")){
  
     System.out.println(MonMap[x][y].name + " Attacks for " + MonMap[x][y].damage);
     System.out.println("You now have" + PHealth);
   
   Boolean EnemyDefeated = false;
   System.out.print("You are now battling " + MonMap[x][y].name);
   System.out.print("What would you like to do?");
  
   while(EnemyDefeated ==  false){
   UserInput = input.nextLine();
   UserInput = UserInput.toUpperCase();
    if(UserInput.equals("ATTACK")){
     MonMap[x][y].hp = MonMap[x][y].hp - PDam;
     System.out.println("You attack the monster for " + PDam + " points of damage");
     System.out.println();
      if(MonMap[x][y].hp <= 0){
      Map[x][y].RmClr = true;
      EnemyDefeated = true;
      PScore = PScore + 10;
      System.out.print("The enemy has been defeated");
       if(PScore >= 250){
        System.out.println("You have completed the game, well done");
        System.exit(0);
       }
      }
    }
   
    if (UserInput.equals("KILL")){
     MonMap[x][y].hp = 0;
     Map[x][y].RmClr = true;
    }
    if(UserInput.equals("RUN")){
     System.out.print("In which direction would you like to run?");
     UserInput = input.nextLine();
     UserInput = UserInput.toUpperCase();
      if(UserInput.equals("NORTH")){
       y = y + 1;
       EnemyDefeated = true;
      }
      if(UserInput.equals("SOUTH")){
       y = y - 1;
       EnemyDefeated = true;
      }
      if(UserInput.equals("EAST")){
       x= x + 1;
       EnemyDefeated = true;
      }
     
      if(UserInput.equals("WEST")){
       x = x - 1;
       EnemyDefeated = true;
      }
    }
   
     PHealth = PHealth - MonMap[x][y].damage;
      if(PHealth <=0){
       System.out.println("I am afraid you have died, please try again.");
       System.out.println("The game will now return to the beggining");
       for(int i=0;i<=4;i++){
        Map[i][1].RmClr = false;
        Map[i][2].RmClr = false;
        Map[i][3].RmClr = false;
        Map[i][4].RmClr = false;
        PScore = 0;
        x=0;
        y=0;
       }
      }   
}
}

No comments:

Post a Comment