Example #1
0
        /// <summary>
        /// Sets the <see cref="playerSpinner"/> up with a list of players
        /// </summary>
        /// <param name="setupRequest"></param>
        private void SetupPlayerlist(SetupRequest setupRequest)
        {
            RunOnUiThread(() =>
            {
                String[] players = new String[setupRequest.Players.Count - 1];
                int counter      = 0;
                foreach (string player in setupRequest.Players)
                {
                    if (player != localPlayer)
                    {
                        players[counter] = player;
                        counter++;
                    }
                }

                ArrayAdapter adapter = new ArrayAdapter(this, (Resource.Layout.support_simple_spinner_dropdown_item), players);

                playerSpinner.Adapter = adapter;
            });
        }
Example #2
0
        private void ReceiveData(TcpClient client)
        {
            // Receive requests
            NetworkStream ns = client.GetStream();

            byte[] receiveBytes = new byte[1024];
            int    byteCount;

            while ((byteCount = ns.Read(receiveBytes, 0, receiveBytes.Length)) > 0)
            {
                Request request;

                // Set request type either GameRequest or SetupRequest.
                if (Encoding.UTF8.GetString(receiveBytes, 0, byteCount).Contains("Players"))
                {
                    request = JsonConvert.DeserializeObject <SetupRequest>(Encoding.UTF8.GetString(receiveBytes, 0, byteCount));
                }
                else
                {
                    request = JsonConvert.DeserializeObject <GameRequest>(Encoding.UTF8.GetString(receiveBytes, 0, byteCount));
                }

                GameRequest gameRequest;

                switch (request.RequestType)
                {
                // End game
                case 0:
                    gameEnded           = true;
                    statusTextView.Text = "Spillet er s**t!";
                    AnswerPointRequest();
                    break;

                // Answer on request
                case 1:
                    gameRequest = (GameRequest)request;

                    if (gameRequest.UserTo == localPlayer)
                    {
                        statusTextView.Text = "Det er din tur!";
                    }
                    else
                    {
                        statusTextView.Text = "Det er ikke din tur endnu!";
                    }
                    break;

                // Receive card(s)
                case 2:
                    gameRequest = (GameRequest)request;
                    UpdateUIOnReceive(gameRequest);

                    AddCardsToCollection(gameRequest.Cardlist, gameRequest.UserFrom);
                    CheckForSets();

                    SetupSpinner();
                    break;

                // Give cards away
                case 3:
                    gameRequest = (GameRequest)request;

                    GiveCardsAway(gameRequest, client);

                    SetupSpinner();
                    break;

                // Set up list of players for the spinner
                case 4:
                    SetupRequest setupRequest = (SetupRequest)request;
                    SetupPlayerlist(setupRequest);
                    break;

                case 10:
                    gameRequest = (GameRequest)request;
                    receivedCardsTextView.Text = (gameRequest.UserFrom + " vandt med " + gameRequest.CardValue + " stik!");
                    break;

                default:
                    break;
                }
            }
        }