/// <summary>Method: pnlField_MouseUp
 /// method to stop dragging of piece
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void pnlField_MouseUp(object sender, MouseEventArgs e)
 {
     if (topPiece != null)
     {
         topPiece.Highlight = false;
         model.UpdateViews();
         dragging = false;
     }
 }
Esempio n. 2
0
        /// <summary>Method: btnUpdate_Click
        /// Update selected piece
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            string o             = string.Empty;
            var    checkedButton = Controls.OfType <RadioButton>()
                                   .FirstOrDefault(r => r.Checked);

            if (checkedButton == null)
            {
                MessageBox.Show("Please select the object first");
                return;
            }
            string obj      = checkedButton.Text;
            string selector = txbSelector.Text;

            if (selector.Equals(o) && !obj.Equals("Ball"))
            {
                MessageBox.Show("Please type in the selector.");
                return;
            }
            int x = txbX.Text.Equals(string.Empty) ? 0 : Convert.ToInt32(txbX.Text);
            int y = txbY.Text.Equals(string.Empty) ? 0 : Convert.ToInt32(txbY.Text);

            if (x > max_X || y > max_Y)
            {
                MessageBox.Show("Maximum value for X is " + max_X
                                + "\r\n" + "Maximum value for Y is " + max_Y + "\r\n",
                                "Please Check the Values Entered",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (obj.Equals("Player"))
            {
                string selected_side   = string.Empty;
                string selected_number = string.Empty;
                string pattern         = @"^(home|away) (\d+)$";
                foreach (Match match in Regex.Matches(selector, pattern, RegexOptions.IgnoreCase))
                {
                    selected_side   = match.Groups[1].Value;
                    selected_number = match.Groups[2].Value;
                }
                if (selected_side == string.Empty || selected_number == string.Empty)
                {
                    MessageBox.Show("The selector of player should be Home/Away<space>Number.");
                    return;
                }
                Player player = (Player)model.GetAPiece(typeof(Player),
                                                        selected_side.ToLower(), Convert.ToInt32(selected_number));
                if (player == null)
                {
                    MessageBox.Show("Not Found the player.");
                    return;
                }
                string name = txbName.Text;
                if (!cbbColor.Text.Equals(o))
                {
                    player.Color = Color.FromName(cbbColor.Text);
                }
                if (!txbNumber.Text.Equals(o))
                {
                    player.Number = Convert.ToInt32(txbNumber.Text);
                }
                if (!txbName.Text.Equals(o))
                {
                    player.Name = txbName.Text;
                }
                if (!txbX.Text.Equals(o))
                {
                    player.x_pos = Convert.ToInt32(txbX.Text);
                }
                if (!txbY.Text.Equals(o))
                {
                    player.y_pos = Convert.ToInt32(txbY.Text);
                }
                model.BringToFront(player);
            }
            else if (obj.Equals("Ball"))
            {
                Ball ball = (Ball)model.GetAPiece(typeof(Ball), "Ball");
                if (!txbX.Text.Equals(o))
                {
                    ball.x_pos = Convert.ToInt32(txbX.Text);
                }
                if (!txbY.Text.Equals(o))
                {
                    ball.y_pos = Convert.ToInt32(txbY.Text);
                }
                if (!cbbBallType.Text.Equals(""))
                {
                    ball.BallImage = cbbBallType.Text.Equals("White")? Ball.ImageType.White : Ball.ImageType.Orange;
                }
                model.BringToFront(ball);
            }
            else if (obj.Equals("Referee"))
            {
                Referee referee = (Referee)model.GetAPiece(typeof(Referee), selector);
                if (referee == null)
                {
                    MessageBox.Show("Not Found the referee. You can check the selector example above the textbox.");
                    return;
                }
                if (!txbX.Text.Equals(o))
                {
                    referee.x_pos = Convert.ToInt32(txbX.Text);
                }
                if (!txbY.Text.Equals(o))
                {
                    referee.y_pos = Convert.ToInt32(txbY.Text);
                }
                model.BringToFront(referee);
            }
            model.UpdateViews();
        }