Write a Java program to implement a text based Role Playing Game This program uses of inheritance & polymorphism. Giving an abstract class Actor with code. Create 2 classes - Player and Monster - that...




Write a Java program to implement a text based Role Playing Game
This program uses of inheritance & polymorphism. Giving an abstract class Actor with code. Create 2 classes - Player and Monster - that inherit from Actor. The program will implement a class map as a 9x9 of char. The player should begin at the centre of the map and be represented as "P". Randomly placing a Monster -"M" on the map. A blank can be "-". The Player should be able move around the map using "was d". The player cannot move out the map. When "P" move to Monter' s location which contains a "M" initiate a battle loop that generates the attacks for each Player.


------------------------


public abstract class Actor {

// character statistics

private String name = "";

private int hp = 0;

private char symbol = ' ';

// map coordinates

private int x;

private int y;

Actor(String name, int hp, char symbol, int x, int y)

{

this.name = name;

this. hp = hp;

this. symbol = symbol;

this.x = x;

this .y = y;

}

public String get Name() {

return this.name;

}

public int get HP() {

return this. hp;

}

public void set HP(int hp) {

this .hp = hp;

}

public int get X()

{

return this .x;

}

public int get Y()

{

return this .y;

}

public void set X(int x)

{

this. x = x;

}

public void set Y(int y)

{

this. y = y;

}

public char get Symbol()

{

return this .symbol;

}

abstract int generate Random Attack();

}


-----------------------------


public class Combat {

public Combat()

{}

public void init Combat(Player player, Monster monster)

{

System. Out .print ln(player);

System. out .print ln(monster);

//while(true) loop that calls attack Sequence() for each actor

}

public void attack Sequence(Actor attacker, Actor defender)

{

//calls get Damage(attacker)

//sets defenders hp to new value

//calls combat Results()

//prints defender's new hp

//calls check Defeat(defender)

}

private void combat Results(Actor actor, int damage)

{

//print actor name and attack damage

}


private int get Damage (Actor actor)

{

//calls actor .generate Random Attack()

}

private void check Defeat(Actor actor)

{

//code given on page two of this document

}

}


------------------------


public class Input {

//contains private Scanner member variable

public Input()

{

//initializes Scanner object

}

public char read Input()

{

//reads only the first char from keyboard input

//loop to receive valid input--'while(!valid Input(c))'

//returns valid char input

}

private Boolean valid Input(char input)

{

//return Boolean if input is/is n 'tn valid

}

}


------------------


public class Map {

private final int SIZE;

private final int PLAYER_LOCATION;

private char[][] map;

private final Player player;

private final Monster monster;

private final Combat combat;

public Map()

{

//initialize SIZE and PLAYER_LOCATION

//call initialize Map()

//call generate Random Location() for monster X and monster Y

//ensure monster is not generate in the same location as player


//cal player, monster, and combat constructors

//initialize 9x9 map of char

}

private void initialize Map()

{

//intialize each cell of map to '-'

}

public void draw Map()

{

// all initialize Map()

//call assign Actor Location() for player and monster objects

//print map to screen with a space between each element

}

public void assign Actor Location(Actor actor)

{

//get actor x and y location

//assign actor .get Symbol() to location on map

}


private int generate Random n Location()

{

//return random number within range of map edges

}

public void move Player(char move)

{

//get player current location

//use switch statement to determine  player new location or quit

//call valid Coordinates() to determine if player is at map edge

//if player Encounters Monster() call combat. in it Combat()

}

private Boolean player Encounters Monster()

{

//return true if player location matches monster location

}

private Boolean valid Coordinates(int new X, int new Y)

{

//return true if player location within range of map

}

}


------------------


public class RPG {

public static void main(String[] args) {

Map map = new Map();

Input input = new Input();

map. draw Map();


//while(true) loop

}

}


--------------



May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here