/// <summary> /// metodo que recibe el nombre del jugador y gestiona /// su incorporación a la mesa. /// </summary> public void RequestSitPlayer(string PlayerName, IDominoServiceCallbackContract Callback) { this.Callback = Callback; if ((PlayerName == null) || (Callback == null)) { throw new InvalidTableArgument("el nombre no es valido"); } else { if (PlayersRegistered.Count < MAX_PLAYERS) { bool RepeatedName = false; int index = 0; /// <summary> /// Comprobar si el nombre esta repetido /// </summary> CheckedRepeatedName(PlayerName, ref RepeatedName, ref index); if (!RepeatedName) { int PlayerPosition = PlayersRegistered.Count; /// <summary> /// Ha podido sentar al nuevo jugador y se notifica a todos los sentados los datos del nuevo jugador /// </summary> servidor.InfoPlayerJoined(PlayersRegistered, PlayerName, Callback, PlayerPosition); /// <summary> /// Se añade el nuevo jugador a la lista de los sentados en la mesa /// </summary> PlayersRegistered.Add(new Player(PlayerName, PlayerPosition, Callback)); /// <summary> /// La mesa está completa y el juego todavía no ha empezado /// </summary> if (PlayersRegistered.Count == MAX_PLAYERS && !GameHasStarted) //metodo stargame { StarGame(); } } else { Callback.PlayerNotSat("Ya hay un jugador sentado a la mesa con ese nombre"); } } else { Callback.PlayerNotSat("La mesa ya tiene todas las posiciones ocupadas"); } } }
public void RequestSitPlayer(string PlayerName) { IDominoServiceCallbackContract Callback = OperationContext. Current.GetCallbackChannel <IDominoServiceCallbackContract>(); if (Table.getInstance().TableIsNotFull()) { if (Table.getInstance().IsNameRegistered(PlayerName) == false) { Table.getInstance().SitPlayer(PlayerName, Callback); } else { Callback.PlayerNotSat("Ya hay un jugador sentado a la mesa con ese nombre"); } } else { Callback.PlayerNotSat("La mesa ya tiene todas las posiciones ocupadas"); } }
public void RequestSitPlayer(string PlayerName) { IDominoServiceCallbackContract Callback = OperationContext.Current.GetCallbackChannel <IDominoServiceCallbackContract>(); try { Table.getTable().RequestSitPlayer(PlayerName, Callback); int PlayerPosition = Table.getTable().playersRegistered.Count; // Ha podido sentar al nuevo jugador y se notifica a todos los sentados los datos del nuevo jugador //Callback.NewPlayerJoined(PlayerName, PlayerPosition); PlayerData jugadorNuevo = new PlayerData(PlayerName, PlayerPosition - 1); Callback.NewPlayerJoined(jugadorNuevo); foreach (Player PlayerRegistered in Table.getTable().playersRegistered) { PlayerData jugadorRegistrado = new PlayerData(PlayerRegistered.playerName, PlayerRegistered.tablePosition); PlayerRegistered.PlayerCallbackChannel.NewPlayerJoined(jugadorNuevo); Callback.NewPlayerJoined(jugadorRegistrado); //PlayerRegistered.PlayerCallbackChannel.NewPlayerJoined(PlayerName, PlayerPosition-1); //Callback.NewPlayerJoined(PlayerRegistered.playerName, PlayerRegistered.tablePosition); } if (Table.getTable().playersRegistered.Count == Table.getTable().GetMAX_PLAYERS() && !Table.getTable().gameHasStarted) { Table.getTable().StartGame(); } } catch (ExcepcionNombreRepetido) { Callback.PlayerNotSat("Ya hay un jugador sentado a la mesa con ese nombre"); } catch (ExcepcionMesaLlena) { Callback.PlayerNotSat("La mesa ya tiene todas las posiciones ocupadas"); } }
/// <summary> /// metodo que recibe la ficha del jugador y lo envía a todas las instancias /// </summary> public void RequestPutPiecePlayer(PieceData piece, PieceData prevPiece, IDominoServiceCallbackContract Callback) { Piece pieceAux = null; for (int i = 0; i < PlayersRegistered.ElementAt(piece.PlayerPosition).PlayerPieces.Pieces.Count; i++) { if (PlayersRegistered.ElementAt(piece.PlayerPosition).PlayerPieces.Pieces.ElementAt(i).ToInt() == piece.PieceValue) { pieceAux = PlayersRegistered.ElementAt(piece.PlayerPosition).PlayerPieces.Pieces.ElementAt(i); } } int compare = prevPiece.PieceValue; if (TablePieces.ElementAt(0).ToInt() == compare) { TablePieces.Insert(0, pieceAux); Console.WriteLine(TablePieces.ElementAt(0).ToInt()); int ret = IsHandEnded(); if (ret != -1) { EndHand(ret); return; } else { cambiaTurno(); } //turno = (turno + 1) % 4;//actualizo correctamente quien tiene el turno //servidor.ActualizaLosTurnos(PlayersRegistered, turno, ElDelTurnoPuedePoner(TablePieces, PlayersRegistered[turno]), puedoColocar[0], puedoColocar[1]); } else if (TablePieces.ElementAt(TablePieces.Count - 1).ToInt() == compare) { TablePieces.Add(pieceAux); int ret = IsHandEnded(); if (ret != -1) { EndHand(ret); return; } else { cambiaTurno(); } // turno = (turno + 1) % 4;//actualizo correctamente quien tiene el turno // servidor.ActualizaLosTurnos(PlayersRegistered, turno, ElDelTurnoPuedePoner(TablePieces, PlayersRegistered[turno]), puedoColocar[0], puedoColocar[1]); } else { Callback.PlayerNotSat("error no tiene que entrar aqui"); //Lanzar Error } piece.PiecePosition = RemovePiecePlayer(piece.PlayerPosition, piece); servidor.InfoPiecePutOntable(PlayersRegistered, piece, Callback); //actualiza la mano en las demas Instancias servidor.UpdatePiecesPlayers(PlayersRegistered, piece); //esto es de los turnos //turno = (turno + 1) % 4;//actualizo correctamente quien tiene el turno //servidor.ActualizaLosTurnos(PlayersRegistered, turno, ElDelTurnoPuedePoner(TablePieces, PlayersRegistered[turno]) , puedoColocar[0], puedoColocar[1]); }