From: Erik V. <eri...@xs...> - 2011-05-08 20:11:54
|
Martin, OK, it seems to work fine now. I have it all checked in. I have taken the liberty to stay with my own version of the reordering procedure. I have replaced the unclear ‘high’ by ‘ascending’, because that’s what it turns out to mean. My previous code proposal was wrong because I had overlooked that an anonymous class instance can only access final variables defined outside of it. That’s fixed now. On the UI, I’m currently in doubt if it is worthwhile to change the player order. No doubt it’s possible, but it’ll take quite some work. Let’s first check if all data in the player columns still ends up being in the right place. The cash is OK, I haven’t checked the rest yet. Erik. Van: Dr....@t-... [mailto:Dr....@t-...] Verzonden: zaterdag 7 mei 2011 9:17 Aan: Rails Development Onderwerp: [Rails-devel] Correction for Gamemanager Hi Erik et al. a new version of the routine to reorder the players. Had some unnecessary code. public Player reorderPlayersByCash(boolean high) { Player player; if (high) { Collections.sort (players, new Comparator<Player>() { public int compare (Player p1, Player p2) { return ( p1.getCash() > p2.getCash() ? 1 : (p2.getCash() == p1.getCash() ? 0: -1)); } }); } else { Collections.sort (players, new Comparator<Player>() { public int compare (Player p1, Player p2) { return ( p1.getCash() < p2.getCash() ? 1 : (p2.getCash() == p1.getCash() ? 0: -1)); } }); } setCurrentPlayer(players.get(0)); for (int i=0; i<players.size(); i++) { player = players.get(i); player.setIndex(i); playerNames.set(i, player.getName()); } return players.get(0); } Regards, Martin |