1 of 10 Homework 4: Adventure Game Description: The purpose of this assignment i
ID: 3739488 • Letter: 1
Question
1 of 10 Homework 4: Adventure Game Description: The purpose of this assignment is to build a simple text-based adventure game where the player explores the game world by travelling north, west, east, or south. The player chooses where to go and the game describes that area of the game world and what options that they have to explore. You are the designer tasked with creating your own map layout, whether it a castle, a hotel, a dungeon, or a space station. See the last page for sample output of a final build of such an adventure game. Managing this project: You should subdivide this assignment into the following three development phases. First, you should design your game world using paper and pencil. Second, you should model your game world into data and develop an algorithm, in pseudo code, that defines how to move within this model of your game world. Third, implement your pseudo code into a fully playable java application. Required Concepts: This homework requires that you implement the following concepts: 1. Array for String data (Room Descriptions) 2. Multidimensional array for integer data (Room Exits) 3. Initializer lists (Initializing Room Descriptions) 4. Multidimensional Initializer lists (Initializing Room Exits) 5. Retrieve values from array (Getting a room's description) 6. Retrieve values from multidimensional array (Getting room's exit) 7. Named constants (Column indexers for exit array) 8. Repetition Statement (Game loop) 9. Selection Statement (Execute the player's choice)Explanation / Answer
package com.jadventure.game;
import com.jadventure.game.entities.Player;
import com.jadventure.game.monsters.Monster;
import com.jadventure.game.monsters.MonsterFactory;
import com.jadventure.game.repository.LocationRepository;
import com.jadventure.game.prompts.CommandParser;
import java.util.ArrayList;
public class Game {
public ArrayList<Monster> monsterList = new ArrayList<Monster>();
public MonsterFactory monsterFactory = new MonsterFactory();
public CommandParser parser;
public Monster monster;
Player player = null;
public Game(Player player, String playerType) throws DeathException {
this.parser = new CommandParser(player);
this.player = player;
switch (playerType) {
case "new":
newGameStart(player);
break;
case "old":
QueueProvider.offer("Welcome back, " + player.getName() + "!");
QueueProvider.offer("");
player.getLocation().print();
gamePrompt(player);
break;
default:
QueueProvider.offer("Invalid player type");
break;
}
}
public void newGameStart(Player player) throws DeathException {
QueueProvider.offer(player.getIntro());
String userInput = QueueProvider.take();
player.setName(userInput);
LocationRepository locationRepo = GameBeans.getLocationRepository(player.getName());
this.player.setLocation(locationRepo.getInitialLocation());
player.save();
QueueProvider.offer("Welcome to Silliya, " + player.getName() + ".");
player.getLocation().print();
gamePrompt(player);
}
public void gamePrompt(Player player) throws DeathException {
boolean continuePrompt = true;
try {
while (continuePrompt) {
QueueProvider.offer(" Prompt:");
String command = QueueProvider.take().toLowerCase();
continuePrompt = parser.parse(player, command);
}
} catch (DeathException e) {
if (e.getLocalisedMessage().equals("replay")) {
return;
} else {
throw e;
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.