Risk.java

Index Score
risk.engine
Risk

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
EXEC_COMMENTSComments in executable code
COMPARISONSNumber of comparison operators
LINE_COMMENTNumber of line comments
BLOCKSNumber of blocks
WHITESPACENumber of whitespace lines
CYCLOMATICCyclomatic complexity
OPERATORSNumber of operators
PROGRAM_LENGTHHalstead program length
JAVA0049JAVA0049 Nested block at depth N (maximum: M)
LINESNumber of lines in the source file
JAVA0145JAVA0145 Tab character used in source file
OPERANDSNumber of operands
SIZESize of the file in bytes
LOCLines of code
LOGICAL_LINESNumber of statements
ELOCEffective lines of code
JAVA0081JAVA0081 Boolean literal in comparison
LOOPSNumber of loops
EXITSProcedure exits
UNIQUE_OPERANDSNumber of unique operands
PROGRAM_VOCABHalstead program vocabulary
JAVA0084JAVA0084 Should use compound assignment operator
JAVA0082JAVA0082 Unnecessary widening cast
JAVA0144JAVA0144 Line exceeds maximum M characters
COMMENTSComment lines
JAVA0166JAVA0166 Generic exception caught
JAVA0177JAVA0177 Variable declaration missing initializer
JAVA0285JAVA0285 Dereference of potentially null variable
JAVA0265JAVA0265 Use of Throwable.printStackTrace()
JAVA0117JAVA0117 Missing javadoc: method 'method'
JAVA0067JAVA0067 Array descriptor on identifier name
DECL_COMMENTSComments in declarations
NEST_DEPTHMaximum nesting depth
RETURNSNumber of return points from functions
JAVA0272JAVA0272 Thread.run() called
BLOCK_COMMENTNumber of block comment lines
FUNCTIONSNumber of function declarations
INTERFACE_COMPLEXITYInterface complexity
JAVA0270JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0080JAVA0080 Import declaration not used
JAVA0119JAVA0119 Control variable changed within body of for loop
JAVA0008JAVA0008 Empty catch block
JAVA0087JAVA0087 Use of Thread.sleep()
UNIQUE_OPERATORSNumber of unique operators
JAVA0266JAVA0266 Use of System.out
JAVA0163JAVA0163 Empty statement
JAVA0267JAVA0267 Use of System.err
DOC_COMMENTNumber of javadoc comment lines
JAVA0143JAVA0143 Synchronized method
JAVA0128JAVA0128 Public constructor in non-public class
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0032JAVA0032 Switch statement missing default
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0273JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0034JAVA0034 Missing braces in if statement
PARAMSNumber of formal parameter declarations
JAVA0171JAVA0171 Unused local variable
JAVA0123JAVA0123 Use all three components of for loop
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0068JAVA0068 Modifiers not declared in recommended order
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
// Yura Mamyrin, Group D package risk.engine; import risk.engine.core.*; import risk.engine.guishared.*; import risk.engine.ai.AIPlayer; import java.util.StringTokenizer; import java.awt.Color; import java.util.Vector; import java.io.*; import java.net.*; import java.util.Random; import java.util.ResourceBundle; import java.awt.Toolkit; import javax.crypto.SealedObject; import javax.crypto.NullCipher; import java.util.Enumeration; import java.applet.Applet; import javax.swing.JFileChooser; import java.awt.Frame; import javax.swing.JOptionPane; import javax.swing.JComboBox; import java.awt.Container; import java.util.Properties; import java.awt.Dimension; import javax.swing.UIManager; import java.util.Locale; import java.util.ResourceBundle; /** * <p> Main Risk Class </p> * @author Yura Mamyrin */ public class Risk extends Thread { public final static String RISK_VERSION="1.0.9.7"; private StringTokenizer StringT; protected RiskController controller; protected RiskGame game; //private String message; private PrintWriter outChat = null; private BufferedReader inChat = null; private ChatArea chatter = null; private Socket chatSocket = null; private ChatDisplayThread myReader = null; private int port; protected String myAddress; // crashes on a mac too much //private SealedObject Undo; private ByteArrayOutputStream Undo = new ByteArrayOutputStream(); protected boolean unlimitedLocalMode; private boolean autoplaceall; private boolean battle; private boolean replay; protected Vector inbox; protected ResourceBundle resb; protected Properties riskconfig; public Risk(Applet a, String b,String c) { this(a); RiskGame.setDefaultMapAndCards(b,c); } public Risk(Applet a) { super(RiskUtil.getGameName()+"-GAME-THREAD"); resb = risk.engine.translation.TranslationBundle.getBundle(); setupMapsDir(a); String strUsername = RiskUtil.getGameName()+"Player"; if (RiskUtil.checkForNoSandbox()) { strUsername = System.getProperty("user.name"); } riskconfig = new Properties(); riskconfig.setProperty("default.port","4444"); riskconfig.setProperty("default.host","localhost"); riskconfig.setProperty("default.map", RiskUtil.getDefaultMap() ); riskconfig.setProperty("default.cards", "risk.cards" ); riskconfig.setProperty("default.player1.type","human"); riskconfig.setProperty("default.player1.color","green"); riskconfig.setProperty("default.player1.name", strUsername ); riskconfig.setProperty("default.player2.type","ai easy"); riskconfig.setProperty("default.player2.color","blue"); riskconfig.setProperty("default.player2.name","bob"); riskconfig.setProperty("default.player3.type","ai easy"); riskconfig.setProperty("default.player3.color","red"); riskconfig.setProperty("default.player3.name","fred"); riskconfig.setProperty("default.player4.type","ai easy"); riskconfig.setProperty("default.player4.color","cyan"); riskconfig.setProperty("default.player4.name","ted"); riskconfig.setProperty("default.player5.type","ai hard"); riskconfig.setProperty("default.player5.color","magenta"); riskconfig.setProperty("default.player5.name","yura"); riskconfig.setProperty("default.player6.type","ai hard"); riskconfig.setProperty("default.player6.color","yellow"); riskconfig.setProperty("default.player6.name","lala"); try { riskconfig.load( RiskUtil.openStream("risk.ini") ); } catch (Exception ex) { // can not find file, no problem } String randomString = "#"+String.valueOf( Math.round(Math.random()*Long.MAX_VALUE) ); try { if (RiskUtil.checkForNoSandbox()) { myAddress = InetAddress.getLocalHost().getHostName() + randomString; } else { myAddress = "sandbox" + randomString; } /* //InetAddress localAddr = InetAddress.getLocalHost(); //myAddress = localAddr.getHostAddress(); myAddress=null; Enumeration ifaces = NetworkInterface.getNetworkInterfaces(); search: while (ifaces.hasMoreElements()) { NetworkInterface ni = (NetworkInterface)ifaces.nextElement(); //System.out.println(ni.getName() + ":"); Enumeration addrs = ni.getInetAddresses(); while (addrs.hasMoreElements()) { InetAddress ia = (InetAddress)addrs.nextElement(); //System.out.println(" " + ia.getHostAddress()); String tmpAddr = ia.getHostAddress(); if (!tmpAddr.equals("127.0.0.1")) { myAddress = tmpAddr; break search; } } } if (myAddress==null) { throw new Exception("no IP found"); } */ } catch (Exception e) { // if network has not been setup myAddress = "nonet" + randomString; } RiskGame.setDefaultMapAndCards( riskconfig.getProperty("default.map") , riskconfig.getProperty("default.cards") ); port = Integer.parseInt( riskconfig.getProperty("default.port") ); battle = false; replay = false; controller = new RiskController(); inbox = new Vector(); this.start(); } public void setupMapsDir(Applet a) { RiskUtil.setupMapsDir(a); } /** * This gets the next token of the string tokenizer * @return String Returns the next token as a string */ public String GetNext() { return StringT.nextToken(); } public String getRiskConfig(String a) { return riskconfig.getProperty(a); } public void addRiskListener(RiskListener o) { controller.addListener(o); setHelp(); } public void deleteRiskListener(RiskListener o) { controller.deleteListener(o); } /** * This parses the string, calls the relavant method and displays the correct error messages * @param m The string needed for parsing */ public void parser(String m) { //System.out.print("GOT: "+m+"\n"); synchronized(inbox) { inbox.add(m); inbox.notify(); } } public void run() { String message; try { while (true) { synchronized(inbox) { if( inbox.isEmpty() ) { try { inbox.wait(); } catch(InterruptedException e) { System.err.println("InterruptedException in "+getName()); } } try { message = (String)inbox.remove(0); } catch (ArrayIndexOutOfBoundsException ex) { // this should never happen but it does continue; } } //System.out.print("PROCESSING: "+message+"\n"); String input; String output; StringT = new StringTokenizer( message ); if (StringT.hasMoreTokens() == false) { controller.sendMessage(">", false, false ); getInput(); continue; // used to be return; when this was not a thread } else { input=GetNext(); output=""; } // Show version if (message.equals("ver")) { controller.sendMessage(">" + message, false, false ); controller.sendMessage(RiskUtil.getGameName()+" Game Engine [Version " + RISK_VERSION + "]", false, false ); getInput(); } // take no action else if (input.equals("rem")) { controller.sendMessage(">" + message, false, false ); //controller.sendMessage("no action", false, false ); getInput(); } // out of game commands else if (game==null) { // if no game controller.sendMessage(">" + message, false, false ); // NEW GAME if (input.equals("newgame")) { if (StringT.hasMoreTokens()==false) { // already checked //if (game == null) { try { // CREATE A GAME game = new RiskGame(); // NO SERVER OR CLIENT IS STARTED unlimitedLocalMode = true; controller.newGame(true); setupPreview(); controller.showCardsFile( game.getCardsFile() , true); output=resb.getString( "core.newgame.created"); } catch (Exception e) { output=resb.getString( "core.newgame.error") + " " + e.getMessage(); } //} //else { // output=resb.getString( "core.newgame.alreadyloaded"); //} } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "newgame"); } } // LOAD GAME else if (input.equals("loadgame")) { if (StringT.countTokens() >= 1) { // this is not needed here as u can only get into this bit of code if game == null //if (game == null) { String filename = GetNext(); while ( StringT.hasMoreElements() ) { filename = filename + " " + GetNext(); } try { game = RiskGame.loadGame( filename ); if (game == null) { throw new Exception("no game"); } unlimitedLocalMode = true; if (game.getState()==RiskGame.STATE_NEW_GAME) { controller.newGame(true); } else { controller.startGame(unlimitedLocalMode); } output=resb.getString( "core.loadgame.loaded"); Player player = game.getCurrentPlayer(); if ( player != null ) { // the game is saved saveGameToUndoObject(); output=output+ System.getProperty("line.separator") + resb.getString( "core.loadgame.currentplayer") + " " + player.getName(); } } catch (Exception ex) { output=resb.getString( "core.loadgame.error.load")+" "+ex.toString(); controller.showMessageDialog(output); } //} //else { // output=resb.getString( "core.newgame.alreadyloaded"); //} } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "loadgame filename"); } } else if (input.equals("join")) { if (StringT.countTokens() == 1) { // already checked //if (game == null) { // CREATE A CLIENT try { chatSocket = new Socket( GetNext() , port); // Create a PrintWriter object for socket output outChat = new PrintWriter( chatSocket.getOutputStream(), true); // Create a BufferedReader object for socket input inChat = new BufferedReader( new InputStreamReader( chatSocket.getInputStream())); myReader = new ChatDisplayThread(this, inChat); myReader.start(); // CREATE A GAME game = new RiskGame(); unlimitedLocalMode = false; controller.newGame(false); setupPreview(); controller.showCardsFile( game.getCardsFile() , true); output=resb.getString( "core.join.created"); //if ( chatSocket==null ) { controller.closeGame(); throw new ConnectException("conection refused"); } outChat.println( RiskGame.SAVE_VERSION ); } catch (UnknownHostException e) { game = null; output=resb.getString( "core.join.error.unknownhost"); } catch (ConnectException e) { game = null; output=resb.getString( "core.join.error.connect"); } catch (IllegalArgumentException e) { game = null; output=resb.getString( "core.join.error.nothostname"); } catch (IOException e) { game = null; output=resb.getString( "core.join.error.002"); } catch (java.security.AccessControlException e) { game = null; output="AccessControlException:\n"+resb.getString( "core.error.applet"); } catch (Exception e) { // catch not being able to make a new game, so game is null output=resb.getString( "core.join.error.create")+" "+e.toString(); } if (game==null) { controller.showMessageDialog(output); } //} //else { // output=resb.getString( "core.join.error.001"); //} } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "join server"); } } // NEW SERVER else if (input.equals("startserver")) { if (StringT.hasMoreTokens()==false) { if ( chatter == null ) { // CREATE A SERVER try { chatter = new ChatArea(controller,port); output=resb.getString( "core.startserver.started"); controller.serverState(true); } catch(Exception e) { chatter = null; output=resb.getString( "core.startserver.error")+" "+e.getMessage(); controller.showMessageDialog(output); } } else { output=resb.getString( "core.startserver.error"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "startserver"); } } // KILL SERVER else if (input.equals("killserver")) { if (StringT.hasMoreTokens()==false) { if ( chatter != null ) { try { // shut down the server //if (chatter.serverSocket != null) { // chatter.serverSocket.close(); // chatter=null; //} if (chatter != null) { chatter.closeSocket(); chatter=null; } output=resb.getString( "core.killserver.killed"); controller.serverState(false); } catch (Exception e) { output=resb.getString( "core.killserver.error")+" "+e.getMessage(); } } else { output=resb.getString( "core.killserver.noserver"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "killserver"); } } else { // if there is no game and the command was unknown output=resb.getString( "core.loadgame.nogame"); } // if there was NO game controller.sendMessage(output, false, true ); setHelp(); getInput(); } // IN GAME COMMANDS else { //replace all country names with there numbers // 5 commands have to be checked: // capital x1 // trade x3 // placearmies x1 // attack x2 // movearmies x2 // send the message to all the clients String mtemp = myAddress+" " + message; if ( chatSocket == null ) { //GameParser( "game " + message ); // change for yura:lobby GameParser( mtemp ); } else { // if this is a network game outChat.println( mtemp ); } } //System.out.print("END PROCESSING\n"); } } catch(RuntimeException ex) { System.err.println("FAITAL ERROR IN RISK"); ex.printStackTrace(); run(); } } private void saveGameToUndoObject() { if ( unlimitedLocalMode ) { // the game is saved try { //Undo = new SealedObject( game, nullCipher ); Undo.reset(); ObjectOutputStream out = new ObjectOutputStream(Undo); out.writeObject(game); out.flush(); out.close(); } catch (Exception e) { System.out.print(resb.getString( "core.loadgame.error.undo") + "\n"); e.printStackTrace(); } } } /** * This parses the string, calls the relavant method and displays the correct error messages * @param mem The string needed for parsing */ public void GameParser(String message) { controller.sendDebug(message); game.addCommand(message); int oldState=game.getState(); boolean needInput=true; String input; String output=null; StringT = new StringTokenizer( message ); String Addr = GetNext(); if (Addr.equals("ERROR")) { // server has sent us a error String Pname = GetNext(); while ( StringT.hasMoreElements() ) { Pname = Pname +" "+ GetNext(); } controller.showMessageDialog(Pname); } else if (Addr.equals("DICE")) { // a server command int attSize = RiskGame.getNumber(GetNext()); int defSize = RiskGame.getNumber(GetNext()); output=resb.getString( "core.dice.rolling") + System.getProperty("line.separator") + resb.getString( "core.dice.results"); int att[] = new int[ attSize ]; output = output + " " + resb.getString( "core.dice.attacker"); for (int c=0; c< attSize ; c++) { att[c] = RiskGame.getNumber(GetNext()); output = output + " " + (att[c]+1); } int def[] = new int[ defSize ]; output = output + " " + resb.getString( "core.dice.defender"); for (int c=0; c< defSize ; c++) { def[c] = RiskGame.getNumber(GetNext()); output = output + " " + (def[c]+1); } output = output + System.getProperty("line.separator"); int result[] = game.battle( att, def ); if ( result[0]==1 ) { output = output + resb.getString( "core.dice.result"). replaceAll( "\\{0\\}", "" + result[2]).//defeated replaceAll( "\\{1\\}", "" + result[1]);//lost if (result[3]==0) { int n=((Country)game.getAttacker()).getArmies()-1; output=output + System.getProperty("line.separator") + resb.getString( "core.dice.notdefeated") + " "; if (n > 0) { if (n > 3) { n=3; } output=output + resb.getString( "core.dice.attackagain").replaceAll( "\\{0\\}", "" + n); Player attackingPlayer = ((Country)game.getAttacker()).getOwner(); if ( showHumanPlayerThereInfo( attackingPlayer ) ) { controller.showDice(n, true); } } else { output=output + resb.getString( "core.dice.noattackagain"); } } else { Player attackingPlayer = ((Country)game.getAttacker()).getOwner(); if ( showHumanPlayerThereInfo( attackingPlayer ) ) { //controller.setSlider(result[4], result[5]); controller.setSlider(result[4], ((Country)game.getAttacker()).getColor(), ((Country)game.getDefender()).getColor() ); } output=output + System.getProperty("line.separator") + resb.getString( "core.dice.defeated") + " "; if ( result[3]==2 ) { output=output + resb.getString( "core.dice.eliminated") + " "; } // if there is only one amount of troops u can move if ( result[4] == result[5] ) { int noa = game.moveAll(); int ma = game.moveArmies( noa ); //Moved {0} armies to captured country. output=output + resb.getString( "core.dice.armiesmoved").replaceAll( "\\{0\\}", "" + noa); if (ma==2) { output=output + whoWon(); } } else { //How many armies do you wish to move? ({0} to {1}) output=output + resb.getString( "core.dice.howmanyarmies") .replaceAll( "\\{0\\}", "" + result[4]) .replaceAll( "\\{1\\}", "" + result[5]); } } if ( battle ) { controller.showDiceResults( att, def ); try{ Thread.sleep(1000); } catch(InterruptedException e){} } } else { output=resb.getString( "core.dice.error.unabletoroll"); } // ==1 this fixes the automove bug, when u need to trade after rolling and automove if ( game.getState()!=RiskGame.STATE_ROLLING && game.getState()!=RiskGame.STATE_DEFEND_YOURSELF) { closeBattle(); } } else if (Addr.equals("PLAYER")) { // a server command String Pname = GetNext(); while ( StringT.hasMoreElements() ) { Pname = Pname +" "+ GetNext(); } Player p = game.setCurrentPlayer( Pname ); controller.sendMessage("Game started", false, false); // moved to startgame for lobby //if ( chatSocket != null ) { // controller.startGame(false); //} //else { // controller.startGame(true); //} output=resb.getString( "core.player.randomselected").replaceAll( "\\{0\\}", p.getName()); if ( game.getGameMode()==RiskGame.MODE_SECRET_MISSION || autoplaceall==true ) { needInput=false; } else { saveGameToUndoObject(); } } else if (Addr.equals("CARD")) { // a server command // if the player deserves a card if ( StringT.hasMoreTokens() ) { // get the cards Vector cards = game.getCards(); String name = GetNext(); Card card = game.findCard( name ); ((Player)game.getCurrentPlayer()).giveCard( card ); // find the card and remove it cards.remove( card ); cards.trimToSize(); if ( showHumanPlayerThereInfo( game.getCurrentPlayer() ) ) { String cardName; if (name.equals(Card.WILDCARD)) { cardName = name; } else { cardName = card.getName() + " " + game.getCountryInt( Integer.parseInt(name) ).getName(); } controller.sendMessage("You got a new card: \"" + cardName +"\"", false , false); } } Player newplayer = game.endGo(); output = resb.getString( "core.player.newselected").replaceAll( "\\{0\\}", newplayer.getName()); // this is not a bug! (Easter egg) if ( unlimitedLocalMode && game.getSetup() && newplayer.getName().equals("Theo")) { newplayer.addArmies( newplayer.getExtraArmies() ); } saveGameToUndoObject(); } else if (Addr.equals("PLACE")) { // a server command Country c = game.getCountryInt( Integer.parseInt( GetNext() ) ); game.placeArmy( c ,1); controller.sendMessage( resb.getString( "core.place.oneplacedin").replaceAll( "\\{0\\}", c.getName()) , false, false); // Display output=resb.getString( "core.place.autoplaceok"); } else if (Addr.equals("PLACEALL")) { // a server command for (int c=0; c< game.getNoCountries() ; c++) { Country t = game.getCountryInt( Integer.parseInt( GetNext() ) ); game.placeArmy( t ,1); controller.sendMessage( resb.getString("core.place.getcountry") .replaceAll( "\\{0\\}", ((Player)game.getCurrentPlayer()).getName()) .replaceAll( "\\{1\\}", t.getName()) // Display , false, false); game.endGo(); } // the game is saved saveGameToUndoObject(); controller.sendMessage("Auto place all successful.", false, false); //New player selected: {0}. output=resb.getString( "core.player.newselected").replaceAll( "\\{0\\}", ((Player)game.getCurrentPlayer()).getName()); } else if (Addr.equals("MISSION")) { // a server command Vector m = game.getMissions(); Vector p = game.getPlayers(); for (int c=0; c< p.size() ; c++) { int i = RiskGame.getNumber( GetNext() ); ((Player)p.elementAt(c)).setMission( (Mission)m.elementAt(i) ); m.removeElementAt(i); } output=null; needInput=false; } else { // parse this normal cammand String echo = message.substring( Addr.length()+1 ); if (game != null && game.getCurrentPlayer() != null && game.getState()!=RiskGame.STATE_GAME_OVER ) { if ( ((Player)game.getCurrentPlayer()).getType()==Player.PLAYER_HUMAN ) { // if the player is human controller.sendMessage( ((Player)game.getCurrentPlayer()).getName()+ "("+resb.getString("newgame.player.type.human")+")>"+echo, false, false ); } else if ( ((Player)game.getCurrentPlayer()).getType()==Player.PLAYER_AI_CRAP ) { // if the player is AI controller.sendMessage( ((Player)game.getCurrentPlayer()).getName()+ "("+resb.getString("newgame.player.type.crapai")+")>"+echo, false, false ); } else if ( ((Player)game.getCurrentPlayer()).getType()==Player.PLAYER_AI_EASY ) { // if the player is AI controller.sendMessage( ((Player)game.getCurrentPlayer()).getName()+ "("+resb.getString("newgame.player.type.easyai")+")>"+echo, false, false ); } else if ( ((Player)game.getCurrentPlayer()).getType()==Player.PLAYER_AI_HARD ) { // if the player is AI controller.sendMessage( ((Player)game.getCurrentPlayer()).getName()+ "("+resb.getString("newgame.player.type.hardai")+")>"+echo, false, false ); } } else { controller.sendMessage( "game>" + echo, false, false ); } //if (StringT.hasMoreTokens()) { input=GetNext(); output=""; // CLOSE GAME if (input.equals("closegame")) { if (StringT.hasMoreTokens()==false) { boolean doclose=false; if ( chatSocket == null ) { // LOCAL GAME/ OR LOBBY CLIENT doclose = true; } else { // NETWORK GAME if ( myAddress.equals(Addr) ) { // only on the pc of who called it doclose = true; try { outChat.close(); inChat.close(); chatSocket.shutdownInput(); chatSocket.shutdownOutput(); chatSocket.close(); } catch (IOException except) { } chatSocket = null; } else { // @todo, do we set needinput to flase, so that ai wont go twice, if its there go // but then if there needinput was ignored coz this command was in the inbox, no needinput will get called // if it is NOT there go the set needinput to false if (game.getCurrentPlayer()!=null && !(game.getCurrentPlayer().getAddress().equals(Addr) && game.getCurrentPlayer().getType() == Player.PLAYER_HUMAN)) { needInput = false; } // if this command stopped the last needInput from being called, then this will be screwed // at worst AI or human wont get a chance to put any input in, game stalled output = "someone has gone: "; // get all the players and make all with the ip of the leaver become nutral Vector leavers = game.getPlayers(); String newPlayerAddress=""; // find the first player that is NOT playing on this computer // this happens in the same way on each computer for (int c=0; c< leavers.size() ; c++) { if ( !((Player)leavers.elementAt(c)).getAddress().equals(Addr) ) { newPlayerAddress = ((Player)leavers.elementAt(c)).getAddress(); break; } } for (int c=0; c < leavers.size(); c++) { Player patc = ((Player)leavers.elementAt(c)); if ( patc.getAddress().equals(Addr) ) { if ( patc.getType() == Player.PLAYER_HUMAN ) { output = output + patc.getName()+" "; if (game.getState() == RiskGame.STATE_NEW_GAME ) { // should never return false if ( game.delPlayer( patc.getName() ) ) { c--; controller.delPlayer( patc.getName() ); patc = null; } } else { patc.setType( Player.PLAYER_AI_CRAP ); } } if (patc!=null) { if (newPlayerAddress!=null) { patc.setAddress( newPlayerAddress ); } else { // this means there are only spectators left // so nothing really needs to be done // game will stop, but hay there r no more players } } } } } } if (doclose) { // does not work from here closeBattle(); controller.closeGame(); output=resb.getString( "core.close.closed"); game = null; } //else { // output=resb.getString( "core.close.error.unable"); //} } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "closegame"); } } /* THIS DOES NOT WORK AT ALL, ONLY HERE FOR HISTORY // LEAVE GAME else if (input.equals("leave")) { if (StringT.hasMoreTokens()==false) { if (chatSocket != null) { if (game.getState() != RiskGame.STATE_NEW_GAME ) { // get all the players and make all with the ip of the leaver become nutral Vector leavers = game.getPlayers(); for (int c=0; c< leavers.size() ; c++) { if ( ((Player)leavers.elementAt(c)).getAddress().equals(Addr) ) { ((Player)leavers.elementAt(c)).setType(3); WRONG! ((Player)leavers.elementAt(c)).setAddress("all"); WRONG! } } } try { // shut down the client if (chatSocket !=null && myAddress.equals(Addr) ) { game = null; outChat.close(); inChat.close(); chatSocket.close(); chatSocket = null; } } catch (IOException except) { //System.out.println("IOException in main"); } if (game == null) { // does not work from here closeBattle(); controller.closeGame(); output=resb.getString( "core.leave.left"); } else { //{0} has left the game. if (game.getState()==RiskGame.STATE_NEW_GAME) { output = "someone has gone"; } else { This will not work if the player quits when its not there go output = resb.getString("core.leave.otherhasleft").replaceAll("\\{0\\}", ((Player)game.getCurrentPlayer()).getName()); } } } else { output=resb.getString( "core.leave.error.nonetwork"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "leave"); } } */ else if (game.getState()==RiskGame.STATE_NEW_GAME) { if (input.equals("choosemap")) { if (StringT.countTokens() >= 1) { String filename=GetNext(); while ( StringT.hasMoreElements() ) { filename = filename + " " + GetNext(); } try { boolean yesmissions = game.setMapfile(filename); setupPreview(); controller.showCardsFile( game.getCardsFile() , yesmissions ); //New map file selected: "{0}" (cards have been reset to the default for this map) output=resb.getString( "core.choosemap.mapselected").replaceAll( "\\{0\\}", filename); } catch (Exception e) { output=resb.getString( "core.choosemap.error.unable"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "choosemap filename"); } } else if (input.equals("choosecards")) { if (StringT.countTokens() >= 1) { String filename=GetNext(); while ( StringT.hasMoreElements() ) { filename = filename + " " + GetNext(); } try { boolean yesmissions = game.setCardsfile(filename); controller.showCardsFile( game.getCardsFile() , yesmissions ); //New cards file selected: "{0}" output=resb.getString( "core.choosecards.chosen").replaceAll( "\\{0\\}", filename); } catch (Exception e) { output=resb.getString( "core.choosecards.error.unable"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "choosecards filename"); } } else if (input.equals("newplayer")) { if (StringT.countTokens()>=3) { String type=GetNext(); if (type.equals("ai")) { type = type+" "+GetNext(); } int t=getType(type); String c=GetNext(); Color color=RiskGame.getColor( c ); String name=""; while ( StringT.hasMoreElements() ) { name = name + GetNext(); if ( StringT.hasMoreElements() ) { name = name + " "; } } name = name.replaceAll("\\$","").replaceAll("\\\\","").replaceAll(" +"," "); // YURA:LOBBY CHANGE // ( ( chatSocket != null && game.addPlayer(t, name, color, Addr) ) || ( chatSocket == null && game.addPlayer(t, name, color, "all") ) ) // name.replaceAll(" ","")+"#"+String.valueOf( Math.round(Math.random()*Long.MAX_VALUE) ) if ( color != null && t != -1 && !name.equals("") && ( ( unlimitedLocalMode && game.addPlayer(t, name, color, "LOCALGAME" ) ) || ( !unlimitedLocalMode && game.addPlayer(t, name, color, Addr) ) ) ) { //New player created, name: {0} color: {1} output=resb.getString( "core.newplayer.created") .replaceAll( "\\{0\\}", name) .replaceAll( "\\{1\\}", c); controller.addPlayer(t, name, color, Addr); //System.out.print("New player has Address: "+Addr+"\n"); } else { output=resb.getString( "core.newplayer.error.unable"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "newplayer type (skill) color name"); } } else if (input.equals("delplayer")) { if (StringT.countTokens()>=1) { String name=GetNext(); while ( StringT.hasMoreElements() ) { name = name +" "+ GetNext(); } if ( game.delPlayer(name) ) { controller.delPlayer(name); output=resb.getString( "core.delplayer.deleted").replaceAll( "\\{0\\}", name); } else { output=resb.getString( "core.delplayer.error.unable"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "delplayer name"); } } else if (input.equals("info")) { if (StringT.hasMoreTokens()==false) { output=resb.getString( "core.info.title") + "\n"; Vector players = game.getPlayers(); for (int a=0; a< players.size() ; a++) { output = output + resb.getString( "core.info.player") + " " + ((Player)players.elementAt(a)).getName() +"\n"; } output = output + resb.getString( "core.info.mapfile") + " "+ game.getMapFile() +"\n"; output = output + resb.getString( "core.info.cardsfile") + " "+ game.getCardsFile() ; } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "info"); } } else if (input.equals("autosetup")) { if (StringT.hasMoreTokens()==false) { if ( game.getPlayers().size() == 0) { if (!replay) { for (int c=1;c<=RiskGame.MAX_PLAYERS;c++) { parser("newplayer " + riskconfig.getProperty("default.player"+c+".type")+" "+ riskconfig.getProperty("default.player"+c+".color")+" "+ riskconfig.getProperty("default.player"+c+".name") ); } output = resb.getString( "core.info.autosetup"); } else { output = "replay mode, nothing done"; } } else { output = resb.getString( "core.info.autosetup.error"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "autosetup"); } } else if (input.equals("startgame")) { if (StringT.countTokens() >= 2 && StringT.countTokens() <= 4) { int n=((Vector)game.getPlayers()).size(); int newgame_type = -1; int newgame_cardType = -1; boolean newgame_autoplaceall = false; boolean newgame_recycle = false; boolean nocrap = true; while (StringT.hasMoreTokens()) { String newOption = GetNext(); if ( newOption.equals("domination") ) { newgame_type = RiskGame.MODE_DOMINATION; } else if ( newOption.equals("capital") ) { newgame_type = RiskGame.MODE_CAPITAL; } else if ( newOption.equals("mission") ) { newgame_type = RiskGame.MODE_SECRET_MISSION; } else if ( newOption.equals("increasing") ) { newgame_cardType = RiskGame.CARD_INCREASING_SET; } else if ( newOption.equals("fixed") ) { newgame_cardType = RiskGame.CARD_FIXED_SET; } else if ( newOption.equals("autoplaceall") ) { newgame_autoplaceall = true; } else if ( newOption.equals("recycle") ) { newgame_recycle = true; } else { nocrap = false; } } // checks all the options are correct to start a game if ( newgame_type!=-1 && newgame_cardType!=-1 && n>=2 && n<=RiskGame.MAX_PLAYERS && nocrap) { autoplaceall = newgame_autoplaceall; try { game.startGame(newgame_type,newgame_cardType,newgame_recycle); } catch (Exception e) { e.printStackTrace(); } } // this checks if the game was able to start or not if (game.getState() != RiskGame.STATE_NEW_GAME ) { controller.noInput(); controller.startGame( unlimitedLocalMode ); if (!replay) { // this cant be if(unlimitedLocalMode) as then it wont get called on the lobby server, as it IS restricted if ( chatSocket == null ) { GameParser( "PLAYER " + game.getRandomPlayer() ); } else if ( myAddress.equals(Addr) ) { // if this is a network game outChat.println( "PLAYER " + game.getRandomPlayer() ); // recursive call } // do that mission thing if (game.getGameMode()== RiskGame.MODE_SECRET_MISSION ) { // do that mission thing if ( chatSocket == null || myAddress.equals(Addr) ) { // give me a array of random numbers Random r = new Random(); int a = game.getNoMissions(); int b = game.getNoPlayers(); String outputa="MISSION"; for (int c=0; c< b ; c++) { outputa=outputa + " " + r.nextInt(a) ; a--; } if (chatSocket == null) { GameParser( outputa ); } else if ( myAddress.equals(Addr) ) { outChat.println( outputa ); } } } // do that autoplace thing if ( game.getGameMode()==RiskGame.MODE_SECRET_MISSION || autoplaceall==true ) { if ( chatSocket == null || myAddress.equals(Addr) ) { Vector a = game.shuffleCountries(); String outputb="PLACEALL"; for (int c=0; c< a.size() ; c++) { outputb=outputb + " " + ((Country)a.elementAt(c)).getColor(); //outputb=outputb + " " + ((Country)a.elementAt(c)).getName() ; } if (chatSocket == null) { GameParser( outputb ); } else if ( myAddress.equals(Addr) ) { outChat.println( outputb ); } } } } output=null; needInput=false; } else { output=resb.getString( "core.start.error.players"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "startgame gametype cardtype (autoplaceall recycle)"); } } // REPLAY A GAME else if (input.equals("play")) { if (StringT.countTokens() >= 1) { String filename = GetNext(); while ( StringT.hasMoreElements() ) { filename = filename + " " + GetNext(); } try { URL url; // TODO dont think this can ever work as an applet anyway //if (Risk.applet==null) { url = (new File(filename)).toURI().toURL(); //} //else { // url = new URL( risk.engine.Risk.applet.getCodeBase() , filename ); //} BufferedReader bufferin=new BufferedReader(new InputStreamReader(url.openStream())); //create thread with bufferin class Replay extends Thread { private Risk risk; private BufferedReader bufferin; public Replay(Risk r, BufferedReader in) { risk=r; bufferin=in; } public void run() { try { String input = bufferin.readLine(); while(input != null) { //System.out.print(input+"\n"); risk.GameParser(input); input = bufferin.readLine(); } bufferin.close(); } catch(Exception error) { error.printStackTrace(); } //set replay off replay = false; getInput(); } }; Thread replaythread = new Replay(this, bufferin); //set boolean that replay is on replay = true; replaythread.start(); output="playing \""+filename+"\""; } catch(Exception error) { output="unable to play \""+filename+"\""; } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "play filename"); } } else { output=resb.getString( "core.error.incorrect").replaceAll( "\\{0\\}", "newplayer, delplayer, startgame, choosemap, choosecards, info, autosetup"); } } // UNDO else if (input.equals("undo")) { if ( StringT.hasMoreTokens()==false ) { if ( unlimitedLocalMode ) { try { if (Undo!=null && Undo.size()!=0) { ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(Undo.toByteArray())); game = (RiskGame)in.readObject(); //game = (RiskGame)Undo.getObject( nullCipher ); output =resb.getString( "core.undo.undone"); } else { output =resb.getString( "core.undo.error.unable"); } } catch (Exception e) { System.out.print(resb.getString( "core.loadgame.error.undo") + "\n"); e.printStackTrace(); } } else { output = resb.getString( "core.undo.error.network"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "undo"); } } // REPLAY A GAME FROM THE GAME FILE else if (input.equals("replay")) { if ( StringT.hasMoreTokens()==false ) { if ( unlimitedLocalMode ) { try { Vector replayCommands = game.getCommands(); replayCommands.remove( replayCommands.size()-1 ); saveGameToUndoObject(); game = new RiskGame(); replay = true; for (Enumeration e = replayCommands.elements() ; e.hasMoreElements() ;) { GameParser( (String)e.nextElement() ); //try{ Thread.sleep(1000); } //catch(InterruptedException e){} } replay = false; output="replay of game finished"; } catch (Exception e) { System.out.print(resb.getString( "core.loadgame.error.undo") + "\n"); e.printStackTrace(); } } else { output = resb.getString( "core.undo.error.network"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "replay"); } } // SAVE GAME else if (input.equals("savegame")) { if (StringT.countTokens() >= 1) { if ( unlimitedLocalMode ) { Vector replayCommands = game.getCommands(); replayCommands.remove( replayCommands.size()-1 ); String filename = GetNext(); while ( StringT.hasMoreElements() ) { filename = filename + " " + GetNext(); } if ( battle==false && game.saveGame(filename) ) { output=resb.getString( "core.save.saved"); } else { output=resb.getString( "core.save.error.unable"); } } else { output = resb.getString( "core.save.error.unable" ); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "savegame filename"); } } else if (input.equals("showmission")) { if (StringT.hasMoreTokens()==false) { // only show to the right player! if ( showHumanPlayerThereInfo( game.getCurrentPlayer() ) ) { output = resb.getString( "core.showmission.mission") + " " + getCurrentMission(); } else { output=resb.getString( "core.showmission.error"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "showmission"); } } else if (input.equals("showarmies")) { if (StringT.hasMoreTokens()==false) { if ( game.getState() != RiskGame.STATE_NEW_GAME) { Country[] v = game.getCountries(); output=resb.getString( "core.showarmies.countries") + System.getProperty("line.separator"); for (int c=0; c< v.length ; c++) { output = output + v[c].getColor() + " " + v[c].getName()+" - "; // Display if ( v[c].getOwner() != null ) { output = output + ((Player)v[c].getOwner()).getName() +" ("+v[c].getArmies() +")"; if (game.getGameMode() == 2 && game.getSetup() && game.getState() !=RiskGame.STATE_SELECT_CAPITAL) { Vector players = game.getPlayers(); for (int a=0; a< players.size() ; a++) { if ( ((Player)players.elementAt(a)).getCapital() != null && ((Player)players.elementAt(a)).getCapital() == v[c] ) { output = output + " " + resb.getString( "core.showarmies.captial") .replaceAll( "\\{0\\}", ((Player)players.elementAt(a)).getName()); } } } output = output + System.getProperty("line.separator"); } else { output = output + resb.getString( "core.showarmies.noowner") + System.getProperty("line.separator"); } } } else { output=resb.getString( "core.showarmies.error.unable"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "showarmies"); } } else if (input.equals("showcards")) { if (StringT.hasMoreTokens()==false) { if ( showHumanPlayerThereInfo( game.getCurrentPlayer() ) ) { Vector c = ((Player)game.getCurrentPlayer()).getCards(); if (c.size() == 0) { output=resb.getString( "core.showcards.nocards"); } else { output=resb.getString( "core.showcards.youhave"); for (int a=0; a< c.size() ; a++) { if ( ((Card)c.elementAt(a)).getName().equals(Card.WILDCARD) ) { output = output + " " + Card.WILDCARD; // resb.getString( "core.showcards.wildcard"); // dont use this as user needs to type it in } else { output = output + " \"" + ((Card)c.elementAt(a)).getName() +" "+ ((Country)((Card)c.elementAt(a)).getCountry()).getName() +" ("+((Country)((Card)c.elementAt(a)).getCountry()).getColor()+")\""; // Display } } } if(game.getCardMode()==RiskGame.CARD_FIXED_SET) { output = output+"\n"+ resb.getString("cards.fixed"); } else { output = output+"\n"+ resb.getString("cards.nexttrade").replaceAll( "\\{0\\}", "" + getNewCardState()); } } else { output=resb.getString( "core.showcards.error.unable"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "showcards"); } } else if (input.equals("autoendgo")) { if (StringT.hasMoreTokens()==false) { String strSelected; if ( game.getCurrentPlayer().getAutoEndGo() ) { strSelected = "core.autoendgo.on"; } else { strSelected = "core.autoendgo.off"; } output = resb.getString( "core.autoendgo.setto").replaceAll( "\\{0\\}", resb.getString( strSelected)); } else if (StringT.countTokens() == 1) { String option = GetNext(); if (option.equals("on") ) { game.getCurrentPlayer().setAutoEndGo(true); output = resb.getString( "core.autoendgo.setto").replaceAll( "\\{0\\}", resb.getString( "core.autoendgo.on")); } else if (option.equals("off") ) { game.getCurrentPlayer().setAutoEndGo(false); output = resb.getString( "core.autoendgo.setto").replaceAll( "\\{0\\}", resb.getString( "core.autoendgo.off")); } else { output=resb.getString( "core.autoendgo.error.unknown").replaceAll( "\\{0\\}", option); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "autoendgo on/off"); } } else if (input.equals("autodefend")) { if (StringT.hasMoreTokens()==false) { String strSelected; if ( game.getCurrentPlayer().getAutoDefend() ) { strSelected = "core.autodefend.on"; } else { strSelected = "core.autodefend.on"; } output = resb.getString( "core.autodefend.setto").replaceAll( "\\{0\\}", resb.getString( strSelected)); } else if (StringT.countTokens() == 1) { String option = GetNext(); if (option.equals("on") ) { game.getCurrentPlayer().setAutoDefend(true); output = resb.getString( "core.autodefend.setto").replaceAll( "\\{0\\}", resb.getString( "core.autodefend.on")); } else if (option.equals("off") ) { game.getCurrentPlayer().setAutoDefend(false); output = resb.getString( "core.autodefend.setto").replaceAll( "\\{0\\}", resb.getString( "core.autodefend.off")); } else { output=resb.getString( "core.autodefend.error.unknown").replaceAll( "\\{0\\}", option); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "autodefend on/off"); } } else if (game.getState()==RiskGame.STATE_TRADE_CARDS) { if (input.equals("trade")) { if (StringT.countTokens()==3) { // trade Japan wildcard Egypt int noa=0; Card cards[] = game.getCards(GetNext(),GetNext(),GetNext()); if (cards[0] != null && cards[1] != null && cards[2] != null) { // if the player DOES HAVE all the cards he chose noa = game.trade(cards[0], cards[1], cards[2]); } if ( noa != 0 ) { // if the trade WAS SUCCESSFUL output=resb.getString( "core.trade.traded").replaceAll( "\\{0\\}", "" + noa); } else { output=resb.getString( "core.trade.error.unable"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "trade card card card"); } } else if (input.equals("endtrade")) { if (StringT.hasMoreTokens()==false) { if ( game.endTrade() ) { output=resb.getString( "core.trade.endtrade"); } else { output=resb.getString( "core.trade.end.error.unable"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "endtrade"); } } else { output=resb.getString( "core.error.incorrect").replaceAll( "\\{0\\}", "showcards, trade, endtrade"); } } else if (game.getState()==RiskGame.STATE_PLACE_ARMIES) { if (input.equals("placearmies")) { if (StringT.countTokens()==2) { String country=GetNext(); int c=RiskGame.getNumber( country ); int num=RiskGame.getNumber( GetNext() ); Country t; if (c != -1) { t=game.getCountryInt(c); } else { //YURA:LANG t=game.getCountryByName(country); t=null; } if ( t != null && num!=-1 && !( game.getGameMode() == 1 && t.getOwner() == null) && !( game.getGameMode() == 3 && t.getOwner() == null) ) { int result = game.placeArmy(t, num); if (result!=0) { //{0} new army placed in: {1} output= resb.getString( "core.place.placed") .replaceAll( "\\{0\\}", "" + num) .replaceAll( "\\{1\\}", t.getName()); // Display if (result == 2) { output=output + whoWon(); } } else { output=resb.getString( "core.place.error.unable"); } } else { output=resb.getString( "core.place.error.invalid"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "placearmies country number"); } } else if (input.equals("autoplace")) { if (StringT.hasMoreTokens()==false) { if ( game.NoEmptyCountries() == false ) { if (!replay) { if ( chatSocket == null) { GameParser( "PLACE " + game.getEmptyCountry() ); } else if ( myAddress.equals(Addr) ) { // if this is a network game outChat.println( "PLACE " + game.getEmptyCountry() ); // recursive call } } needInput=false; output = null; } else { output = resb.getString( "core.autoplace.error.unable"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "autoplace"); } } else { output=resb.getString( "core.error.incorrect").replaceAll( "\\{0\\}", "showarmies, placearmies, autoplace"); } } else if (game.getState()==RiskGame.STATE_ATTACKING) { if (input.equals("attack")) { if (StringT.countTokens()==2) { String arg1=GetNext(); String arg2=GetNext(); int a1=RiskGame.getNumber(arg1); int a2=RiskGame.getNumber(arg2); Country country1; Country country2; if (a1 != -1) { country1=game.getCountryInt(a1); } else { //YURA:LANG country1=game.getCountryByName(arg1); country1=null; } if (a2 != -1) { country2=game.getCountryInt(a2); } else { //YURA:LANG country2=game.getCountryByName(arg2); country2=null; } int a[]=game.attack(country1, country2); if ( a[0]==1 ) { //Attack {0} ({1}) with {2} ({3}). (You can use up to {4} dice to attack) output = resb.getString( "core.attack.attacking") .replaceAll( "\\{0\\}", country2.getName()) // Display .replaceAll( "\\{1\\}", "" + country2.getArmies()) .replaceAll( "\\{2\\}", country1.getName()) // Display .replaceAll( "\\{3\\}", "" + country1.getArmies()) .replaceAll( "\\{4\\}", "" + a[1]); Player attackingPlayer = ((Country)game.getAttacker()).getOwner(); if ( showHumanPlayerThereInfo( attackingPlayer ) ) { controller.showDice(a[1], true); } } else { output=resb.getString( "core.attack.error.unable"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "attack country country"); } } else if (input.equals("endattack")) { if (StringT.hasMoreTokens()==false) { if ( game.endAttack() ) { output=resb.getString( "core.attack.end.ended"); } else { output=resb.getString( "core.attack.end.error.unable"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "endattack"); } } else { output=resb.getString( "core.error.incorrect").replaceAll( "\\{0\\}", "attack, endattack"); } } else if (game.getState()==RiskGame.STATE_ROLLING) { if (input.equals("roll")) { if (StringT.countTokens()==1) { int dice=RiskGame.getNumber( GetNext() ); if ( dice != -1 && game.rollA(dice) ) { if ( battle ) { controller.setNODAttacker(dice); } int n=((Country)game.getDefender()).getArmies(); if (game.getSimone()) { if (n>3) { n=3; } } else { if (n>2) { n=2; } } //Rolled attacking dice, {0} defend yourself! (you can use up to {1} dice to defend) output = resb.getString( "core.roll.rolled") .replaceAll( "\\{0\\}", ((Player)game.getCurrentPlayer()).getName()) .replaceAll( "\\{1\\}", "" + n); Player defendingPlayer = ((Country)game.getDefender()).getOwner(); if ( showHumanPlayerThereInfo(defendingPlayer) ) { controller.showDice(n, false); } } else { output=resb.getString( "core.roll.error.unable"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "roll number"); } } else if (input.equals("retreat")) { if (StringT.hasMoreTokens()==false) { if ( game.retreat() ) { output=resb.getString( "core.retreat.retreated"); } else { output=resb.getString( "core.retreat.error.unable"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "retreat"); } } else { output=resb.getString( "core.error.incorrect").replaceAll( "\\{0\\}", "roll, retreat"); } } else if (game.getState()==RiskGame.STATE_BATTLE_WON) { if (input.equals("move")) { if (StringT.countTokens()==1) { String num = GetNext(); int noa; if (num.equals("all")) { noa=game.moveAll(); } else { noa=RiskGame.getNumber( num ); } int mov=game.moveArmies(noa); if ( mov != 0 ) { //Moved {0} armies to captured country. output = resb.getString( "core.move.moved").replaceAll( "\\{0\\}", "" + noa); if (mov == 2) { output=output + whoWon(); } } else { output=resb.getString( "core.move.error.unable"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "move number"); } } else { output=resb.getString( "core.error.incorrect").replaceAll( "\\{0\\}", "move"); } } else if (game.getState()==RiskGame.STATE_FORTIFYING) { if (input.equals("movearmies")) { if (StringT.countTokens()==3) { String arg1=GetNext(); String arg2=GetNext(); int a1=RiskGame.getNumber(arg1); int a2=RiskGame.getNumber(arg2); Country country1; Country country2; if (a1 != -1) { country1=game.getCountryInt(a1); } else { //YURA:LANG country1=game.getCountryByName(arg1); country1=null; } if (a2 != -1) { country2=game.getCountryInt(a2); } else { //YURA:LANG country2=game.getCountryByName(arg2); country2=null; } int noa=RiskGame.getNumber( GetNext() ); if ( game.moveArmy(country1, country2, noa) ) { //Moved {0} armies from {1} to {2}. output = resb.getString( "core.tacmove.movedfromto") .replaceAll("\\{0\\}", "" + noa) .replaceAll("\\{1\\}", country1.getName()) // Display .replaceAll("\\{2\\}", country2.getName()); // Display } else { output=resb.getString( "core.tacmove.error.unable"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "movearmies country country number"); } } else if (input.equals("nomove")) { if (StringT.hasMoreTokens()==false) { if ( game.noMove() ) { output=resb.getString( "core.tacmove.no.nomoves"); } else { output=resb.getString( "core.tacmove.no.error.unable"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "nomove"); } } else { output=resb.getString( "core.error.incorrect").replaceAll( "\\{0\\}", "movearmies, nomove"); } } else if (game.getState()==RiskGame.STATE_END_TURN) { if (input.equals("endgo")) { if (StringT.hasMoreTokens()==false) { needInput=false; output=null; controller.sendMessage(resb.getString( "core.endgo.ended"), false , false); DoEndGo(); } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "endgo"); } } else { output=resb.getString( "core.error.incorrect").replaceAll( "\\{0\\}", "emdgo"); } } else if (game.getState()==RiskGame.STATE_GAME_OVER) { if (input.equals("continue")) { if (StringT.hasMoreTokens()==false) { if ( game.continuePlay() ) { output=resb.getString( "core.continue.successful"); } else { output=resb.getString( "core.continue.error.unable"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "continue"); } } else { //The game is over. {0} won! (current possible commands are: continue) output = resb.getString( "core.gameover.won").replaceAll( "\\{0\\}", ((Player)game.getCurrentPlayer()).getName()); } } else if (game.getState()==RiskGame.STATE_SELECT_CAPITAL) { if (input.equals("capital")) { if (StringT.countTokens()==1) { String strCountry = GetNext(); int nCountryId = RiskGame.getNumber(strCountry); Country t; if (nCountryId != -1) { t = game.getCountryInt( nCountryId); } else { //YURA:LANG t = game.getCountryByName( strCountry); t=null; } if ( t != null && game.setCapital(t) ) { if ( showHumanPlayerThereInfo( game.getCurrentPlayer() ) ) { output=resb.getString( "core.capital.selected").replaceAll( "\\{0\\}", t.getName()); // Display } else { output=resb.getString( "core.capital.hasbeenselected"); } } else { output=resb.getString( "core.capital.error.unable"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "capital country"); } } else { output=resb.getString( "core.error.incorrect").replaceAll( "\\{0\\}", "capital"); } } else if (game.getState()==RiskGame.STATE_DEFEND_YOURSELF) { if (input.equals("roll")) { if (StringT.countTokens()==1) { int dice=RiskGame.getNumber( GetNext() ); if ( dice != -1 && game.rollD(dice) ) { if ( battle ) { controller.setNODDefender(dice); try{ Thread.sleep(500); } catch(InterruptedException e){} } // client does a roll, and this is not called if ( !replay && (chatSocket == null || myAddress.equals(Addr)) ) { // recursive call int[] attackerResults = game.rollDice( game.getAttackerDice() ); int[] defenderResults = game.rollDice( game.getDefenderDice() ); String serverRoll = "DICE "; serverRoll = serverRoll + attackerResults.length + " "; serverRoll = serverRoll + defenderResults.length + " "; for (int c=0; c< attackerResults.length ; c++) { serverRoll = serverRoll + attackerResults[c] + " "; } for (int c=0; c< defenderResults.length ; c++) { serverRoll = serverRoll + defenderResults[c] + " "; } if (chatSocket == null ) { GameParser( serverRoll ); } else if ( myAddress.equals(Addr) ) { outChat.println( serverRoll ); } } output=null; needInput=false; } else { output=resb.getString( "core.roll.error.unable"); } } else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "roll number"); } } else { output=resb.getString( "core.error.incorrect").replaceAll( "\\{0\\}", "roll"); } } else { output=resb.getString( "core.error.unknownstate"); } //} // this was the end of "if there is somthing to pass" but not needed any more if (game != null ) { //System.out.print("oldstate = " +oldState+" newstate = " +game.getState()+"\n"); if (game.getState()==RiskGame.STATE_ROLLING && battle==false) { Player attackingPlayer = ((Country)game.getAttacker()).getOwner(); Player defendingPlayer = ((Country)game.getDefender()).getOwner(); if ( showHumanPlayerThereInfo(attackingPlayer) || showHumanPlayerThereInfo(defendingPlayer) ) { controller.openBattle( ((Country)game.getAttacker()).getColor() , ((Country)game.getDefender()).getColor() ); battle=true; } } // if someone retreats else if ( game.getState()==RiskGame.STATE_ATTACKING ) { closeBattle(); } } }// end of parse of normal command // give a output if there is one if (output!=null) { // give a output if (game==null) { controller.sendMessage(output, false, true ); setHelp(); } else if ( game.getState()==RiskGame.STATE_NEW_GAME ) { controller.sendMessage(output, false, true ); setHelp(); } else if ( game.getState()==RiskGame.STATE_GAME_OVER ) { controller.sendMessage(output, true, true ); setHelp(); } else if (game.getState()==RiskGame.STATE_END_TURN) { // if ( game.getCurrentPlayer().getAutoEndGo() && chatSocket == null ) { // @todo:????? if ( game.getCurrentPlayer().getAutoEndGo() ) { controller.sendMessage(output, false, false ); } else { controller.sendMessage(output, true, true ); setHelp(); } } else {// if player type is human or neutral or ai controller.sendMessage(output, true, true ); if ( inbox.isEmpty() ) setHelp(); } } // check to see if the players go should be ended if ( game != null && game.getState()==RiskGame.STATE_END_TURN && game.getCurrentPlayer().getAutoEndGo() ) { needInput=false; DoEndGo(); } // ask for input if u need one if (needInput && inbox.isEmpty() ) { getInput(); } } private void setupPreview() { if (controller.countListeners()>0) try { controller.showMapPic( PicturePanel.getImage( game ) ); } catch(Throwable e) { controller.showMapPic(null); } } public static int getType(String type) { if (type.equals("human")) { return Player.PLAYER_HUMAN; } if (type.equals("ai easy")) { return Player.PLAYER_AI_EASY; } if (type.equals("ai hard")) { return Player.PLAYER_AI_HARD; } if (type.equals("ai crap")) { return Player.PLAYER_AI_CRAP; } return -1; } /** * return true ONLY if info of this Player p should be disclosed to this computer */ private boolean showHumanPlayerThereInfo(Player p) { return (p != null) && ( p.getType()==Player.PLAYER_HUMAN ) && ( unlimitedLocalMode || myAddress.equals( p.getAddress() ) ); } /** * Method that deals with an end of a player's turn */ public void DoEndGo() { if (!replay) { controller.noInput(); // definatly need to block input at the end of someones go //give them a card if they deserve one if ( chatSocket == null ) { GameParser( "CARD " + game.getDesrvedCard() ); } else if ( (((Player)game.getCurrentPlayer()).getAddress().equals( myAddress ) ) ) { // || ((Player)game.getCurrentPlayer()).getAddress().equals( "all" ) // if this is a network game // recursive call // YURA:LOBBY this will never happen //if (((Player)game.getCurrentPlayer()).getAddress().equals( "all" )) { // GameParser("CARD"); //} //else { // that was here V //} outChat.println( "CARD " + game.getDesrvedCard() ); } } } public void setReplay(boolean a) { replay = a; } /** * This deals with trying to find out what input is required for the parser */ public void getInput() { if (game==null) { controller.needInput( -1 ); } // work out what to do next else if ( game!=null && game.getCurrentPlayer()!=null && game.getState()!=RiskGame.STATE_GAME_OVER ) {// if player type is human or neutral or ai if (game.getState()==RiskGame.STATE_TRADE_CARDS) { controller.sendMessage(resb.getString( "core.input.newarmies").replaceAll( "\\{0\\}", ((Player)game.getCurrentPlayer()).getExtraArmies() + "") , false, false); controller.armiesLeft( ((Player)game.getCurrentPlayer()).getExtraArmies() , game.NoEmptyCountries() ); } else if (game.getState()==RiskGame.STATE_PLACE_ARMIES) { controller.sendMessage(resb.getString( "core.input.armiesleft").replaceAll( "\\{0\\}", ((Player)game.getCurrentPlayer()).getExtraArmies() + ""), false, false); controller.armiesLeft( ((Player)game.getCurrentPlayer()).getExtraArmies() , game.NoEmptyCountries() ); } setHelp(); if (!replay) { // yura:lobby taken out: || ((Player)game.getCurrentPlayer()).getAddress().equals("all") // IF local game, OR addres match get input if ( unlimitedLocalMode || ((Player)game.getCurrentPlayer()).getAddress().equals(myAddress) ) { if ( game.getState() == RiskGame.STATE_DEFEND_YOURSELF && game.getCurrentPlayer().getAutoDefend() ) { parser( AIPlayer.getOutput(game,AIPlayer.aicrap) ); } // || ((Player)game.getCurrentPlayer()).getType()==Player.PLAYER_NEUTRAL else if ( ((Player)game.getCurrentPlayer()).getType()==Player.PLAYER_HUMAN ) { controller.needInput( game.getState() ); } else { AIPlayer.play(this); } } //else if ( game.getCurrentPlayer().getType()==Player.PLAYER_HUMAN ) { // this is here for the lobby //getHumanInput(); //} } } else { controller.needInput( game.getState() ); } } //public void getHumanInput() { } public String whoWon() { String winner = System.getProperty("line.separator") + resb.getString("core.whowon.hehaswon").replaceAll( "\\{0\\}", ((Player)game.getCurrentPlayer()).getName()); if ( game.getGameMode() == RiskGame.MODE_SECRET_MISSION ) { //There mission was: {0} winner=winner + System.getProperty("line.separator") + resb.getString( "core.whowon.mission").replaceAll( "\\{0\\}", ((Mission)((Player)game.getCurrentPlayer()).getMission()).getDiscription()); } return winner; } /** Shows helpful tips in each game state */ public void setHelp() { String help=""; if ( game!=null && game.getCurrentPlayer() != null ) { String strId = null; switch ( ((Player)game.getCurrentPlayer()).getType() ) { case Player.PLAYER_HUMAN: strId = "core.help.move.human"; break; case Player.PLAYER_AI_CRAP: strId = "core.help.move.ai.crap"; break; case Player.PLAYER_AI_EASY: strId = "core.help.move.ai.easy"; break; case Player.PLAYER_AI_HARD: strId = "core.help.move.ai.hard"; break; } help = resb.getString( strId).replaceAll( "\\{0\\}", ((Player)game.getCurrentPlayer()).getName()) +" "; } if (game == null) { help = resb.getString( "core.help.newgame"); } else if (game.getState()==RiskGame.STATE_NEW_GAME) { help = resb.getString( "core.help.createplayers"); } else if (game.getState()==RiskGame.STATE_TRADE_CARDS) { help = help + resb.getString( "core.help.trade"); } else if (game.getState()==RiskGame.STATE_PLACE_ARMIES) { if ( game.getSetup() ) { help = help + resb.getString( "core.help.placearmies"); } else if ( game.NoEmptyCountries() ) { help = help + resb.getString( "core.help.placearmy"); } else { help = help + resb.getString( "core.help.placearmyempty"); } } else if (game.getState()==RiskGame.STATE_ATTACKING) { help = help + resb.getString( "core.help.attack"); } else if (game.getState()==RiskGame.STATE_ROLLING) { help = help + resb.getString( "core.help.rollorretreat"); } else if (game.getState()==RiskGame.STATE_BATTLE_WON) { help = help + resb.getString( "core.help.youhavewon"); } else if (game.getState()==RiskGame.STATE_FORTIFYING) { help = help + resb.getString( "core.help.fortifyposition"); } else if (game.getState()==RiskGame.STATE_END_TURN) { help = help + resb.getString( "core.help.endgo"); } else if (game.getState()==RiskGame.STATE_GAME_OVER) { //the game is over, {0} has won! close the game to create a new one help = resb.getString( "core.help.gameover").replaceAll( "\\{0\\}", ((Player)game.getCurrentPlayer()).getName()); } else if (game.getState()==RiskGame.STATE_SELECT_CAPITAL) { help = help + resb.getString( "core.help.selectcapital"); } else if (game.getState()==RiskGame.STATE_DEFEND_YOURSELF) { help = help + resb.getString( "core.help.defendyourself"); } else { help = resb.getString( "core.help.error.unknownstate"); } controller.setGameStatus( help ); } public synchronized void kickedOff() { //System.out.print("Got kicked off the server!\n"); try { game = null; outChat.close(); inChat.close(); chatSocket.close(); chatSocket = null; } catch (IOException except) { //System.out.println("IOException in main"); } // does not work from here closeBattle(); controller.closeGame(); controller.sendMessage(resb.getString( "core.kicked.error.disconnected"),false,false); setHelp(); getInput(); } protected void closeBattle() { if ( battle ) { controller.closeBattle(); battle=false; } } /** * Shows the cards a Player has in his/her possession * @return Vector Returns the cards in a vector */ public Vector getCurrentCards() { //return game.getCards(); // for testing cards return ((Player)game.getCurrentPlayer()).getCards(); } /** * Checks whether a Player has armies in a country * @param name The index of the country * @return int Returns the number of armies */ public int hasArmiesInt(int name) { return ((Country)game.getCountryInt(name)).getArmies(); } /** * Checks whether a Player can attack a country * @param a The name of the country attacking * @param d The name of the country defending * @return boolean Returns true if the player owns the country, else returns false * // * @deprecated public boolean canAttack(String a, String d) { if ( ((Country)game.getCountry(a)).isNeighbours( (Country)game.getCountry(d) ) ) { return true; } else { return false; } } */ /** * checks whether a Player can attach a country * @param nCountryFrom The name of the country attacking * @param nCountryTo The name of the country defending * @return boolean Returns true if the player can attack the other one, false if not */ public boolean canAttack(int nCountryFrom, int nCountryTo) { if (game.getCountryInt( nCountryFrom).isNeighbours( game.getCountryInt( nCountryTo))) { return true; } return false; }//public boolean canAttack(int nCountryFrom, int nCountryTo) /** * Checks whether a Player owns a country * @param name The name of the country * @return boolean Returns true if the player owns the country, else returns false */ public boolean isOwnedCurrentPlayerInt(int name) { // not thread safe, so this can cause problems, but this method is used in display to thats ok if ( (game!=null && game.getCurrentPlayer()!=null && game.getCountryInt( name )!=null) && ( ((Country)game.getCountryInt( name )).getOwner() == null || ((Country)game.getCountryInt( name )).getOwner() == game.getCurrentPlayer() ) ) { return true; } else { return false; } } /** * Get the current mission of the game, depending on the game mode * @return String Returns the current mission */ public String getCurrentMission() { if ( game.getGameMode() == RiskGame.MODE_DOMINATION ) { return resb.getString( "core.mission.conquerworld"); } //else if ( game.getGameMode() == 1 ) { // return resb.getString( "core.mission.eliminateenemy"); //} else if ( game.getGameMode() == RiskGame.MODE_CAPITAL ) { return resb.getString( "core.mission.capturecapitals"); } else if ( game.getGameMode() == RiskGame.MODE_SECRET_MISSION ) { return ((Mission)((Player)game.getCurrentPlayer()).getMission()).getDiscription(); } else { return resb.getString( "core.mission.error.cantshow"); } } /** * Get the colours of the players in the game * @return Color[] Return the colour of the game players */ public Color[] getPlayerColors() { if ( game.getState() == RiskGame.STATE_DEFEND_YOURSELF ) { return new Color[] { game.getDefender().getOwner().getColor() }; } Vector Players = game.getPlayers(); boolean setup = game.NoEmptyCountries(); int num=0; int start=0; for (int c=0; c< Players.size() ; c++) { if ( ((Player)Players.elementAt(c)).getNoTerritoriesOwned() > 0 || setup==false ) { num++; } if ( ((Player)Players.elementAt(c)) == game.getCurrentPlayer() ) { start=c; } } Color playerColors[] = new Color[num]; int current=0; for (int c=start; c< Players.size() ; c++) { if ( ((Player)Players.elementAt(c)).getNoTerritoriesOwned() > 0 || setup==false ) { playerColors[ current ] = ((Player)Players.elementAt(c)).getColor() ; current++; } if ( current==num ) { break; } if ( c==Players.size()-1 ) { c=-1; } } return playerColors; } /** * Get the colour of the current player * @return Color Return the colour of the current player in the game */ public Color getCurrentPlayerColor() { if (game != null && game.getState() != RiskGame.STATE_NEW_GAME) { return ((Player)game.getCurrentPlayer()).getColor(); } else { return null; } } /** * Get the colour of the current player * @param n the Country number identifier * @return Color Return the colour of a player that owns a country */ public Color getColorOfOwner(int n) { return ((Player)((Country)game.getCountryInt(n)).getOwner()).getColor(); } /** * Checks whether a set of cards can be traded in for extra armies * @param c1 the name of the first card * @param c2 the name of the second card * @param c3 the name of the third card * @return boolean Return true if the card can be traded, else return false */ public boolean canTrade(String c1, String c2, String c3) { if (game.getState() == RiskGame.STATE_TRADE_CARDS ) { Card[] cards = game.getCards(c1,c2,c3); return game.checkTrade(cards[0], cards[1], cards[2]); } return false; } /** * Get the state of the cards * @return int Return the newCardState */ public int getNewCardState() { return game.getNewCardState(); } /** * Get the present game * @return RiskGame Return the current game */ public RiskGame getGame() { return game; } /** * Get the name of the country from the game * @param c The (unique) country identifier * @return String Return Country name if it is there, else return empty speech-marks otherwise */ public String getCountryName(int c) { Country t = game.getCountryInt(c); if (t==null) { return ""; } else { return t.getName(); } } /** * returns the country display name * @param nCountryId The ID of the country * @return The country's display name public String getCountryDisplayName(int nCountryId) { Country country = game.getCountryInt( nCountryId); if (country == null) { return ""; } else { return country.getName(); // Display } }//public String getCountryDisplayName(int nCountryId) */ /** * Checks whether the current Player has autoEndGo on * @return boolean Return autoEndGo */ public boolean getAutoEndGo() { if (game != null && game.getCurrentPlayer()!=null) { return game.getCurrentPlayer().getAutoEndGo(); } else { // this should never happen, but can come up with bad timing problems return false; } } /** * Checks whether the current Player has autoDefend on * @return boolean Return autoDefend */ public boolean getAutoDefend() { if (game !=null && game.getCurrentPlayer()!=null) { return game.getCurrentPlayer().getAutoDefend(); } else { // this should never happen, but can come up with bad timing problems return false; } } public void newMemoryGame(RiskGame g,java.awt.Image p) { if (game == null) { try { // make a copy NullCipher nullCipher = new NullCipher(); // @TODO, this will crash on macs game = (RiskGame) (new SealedObject( g, nullCipher ).getObject( nullCipher )); for (int c=1;c<=RiskGame.MAX_PLAYERS;c++) { game.delPlayer("PLAYER"+c); } } catch (Exception e) { // should never happen //e.printStackTrace(); throw new RuntimeException(e); } controller.newGame(true); controller.showMapPic( p.getScaledInstance(203,127, java.awt.Image.SCALE_SMOOTH ) ); controller.showCardsFile( "loaded from memory" , (game.getNoMissions()!=0) ); unlimitedLocalMode = true; } } public void showMessageDialog(String a) { controller.showMessageDialog(a); } public void renamePlayer(String oldser,String newuser) { Vector players = game.getPlayers(); for (int c=0;c<players.size(); c++) { Player player = (Player)players.elementAt(c); if ( player.getName().equals(oldser) ) { player.rename(newuser); } } } }

The table below shows all metrics for Risk.java.

MetricValueDescription
BLOCKS543.00Number of blocks
BLOCK_COMMENT109.00Number of block comment lines
COMMENTS420.00Comment lines
COMMENT_DENSITY 0.34Comment density
COMPARISONS488.00Number of comparison operators
CYCLOMATIC455.00Cyclomatic complexity
DECL_COMMENTS28.00Comments in declarations
DOC_COMMENT121.00Number of javadoc comment lines
ELOC1234.00Effective lines of code
EXEC_COMMENTS133.00Comments in executable code
EXITS199.00Procedure exits
FUNCTIONS40.00Number of function declarations
HALSTEAD_DIFFICULTY135.63Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY88.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 1.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 1.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 3.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 1.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA0034 2.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA004995.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 1.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 6.00JAVA0067 Array descriptor on identifier name
JAVA0068 1.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 1.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA0076 0.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 9.00JAVA0080 Import declaration not used
JAVA008128.00JAVA0081 Boolean literal in comparison
JAVA008252.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA008459.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 2.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 1.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 1.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 1.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA0108 2.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 1.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 1.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 0.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 1.00JAVA0116 Missing javadoc: field 'field'
JAVA011715.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 2.00JAVA0119 Control variable changed within body of for loop
JAVA0123 1.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 1.00JAVA0128 Public constructor in non-public class
JAVA0130 0.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 1.00JAVA0143 Synchronized method
JAVA014440.00JAVA0144 Line exceeds maximum M characters
JAVA01459568.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 1.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA016618.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 1.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 1.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 1.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA017715.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 0.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 6.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 3.00JAVA0266 Use of System.out
JAVA0267 2.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 3.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 1.00JAVA0272 Thread.run() called
JAVA0273 1.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 6.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES3028.00Number of lines in the source file
LINE_COMMENT190.00Number of line comments
LOC1681.00Lines of code
LOGICAL_LINES795.00Number of statements
LOOPS32.00Number of loops
NEST_DEPTH11.00Maximum nesting depth
OPERANDS4311.00Number of operands
OPERATORS9005.00Number of operators
PARAMS29.00Number of formal parameter declarations
PROGRAM_LENGTH13316.00Halstead program length
PROGRAM_VOCAB946.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS59.00Number of return points from functions
SIZE80336.00Size of the file in bytes
UNIQUE_OPERANDS890.00Number of unique operands
UNIQUE_OPERATORS56.00Number of unique operators
WHITESPACE927.00Number of whitespace lines