public void timerDing()
        {
            if (clientState == state.connectToServer)
            {
                client = new ClientSocket(serverPort, 2, clientPort, clientIP, serverIP);
                clientState = state.getNewPort;
            }

            if (clientState == state.getNewPort)
            {
                byte[] storage = null;
                storage = client.pollAndReceiveData(client.Server, 2);
                if (storage.Count() > 2)
                {
                    sendAcknowledgement();
                    string tempString = GetString(storage);
                    currGameState = Newtonsoft.Json.JsonConvert.DeserializeObject<gameState>(tempString);
                    serverPort = currGameState._serverPort;
                    myPlayerNum = currGameState._myPlayerNum;
                    numOfPlayers = currGameState._numOfPlayers;
                    numOfPlayersConnected = currGameState._numOfPlayersConnected;
                    playerNames = currGameState._playerNames;
                    beginGame = currGameState._beginGame;
                    initializeDisplay();
                    client.stop();
                    Thread.Sleep(100);
                    client = new ClientSocket(serverPort, 2, clientPort, clientIP, serverIP);
                    storage = GetBytes(myName);
                    client.sendData(storage);
                    if (beginGame)
                    {
                        clientState = state.beginGame;
                    }
                    else
                    {
                        clientState = state.waitForOthers;
                    }
                }
            }
            if (clientState == state.waitForOthers)
            {
                myDisplay.Prompt.Content = "Waiting on " + (numOfPlayers - numOfPlayersConnected) + " more players...";
                byte[] storage = null;
                storage = client.pollAndReceiveData(client.Server, 2);
                if (storage.Count() > 2)
                {
                    sendAcknowledgement();
                    string tempString = GetString(storage);
                    currGameState = Newtonsoft.Json.JsonConvert.DeserializeObject<gameState>(tempString);
                    numOfPlayersConnected = currGameState._numOfPlayersConnected;
                    playerNames = currGameState._playerNames;
                    beginGame = currGameState._beginGame;
                }
                if (beginGame)
                {
                    clientState = state.beginGame;
                }
            }
            if (clientState == state.beginGame)
            {
                byte[] storage = null;
                storage = client.pollAndReceiveData(client.Server, 2);
                if (storage.Count() > 2)
                {
                    sendAcknowledgement();
                    string tempString = GetString(storage);
                    currGameState = Newtonsoft.Json.JsonConvert.DeserializeObject<gameState>(tempString);
                    AllHands = currGameState._AllHands;
                    AllTableMoney = currGameState._AllTableMoney;
                    AllTableProperties = currGameState._AllTableProperties;
                    myDisplay.button1.Content = currGameState._button1Text;
                    myDisplay.button1.Visibility = currGameState._button1Visibility;
                    myDisplay.button2.Content = currGameState._button2Text;
                    myDisplay.button2.Visibility = currGameState._button2Visibility;
                    myDisplay.button3.Content = currGameState._button3Text;
                    myDisplay.button3.Visibility = currGameState._button3Visibility;
                    myDisplay.buttonBack.Content = currGameState._buttonBackText;
                    myDisplay.buttonBack.Visibility = currGameState._buttonBackVisibility;
                    myDisplay.Prompt.Content = currGameState._individualPrompt;
                    myDisplay.universalPrompt.Text += currGameState._newUniversalPrompt;
                    numCardsInDeck = currGameState._numCardsInDeck;
                    playNum = currGameState._playNum;
                    playerNum = currGameState._playerNum;
                    playerNames = currGameState._playerNames;
                    showFullDisplay();
                    clientState = state.transmit;
                }
            }
            if (clientState == state.transmit)
            {
                byte[] storage = null;
                storage = client.pollAndReceiveData(client.Server, 2);
                if (storage.Count() > 2)
                {
                    sendAcknowledgement();
                    string tempString = GetString(storage);
                    currGameState = Newtonsoft.Json.JsonConvert.DeserializeObject<gameState>(tempString);
                    AllHands = currGameState._AllHands;
                    AllTableMoney = currGameState._AllTableMoney;
                    AllTableProperties = currGameState._AllTableProperties;
                    myDisplay.button1.Content = currGameState._button1Text;
                    myDisplay.button1.Visibility = currGameState._button1Visibility;
                    myDisplay.button2.Content = currGameState._button2Text;
                    myDisplay.button2.Visibility = currGameState._button2Visibility;
                    myDisplay.button3.Content = currGameState._button3Text;
                    myDisplay.button3.Visibility = currGameState._button3Visibility;
                    myDisplay.buttonBack.Content = currGameState._buttonBackText;
                    myDisplay.buttonBack.Visibility = currGameState._buttonBackVisibility;
                    myDisplay.Prompt.Content = currGameState._individualPrompt;
                    myDisplay.universalPrompt.Text += currGameState._newUniversalPrompt;
                    numCardsInDeck = currGameState._numCardsInDeck;
                    playNum = currGameState._playNum;
                    playerNum = currGameState._playerNum;
                    playerNames = currGameState._playerNames;
                    showTable(currGameState._updateCards);
                }
            }
            aTimer.Enabled = true;
        }
Ejemplo n.º 2
0
        public void timerDing()
        {
            if (clientState == state.connectToServer)
            {
                client = new ClientSocket(serverPort, 2, clientPort, clientIP, serverIP);
                clientState = state.getNewPort;
            }

            if (clientState == state.getNewPort)
            {
                byte[] storage = null;
                storage = client.pollAndReceiveData(client.Server, 2);
                if (storage.Count() > 2)
                {
                    //sendAcknowledgement();
                    string tempString = GetString(storage);
                    currGameState = Newtonsoft.Json.JsonConvert.DeserializeObject<gameState>(tempString);
                    serverPort = currGameState._serverPort;
                    myPlayerNum = currGameState._myPlayerNum;
                    numOfPlayers = currGameState._numOfPlayers;
                    numOfPlayersConnected = currGameState._numOfPlayersConnected;
                    playerNames = currGameState._playerNames;
                    beginGame = currGameState._beginGame;
                    initializeDisplay();
                    client.stop();
                    Thread.Sleep(100);
                    client = new ClientSocket(serverPort, 2, clientPort, clientIP, serverIP);
                    storage = GetBytes(myName);
                    client.sendData(storage);
                    if (beginGame)
                    {
                        clientState = state.beginGame;
                    }
                    else
                    {
                        clientState = state.waitForOthers;
                    }
                }
            }
            if (clientState == state.waitForOthers)
            {
                myDisplay.Prompt.Content = "Waiting on " + (numOfPlayers - numOfPlayersConnected) + " more players...";
                byte[] storage = null;
                storage = client.pollAndReceiveData(client.Server, 2);
                if (storage.Count() > 2)
                {
                    //sendAcknowledgement();
                    string tempString = GetString(storage);
                    currGameState = Newtonsoft.Json.JsonConvert.DeserializeObject<gameState>(tempString);
                    numOfPlayersConnected = currGameState._numOfPlayersConnected;
                    playerNames = currGameState._playerNames;
                    beginGame = currGameState._beginGame;
                }
                if (beginGame)
                {
                    clientState = state.beginGame;
                }
            }
            if (clientState == state.beginGame)
            {
                byte[] storage = null;
                storage = client.pollAndReceiveData(client.Server, 2);
                if (storage.Count() > 2)
                {
                    //sendAcknowledgement();
                    string tempString = GetString(storage);
                    currGameState = Newtonsoft.Json.JsonConvert.DeserializeObject<gameState>(tempString);
                    AllHands = currGameState._AllHands;
                    AllTableMoney = currGameState._AllTableMoney;
                    AllTableProperties = currGameState._AllTableProperties;
                    myDisplay.button1.Content = currGameState._button1Text;
                    myDisplay.button1.Visibility = currGameState._button1Visibility;
                    myDisplay.button2.Content = currGameState._button2Text;
                    myDisplay.button2.Visibility = currGameState._button2Visibility;
                    myDisplay.button3.Content = currGameState._button3Text;
                    myDisplay.button3.Visibility = currGameState._button3Visibility;
                    myDisplay.buttonBack.Content = currGameState._buttonBackText;
                    myDisplay.buttonBack.Visibility = currGameState._buttonBackVisibility;
                    myDisplay.Prompt.Content = currGameState._individualPrompt;
                    myDisplay.universalPrompt.Text += currGameState._newUniversalPrompt;
                    numCardsInDeck = currGameState._numCardsInDeck;
                    playNum = currGameState._playNum;
                    playerNum = currGameState._playerNum;
                    playerNames = currGameState._playerNames;
                    showFullDisplay();
                    clientState = state.transmit;
                }
            }
            if (clientState == state.transmit)
            {
                byte[] storage = null;
                storage = client.pollAndReceiveData(client.Server, 2);
                if (storage.Count() > 2)
                {
                    //sendAcknowledgement();
                    string tempString = GetString(storage);
                    currGameState = Newtonsoft.Json.JsonConvert.DeserializeObject<gameState>(tempString);
                    if (currGameState._messageNumber > messageNum)
                    {
                        messageNum = currGameState._messageNumber;
                        eventHappened = false;
                        clearEvents();
                        AllHands = currGameState._AllHands;
                        AllTableMoney = currGameState._AllTableMoney;
                        AllTableProperties = currGameState._AllTableProperties;
                        myDisplay.button1.Content = currGameState._button1Text;
                        myDisplay.button1.Visibility = currGameState._button1Visibility;
                        myDisplay.button2.Content = currGameState._button2Text;
                        myDisplay.button2.Visibility = currGameState._button2Visibility;
                        myDisplay.button3.Content = currGameState._button3Text;
                        myDisplay.button3.Visibility = currGameState._button3Visibility;
                        myDisplay.buttonBack.Content = currGameState._buttonBackText;
                        myDisplay.buttonBack.Visibility = currGameState._buttonBackVisibility;
                        myDisplay.Prompt.Content = currGameState._individualPrompt;
                        myDisplay.universalPrompt.Text = currGameState._newUniversalPrompt;
                        numCardsInDeck = currGameState._numCardsInDeck;
                        playNum = currGameState._playNum;
                        playerNum = currGameState._playerNum;
                        playerNames = currGameState._playerNames;
                        string bob = currGameState._stage;
                        stage = currGameState._turnStage;
                        //Other player needs to choose cards
                        if ((stage == turnStage.acknowledgeAttack1) || (stage == turnStage.acknowledgeAttack2))
                        {
                            if (playerNum == myPlayerNum)
                            {
                                allowEvents = false;
                            }
                            else
                            {
                                allowEvents = true;
                            }
                        }
                        else //Playernum needs to choose cards
                        {
                            if (playerNum == myPlayerNum)
                            {
                                allowEvents = true;
                            }
                            else
                            {
                                allowEvents = false;
                            }
                        }
                        showTable(currGameState._updateCards);
                    }
                    else if(eventHappened)
                    {
                        TimeSpan duration = DateTime.Now - lastSend;
                        if (duration.Milliseconds > 5000)
                        {
                            resendClientEvent();
                            lastSend = DateTime.Now;
                        }
                    }
                }
            }
            aTimer.Enabled = true;
        }