×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Create A Program to Create a Trivia Maze in Java Assignment Solution

July 01, 2024
Dr. Ethan Taylor
Dr. Ethan
🇬🇧 United Kingdom
Java
Dr. Ethan Taylor holds a Ph.D. in Computer Science from the University of Oxford. With over 850 assignments completed, he brings extensive expertise in data structures, algorithms, and programming languages. Ethan specializes in array manipulation, dynamic memory allocation, and algorithm optimization, providing students with comprehensive guidance and practical solutions for their Array class interface homework.
Key Topics
  • Instructions
    • Objective
  • Requirements and Specifications
Tip of the day
Use Python libraries effectively by importing only what you need. For example, if you're working with data, using libraries like pandas and numpy can save time and simplify complex tasks like data manipulation and analysis.
News
In 2024, the Biden-Harris Administration has expanded high-dosage tutoring and extended learning programs to boost academic achievement, helping programming students and others recover from pandemic-related setbacks. These initiatives are funded by federal resources aimed at improving math and literacy skills​

Instructions

Objective

Write a program to create a trivia maze in java language.

Requirements and Specifications

Write a Java assignment program to create a trivia maze game.

Implement

  • Classes
  • methods

Source Code

package maze; /** * * */ import java.io.Serializable; public class Maze implements Serializable { private static final long serialVersionUID = 5205114282657699300L; /** * */ private Room[][] rooms; private int row; private int column; private Player player; private int locR = 0; private int locC = 0; private QuestionDatabase question; /** * * * @param r * @param c * @param player */ public Maze(int r, int c, Player p) { this.row = r; this.column = c; this.player = p; setPlayerLoc(p.getLocRow(), p.getLocColumns()); generateMaze(r, c); this.question = new QuestionDatabase(); } public int getRow() { return row; } public int getColumn() { return column; } /** * * * @return */ public String getPlayerLoc() { return "Player Location: R: " + this.locR + " " + "C: " + this.locC; } /** * * */ public void playerMovement(String direction) { int r = this.locR; int c = this.locC; if (isDoorlocked(direction) == false && questionAnswered() == true) { // playermovement in that direction method playerMoveDirection(direction); } } public boolean isDoorlocked(String direction) { int r = this.locR; int c = this.locC; Door d = this.rooms[r][c].getDoor(direction); if (d.getLocked() == true) { return true; } else { return false; } } public boolean questionAnswered() { int r = this.locR; int c = this.locC; if (this.rooms[r][c].getQuestionAnswered() == true) { return true; } else { return false; } } public void playerMoveDirection(String direction) { int r = this.locR; int c = this.locC; if (direction == "N" || direction == "n") { setPlayerLoc(r - 1, c); } else if (direction == "W" || direction == "w") { setPlayerLoc(r, c - 1); } else if (direction == "S" || direction == "s") { setPlayerLoc(r + 1, c); } else if (direction == "E" || direction == "e") { setPlayerLoc(r, c + 1); } else { System.out.println("Enter the right direction letters"); } } public void setPlayerLoc(int i, int j) { this.locR = i; this.locC = j; player.setLocation(i, j); } public void generateMaze(int rows, int columns) { this.rooms = new Room[rows][columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { if (i == 0 && j == 0) { this.rooms[i][j] = new Room(false, true); this.rooms[i][j].setDoor("N", true); this.rooms[i][j].setWall("N", true); this.rooms[i][j].setDoor("W", true); this.rooms[i][j].setWall("W", true); } else if (i == rows - 1 && j == columns - 1) { this.rooms[i][j] = new Room(true, false); this.rooms[i][j].setDoor("S", true); this.rooms[i][j].setWall("S", true); this.rooms[i][j].setDoor("E", true); this.rooms[i][j].setWall("E", true); } else { this.rooms[i][j] = new Room(); if (i == 0) { this.rooms[i][j].setDoor("N", true); this.rooms[i][j].setWall("N", true); } if (i == rows - 1) { this.rooms[i][j].setDoor("S", true); this.rooms[i][j].setWall("S", true); } if (j == 0) { this.rooms[i][j].setDoor("W", true); this.rooms[i][j].setWall("W", true); } if (j == columns - 1) { rooms[i][j].setDoor("E", true); rooms[i][j].setWall("E", true); } } } } } /** * * Room 0, 0 = 0 int k = 0, index = k+i k++; Room 0, 1 = 1 Room 0, 2 = 2 Room 0, * 3 = 3 Room 1, 0 = 4 Room 1, 1 = 5 Room 1, 2 = 6 Room 1, 3 = 7 room 2, 3 * */ public void generateQuestionInRoom(int r, int c) { int k = 0; this.rooms = new Room[r][c]; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { this.rooms[i][j] = new Room(); this.rooms[i][j].setQuestion(k + i); k++; } } } public Room getRoom(int r, int c) { return this.rooms[r][c]; } public void displayMaze() { int i = this.locR; int j = this.locC; System.out.println("Room " + "[Row = " + i + " " + "Col = " + j + "]"); this.rooms[i][j].displayRoom(); System.out.println(question.getQuestionA(i, j)); } }

Similar Samples

Welcome to ProgrammingHomeworkHelp.com, your premier destination for expert programming assistance. Whether it's tackling assignments in C++, Java, Python, or any programming language, our dedicated team of professionals is here to deliver accurate and timely solutions. With years of experience and a commitment to excellence, we ensure your academic success. Get reliable programming help tailored to your needs—explore our services today!