Skip to main content

Posts

Showing posts from December, 2014

Libgdx: Create Item Database using JSON files

This blog post describes how to create an Item database using libgdx JSON parser and storing it in a Collections object to retrieve from. 0.) Create the JSON file Save this as "weaponDb.json". This JSON object is used to create a list of Items in which we can grab items from. [ { "id": 1, "name": "Dumb Basic Sword", }, { "id": 2, "name": "Bad Ass Flaming Sword", }, { "id": 3, "name": "Sword of Kick Ass", } ] 1.) Create the test A simple JUnit test to test our database import com.mygdx.items.Item; import com.mygdx.items.ItemLoader; import org.junit.Test; import java.io.IOException; import java.util.ArrayList; /*Simple Test Case*/ public class TestDb { @Test public void testDb() throws IOException { ItemLoader itemLoader = new ItemLoader(); ArrayList database = itemLoader.load("