Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Makeing dungeon system should I use a 2d array  (Read 964 times)
0 Members and 1 Guest are viewing this topic.
Offline cloudwindgate

Senior Newbie





« Posted 2013-07-08 03:13:39 »

So I've started my Text based RPG game however my room system is lacking depth. In basic I create a room object and add it to ArrayList I was looking into how to make a 2d array, but seems like that not an option. However I'm unsure how I can make an array that holds objects other then ArrayList.

Is my logic wrong and I'm looking at it wrong.

Sorry if this seems lacking I'm still pretty new at this.   
Offline TrinityGamer

Senior Newbie


Medals: 2



« Reply #1 - Posted 2013-07-08 04:56:16 »

?_? what do you mean it isn't possible to do a 2d array? 2d arrays are done as :

1  
private Array[][] map;


or

1  
 private Array Money[][];


(can also be public instead of private, and various other things)


the '[]' doubled up make it into a 2d array, if there were 3, then it would be 3d array (there isn't a limit, but please note that the more dimensions it has, the more memory and processor usage it takes up)

Anyway, basically the map coding is pretty much the same for 2d games AND text based games, (if you actually mean the map when you say 'room object'. sorry, but there are dozens of things that 'room object' could mean, i'm assuming you mean a 2d text map with # as walls and things like that since you want to know about 2d arrays)

If that's not what you mean, then could you give us more information? (Ps. don't worry about being new, so long as you know the basics of java, we can help)

And don't worry abou
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 136
Projects: 4
Exp: 3 years



« Reply #2 - Posted 2013-07-08 12:13:10 »

Your question is pretty confusing. You're "unsure how make an array that holds objects other then ArrayList?" What?
Why is a 2d array not an option?
What do you mean by "lacking depth"? 2d games don't use depth...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cloudwindgate

Senior Newbie





« Reply #3 - Posted 2013-07-08 17:42:52 »

Okay sorry that the question is so confusing. I'm just really unsure and confused myself.

My Room object repersents whats inside the current room ie. enemies to encounter, and items to find, I'm also considering it holding events but this isn't implmented yet.

I then have another object called -_- locationObject which holds an arraylist of the rooms.

current progrssion in the game is done by adding(or subtracting) one to a variable called currentRoom and then getting the object at the index inside the arraylist in the location object.

I realize 2D arrays can be done with things like String[][] however I'm unsure how to use it to create a map that the player can move around in beyound going back and forth.

When I say lacking depth I'm refering to the fact you can only go from room 1, to room 2, to room3, and back they is no left or west and east from currentRoom.

I have atleast a basic understanding of java.

I'm unsure where the problem is in my logic. Again thank-you for your help.


Offline sproingie

JGO Kernel


Medals: 202



« Reply #4 - Posted 2013-07-08 18:10:18 »

Don't use arrays for this stuff, use collections like List, which will let you do far more than arrays.  If you need an extra dimension, use a List of Lists, and also look at things like Map while you're at it.

Arrays do have their uses, but not in a text-based game.
Offline TrinityGamer

Senior Newbie


Medals: 2



« Reply #5 - Posted 2013-07-09 08:09:45 »

Don't use arrays for this stuff, use collections like List, which will let you do far more than arrays.  If you need an extra dimension, use a List of Lists, and also look at things like Map while you're at it.

Arrays do have their uses, but not in a text-based game.


Actually, i think what they mean is that they want to make a text based roguelike, which usually IS made with 2d arrays (or 2d char arrays, at least). i think that the confusion is because there is also the old fashioned text based RPG games where it's just dialogue and you loosing hp.  usually roguelike games have maps that look almost EXACTLY like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
##########################
##                                              G
############    ########    ##
##M            M##    ######        ##
##                ##    ######        ##
##                      M############
############                        ##
######################    ##
##                                ####    ##
##    ######    ####    ####    ##
##    ##              M##    ####    ##
##C  ##                ##                ##
##    ######################


Okay sorry that the question is so confusing. I'm just really unsure and confused myself.

My Room object repersents whats inside the current room ie. enemies to encounter, and items to find, I'm also considering it holding events but this isn't implmented yet.

I then have another object called -_- locationObject which holds an arraylist of the rooms.

current progrssion in the game is done by adding(or subtracting) one to a variable called currentRoom and then getting the object at the index inside the arraylist in the location object.

I realize 2D arrays can be done with things like String[][] however I'm unsure how to use it to create a map that the player can move around in beyound going back and forth.

When I say lacking depth I'm refering to the fact you can only go from room 1, to room 2, to room3, and back they is no left or west and east from currentRoom.

I have atleast a basic understanding of java.

I'm unsure where the problem is in my logic. Again thank-you for your help.


you need to set 2 variables. have 1 stand for the characters y position, and  1 for the x position.

now do something like this (note that this is not an actual code, it's just an outline of what you need to do):


1  
2  
3  
4  
5  
6  
if buttonup true: 
       check if maparray[x][y+1] has something in it(should return a true or false)
       if false:
              maparray[x][y] = blank space;
              y++;
              maparray[x][y] = character symble;


basically, you need to do that for each direction. (if down it should be y-1 and y--, if left it should be x-1 and x--, and if right it should be x +1 and x++)

there you go, you now have your character and map working together in perfect harmony. now you basically have to do the same for each mob, (basically, it's a for loop that checks if the slot is taken up by a mob, if it is, then an if statement to see if the player is near by, then if the player IS then you need to do the attack. if it's not, then either randomly move 1 (again, check if the mob can actually move).

basically, that's it. it's really easy and it's also the 'begginers programming to rpgs'. there are actually a LOT of online tutorials that will tell you how to code every single line. though not all use 2d arrays or 2d char arrays. anyway, here is one of the youtube tutorials i found in my favs, (though i have no idea if it uses arrays or not):
http://www.youtube.com/playlist?list=PLB062D4D37FECD5A6




Offline sproingie

JGO Kernel


Medals: 202



« Reply #6 - Posted 2013-07-09 18:40:59 »

Yeah an array is appropriate for the actual map of a roguelike where all you need is direct access to 2d locations and aren't going to go inserting, deleting, searching, copying into other collections, and so forth.  But in this thread I'm reading about discrete rooms and exits and thinking more "MUD" than "Roguelike", and there doesn't seem to be much use for arrays there.  ArrayLists, sure, but that's just an implementation detail.
Offline cloudwindgate

Senior Newbie





« Reply #7 - Posted 2013-07-09 20:02:19 »

@TrinityGamer 
     Thank-you for the insight. I like the sound of a rougelike game and I think that the story idea behind the game would probably fit this type of game. However I'm not sure the difference fully is. The game has three option at any point when not in a fight or event. Go, Search, and rest. Go I would like to use to move the player from room to room however all it does is get the next room. If I choose to use the method you detail with out a drawn map but how would I pull up the next room with it. I do like the idea of the rouge like game but I would like to just finish what I have. At this moment rooms are like containers that hold enemies items and events. I don't know if thats bad practice or something.

I obviously am just going to have to dive into and play with these things.

@sproingie

I was trying to make a map like
     ####
###
#  # 

just to start but each room is a object so I was calling them by getting there index and changing what index was being referenced. however I was unsure how to code the getting and finding out if there was a room to the right. Would I assign each with a XY value and then test to see if the player is next to that value? and then test each of the objects in the arraylist (im reading the tut on collection and colletion api right now) to see if they have the same value?

Sorry if any of these question are confusing I'm still pretty fresh in the all this. Again Thank-you for the help
Offline tdegroot96

Junior Duke


Projects: 1



« Reply #8 - Posted 2013-07-09 21:38:56 »

When I'm making a tilemap, I use a 1d array:
1  
private int[] tiles = new int[width * height]

This only works with int - int relations.
For a real key - value array I'd use an ArrayList
Offline TrinityGamer

Senior Newbie


Medals: 2



« Reply #9 - Posted 2013-07-10 11:26:47 »

@TrinityGamer 
     Thank-you for the insight. I like the sound of a rougelike game and I think that the story idea behind the game would probably fit this type of game. However I'm not sure the difference fully is. The game has three option at any point when not in a fight or event. Go, Search, and rest. Go I would like to use to move the player from room to room however all it does is get the next room. If I choose to use the method you detail with out a drawn map but how would I pull up the next room with it. I do like the idea of the rouge like game but I would like to just finish what I have. At this moment rooms are like containers that hold enemies items and events. I don't know if thats bad practice or something.

I obviously am just going to have to dive into and play with these things.

@sproingie

I was trying to make a map like
     ####
###
#  # 

just to start but each room is a object so I was calling them by getting there index and changing what index was being referenced. however I was unsure how to code the getting and finding out if there was a room to the right. Would I assign each with a XY value and then test to see if the player is next to that value? and then test each of the objects in the arraylist (im reading the tut on collection and colletion api right now) to see if they have the same value?

Sorry if any of these question are confusing I'm still pretty fresh in the all this. Again Thank-you for the help
OOOOOOOOOOOOOOOOOOOOOOH.

yes, that is essentially what you would do. there are many ways to do it, but that is the most common method. there are a lot of ways, but most of them do pretty much the same thing.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (46 views)
2014-10-17 03:59:02

Norakomi (37 views)
2014-10-16 15:22:06

Norakomi (29 views)
2014-10-16 15:20:20

lcass (32 views)
2014-10-15 16:18:58

TehJavaDev (62 views)
2014-10-14 00:39:48

TehJavaDev (62 views)
2014-10-14 00:35:47

TehJavaDev (52 views)
2014-10-14 00:32:37

BurntPizza (70 views)
2014-10-11 23:24:42

BurntPizza (41 views)
2014-10-11 23:10:45

BurntPizza (82 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!