public static String infoComplete() { String info = ""; try { // Board info = infoGame(); // Players ArrayList<I_InfoPlayer> players = game.getPlayers(); for (int i = 0; i < players.size(); i++) { info += "%%%" + infoPlayer(players.get(i)); } info += "%%%%%"; info += Integer.toString(ghostdx[0]); for (int i = 1; i < game.getNrofghosts(); i++) { info += " " + Integer.toString(ghostdx[i]); } for (int i = 0; i < game.getNrofghosts(); i++) { info += " " + Integer.toString(ghostdy[i]); } for (int i = 0; i < game.getNrofghosts(); i++) { info += " " + Integer.toString(ghostspeed[i]); } } catch (Exception exc) { exc.printStackTrace(); } return info; }
/* *function who transformed all the caracteristic of InfoGame in a string *to sent them at the new server */ public static String infoGame() { String info = ""; try { info = Integer.toString(game.getNrofghosts()); info += " " + Integer.toString(game.getDeathcounter()); int[] ghostx = game.getGhostx(); for (int i = 0; i < game.getNrofghosts(); i++) { info += " " + Integer.toString(ghostx[i]); } int[] ghosty = game.getGhosty(); for (int i = 0; i < game.getNrofghosts(); i++) { info += " " + Integer.toString(ghosty[i]); } short[] screenData = game.getScreendata(); for (int i = 0; i < screenData.length; i++) { info += " " + Integer.toString(screenData[i]); } info += " " + Integer.toString(game.getNumberPlayer()); info += " " + Integer.toString(game.getNbPlayerExpected()); info += " " + Integer.toString(game.getNbPlayerWaiting()); info += " " + Integer.toString(game.getNbrPlayerInGame()); info += " " + String.valueOf(game.isPlaying()); info += " " + String.valueOf(game.isWaiting()); info += " " + String.valueOf(game.isEnded()); info += " " + String.valueOf(game.isPause()); info += " " + game.getPlayerCallPause(); } catch (Exception exc) { exc.printStackTrace(); } return info; }
public void LevelContinue() { short i; int dx = 1; int random; try { int blocksize = game.getBlocksize(); int[] ghosty = game.getGhosty(); int[] ghostx = game.getGhostx(); int nrofghosts = game.getNrofghosts(); for (i = 0; i < nrofghosts; i++) { ghosty[i] = 4 * blocksize; ghostx[i] = 4 * blocksize; ghostdy[i] = 0; ghostdx[i] = dx; dx = -dx; random = (int) (Math.random() * (currentspeed + 1)); if (random > currentspeed) random = currentspeed; ghostspeed[i] = validspeeds[random]; } } catch (Exception e) { e.printStackTrace(); } }
public static void serverConstruction(String s) { String[] infos = s.split(" "); int cont = 0; for (int i = 0; i < game.getNrofghosts(); i++) { ghostdx[i] = Integer.valueOf(infos[cont]); cont++; } for (int i = 0; i < game.getNrofghosts(); i++) { ghostdy[i] = Integer.valueOf(infos[cont]); cont++; } for (int i = 0; i < game.getNrofghosts(); i++) { ghostspeed[i] = Integer.valueOf(infos[cont]); cont++; } }
public void finished() { int numberPlayer = game.getNumberPlayer(); numberFinished += 1; if (numberFinished == numberPlayer) { // Ghosts update int nrOfGhosts = game.getNrofghosts(); if (nrOfGhosts < maxghosts) { game.setNrofghosts(nrOfGhosts++); } if (currentspeed < maxspeed) { currentspeed++; } LevelInit(); } }
public void moveGhosts() { saveStateServer(); // We save the configuration of the game try { int nbrPlayerInGame = game.getNbrPlayerInGame(); int[] ghosty = game.getGhosty(); int[] ghostx = game.getGhostx(); if (ghostMove == 0) { short i; int pos; int count; int blocksize = game.getBlocksize(); int nrofblocks = game.getNrofblocks(); int nrofghosts = game.getNrofghosts(); short[] screendata = game.getScreendata(); for (i = 0; i < nrofghosts; i++) { if (ghostx[i] % blocksize == 0 && ghosty[i] % blocksize == 0) { pos = ghostx[i] / blocksize + nrofblocks * (int) (ghosty[i] / blocksize); count = 0; if ((screendata[pos] & 1) == 0 && ghostdx[i] != 1) { dx[count] = -1; dy[count] = 0; count++; } if ((screendata[pos] & 2) == 0 && ghostdy[i] != 1) { dx[count] = 0; dy[count] = -1; count++; } if ((screendata[pos] & 4) == 0 && ghostdx[i] != -1) { dx[count] = 1; dy[count] = 0; count++; } if ((screendata[pos] & 8) == 0 && ghostdy[i] != -1) { dx[count] = 0; dy[count] = 1; count++; } if (count == 0) { if ((screendata[pos] & 15) == 15) { ghostdx[i] = 0; ghostdy[i] = 0; } else { ghostdx[i] = -ghostdx[i]; ghostdy[i] = -ghostdy[i]; } } else { count = (int) (Math.random() * count); if (count > 3) count = 3; ghostdx[i] = dx[count]; ghostdy[i] = dy[count]; } } ghostx[i] = ghostx[i] + (ghostdx[i] * ghostspeed[i]); ghosty[i] = ghosty[i] + (ghostdy[i] * ghostspeed[i]); } } ghostMove = (ghostMove + 1) % nbrPlayerInGame; game.setGhostx(ghostx); game.setGhosty(ghosty); } catch (Exception e) { e.printStackTrace(); } }