public Player(string Name, int Position, IDominoServiceCallbackContract Channel) { if (Name == null) { throw new InvalidPlayerArgument("el nombre no es valido"); } else if ((Position < 0) || (Position > 3)) { throw new InvalidPlayerArgument("la posicion no es valida"); } else { this.Bot = false; for (int i = 0; i < NombresReservados.Length; i++) {//nombre de bot if (Name.ToLower().Trim().Equals(NombresReservados[i].ToLower().Trim())) { this.Bot = true; } } this.PlayerName = Name; this.TablePosition = Position; this.PlayerCallbackChannel = Channel; this.PlayerPieces = new Hand(); } }
public Player(string Name, int Position, IDominoServiceCallbackContract Channel) { if (Name == null) { throw new ExcepcionInvalidPlayerArguments("El nombre es nulo"); } else if (Position > 3 || Position < 0) { throw new ExcepcionInvalidPlayerArguments("La posicion no es correcta"); } else if (Name.Length == 0) { throw new ExcepcionInvalidPlayerArguments("El nombre esta vacio"); } /*else if (Channel == null) * { * throw new ExcepcionInvalidPlayerArguments("El canal es nulo"); * }*/ else { this.Bot = false; for (int i = 0; i < NombresReservados.Length; i++) {//nombre de bot if (Name.ToLower().Trim().Equals(NombresReservados[i].ToLower().Trim())) { this.Bot = true; } } this.PlayerName = Name; this.TablePosition = Position; this.PlayerCallbackChannel = Channel; this.PlayerPieces = new Hand(); } }
/// <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 NotifyNewPlayer(List <Player> PlayersRegistered, IDominoServiceCallbackContract Callback, int PlayerPosition, string PlayerName) { PlayerData playerData = new PlayerData(PlayerName, PlayerPosition); Callback.NewPlayerJoined(playerData); foreach (Player PlayerRegistered in PlayersRegistered) { PlayerData PlayerRegisteredData = new PlayerData(PlayerRegistered.getName(), PlayerRegistered.getPosition()); PlayerRegistered.getCallback().NewPlayerJoined(playerData); Callback.NewPlayerJoined(PlayerRegisteredData); } }
public void SitPlayer(string PlayerName, IDominoServiceCallbackContract Callback) { int PlayerPosition = PlayersRegistered.Count; // Se añade el nuevo jugador a la lista de los sentados en la mesa this.PlayersRegistered.Add(new Player(PlayerName, PlayerPosition, Callback)); // Ha podido sentar al nuevo jugador y se notifica a todos los sentados los datos del nuevo jugador DominoService.getInstance().NotifyNewPlayer(PlayersRegistered, Callback, PlayerPosition, PlayerName); // La mesa está completa y el juego todavía no ha empezado if (!this.TableIsNotFull() && !this.IsGameStarted()) { StartGame(); } }
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"); } }
//pido sentar nuevo jugador public void RequestSitPlayer(string playerName, IDominoServiceCallbackContract callback) { if (playersRegistered.Count < MAX_PLAYERS) { if (NombreRepetido(playerName) == false) { int PlayerPosition = playersRegistered.Count; // Se añade el nuevo jugador a la lista de los sentados en la mesa playersRegistered.Add(new Player(playerName, PlayerPosition, callback)); } else { ExcepcionNombreRepetido ex = new ExcepcionNombreRepetido("Ya hay un jugador sentado a la mesa con ese nombre"); throw ex; } } else { ExcepcionMesaLlena ex = new ExcepcionMesaLlena("La mesa ya tiene todas las posiciones ocupadas"); throw ex; } }
public Player(string name, int position, IDominoServiceCallbackContract Channel) { if (name == null) { throw new InvalidPlayerArguments("Name can't be null."); } else if (name.Equals("")) { throw new InvalidPlayerArguments("Name can't be empty."); } else if ((position < 0) || (position > 3)) { throw new InvalidPlayerArguments("Invalid Position."); } else { this.PlayerName = name; this.TablePosition = position; this.PlayerCallbackChannel = Channel; this.PlayerPieces = new Hand(); } }
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]); }
public void RequestSitPlayer(string PlayerName) { IDominoServiceCallbackContract Callback = OperationContext.Current.GetCallbackChannel <IDominoServiceCallbackContract>(); mesa.RequestSitPlayer(PlayerName, Callback); }
/// <summary> /// Envío la ficha a todas las Instancias /// </summary> public void InfoPiecePutOntable(List <Player> PlayersRegistered, PieceData piece, IDominoServiceCallbackContract Callback) { foreach (Player PlayerRegistered in PlayersRegistered) { //La ficha que manda ese jugador, que sea diferente a los demás jugadores, para así no mandarme a mí mismo la ficha if (piece.PlayerPosition != PlayerRegistered.tablePosition) { //aqui informo a los demas jugadores la ficha que se ha puesto PlayerRegistered.PlayerCallbackChannel.NewPutPieceOnPanel(piece); } } }
public void InfoPlayerJoined(List <Player> PlayersRegistered, string PlayerName, IDominoServiceCallbackContract Callback, int PlayerPosition) { playerD = new PlayerData(PlayerName, PlayerPosition); //aqui me siento yo Callback.NewPlayerJoined(playerD); foreach (Player PlayerRegistered in PlayersRegistered) { //aqui informo a los demas jugadores que me he sentado yo PlayerRegistered.PlayerCallbackChannel.NewPlayerJoined(playerD); PlayerData playerOld = new PlayerData(PlayerRegistered.playerName, PlayerRegistered.tablePosition); //aqui me informo yo de los jugadores que ya estan sentados Callback.NewPlayerJoined(playerOld); } }
//envia la ficha al servidor ,para ponerlo en todas las instancias public void RequestPutPiecePlayer(PieceData piece, PieceData prevPiece) { IDominoServiceCallbackContract Callback = OperationContext.Current.GetCallbackChannel <IDominoServiceCallbackContract>(); mesa.RequestPutPiecePlayer(piece, prevPiece, Callback); }