Demo the program to the instructor during open lab.

Finish your game so that enemies move and attack the player and the player can attack the enemies.  Implement Enemies in an ArrayList.  The game should end when the player or all enemies are eliminated (HitPoints <= 0). Optionally implement items - e.g. gold, weapons, armor.  The code below should help you get started.

import java.util.*;
public class game
{
   public static void main (String[] args)
   {
      Scanner in = new Scanner(System.in);
      String Choice = "";

     
// creating the player will initialize the world
      Player Kirk = new Player("Kirk",'K',2,2);

     
// create an ArrayList of enemies and add add some
      ArrayList<Enemy> Enemies = new ArrayList<Enemy>();
      Enemies.add(new Enemy("Orc",12,2));

     
// create an ArrayList of items and add add some
      
      while (!Choice.equals("q") && Kirk.HP >= 0)
      {
         Kirk.PrintWorld();
         System.out.println("Enter your command: ");
         Choice = in.nextLine();

        
// player move
         if (Choice.equals("a"))
            Kirk.MoveLeft();
         if (Choice.equals("d"))
            Kirk.MoveRight();
         if (Choice.equals("w"))
            Kirk.MoveUp();
         if (Choice.equals("s"))
            Kirk.MoveDown();
 
        
// Step through Enemy ArrayList and attack if adjacent to player
         for (int i=0; i<Enemies.size(); i++)
         {
            if ((Enemies.get(i).Ypos == Kirk.Ypos && (Enemies.get(i).Xpos == Kirk.Xpos+1)) ||
// player is to the left
               (Enemies.get(i).Ypos == Kirk.Ypos && (Enemies.get(i).Xpos == Kirk.Xpos-1)) || 
// player is to the right
               (Enemies.get(i).Xpos == Kirk.Xpos && (Enemies.get(i).Ypos == Kirk.Ypos+1)) ||
 // player is above
               (Enemies.get(i).Xpos == Kirk.Xpos && (Enemies.get(i).Ypos == Kirk.Ypos-1)))   
// player is below
            {
               Enemies.get(i).HP -= Kirk.Attack;   
// Player attacks Enemy
               Kirk.HP -= Enemies.get(i).Attack;   
// Enemy attacks Player
               if (Enemies.get(i).HP <= 0)   
// Enemy dies   
               {
                  Kirk.World[Enemies.get(i).Xpos][Enemies.get(i).Ypos] = ' ';
                  Enemies.remove(i);
               }
            }
         }

        
// Insert the code to step through Item ArrayList and pick up item if adjacent to player
         // Start with the code above for stepping through Enemy Arraylist and modify

         // Step through Enemy ArrayList and move towards the player
        
for (int i=0; i<Enemies.size(); i++)
         {
            if (Enemies.get(i).Xpos > Player.Xpos)
               Enemies.get(i).MoveLeft();
            else
               Enemies.get(i).MoveRight();
            if (Enemies.get(i).Ypos > Player.Ypos)
               Enemies.get(i).MoveUp();
            else
               Enemies.get(i).MoveDown();
         }
      }
   }
}