package com.lucasdnd.ags.system;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;
public class GameSystem extends StateBasedGame {
// The Scale values
public static float globalScale = 4f;
// The Game States
public static MenuState menuState;
public static MainState mainState;
public static final int MENU_STATE = 0;
public static final int MAIN_STATE = 1;
// Useful stuff
public static NumberFormat formatter;
// Game Settings
private String storeName;
// Version
public static final String VERSION = "0.1.0";
private int difficulty = 0;
public class Difficulty {
public static final int EASY = 0;
public static final int MEDIUM = 1;
public static final int HARD = 2;
}
private int mapSize = 0;
public class MapSize {
public static final int SMALL = 0;
public static final int MEDIUM = 1;
public static final int LARGE = 2;
}
public GameSystem(String name) {
// Initialize the Menu State
super(name);
menuState = new MenuState();
mainState = new MainState();
// Get currency format
formatter = NumberFormat.getCurrencyInstance();
}
@Override
public void initStatesList(GameContainer container) throws SlickException {
addState(menuState);
}
/**
* Formats the money int into currency format. It prints the money with a "$" symbol in front of it.
* @param money
* @param showCurrencySymbol
* @return
*/
public static String printMoney(int money, boolean showSign) {
NumberFormat nf = NumberFormat.getCurrencyInstance();
DecimalFormatSymbols decimalFormatSymbols = ((DecimalFormat) nf).getDecimalFormatSymbols();
decimalFormatSymbols.setCurrencySymbol("");
((DecimalFormat) nf).setDecimalFormatSymbols(decimalFormatSymbols);
if(showSign) {
return "$ " + nf.format((float)money / 100).trim();
}
return nf.format((float)money / 100).trim();
}
public static String printDate(long time) {
String result = "";
// Format the Date
Date date = new Date();
SimpleDateFormat dayFormat = new SimpleDateFormat("dd");
SimpleDateFormat monthFormat = new SimpleDateFormat("MM");
SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy");
// Format and concat
date.setTime(time);
result = dayFormat.format(date) + "/" + monthFormat.format(date) + "/" + yearFormat.format(date);
return result;
}
/**
* Pass in each % and a value from 0 to 4 will be returned, saying in which category the random fell
* @param c1
* @param c2
* @param c3
* @param c4
* @return
*/
public static int getRandomFrom100(int c1, int c2, int c3, int c4) {
int randomResult = new Random().nextInt(100);
if(randomResult < c1) return 0;
else if(randomResult < c1 + c2) return 1;
else if(randomResult < c1 + c2 + c3) return 2;
else if(randomResult < c1 + c2 + c3 + c4) return 3;
return 4;
}
public int getDifficulty() {
return difficulty;
}
public void setDifficulty(int difficulty) {
this.difficulty = difficulty;
}
public int getMapSize() {
return mapSize;
}
public void setMapSize(int mapSize) {
this.mapSize = mapSize;
}
public String getStoreName() {
return storeName;
}
public void setStoreName(String storeName) {
this.storeName = storeName;
}
}