Skip to content
Snippets Groups Projects
Commit a179395e authored by tildiko97's avatar tildiko97
Browse files

printStat

parent 845c0217
Branches
Tags
No related merge requests found
......@@ -53,4 +53,11 @@ public class Crate extends Moveable {
couldMove=b;
}
public void printStat()
{
super.printStat();
System.out.println("couldMove: " + couldMove);
System.out.println("isOnTarget: " + isOnTarget);
}
}
package killer_sokoban;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Logger {
static private Map<Object, String> map=new HashMap<Object, String>();
private static int depth=0;
private static boolean enabled = false;
public static void register(Object o, String name)
{
map.put(o, name);
}
public static void enter(Object o, String funcName, List<Object> parameters)
{
//not doing anything if logger disabled
if (!enabled) return;
//Intendation
String tab="";
for (int i=0; i<depth; i++) tab+=" ";
depth++;
//Fetching parameter list
String param = "";
for (Object i : parameters) {
param += ", "; //separator
if (i == null)
param += "null";
else if (map.containsKey(i))
param += map.get(i);
else
param += i.toString();
}
if(param.length()>2) param = param.substring(2); //we had a comma and a space in the front
//Logging
System.out.println(tab+"-> " + map.get(o) + "." + funcName +"(" + param +")");
}
public static void exit(Object o, String funcName, Object returnValue)
{
//not doing anything if logger disabled
if (!enabled) return;
//Intendation
String tab="";
depth--;
for (int i=0; i<depth; i++) tab+=" ";
//Converting return value into string
String retVal = "";
if (returnValue != null) {
if (map.containsKey(returnValue)) retVal = map.get(returnValue);
else retVal = returnValue.toString();
}
//Logging
System.out.println(tab+"<- " + map.get(o)+ "." + funcName+ "(" + ")" + (retVal.equals("") ? "" : (" [" + retVal + "]")));
}
public static void enable() {enabled=true;}
public static void disable() {enabled=false;}
}
......@@ -76,6 +76,9 @@ public abstract class Moveable {
return ret || couldSqueez;
}
public void printStat()
{
System.out.println(myField + ": " + Main.getFieldName(myField) );
}
}
......@@ -87,4 +87,12 @@ public class Worker extends Moveable {
return (activeForce>=0.0);
}
public void printStat()
{
super.printStat();
System.out.println("points: " + points);
System.out.println("force: " + force);
System.out.println("alive: " + alive);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment