Пример #1
0
 private void SendAction(TPokerAction PokerAction)
 {
     JsonHandle.SendObject(handler, PokerAction);
     if (PokerAction == TPokerAction.Rais)
     {
         int bet = trackBarRaise.Value;
         //Thread.Sleep(200);
         JsonHandle.SendObject(handler, bet);
     }
 }
Пример #2
0
        //const string login = "******";
        //const string name = "Ami";
        public Socket Go(string name, string login, int port)
        {
            List <PictureBox> UserCard = new List <PictureBox>()
            {
                UserCard10,
                UserCard9,
                UserCard8,
                UserCard7,
                UserCard6,
                UserCard5,
                UserCard4,
                UserCard3,
                UserCard2,
                UserCard1
            };
            List <PictureBox> UserPicth = new List <PictureBox>()
            {
                pictureBox6,
                pictureBox5,
                pictureBox3,
                pictureBox4,
                pictureBox2
            };
            List <Label> namesLabel = new List <Label>()
            {
                label3,
                label4,
                label6,
                label7,
                label5
            };

            try

            {
                //int quit = 0;
                //11006
                //конечная локальная точка
                IPHostEntry ipHost     = Dns.GetHostEntry("localhost");
                IPAddress   ipAddr     = ipHost.AddressList[1];
                IPEndPoint  ipEndPoint = new IPEndPoint(ipAddr, port);

                //Сoздаем сокет Tcp/Ip
                Socket sender = new Socket(ipAddr.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

                //Сокет подключение
                sender.Connect(ipEndPoint);

                User user = new User(login, name);
                //общаемся с сервером
                JsonHandle.SendObject(sender, user);

                //слушаем
                port = (int)JsonConvert.DeserializeObject <int>(JsonHandle.ReciveString(sender));

                LOgi.Items.Add("Connect to port:" + port.ToString());

                //close
                sender.Disconnect(true);
                //sender.Shutdown(SocketShutdown.Both);
                sender.Close();
                //sender = null;

                //open
                Socket UserListener = new Socket(ipAddr.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                ipEndPoint = new IPEndPoint(ipAddr, port);

                //Сокет подключение
                UserListener.Bind(ipEndPoint);
                UserListener.Listen(1);
                Socket handler = UserListener.Accept();
                //Console.WriteLine("Ожидаем соединения через {0}", ipEndPoint);


                //раздача
                JsonConvert.DeserializeObject <bool>(JsonHandle.ReciveString(handler));
                playerList = (List <Player>)JsonConvert.DeserializeObject <List <Player> >(JsonHandle.ReciveString(handler));

                for (int i = 0; i < playerList.Count(); i++)
                {
                    //BeginInvoke(new MyDelegate(IzmeniLogi), );
                    LOgi.Items.Add(" Add player: " + playerList[i].login);
                    //BeginInvoke(new MyDelegate(IzmeniUserPicth), "", i);
                    UserPicth[i].BackgroundImage = Image.FromFile("D:\\RepositHub\\webPoker\\WindowsFormsWebPOkerClient\\Resources\\active.png");
                    //BeginInvoke(new MyDelegate(IzmeniLabel), playerList[i].ToString(), i);
                    namesLabel[i].Text = playerList[i].name;
                    if (playerList[i].login == login)
                    {
                        gamerNumber = i;
                        break;
                    }
                }

                // LOgi.Text = LOgi.Text + "D:\\RepositHub\\webPoker\\WindowsFormsWebPOkerClient\\Resources\\" + playerList[gamerNumber].card1 + ".jpg" + "Карта1:" + playerList[gamerNumber].card1 + ", Карта2:" + playerList[gamerNumber].card2 + ", Ставка:" + playerList[gamerNumber].bet + ", Остаток:" + playerList[gamerNumber].money + "\n";
                UserCard[gamerNumber * 2].BackgroundImage     = Image.FromFile("D:\\RepositHub\\webPoker\\WindowsFormsWebPOkerClient\\Resources\\" + playerList[gamerNumber].card1 + ".jpg");
                UserCard[gamerNumber * 2 + 1].BackgroundImage = Image.FromFile("D:\\RepositHub\\webPoker\\WindowsFormsWebPOkerClient\\Resources\\" + playerList[gamerNumber].card2 + ".jpg");


                return(handler);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            return(null);
        }