public static void ResetGame() { ListOfPlayers.Clear(); ListOfOrderedPlayers.Clear(); Grid.Empty(); Bag.EmptyTheBag(); }
private void Give_Two_Cards_Every_Player() { Sut.GiveCards(BetCards); ListOfPlayers.Take(2) .ToList() .ForEach(player => player.Verify(x => x.GiveCard(It.IsAny <IBetCard>()), Times.Exactly(2))); }
public void Init(ListOfPlayers owner, int playerId, string playerName, bool isLocal, bool isReady) { this.owner = owner; ownerId = playerId; PlayerNameText.text = playerName; readyLabel.SetActive(isReady); waitingLabel.SetActive(!isReady && !isLocal); readyButton.gameObject.SetActive(!isReady && isLocal); // if (isReady) // { // readyLabel.SetActive(true); // waitingLabel.SetActive(false); // readyButton.gameObject.SetActive(false); // } // else // { // if (isLocal) // { // // } // else // { // } // } }
private IEnumerator GetPlayersOnline() { Player player = FindObjectOfType <Player>(); UnityWebRequest httpClient = new UnityWebRequest(player.GetHttpServer() + "/api/Player/GetPlayersOnline", "POST"); httpClient.SetRequestHeader("Authorization", "bearer " + player.Token); httpClient.SetRequestHeader("Content-type", "application/json"); httpClient.downloadHandler = new DownloadHandlerBuffer(); httpClient.certificateHandler = new ByPassCertificate(); yield return(httpClient.SendWebRequest()); if (httpClient.isNetworkError || httpClient.isHttpError) { throw new Exception("Games > GetPlayersOnline: " + httpClient.error); } else { string jsonResponse = httpClient.downloadHandler.text; string response = "{\"players\":" + jsonResponse + "}"; ListOfPlayers listOfPlayers = JsonUtility.FromJson <ListOfPlayers>(response); playersOnline.text = ""; foreach (PlayerSerializable p in listOfPlayers.players) { string userName = p.Id.Substring(0, 4); playersOnline.text += "\n" + userName + "(" + p.NickName + ")"; } } }
private void LoadSavedData() //Loads the previous LeaderBoard players from JSON string { try { if (leaderBoardObject.Count == 0) { GetDataFromDB(); if (dbLeaderBoardData == null) { string jsonData = PlayerPrefs.GetString(key); if (Misc.IsStringValid(jsonData)) { Debug.Log($"{nameof(dbLeaderBoardData)} <color=blue>is null</color>. Loading & building LeaderBoard data from PlayerPrefs"); ListOfPlayers savedData = JsonUtility.FromJson <ListOfPlayers>(jsonData); SortingAlgorithm(savedData.leaderBList); Debug.Log($"Loaded PlayerPrefs data: {jsonData}"); } } else { Debug.Log($"{nameof(dbLeaderBoardData)} <color=blue>is NOT null</color>. Building LeaderBoard from db Data"); SortingAlgorithm(dbLeaderBoardData.leaderBList); } } } catch (Exception e) { Misc.HandleException(e, gameData.GetExcLeaderBoardLoadSave()); } }
/// <summary> /// Retrieve the current player /// </summary> /// <returns>The player who is playing</returns> public Player GetCurrentPlayer() { Predicate <Player> filtrePlayer = (Player p) => { return(p.Status == Player.StatusOfPlayer.PLAYING); }; currentPlayer = ListOfPlayers.Find(filtrePlayer); return(currentPlayer); }
/// <summary> /// Search the next player /// </summary> /// <param name="p">Previous player</param> /// <returns>The next player</returns> private Player findNextPlayer(Player p) { Predicate <Player> filterPlayer = (Player player) => { return(player == p); }; int index = (ListOfPlayers.FindIndex(filterPlayer)) % ListOfPlayers.Count; return(ListOfPlayers[index + 1]); }
void SpawnPlayers() { if (newPlayers.Count > 0) { foreach (string playerID in newPlayers) { currentPlayers.Add(playerID, Instantiate(playerGO, new Vector3(0, 0, 0), Quaternion.identity)); currentPlayers[playerID].name = playerID; } newPlayers.Clear(); } if (initialSetofPlayers != null) { if (initialSetofPlayers.players.Length > 0) { foreach (Player player in initialSetofPlayers.players) { if (player.id == myAddress) { continue; } currentPlayers.Add(player.id, Instantiate(playerGO, new Vector3(0, 0, 0), Quaternion.identity)); currentPlayers[player.id].GetComponent <Transform>().position = player.position; currentPlayers[player.id].name = player.id; } initialSetofPlayers = null; } } }
void SpawnPlayers() { if (newPlayers.Count > 0) { foreach (string playerID in newPlayers) { currentPlayers.Add(playerID, Instantiate(playerGO, new Vector3(0, 0, 0), Quaternion.identity)); currentPlayers[playerID].name = playerID; } newPlayers.Clear(); } if (initialSetofPlayers.players.Length > 0) { Debug.Log(initialSetofPlayers); foreach (Player player in initialSetofPlayers.players) { if (player.id == myAddress) { continue; } currentPlayers.Add(player.id, Instantiate(playerGO, new Vector3(0, 0, 0), Quaternion.identity)); currentPlayers[player.id].GetComponent <Renderer>().material.color = new Color(player.color.R, player.color.G, player.color.B); currentPlayers[player.id].name = player.id; } initialSetofPlayers = null; } }
//public List<string> masnames(List<string> list) //{ // List<string> lists = new List<string>(); // foreach (string player in lists) // { // list.Add(player); // } // return lists; //} public void ChandeForm1(List <string> list) { //if (this.InvokeRequired) //{ // ListOfPlayers.Invoke((MethodInvoker)(() => ListOfPlayers.Items.Clear())); //} //else //{ // ListOfPlayers.Items.Clear(); //} if (list != null) { //ListOfPlayers.Items.Clear(); foreach (string player in list) { bool fla = false; ListOfPlayers.Invoke((MethodInvoker)(() => fla = ListOfPlayers.Items.Contains(player))); if (player != name && fla == false) { ListOfPlayers.Invoke((MethodInvoker)(() => ListOfPlayers.Items.Add(player))); } } } }
//public List<string> masnames(List<string> list) //{ // List<string> lists = new List<string>(); // foreach (string player in lists) // { // list.Add(player); // } // return lists; //} public void ChandeForm1(List <string> list) { foreach (string player in list) { ListOfPlayers.Invoke((MethodInvoker)(() => ListOfPlayers.Items.Add(player))); } }
// Start is called before the first frame update void Start() { // Initialize variables newPlayers = new List <string>(); droppedPlayers = new List <string>(); currentPlayers = new Dictionary <string, GameObject>(); initialSetofPlayers = new ListOfPlayers(); // Connect to the client. udp = new UdpClient(); Debug.Log("Connecting..."); udp.Connect("3.96.203.122", 12345); // sent "connect" key to server Byte[] sendBytes = Encoding.ASCII.GetBytes("connect"); udp.Send(sendBytes, sendBytes.Length); // receive message from the server udp.BeginReceive(new AsyncCallback(OnReceived), udp); // Repeat calling (Method, time, repeatRate) // InvokeRepeating("HeartBeat", 1, 1); // send position InvokeRepeating("SendPosition", 1, 0.04f); }
void SpawnPlayers() { if (newPlayers.Count > 0) { foreach (Player player in playerList.players) { if (!currentPlayers.ContainsKey(player.id)) { currentPlayers.Add(player.id, Instantiate(playerGO, new Vector3(player.position.X, player.position.Y, 0), Quaternion.identity)); currentPlayers[player.id].GetComponent <Renderer>().material.color = new Color(player.color.R, player.color.G, player.color.B); currentPlayers[player.id].transform.position = new Vector3(player.position.X, player.position.Y, 0); currentPlayers[player.id].name = player.id; } } newPlayers.Clear(); } foreach (Player player in initialSetofPlayers.players) { if (!currentPlayers.ContainsKey(player.id)) { currentPlayers.Add(player.id, Instantiate(playerGO, new Vector3(player.position.X, player.position.Y, 0), Quaternion.identity)); currentPlayers[player.id].GetComponent <Renderer>().material.color = new Color(player.color.R, player.color.G, player.color.B); currentPlayers[player.id].transform.position = new Vector3(player.position.X, player.position.Y, 0); currentPlayers[player.id].name = player.id; } initialSetofPlayers = new ListOfPlayers(); } //if (newPlayers.Count > 0) //{ // foreach (Player player in lastestGameState.players) // { // if (currentPlayers.ContainsKey(player.id)) // continue; // currentPlayers.Add(player.id, Instantiate(playerGO, new Vector3(0, 0, 0), Quaternion.identity)); // currentPlayers[player.id].GetComponent<Renderer>().material.color = new Color(player.color.R, player.color.G, player.color.B); // currentPlayers[player.id].transform.position = new Vector3(player.position.X, player.position.Y, player.position.Z); // currentPlayers[player.id].name = player.id; // } // newPlayers.Clear(); //} //if (initialSetofPlayers.players.Length > 0) //{ // foreach (Player player in initialSetofPlayers.players) // { // if (player.id == myAddress) // continue; // currentPlayers.Add(player.id, Instantiate(playerGO, new Vector3(0, 0, 0), Quaternion.identity)); // currentPlayers[player.id].GetComponent<Renderer>().material.color = new Color(player.color.R, player.color.G, player.color.B); // currentPlayers[player.id].transform.position = new Vector3(player.position.X, player.position.Y, player.position.Z); // currentPlayers[player.id].name = player.id; // } // initialSetofPlayers = new ListOfPlayers(); //} }
void OnReceived(IAsyncResult result) { // this is what had been passed into BeginReceive as the second parameter: UdpClient socket = result.AsyncState as UdpClient; // points towards whoever had sent the message: IPEndPoint source = new IPEndPoint(0, 0); // get the actual message and fill out the source: byte[] message = socket.EndReceive(result, ref source); // do what you'd like with `message` here: string returnData = Encoding.ASCII.GetString(message); UnityEngine.Debug.Log("Got this: " + returnData); latestMessage = JsonUtility.FromJson <Message>(returnData); try{ switch (latestMessage.cmd) { case commands.NEW_CLIENT: ListOfPlayers newestPlayer = JsonUtility.FromJson <ListOfPlayers>(returnData); foreach (Player player in newestPlayer.players) { newPlayers.Add(player.id); myAddy = player.id; } break; case commands.GAME_UPDATE: latestGameState = JsonUtility.FromJson <GameState>(returnData); UnityEngine.Debug.Log("latestGameState" + returnData); break; case commands.PLAYER_DISCONNECTED: DestroyPlayers(returnData); break; case commands.LIST_OF_PLAYERS: initialPlayers = JsonUtility.FromJson <ListOfPlayers>(returnData); break; default: UnityEngine.Debug.Log("Error"); break; } } catch (Exception e) { UnityEngine.Debug.Log(e.ToString()); } // schedule the next receive operation once reading is done: socket.BeginReceive(new AsyncCallback(OnReceived), socket); }
/// <summary> /// Add a player to the list of players /// </summary> /// <param name="player">Joueur</param> public void AddPlayer(Player player) { if (ListOfPlayers.Exists(x => x.Pawn.ColorValue == player.Pawn.ColorValue)) { throw new InvalidePlayerColorException(); } else { this.ListOfPlayers.Add(player); bankInstance.CreateBankAccount(player); } }
private void Execute_Each_CardTurn_Of_All_Players(int quantitOfExecutionOfCardsTurn, int quantityExecutionOfPlayersCallBack) { Sut = new PlayersQuantityType(new Domain.Player.Players(ListOfPlayers.Select(x => x.Object))); var callback = new Mock <SelectedCardsConfirmationDelegate>(); callback.Setup(x => x(It.IsAny <IRacingCards>())).Returns(true); Enumerable.Range(0, quantitOfExecutionOfCardsTurn) .ToList() .ForEach(x => Sut.CardsTurn(callback.Object)); ListOfPlayers.ForEach(player => player.Verify(x => x.CardsTurn(callback.Object), Times.Exactly(quantityExecutionOfPlayersCallBack))); }
private void StartGameBUT_Click(object sender, EventArgs e) { StartGameBUT.Invoke((MethodInvoker)(() => StartGameBUT.Dispose())); SettingsBUT.Invoke((MethodInvoker)(() => SettingsBUT.Dispose())); EscapeBUT.Invoke((MethodInvoker)(() => EscapeBUT.Dispose())); Title.Invoke((MethodInvoker)(() => Title.Visible = true)); ListOfPlayers.Invoke((MethodInvoker)(() => ListOfPlayers.Visible = true)); Status.Invoke((MethodInvoker)(() => Status.Visible = true)); groupChoose.Invoke((MethodInvoker)(() => groupChoose.Visible = true)); ChooseEnemyBUT.Invoke((MethodInvoker)(() => ChooseEnemyBUT.Visible = true)); RandomEnemyBUT.Invoke((MethodInvoker)(() => RandomEnemyBUT.Visible = true)); this.Width = 622; }
public void OpenGame() { Player newPlayer; for (int playerId = 1; playerId <= NumberOfPlayers; playerId++) { newPlayer = PlayerCreator.CreatePlayer(playerId); ListOfPlayers.Add(newPlayer); } Assigner.AssignLeftAndRightPlayers(ListOfPlayers); CurrentPlayer = TurnsManager.GetNext(ListOfPlayers, CurrentPlayer); }
public bool GameIsFinish() { int nb = ListOfPlayers.Count(x => (x.HasLost == true)); if (nb == GetNumberOfPlayer() - 1) { Player p = ListOfPlayers.Find(x => (x.HasLost != true)); p.IsWinner = true; return(true); } else { return(false); } }
// Start is called before the first frame update void Start() { newPlayers = new List <string>(); currentPlayers = new Dictionary <string, GameObject>(); initialPlayers = new ListOfPlayers(); udp = new UdpClient(); udp.Connect("18.217.204.205", 12345); Byte[] sendBytes = Encoding.ASCII.GetBytes("connect"); udp.Send(sendBytes, sendBytes.Length); udp.BeginReceive(new AsyncCallback(OnReceived), udp); InvokeRepeating("HeartBeat", 1, 4); InvokeRepeating("MovePlayer", 1, 2); }
// Start is called before the first frame update void Start() { newPlayers = new List <string>(); droppedPlayers = new List <string>(); currentPlayers = new Dictionary <string, GameObject>(); initialSetofPlayers = new ListOfPlayers(); udp = new UdpClient(); udp.Connect("52.15.219.197", 12345); Byte[] sendBytes = Encoding.ASCII.GetBytes("connect"); udp.Send(sendBytes, sendBytes.Length); udp.BeginReceive(new AsyncCallback(OnReceived), udp); InvokeRepeating("HeartBeat", 1, 1); }
private void onClickAddPlayer(object sender, RoutedEventArgs e) { try { if (PlayerName == placeholder) { UINotifyAlertMessage("Le nom du joueur est invalide !", AlertDialog.TypeOfAlert.WARNING); } else { if (IndexSelected != -1) { if (ListOfPlayers.Count(x => (x.Pawn.ColorValue == PlayerColor) && (x.Id != PlayerSelected.Id)) != 0) { UINotifyAlertMessage("La couleur est déjà attribuée à un joueur", AlertDialog.TypeOfAlert.WARNING); } else { Player p = ListOfPlayers.Single(x => x.Id == PlayerSelected.Id); p.Name = PlayerName; p.Pawn.ColorValue = PlayerColor; OnPropertyChanged("ListOfPlayers"); PlayerName = placeholder; PlayerColor = defaultColorValue; _ColorHandler.SetColorIndex(0); } } else { if ((ListOfPlayers.Count(x => (x.Pawn.ColorValue == PlayerColor)) != 0)) { UINotifyAlertMessage("La couleur est déjà attribuée à un joueur", AlertDialog.TypeOfAlert.WARNING); } else { this.ListOfPlayers.Add(new Player(PlayerName, new Pawn(PlayerColor), Player.TypeOfPlayer.USER)); PlayerName = placeholder; PlayerColor = defaultColorValue; _ColorHandler.SetColorIndex(0); } } } } catch (Exception exp) { UINotifyAlertMessage(exp.Message, AlertDialog.TypeOfAlert.ERROR); } }
private string PrepareSaveData()//Prepares and returns json data to be saved { List <PlayerInfo> playerScripts = new List <PlayerInfo>(); foreach (PlayerInfo item in leaderBoardPlayers.Values) { playerScripts.Add(item); } ListOfPlayers playerList = new ListOfPlayers { leaderBList = playerScripts }; string jsonData = JsonUtility.ToJson(playerList); return(jsonData); }
private void GetDataFromDB() //Gets the JSON leaderboard string loaded from db { string JSONData = gameData.GetLeaderBoardJSON(); if (Misc.IsStringValid(JSONData)) { dbLeaderBoardData = JsonUtility.FromJson <ListOfPlayers>(JSONData); Debug.Log($"{nameof(dbLeaderBoardData)} will be set to <color=blue>{JSONData}</color>"); } else { dbLeaderBoardData = null; Debug.Log($"{nameof(dbLeaderBoardData)} will be set to <color=red>null</color>"); } //Debug.Log($"{nameof(JSONData)}: {JSONData}."); }
// Start is called before the first frame update void Start() { localPLayerPos = new Vector3(0, 0, 0); newPlayers = new List <string>(); droppedPlayers = new List <string>(); currentPlayers = new Dictionary <string, GameObject>(); initialSetofPlayers = new ListOfPlayers(); udp = new UdpClient(); udp.Connect("52.70.146.214", 12345); Byte[] sendBytes = Encoding.ASCII.GetBytes("connect"); udp.Send(sendBytes, sendBytes.Length); udp.BeginReceive(new AsyncCallback(OnReceived), udp); InvokeRepeating("HeartBeat", 0.033f, 0.033f); }
public MessageType latestMessage; // the last message received from the server // Start is called before the first frame update void Start() { // Initialize variables newPlayers = new List <string>(); droppedPlayers = new List <string>(); currentPlayers = new Dictionary <string, GameObject>(); initialSetofPlayers = new ListOfPlayers(); // Connect to the client. // All this is explained in Week 1-4 slides udp = new UdpClient(); Debug.Log("Connecting..."); udp.Connect("localhost", 12345); Byte[] sendBytes = Encoding.ASCII.GetBytes("connect"); udp.Send(sendBytes, sendBytes.Length); udp.BeginReceive(new AsyncCallback(OnReceived), udp); InvokeRepeating("HeartBeat", 1, 1); }
// Start is called before the first frame update void Start() { newPlayers = new List <string>(); droppedPlayers = new List <string>(); currentPlayers = new Dictionary <string, GameObject>(); initialSetofPlayers = new ListOfPlayers(); udp = new UdpClient(); udp.Connect("52.15.219.197", 12345); MsgConnectionRequest message = new MsgConnectionRequest(); message.cmd = commands.CONNECTION_REQUEST; Byte[] sendBytes = Encoding.ASCII.GetBytes(JsonUtility.ToJson(message)); udp.Send(sendBytes, sendBytes.Length); udp.BeginReceive(new AsyncCallback(OnReceived), udp); InvokeRepeating("HeartBeat", 1, 1); InvokeRepeating("UpdateMe", 1, 0.01f); }
void OnConnect() { Debug.Log("We are now connected to the server"); newPlayers = new List <string>(); initialSetofPlayers = new ListOfPlayers(); networkPlayer = new NetworkObjects.NetworkPlayer(); SpawnPlayer(networkPlayer.id, networkPlayer.cubPos, networkPlayer.rotation); //// Example to send a handshake message: //HandshakeMsg m = new HandshakeMsg(); //m.player.id = m_Connection.InternalId.ToString(); //SendToServer(JsonUtility.ToJson(m)); //Testing Player update //PlayerUpdateMsg m = new PlayerUpdateMsg(); //m.player.id = m_Connection.InternalId.ToString(); //SendToServer(JsonUtility.ToJson(m)); }
internal static IEnumerator GetPlayers() { Player player = FindObjectOfType <Player>(); UnityWebRequest httpClient = new UnityWebRequest("http://localhost:64497/api/Player/Players", "GET"); httpClient.SetRequestHeader("Accept", "application/json"); httpClient.downloadHandler = new DownloadHandlerBuffer(); yield return(httpClient.SendWebRequest()); if (httpClient.isNetworkError || httpClient.isHttpError) { throw new Exception("Helper > GetPlayerInfo: " + httpClient.error); } else { //meter mas campos var texto = "{\"myStrings\":" + httpClient.downloadHandler.text + "}"; ListOfPlayers lista = JsonUtility.FromJson <ListOfPlayers>(texto); textBoard.text += "\nJsonTests > ReceiveJsonListOfString: "; foreach (PlayerSerializable playerInList in lista.players) { textBoard.text += "\n\t" + playerInList.Name; textBoard.text += "\n\t" + playerInList.BirthDay; textBoard.text += "\n\t" + playerInList.LastLog; textBoard.text += "\n\t"; } Task.Delay(3); //PlayerSerializable playerSerializable = JsonUtility.FromJson<PlayerSerializable>(httpClient.downloadHandler.text); //player.Id = playerSerializable.Id; //player.Name = playerSerializable.Name; //player.Email = playerSerializable.Email; //player.BirthDay = DateTime.Parse(playerSerializable.BirthDay); } httpClient.Dispose(); }
// Start is called before the first frame update void Start() { newPlayers = new List <string>(); droppedPlayers = new List <string>(); currentPlayers = new Dictionary <string, GameObject>(); initialSetofPlayers = new ListOfPlayers(); udp = new UdpClient(); udp.Connect("54.152.99.54", 12345); ConnectMessage msg = new ConnectMessage(); msg.cmd = "connect"; Byte[] sendBytes = Encoding.ASCII.GetBytes(JsonUtility.ToJson(msg)); udp.Send(sendBytes, sendBytes.Length); udp.BeginReceive(new AsyncCallback(OnReceived), udp); InvokeRepeating("HeartBeat", 1, 1); InvokeRepeating("Position", 0.5f, 0.5f); }