Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

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 Enemies = new ArrayList();

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

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

}

}

// 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

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();

}

}

}

}

previous question was below and above question is added later in hw

Create an Enemy class, Player class, and GameObject class for your game.java. The Enemy and Player (sub) classes should inherit from the GameObject (super) class. Create a player and a few enemies. Create the basic movements (left/right/up/down) for the player. Develop a menu in the main program that allows the player to move around.

image text in transcribedimage text in transcribedimage text in transcribed he main program will be rather simple since most everything is handled in the classes. 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'); // create some enemies here in random locations while (!Choice.equals("q")) { Kirk.PrintWorld(); System.out.println("Enter your command: "); Choice = in.nextLine(); if (Choice.equals("a")) Kirk.MoveLeft(); if (Choice.equals("d")) Kirk.MoveRight(); if (Choice.equals("w")) Kirk.MoveUp(); if (Choice.equals("s")) Kirk.MoveDown(); } } }

GameObject SuperClass Description Variables static char World[] [ ] = new char [41] [21] ; This is the character array that will store what is at each X,Y location. It is static so there is int Xpo3, Ypos char Avatar Methods PrintWorld() only one World for all objects X,Y location of the game object. The top left of the screen will be 1,1 The character that will be displayed on the screen Description This will print the World to the screen. Example code for (int y=1; y?=20; y++) for {int x=1; x

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Knowledge Discovery In Databases

Authors: Gregory Piatetsky-Shapiro, William Frawley

1st Edition

0262660709, 978-0262660709

More Books

Students also viewed these Databases questions