Skip to content

helper classes

yoel123 edited this page Sep 28, 2020 · 15 revisions

to make development easier I add a few helper class.

gconsole_menu and gmenu_manger have their own wiki page so they won't be covered here (go to start here page to find it).

gyinput:

is a class that helps to get user input, it asks the user for input, validate it, and return the input data. it can get and return ints, Doubles, and strings.

to use it you need to declare and initialize the class gyinput:

gyinput ui = new gyinput(cio);

the argument cio is a GUIConsoleIO object you get by calling c.io as that's the object that manages the consoles input and output, without it gyinput won't work.

let's say you want to get the user name using ui (the gyinput instance we created) you wold write:

String name = ui.get_string("please write your name");

and after that you wand his age:

ing age = ui.get_int("what is your age?");

if the user will input anything but an int he will be asked to enter a number again (aka the validation).

to get a double use the get_num.

so with one line, we do 3 things, ask input, validate and put it on a variable.

IndexableMap:

this class is kind of a combination of a hashmap and linked list. you can use it like a hashmap and get and set data by a string, but unlike a hashmap you can also manipulate data by index.

its a very effective collection.

initialize and create(an IndexableMap with a string key and a string entrySet):

IndexableMap<String,String> db = new IndexableMap<String,String>();

add data and get data:

db.put("tst","test"); db.get("tst");//will return the string test 

loop data:

for (Entry<String, String> e : db.entrySet()) { e.getValue();//returns the data of the current loop iteration } 

as a child of hashmap it has all of its methods too.

S class:

a class used to output to console.

S.o("bla");

is the equivlent of:

System.out.println("bla");

ydb_s:

as of now, it is not used, what I use it for is to save data from serializable object to dat files and retrieve data from dat files.

will probably used for save and load game.

yvars:

a helper class used for converting between datatyps:

//convert int to string yvars.yitostring(2); //convert string to int yvars.ystoint("5"); //string to double yvars.ystodouble("0.5"); //double to string yvars.ydtostring(1.2); 

take a look inside the class its very simple to use.

Clone this wiki locally