Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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  
  Tower Defense Save File  (Read 2085 times)
0 Members and 1 Guest are viewing this topic.
Offline Slyth2727
« Posted 2013-04-27 22:31:25 »

Alright, this is a biggie for me. I need to create a save file that writes the data of all the blocks in the game to the save. The blocks are like this: airBlocks can contain towers which also have upgrades. If the airBlock doesn't contain a tower its value is 0 (Value.airAir) if it's a tower, than it is another int (Value.airTower"insert-tower-name-here"). So what's the best way to write all the values of the current blocks including tower upgrades to the file?
Offline Phyyl

Senior Newbie

« Reply #1 - Posted 2013-04-28 14:22:11 »

A good way to save things to files is to create two functions on every items you want to save. One for creating a byte[] of the values (exporting its values), and another one for decoding an byte[] (importing its values).

Example :
public byte[] getBytes() {

public void fromBytes() { = new String(bytes, "iso-8859-1"); // remplacer l'encodage au besoin


it's a very abstract example but you're probably going to need to add lists or arrays with a correct size for storing your data.
Offline Slyth2727
« Reply #2 - Posted 2013-04-28 14:40:36 »

I'm afraid I don't fully understand what you mean here. Would I put this method everywhere, or in one place and just call it tons of times every auto-save? In all honesty I have no CLUE what I have to do for this, so you may have to walk me through this if you don't mind
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Phyyl

Senior Newbie

« Reply #3 - Posted 2013-04-28 14:48:11 »

Let's say you have an Object(class) called "Player" and this player has value(String name, int life).

You need to make an array of bytes to save to the file. The best way is to make an interface (let's say we call it "ISavable").

this interface forces you to implement the two methods shown previously. when you save your game, you itterate over all your game elements that are "ISavable" and you append the byte array of each object to the file. when you load the game, it's gonna go over all the file byte by byte and put those values in the right place using the fromBytes(byte[] b) method.

hope this helps
Offline Slyth2727
« Reply #4 - Posted 2013-04-28 14:52:54 »

Alright, makes sense. Way less code than I was thinking of doing originally. And I'm guessing that this willl work for a Tower Defense game that is block based? And probably that the fact it is block based will make it easier?
Pages: [1]
  ignore  |  Print  

EgonOlsen (79 views)
2018-06-10 19:43:48

EgonOlsen (59 views)
2018-06-10 19:43:44

EgonOlsen (78 views)
2018-06-10 19:43:20

DesertCoockie (261 views)
2018-05-13 18:23:11

nelsongames (159 views)
2018-04-24 18:15:36

nelsongames (158 views)
2018-04-24 18:14:32

ivj94 (901 views)
2018-03-24 14:47:39

ivj94 (162 views)
2018-03-24 14:46:31

ivj94 (813 views)
2018-03-24 14:43:53

Solater (177 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!