Esempio n. 1
0
        public void RefreshView()
        {
            //try {
            //List<CardUtils.Player> other_players = this.client.Game.Players;
            List <CardUtils.Player> other_players = new List <CardUtils.Player>();

            foreach (CardUtils.Player p in this.client.Game.Players)
            {
                other_players.Add(p);
            }

            CardUtils.Player actualPlayer = this.client.Game.FindPlayer(this.client.playerID);
            other_players.Remove(actualPlayer);

            CardUtils.Player player1 = actualPlayer;
            CardUtils.Player player2 = null, player3 = null;

            if (other_players.Count > 0)
            {
                player2 = other_players[0];
                if (other_players.Count > 1)
                {
                    player3 = other_players[1];
                }
            }

            this.DisplayPlayers(player1, player2, player3);
            this.DisplayGameState();
        }
Esempio n. 2
0
        public void ShowPlayerCards(
            CardUtils.Player player,
            Panel playerPanel,
            bool isPlaying            = false,
            RadioButton playingRadio  = null,
            RadioButton standingRadio = null,
            bool gameFinished         = false)
        {
            List <CardUtils.Card> playerCards = player.Hand.getCards();
            int width   = 65;
            int spacing = 5;
            int row     = 11;
            int cardNb  = 0; // when the number of cards is 4 we reset to 0 so we can start the new row

            //            playerPanel.Controls.Clear();
            playerPanel.Invoke((MethodInvoker) delegate {
                playerPanel.Controls.Clear();
            });


            if (playingRadio != null)
            {
                playingRadio.Invoke((MethodInvoker) delegate {
                    playingRadio.Checked = isPlaying;
                });
            }
            if (standingRadio != null)
            {
                standingRadio.Invoke((MethodInvoker) delegate {
                    standingRadio.Checked = !isPlaying;
                });
            }


            for (int i = 0; i < playerCards.Count; i++)
            {
                if (i == 4)
                {
                    row = 142; cardNb = 0;
                }
                string     cardImage = playerCards[i].ImagePath();
                PictureBox aCard     = new PictureBox();
                aCard.Size     = new System.Drawing.Size(65, 125);
                aCard.Location = new System.Drawing.Point((cardNb * width) + spacing, row);
                aCard.SizeMode = PictureBoxSizeMode.StretchImage;
                if (!gameFinished && !(this.client.playerID == player.ID))
                {
                    cardImage = "_back";
                }
                aCard.Image = (System.Drawing.Image)global::Interface.Properties.Resources.ResourceManager.GetObject(cardImage + "");

                //called from client thread, causing error

                playerPanel.Invoke((MethodInvoker) delegate { playerPanel.Controls.Add(aCard); });


                cardNb++;
            }
        }
Esempio n. 3
0
 public void showWinner()
 {
     CardUtils.Player actualPlayer = this.client.Game.FindPlayer(this.client.playerID);
     if (actualPlayer == this.client.Game.Winner)
     {
         this.turnPictureBox.Image = (System.Drawing.Image)global::Interface.Properties.Resources._you_won;
     }
 }
Esempio n. 4
0
        public void DisplayActualPlayer(CardUtils.Player actualPlayer)
        {
            textBox_balance.Invoke((MethodInvoker) delegate {
                this.textBox_balance.Text = "" + actualPlayer.Bourse;
            });

            btnHitMe.Invoke((MethodInvoker) delegate {
                //this.btnHitMe.Enabled = this.client.Game.isPlaying(actualPlayer);
            });
            btnStand.Invoke((MethodInvoker) delegate {
                //this.btnStand.Enabled = this.client.Game.isPlaying(actualPlayer);
            });
        }
Esempio n. 5
0
        public void ProcessClientMessage(TcpClient client, NETMSG msg)
        {
            switch (msg.Type)
            {
            case NETMSG.MSG_TYPES.CLIENT_REQUEST_SYNC:
                SendClient(client, new NETMSG(NETMSG.MSG_TYPES.SERVER_GAME, objToBytes(this.game)));
                break;

            case NETMSG.MSG_TYPES.CLIENT_DISCONNECT:
                this.clients.Remove(client);
                Console.WriteLine("client disconnected");
                game.Disconnect((uint)NETMSG.bytesToObj(msg.Payload));
                FullBroadCast(new NETMSG(NETMSG.MSG_TYPES.PLAYER_DISCONNECTED, msg.Payload));
                break;

            case NETMSG.MSG_TYPES.CLIENT_OK:
                //for sync purposes
                break;

            case NETMSG.MSG_TYPES.CLIENT_READY:
                //for sync purposes
                break;

            case NETMSG.MSG_TYPES.CLIENT_REQUEST_UID:
                CardUtils.Player p = game.createPlayer();
                game.AddPlayer(p);
                SendClient(client, new NETMSG(NETMSG.MSG_TYPES.SERVER_PLAYER_UID, objToBytes(p)));
                FullBroadCast(new NETMSG(NETMSG.MSG_TYPES.PLAYER_CONNECTED, objToBytes(p)));
                break;

            case NETMSG.MSG_TYPES.PLAYER_PASS:
                game.Pass(((CardUtils.Player)NETMSG.bytesToObj(msg.Payload)).ID);
                BroadCastExceptForClient(client, msg);
                break;

            case NETMSG.MSG_TYPES.PLAYER_PICKS:
                Console.WriteLine("player picked: " + (uint)NETMSG.bytesToObj(msg.Payload));

                game.PickCard((uint)NETMSG.bytesToObj(msg.Payload));
                BroadCastExceptForClient(client, msg);
                break;

            case NETMSG.MSG_TYPES.PLAYER_BETS:
                game.Bet(((BET)NETMSG.bytesToObj(msg.Payload)).PlayerID, ((BET)NETMSG.bytesToObj(msg.Payload)).betTOAdd);
                BroadCastExceptForClient(client, msg);
                break;

            default:
                break;
            }
        }
Esempio n. 6
0
 public void BtnHitMe_Click(object sender, EventArgs e)
 {
     // Button Hit Me Click
     CardUtils.Player actualPlayer = this.client.Game.FindPlayer(this.client.playerID);
     if (actualPlayer.Points > 21)
     {
         StopPlaying();
         MessageBox.Show("GAME OVER! You busted, you have more than 21 pts.");
         this.client.Stand();
     }
     else
     {
         client.HitMe();
     }
 }
Esempio n. 7
0
 public void DisplayPlayers(CardUtils.Player actualPlayer, CardUtils.Player player2, CardUtils.Player player3, bool gameFinished = false)
 {
     if (actualPlayer != null)
     {
         this.ShowPlayerCards(actualPlayer, this.Player1Panel, this.client.Game.isPlaying(actualPlayer), null, null, gameFinished);
         this.DisplayActualPlayer(actualPlayer);
     }
     if (player2 != null)
     {
         this.ShowPlayerCards(player2, this.Player2Panel, this.client.Game.isPlaying(player2), this.radioButton1, this.radioButton2, gameFinished);
     }
     if (player3 != null)
     {
         this.ShowPlayerCards(player3, this.Player3Panel, this.client.Game.isPlaying(player3), this.radioButton3, this.radioButton4, gameFinished);
     }
 }
Esempio n. 8
0
        private void btnBet_Click(object sender, EventArgs e)
        {
            float bet = float.Parse(textBox_Bet.Text);

            this.textBox_Bet.Text = "";
            CardUtils.Player actualPlayer = this.client.Game.FindPlayer(this.client.playerID);
            if (actualPlayer.Bourse >= bet)
            {
                client.Bet(bet);
                this.btnBet.Enabled = false;
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("You're bet exceeds your balance!");
            }
        }
Esempio n. 9
0
        private void processServerMessage(NETMSG msg)
        {
            switch (msg.Type)
            {
            case NETMSG.MSG_TYPES.SERVER_OK:
                //this is a sync message
                break;

            case NETMSG.MSG_TYPES.SERVER_GAME:
                this.Game = (CardUtils.Game)NETMSG.bytesToObj(msg.Payload);

                break;

            case NETMSG.MSG_TYPES.SERVER_FULL:
                MessageBox.Show("The server is full. Closing connection.");
                ExitRequested = true;
                break;

            case NETMSG.MSG_TYPES.SERVER_ERROR:
                MessageBox.Show("SERVER_ERROR received from Server: \n" + msg.Message + ".");
                break;

            case NETMSG.MSG_TYPES.SERVER_CLOSING:
                MessageBox.Show("The server will close or you were kicked.  Disconnecting from server.");
                ExitRequested = true;
                break;

            case NETMSG.MSG_TYPES.SERVER_PLAYER_UID:
                this.playerID = ((CardUtils.Player)NETMSG.bytesToObj(msg.Payload)).ID;
                break;

            case NETMSG.MSG_TYPES.PLAYER_BETS:
                this.Game.Bet(((BET)NETMSG.bytesToObj(msg.Payload)).PlayerID, ((BET)NETMSG.bytesToObj(msg.Payload)).betTOAdd);
                break;

            case NETMSG.MSG_TYPES.PLAYER_CONNECTED:
                CardUtils.Player pla = (CardUtils.Player)NETMSG.bytesToObj(msg.Payload);
                Console.WriteLine("new player!: " + pla.ID);
                Game.AddPlayer(pla);
                break;

            case NETMSG.MSG_TYPES.PLAYER_DISCONNECTED:
                uint id = (uint)NETMSG.bytesToObj(msg.Payload);
                this.Game.Disconnect(id);
                break;

            case NETMSG.MSG_TYPES.PLAYER_PASS:
                this.Game.Pass(((CardUtils.Player)NETMSG.bytesToObj(msg.Payload)).ID);
                break;

            case NETMSG.MSG_TYPES.PLAYER_PICKS:
                this.Game.Pass((uint)NETMSG.bytesToObj(msg.Payload));
                break;

            case NETMSG.MSG_TYPES.END_GAME:
                //say who won
                break;

            default:
                MessageBox.Show("Unknown NETMSG struct object received");
                break;
            }
        }
Esempio n. 10
0
        private void processServerMessage(NETMSG msg)
        {
            switch (msg.Type)
            {
            case NETMSG.MSG_TYPES.SERVER_OK:
                //this is a sync message

                break;

            case NETMSG.MSG_TYPES.SERVER_GAME:
                this.Game = (CardUtils.Game)NETMSG.bytesToObj(msg.Payload);

                break;

            case NETMSG.MSG_TYPES.SERVER_FULL:
                MessageBox.Show("The server is full. Closing connection.");
                ExitRequested = true;
                break;

            case NETMSG.MSG_TYPES.SERVER_ERROR:
                MessageBox.Show("SERVER_ERROR received from Server: \n" + msg.Message + ".");
                break;

            case NETMSG.MSG_TYPES.SERVER_CLOSING:
                MessageBox.Show("The server will close or you were kicked.  Disconnecting from server.");
                ExitRequested = true;
                break;

            case NETMSG.MSG_TYPES.SERVER_PLAYER_UID:
                this.playerID = ((CardUtils.Player)NETMSG.bytesToObj(msg.Payload)).ID;
                break;

            case NETMSG.MSG_TYPES.PLAYER_BETS:
                this.Game.Bet(((BET)NETMSG.bytesToObj(msg.Payload)).PlayerID, ((BET)NETMSG.bytesToObj(msg.Payload)).betTOAdd);
                //ui.RefreshView();
                RefreshUI();
                break;

            case NETMSG.MSG_TYPES.PLAYER_CONNECTED:
                CardUtils.Player pla = (CardUtils.Player)NETMSG.bytesToObj(msg.Payload);
                if (Game.Players.Where(_player => _player.ID == pla.ID).Count() > 0)
                {
                    printl("... real funny, william, but player " + pla.ID + " seems to already be in the list...");
                    break;
                }
                printl("adding a new player: " + pla.ID);
                Game.AddPlayer(pla);
                //printl( playerID + " sees total count:" + Game.Players.Count );
                if (Game.Players.Count == 1)
                {
                    printl("i should now be the one playing. " + pla.ID);
                    Game.PlayingPlayer = Game.Players[0];
                }
                else if (Game.Players.Count > 3)
                {
                    foreach (CardUtils.Player _p in Game.Players)
                    {
                        printl("- " + _p.ID);
                    }
                }


                //ui.RefreshView();
                RefreshUI();
                break;

            case NETMSG.MSG_TYPES.PLAYER_DISCONNECTED:
                uint id = (uint)NETMSG.bytesToObj(msg.Payload);
                this.Game.Disconnect(id);
                //ui.RefreshView();
                RefreshUI();
                break;

            case NETMSG.MSG_TYPES.PLAYER_PASS:
                uint passedID = (uint)NETMSG.bytesToObj(msg.Payload);
                this.Game.Pass(passedID);
                printl(passedID + "told me he passed, i think " + Game.PlayingPlayer.ID + " is now playing.");
                if (this.Game.PlayingPlayer.ID == this.playerID)
                {
                    printl("i will now be playing.");
                    this.IsPlaying = true;
                }
                ShowWinner();
                RefreshUI();
                break;

            case NETMSG.MSG_TYPES.PLAYER_PICKS:
                PICK pick = ((PICK)NETMSG.bytesToObj(msg.Payload));
                this.Game.PickCard(pick.PlayerID, pick.Card);
                ShowWinner();
                RefreshUI();
                break;

            case NETMSG.MSG_TYPES.END_GAME:
                //say who won
                //ui.RefreshView
                RefreshUI();
                break;

            case NETMSG.MSG_TYPES.PLAYER_YOURTURN:
                //this.Game.PlayingPlayer = this.Game.FindPlayer( playerID );
                printl("i will be the first player.");
                IsPlaying = true;
                //ui.RefreshView();
                RefreshUI();
                break;

            default:
                MessageBox.Show("Unknown NETMSG struct object received");
                break;
            }
        }
Esempio n. 11
0
        public void ProcessClientMessage(TcpClient client, NETMSG msg)
        {
            switch (msg.Type)
            {
            case NETMSG.MSG_TYPES.CLIENT_REQUEST_SYNC:
                SendClient(client, new NETMSG(NETMSG.MSG_TYPES.SERVER_GAME, objToBytes(this.game)));
                break;

            case NETMSG.MSG_TYPES.CLIENT_DISCONNECT:
                this.clients.Remove(client);
                printl("client disconnected");
                game.Disconnect((uint)NETMSG.bytesToObj(msg.Payload));
                FullBroadCast(new NETMSG(NETMSG.MSG_TYPES.PLAYER_DISCONNECTED, msg.Payload));
                break;

            case NETMSG.MSG_TYPES.CLIENT_OK:
                //for sync purposes
                break;

            case NETMSG.MSG_TYPES.CLIENT_READY:
                //for sync purposes
                break;

            case NETMSG.MSG_TYPES.CLIENT_REQUEST_UID:
                CardUtils.Player p = game.createPlayer();
                game.AddPlayer(p);

                if (game.Players.Count == 1)
                {
                    printl(p.ID + " is the first so he starts.");
                    game.PlayingPlayer = game.Players[0];
                    clients[client].Add(new NETMSG(NETMSG.MSG_TYPES.PLAYER_YOURTURN, null));
                }
                SendClient(client, new NETMSG(NETMSG.MSG_TYPES.SERVER_PLAYER_UID, objToBytes(p)));

                FullBroadCast(new NETMSG(NETMSG.MSG_TYPES.PLAYER_CONNECTED, objToBytes(p)));
                break;

            case NETMSG.MSG_TYPES.PLAYER_PASS:
                uint passingID = (uint)NETMSG.bytesToObj(msg.Payload);
                printl(passingID + " passed.");
                game.Pass(passingID);
                FullBroadCast(msg);

                break;

            case NETMSG.MSG_TYPES.PLAYER_PICKS:
                printl("player picked: " + (uint)NETMSG.bytesToObj(msg.Payload));
                uint           pid    = (uint)NETMSG.bytesToObj(msg.Payload);
                CardUtils.Card picked = game.PickCard(pid);

                FullBroadCast(
                    new NETMSG(
                        NETMSG.MSG_TYPES.PLAYER_PICKS,
                        objToBytes(
                            new PICK(
                                pid,
                                picked
                                )
                            )
                        )
                    );
                break;

            case NETMSG.MSG_TYPES.PLAYER_BETS:
                game.Bet(((BET)NETMSG.bytesToObj(msg.Payload)).PlayerID, ((BET)NETMSG.bytesToObj(msg.Payload)).betTOAdd);

                FullBroadCast(msg);
                //BroadCastExceptForClient(client, msg);
                break;

            default:
                break;
            }
        }