private static AnswerMessage listGames(RequestMessage rm) { String STATUS = "<LIST GAMES>"; for (int cont = 0; cont <= game_last_id; cont++) { if (GAMES.ContainsKey(cont)) { manager.Game TEMP = (manager.Game)GAMES[cont]; if ((rm.GT.Length <= 1) || rm.GT.Equals(TEMP.GAME_TYPE, StringComparison.CurrentCultureIgnoreCase) || rm.GT.Equals("all", StringComparison.CurrentCultureIgnoreCase)) { String this_game = "<GAME>"; this_game += "<GID>" + cont + "</GID>"; this_game += "<GT>" + TEMP.GAME_TYPE + "</GT>"; this_game += "<ENDED>" + TEMP.gameEnded() + "</ENDED>"; this_game += "<WP>" + TEMP.WAITING_PLAYERS + "</WP>"; this_game += "<#PLAYERS>" + TEMP.PLAYERS.Count + "</#PLAYERS>"; this_game += "</GAME>"; STATUS += this_game; } } } STATUS += "</LIST GAMES>"; return(new AnswerMessage(true, AnswerMessage.GAME_LIST, STATUS, -1)); }
public static String gameGeneralStatus(int gameID, int player) { if (GAMES.ContainsKey(gameID)) { if ((manager.Game)GAMES[gameID] != null) { manager.Game g = (manager.Game)GAMES[gameID]; if (g.GAME_ENDED) { if (g.WINNER < 0) { return(AnswerMessage.GGS_GAME_ENDED + AnswerMessage.DRAWN_GAME + "<GAME LAST MESSAGE>" + g.LAST_MESSAGE + "</GAME LAST MESSAGE>"); } else { return(AnswerMessage.GGS_GAME_ENDED + "<WINNER>" + g.WINNER + "</WINNER>" + "<GAME LAST MESSAGE>" + g.LAST_MESSAGE + "</GAME LAST MESSAGE>"); } } if (g.WAITING_PLAYERS) { return(AnswerMessage.GGS_WAITING_FOR_PLAYERS); } String PlayerTag = ""; if (g.getActualPlayer() == (int)g.PLAYERS[0]) { PlayerTag = AnswerMessage.PLAYER1; } if (g.getActualPlayer() == (int)g.PLAYERS[1]) { PlayerTag = AnswerMessage.PLAYER2; } if (g.getActualPlayer() == player) { return(AnswerMessage.GGS_YOUR_TURN + PlayerTag); } if (g.getActualPlayer() != player) { return(AnswerMessage.GGS_ADVERSARY_TURN + PlayerTag); } return("UNKNOW STATUS"); } return(AnswerMessage.GGS_GAME_DOES_NOT_EXIST); } return(null); }
private static AnswerMessage newGame(RequestMessage message) { AddressPort ClientAddress = message.REQUESTER_ADDRESS; manager.Game NEW_GAME = null; String game_type = message.GT; String game_name = message.GN; int player1 = message.PLAYER; Console.WriteLine("NEW GAME: game type " + game_type + ", game name: " + game_name + ", player id:" + player1); if (game_type.Equals("checkers", StringComparison.CurrentCultureIgnoreCase)) { if (player1 < 0) { NEW_GAME = new manager.CheckersGame(game_name); } else { NEW_GAME = new manager.CheckersGame(game_name, player1); } } else if (game_type.Equals("novojogo", StringComparison.CurrentCultureIgnoreCase)) { if (player1 < 0) { NEW_GAME = new manager.NovoJogoGame(game_name); } else { NEW_GAME = new manager.NovoJogoGame(game_name, player1); } } else if ((game_type.Equals("tictactoe", StringComparison.CurrentCultureIgnoreCase)) || (game_type.Equals("tic tac toe", StringComparison.CurrentCultureIgnoreCase))) { if (player1 < 0) { NEW_GAME = new manager.TictactoeGame(game_name); } else { NEW_GAME = new manager.TictactoeGame(game_name, player1); } } else if (game_type.Equals("deflexion", StringComparison.CurrentCultureIgnoreCase)) { if (player1 < 0) { NEW_GAME = new manager.DeflexionGame(game_name); } else { NEW_GAME = new manager.DeflexionGame(game_name, player1); } } else if (game_type.Equals("chess", StringComparison.CurrentCultureIgnoreCase)) { if (player1 < 0) { NEW_GAME = new manager.ChessGame(game_name); } else { NEW_GAME = new manager.ChessGame(game_name, player1); } } else if (game_type.Equals("checkers", StringComparison.CurrentCultureIgnoreCase)) { if (player1 < 0) { NEW_GAME = new manager.CheckersGame(game_name); } else { NEW_GAME = new manager.CheckersGame(game_name, player1); } } if (NEW_GAME != null) { game_last_id = 1 + game_last_id; NEW_GAME.GAME_ENDED = false; //if (GAMES.ContainsKey(game_last_id)) GAMES.Add(game_last_id, NEW_GAME); Console.WriteLine(" => NEW GAME CREATED " + game_last_id + " players: " + ((manager.Game)(GAMES[game_last_id])).getPlayers().Count); GAMES_PLAYERS.Add(game_last_id, new ArrayList()); if (player1 >= 0) { ((ArrayList)(GAMES_PLAYERS[game_last_id])).Add(ClientAddress); Console.WriteLine("SIZE: " + ((ArrayList)(GAMES_PLAYERS[game_last_id])).Count); } return(new AnswerMessage(true, AnswerMessage.NEW_GAME, "<GID>" + game_last_id + "</GID><LINES>" + ((manager.Game)GAMES[game_last_id]).getLines() + "</LINES><COLUMNS>" + ((manager.Game)GAMES[game_last_id]).getColumns() + "</COLUMNS>", game_last_id)); } return(new AnswerMessage(false, AnswerMessage.NEW_GAME, "", -1)); }