Ejemplo n.º 1
0
        public void UpdateVar2(Message e, Socket client)
        {
            mWhoseTurn = e.WhoseTurn;
            //mColor = e.Color;
            mClientSocket  = client;
            APieces        = e.APieces;
            BPieces        = e.BPieces;
            AColorQ        = e.AColorQ;
            BColorQ        = e.BColorQ;
            mIsUpdateBoard = e.IsUpdateBoard;
            if (mIsUpdateBoard)
            {
                this.Refresh();
                DrawPieces();
                FormClient.delHelp("请落子");
            }

            FormClient.updataPic();

            isGameOver = e.IsGameOver;

            if (isGameOver)
            {
                DrawResult(e);
            }
        }
Ejemplo n.º 2
0
        public static void PingServs(FormClient formClient)
        {
            Program.msgsWithHosts_Semaphore.WaitOne();
            List <MessageSendRecieve> msgsWithHosts = new List <MessageSendRecieve>();

            foreach (var host in Program.msgsWithHosts)
            {
                msgsWithHosts.Add(host);
            }
            Program.msgsWithHosts_Semaphore.Release();

            for (int i = 0; i < msgsWithHosts.Count; i++)
            {
                MessageSendRecieve host = msgsWithHosts[i];
                try
                {
                    IPAddress  ipAddr     = IPAddress.Parse(host.IP);
                    IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, portPingServers);
                    Socket     sender     = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    sender.Connect(ipEndPoint);
                    Byte[] buf = new Byte[1];
                    sender.Send(buf);
                    sender.Receive(buf);
                    formClient.AppendOnOffImg(host.mqName, true);
                }
                catch (Exception)
                {
                    formClient.AppendOnOffImg(host.mqName, false);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 更新变量
        /// </summary>
        public void UpdateVar(Message e, Socket client)
        {
            mWhoseTurn    = e.WhoseTurn;
            mColor        = e.Color;
            mClientSocket = client;
            APieces       = e.APieces;
            BPieces       = e.BPieces;


            mIsUpdateBoard = e.IsUpdateBoard;

            if (mIsUpdateBoard)
            {
                DrawPieces();
                FormClient.delHelp("请落子");
            }

            isGameOver = e.IsGameOver;
            if (isGameOver)
            {
                DrawResult(e);
            }
        }
Ejemplo n.º 4
0
        private void btnSignUp_Click(object sender, EventArgs e)
        {
            RegistrationRequest userDetails = new RegistrationRequest
            {
                FirstName = textFirstName.TextName,
                LastName  = textLastName.TextName,
                Email     = textEmail.TextName,
                UserName  = textUserName.TextName,
                Password  = textPassword.TextName
            };
            Repository repository = new Repository();
            int        statusCode = repository.Registration(userDetails);

            if (statusCode == -1)
            {
                message = "Email already exists!";
                MessageBox.Show(message, title);
            }
            else if (statusCode == -2)
            {
                message = "User Name already taken!";
                MessageBox.Show(message, title);
            }
            else if (statusCode == 0)
            {
                message = "Registration Successfull";
                MessageBox.Show(message, title);
                this.Hide();
                FormClient client = new FormClient();
                client.Show();
            }
            else
            {
                message = "Registration Unsuccessfull";
                MessageBox.Show(message, title);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void ChessPanel_MouseClick(object sender, MouseEventArgs e)
        {
            //isGameOver=true,游戏结束,不响应鼠标点击事件,直接返回
            //mWhoseTurn==Message.COLOR_NONE,没有指定轮到谁,那么谁都不响应
            //mWPieces=null当前还没有组队
            //mColor.Equals(mWhoseTurn)==false没有轮到自己
            if (isGameOver || mWhoseTurn == Message.OPPONENT_NONE || !mColor.Equals(mWhoseTurn) || BPieces == null || APieces == null)
            {
                return;  //
            }

            Point point = new Point();
            Chess chess = new Chess(0, 0, 0);

            // 将点击的坐标转换成棋盘交叉点的坐标   0-14
            point.X      = (int)((e.X - mOffset) / mLineLength);
            point.Y      = (int)(e.Y / mLineLength);
            chess._point = point;

            //如果点击的格子里已经有棋子了,就返回
            if (BPieces.Contains(chess) || APieces.Contains(chess))
            {
                return;
            }
            //判断是否点到外面去了
            if (point.X < 0 || point.Y < 0 || point.X >= ChessPanel.MAX_LINE_COUNT || point.Y >= ChessPanel.MAX_LINE_COUNT)
            {
                return;
            }

            //转换成棋子在控件里的位置坐标
            int x, y;

            if (Width > Height)
            {
                x = (int)((point.X + ratioPieceOfLineHeight / 4) * mLineLength) + mOffset;
                y = (int)((point.Y + ratioPieceOfLineHeight / 4) * mLineLength);
            }
            else
            {
                x = (int)((point.X + ratioPieceOfLineHeight / 4) * mLineLength);
                y = (int)((point.Y + ratioPieceOfLineHeight / 4) * mLineLength) - mOffset;
            }
            int width = (int)(mLineLength * ratioPieceOfLineHeight);
            //创建控件的GDI+,准备绘制棋子
            Graphics g = CreateGraphics();
            //待绘制的棋子的位置
            Rectangle rect = new Rectangle(x, y, width, width);

            //画棋子
            if (mColor.Equals(Message.OPPONENT_A))   //规定AB方  a=black
            {
                g.DrawImage(ACurrentColors[0], rect);
                chess._point = point;
                chess.color  = colors.IndexOf(ACurrentColors[0]);

                APieces.Add(chess);
                isGameOver = ChessFinishiUtils.checkWin(APieces);
            }
            else if (mColor.Equals(Message.OPPONENT_B))
            {
                g.DrawImage(BCurrentColors[0], rect);
                chess.color = colors.IndexOf(BCurrentColors[0]);
                BPieces.Add(chess);
                isGameOver = ChessFinishiUtils.checkWin(BPieces);
            }
            //更新当前颜色队列
            int i = 0;

            //Image LastImage = colors[i];
            if (mColor.Equals(Message.OPPONENT_A))   //规定AB方  a=black
            {
                i = rd.Next(3);
                Image LastImage = colors[i];
                if (ACurrentColors.Count > 0)
                {
                    ACurrentColors.RemoveAt(0);
                }
                ACurrentColors.Add(LastImage);
                if (AColorQ.Count > 0)
                {
                    AColorQ.RemoveAt(0);
                }
                AColorQ.Add(i);
            }
            else if (mColor.Equals(Message.OPPONENT_B))
            {
                i = rd.Next(3) + 3;
                Image LastImage = colors[i];
                if (BCurrentColors.Count > 0)
                {
                    BCurrentColors.RemoveAt(0);
                }
                BCurrentColors.Add(LastImage);
                if (BColorQ.Count > 0)
                {
                    BColorQ.RemoveAt(0);
                }
                BColorQ.Add(i);
            }


            //本方点击,向服务器落子消息
            Message m = new Message();

            m.Action    = Message.ID_STATUS_PUT;
            m.WhoseTurn = mWhoseTurn;
            m.Receiver  = FormClient.yourUUID;
            m.Sender    = FormClient.myUUID;
            m.X         = point.X;
            m.Y         = point.Y;
            m.APieces   = APieces;
            m.BPieces   = BPieces;
            m.AColorQ   = AColorQ;
            m.BColorQ   = BColorQ;
            m.Color     = mColor;

            if (isGameOver)
            {
                m.IsGameOver = true;
                m.Winner     = mColor;
                DrawResult(m);
            }
            else
            {
                m.IsGameOver = false;
            }
            try
            {
                mClientSocket.Send(Encoding.UTF8.GetBytes(XmlUtils.XmlSerializer <Message>(m)));

                FormClient.delHelp("等待对方落子");
                FormClient.updataPic();
                FormClient.delStep(1);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            //禁止本方点击
            mWhoseTurn = Message.OPPONENT_NONE;
        }
Ejemplo n.º 6
0
 public Context(FormClient window)
 {
     this.window = window;
 }