Exemplo n.º 1
0
 public gameState(int _recipient, int stage = 1)
 {
     if (stage == 0)
     {
         _serverPort            = MainWindow.serverPort;
         _numOfPlayers          = MainWindow.numOfPlayers;
         _myPlayerNum           = _recipient;
         _numOfPlayersConnected = MainWindow.numOfPlayersConnected;
         _playerNames           = MainWindow.playerNames;
         _beginGame             = MainWindow.beginGame;
         //_messageNumber = MainWindow.messageNum[_recipient];
     }
     else
     {
         _AllHands             = MainWindow.AllHands;
         _AllTableMoney        = MainWindow.AllTableMoney;
         _AllTableProperties   = MainWindow.AllTableProperties;
         _button1Text          = MainWindow.playerTurns[_recipient].button1.Content.ToString();
         _button1Visibility    = MainWindow.playerTurns[_recipient].button1.Visibility;
         _button2Text          = MainWindow.playerTurns[_recipient].button2.Content.ToString();
         _button2Visibility    = MainWindow.playerTurns[_recipient].button2.Visibility;
         _button3Text          = MainWindow.playerTurns[_recipient].button3.Content.ToString();
         _button3Visibility    = MainWindow.playerTurns[_recipient].button3.Visibility;
         _buttonBackText       = MainWindow.playerTurns[_recipient].buttonBack.Content.ToString();
         _buttonBackVisibility = MainWindow.playerTurns[_recipient].buttonBack.Visibility;
         _individualPrompt     = MainWindow.playerTurns[_recipient].Prompt.Content.ToString();
         _newUniversalPrompt   = MainWindow.newUniversalPrompt;
         _numCardsInDeck       = MainWindow.deckShuffled.Count;
         _playerNames          = MainWindow.playerNames;
         _playerNum            = MainWindow.playerNum;
         _playNum       = MainWindow.playNum;
         _updateCards   = MainWindow.updateCards;
         _messageNumber = MainWindow.messageNum[_recipient];
         _stage         = MainWindow.stage.ToString();
         _turnStage     = MainWindow.stage;
     }
 }
Exemplo n.º 2
0
 public gameState(int _recipient,int stage = 1)
 {
     if (stage == 0)
     {
         _serverPort = MainWindow.serverPort;
         _numOfPlayers = MainWindow.numOfPlayers;
         _myPlayerNum = _recipient;
         _numOfPlayersConnected = MainWindow.numOfPlayersConnected;
         _playerNames = MainWindow.playerNames;
         _beginGame = MainWindow.beginGame;
         //_messageNumber = MainWindow.messageNum[_recipient];
     }
     else
     {
         _AllHands = MainWindow.AllHands;
         _AllTableMoney = MainWindow.AllTableMoney;
         _AllTableProperties = MainWindow.AllTableProperties;
         _button1Text = MainWindow.playerTurns[_recipient].button1.Content.ToString();
         _button1Visibility = MainWindow.playerTurns[_recipient].button1.Visibility;
         _button2Text = MainWindow.playerTurns[_recipient].button2.Content.ToString();
         _button2Visibility = MainWindow.playerTurns[_recipient].button2.Visibility;
         _button3Text = MainWindow.playerTurns[_recipient].button3.Content.ToString();
         _button3Visibility = MainWindow.playerTurns[_recipient].button3.Visibility;
         _buttonBackText = MainWindow.playerTurns[_recipient].buttonBack.Content.ToString();
         _buttonBackVisibility = MainWindow.playerTurns[_recipient].buttonBack.Visibility;
         _individualPrompt = MainWindow.playerTurns[_recipient].Prompt.Content.ToString();
         _newUniversalPrompt = MainWindow.newUniversalPrompt;
         _numCardsInDeck = MainWindow.deckShuffled.Count;
         _playerNames = MainWindow.playerNames;
         _playerNum = MainWindow.playerNum;
         _playNum = MainWindow.playNum;
         _updateCards = MainWindow.updateCards;
         _messageNumber = MainWindow.messageNum[_recipient];
         _stage = MainWindow.stage.ToString();
         _turnStage = MainWindow.stage;
     }
 }
        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;
        }