Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Dungeon {
- private Monster[][] monsters;
- public int gridWidth;
- public int gridHeight;
- public Dungeon(int w, int h) {
- monsters = new Monster[h][w];
- for(int i = 0;i < h; i++) {
- for(int j = 0;j < w; j++) {
- monsters[i][j] = new Monster();
- }
- }
- this.gridWidth = w;
- this.gridHeight = h;
- }
- public void updateMonster(int x, int y, Monster m)
- {
- boolean done = false;
- for (int row = 0; row< monsters.length; row++)
- {
- for (int col = 0; col < monsters[row].length; col++)
- {
- if (row == x && col == y && !done)
- {
- Monster temp = monsters[col][row];
- if (temp.getLevel() == -1 && temp.getName().equals(""))
- {
- monsters[col][row] = m;
- done = true;
- }
- }
- }
- }
- }
- public void shift(char command) {
- Monster temp;
- switch (command) {
- case 'w' :
- for(int i = 0; i < gridWidth; i++) {
- temp = monsters[0][i];
- for(int j = 1; j < gridHeight; j++) {
- monsters[j-1][i] = monsters[j][i];
- }
- monsters[gridHeight -1][i] = temp;
- }
- break;
- case 'd' :
- for(int i = 0; i < gridHeight; i++) {
- temp = monsters[i][gridWidth-1];
- for(int j = gridWidth-1; j > 0; j--) {
- monsters[i][j] = monsters[i][j-1];
- }
- monsters[i][0] = temp;
- }
- break;
- case 's' :
- for(int i = 0; i < gridWidth; i++) {
- temp = monsters[gridHeight-1][i];
- for(int j = gridHeight-1; j>0; j--) {
- monsters[j][i] = monsters[j-1][i];
- }
- monsters[0][i] = temp;
- }
- break;
- case 'a' :
- for(int i = 0; i < gridHeight; i++) {
- temp = monsters[i][0];
- for(int j=1;j<gridWidth;j++) {
- monsters[i][j-1] = monsters[i][j];
- }
- monsters[i][gridWidth-1] = temp;
- }
- break;
- }
- }
- public void shuffle() {
- Random rand = new Random();
- for(int i = monsters.length-1; i>0; i--){
- for(int j = monsters.length-1; j > 0; j--) {
- int y1 = rand.nextInt(j + 1);
- int y2 = rand.nextInt(j + 1);
- int x1 = rand.nextInt(i+1);
- int x2 = rand.nextInt(i+1);
- this.swap(x1, y1, x2, y2);
- }
- }
- }
- private void swap(int x1 , int y1 , int x2 , int y2) {
- Monster temp = monsters[y1][x1];
- monsters[y1][x1] = monsters[y2][x2];
- monsters[y2][x2] = temp;
- }
- public String printInfo(){
- String result = "";
- for(int i=0;i<gridHeight;i++) {
- for(int j=0;j<gridWidth;j++) {
- result += monsters[i][j].getInfo();
- result += " ";
- }
- result += "\n";
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement