Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Help with loading text into arrays

Author
Message
Ranietz
AGK Gold Backer
20
Years of Service
User Offline
Joined: 2nd Sep 2004
Location: Norway
Posted: 25th Jun 2005 01:34
Hi.

I'm making a simple snake game that have several levels. Is it posible to load the levels from a text file and into an array? (I'm using the data in an array to draw the screen)

The sourcecode is what I want the text file to look like. The attachment picture is how it should be in game/on screen.

What I want is that all the x's should be loaded into the array in the right place and given the value 1201. (all the 1201's in the array will be drawed as a wall)

Can anyone help me with this? I know it's not explained very good, but my english is a bit limited. I hope you understand what I mean...

-Ranietz-

Attachments

Login to view attachments
Ranietz
AGK Gold Backer
20
Years of Service
User Offline
Joined: 2nd Sep 2004
Location: Norway
Posted: 25th Jun 2005 03:02
Hmm... Is there a way to edit my post? The sourcecode thing did not work.

Anyway, the text file should look like this:

level1
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
level2
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x.........xxxxxxxxxxxxxxxxxxx..........x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x.........xxxxxxxxxxxxxxxxxxx..........x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
x......................................x
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 25th Jun 2005 05:47 Edited at: 25th Jun 2005 05:49
Your text file isone line per row of boxes in the game, I guess?

You could...



So waht you are doing is reading one line, checking each character and updating the array, then moving to th enext line.

BatVink
Ranietz
AGK Gold Backer
20
Years of Service
User Offline
Joined: 2nd Sep 2004
Location: Norway
Posted: 25th Jun 2005 06:53
Thanks! I got it to work with a little tweaking. Thanks again!

-Ranietz-
Killonyas Slayer
19
Years of Service
User Offline
Joined: 13th Apr 2005
Location: Mozerok,Eartreg
Posted: 29th Jun 2005 03:11
as for your source code, if you are still waiting for your posts to appear, then the source code will not work.

try using code snipetts.

(code)[click the code button above]
print "hello world"
(/code)[click that button again]

-"I'm over twice as strong as I was when we last met"-
-"Good, Twice the fall, double the glory"-
Ranietz
AGK Gold Backer
20
Years of Service
User Offline
Joined: 2nd Sep 2004
Location: Norway
Posted: 30th Jun 2005 02:05
Ok. Thanks for letting me know...

Login to post a reply

Server time is: 2024-11-27 22:42:53
Your offset time is: 2024-11-27 22:42:53