I have no object to me and I can make it with two constructor
public Brick (int x, int y) {..........}
and
public brick (int x, int y , float sizeX, float size (y) {}
I have in map.txt to me
brick 320 brick 0 640 64 64 128 spike 5 12 Spike 75 25 .. ... ...
And here I read that file
filehandle file = Gdx.files.internal ("Data / Map Text"); StringToken Zahoor token = new Stringtoknaijhr (file.readString ()); while (TokenskhasMoreTokens ()) string {type = Toknknakstokn (); If (type.equals ( "block")) {list.add (new brick ( int. Parasiaint (token. Anakstikn ()), integer. Piaraiaiaianti (token. Anakstikn ()), float. Piarsaflot (token. Anakstikn ()), float. Prsflot (token. Next token ())));}
So I need to read my file that both of my constructors will work?
If there is a command in each row, then I will read it in a row like this:
Pre> import java.io.buffferedReader; Import java.io.FileInputStream; Import java.io.InputStream; Import java.io.InputStreamReader; Import java.nio.charset.Charset; Import java.util.StringTokenizer; Public class read {public static brick {public brick} (int a, int b) {System.out.println ("constructor for 2 parameters:" + + a + "," + b) "} public brick (int a, int b, int c, int d) {println ( "Creator 4 parameters:" + a + "," + B + "," + c + "," + e);}} public static void I (String [] Args) Exception {String Line; InputStream fis = New FileInputStream ("map.txt"); InputStreamReader isr = New InputStreamReader (FIS, Charset. Name ("UTF-8")); Buffett reader br = new buffed reader ISR); while ((r Eat = br.readline ()) = null) {//System.out.println(line); stringTokenizer token = new stringTokenizer (line.trim); while (tokens.hasMoreTokens ()) {string type = tokens .nextToken (); if (type.equals ("brick")} {int parameter = tokens.countTokens (); switch (parameter) {case 2: New Brick (Integer.parseInt (tokens.nextToken ()), Integer parseInt (tokens.nextToken ())); break; case 4: new brick (Integer.parseInt (tokens.nextToken ()), Integer.parseInt (tokens.nextToken ()), Integer.parseInt (tokens.nextToken ()) , Integer.parseInt (tokens.nextToken ())); break; Default: Throw new exception ("wrong row:" + line); }; }}}}}
No comments:
Post a Comment