private void Table_MouseDown(object sender, MouseButtonEventArgs e) { if (GetSelectedFigure((int)((e.GetPosition(this).X) / rowHeight), (int)((e.GetPosition(this).Y) / columnWidth))?.Color == nonPlayingColor) { MessageBox.Show("Opssss, it's not step of this color"); } else if (GetSelectedFigure((int)((e.GetPosition(this).X) / rowHeight), (int)((e.GetPosition(this).Y) / columnWidth)) != null) { isFigureCliked = true; clickedMousePosX = (int)((e.GetPosition(this).X) / rowHeight); clickedMousePosY = (int)((e.GetPosition(this).Y) / columnWidth); clickedFigure = GetSelectedFigure(clickedMousePosX, clickedMousePosY); clickedFigure.AddHint(ref hint, ref matrix, figures, GetSelectedFigure(clickedMousePosX, clickedMousePosY)?.Color); deltaX = e.GetPosition(this).X - image[clickedMousePosX, clickedMousePosY].Margin.Left; deltaY = e.GetPosition(this).Y - image[clickedMousePosX, clickedMousePosY].Margin.Top; } }
private void Table_MouseRightButtonDown(object sender, MouseButtonEventArgs e) { if (GetSelectedFigure((int)((e.GetPosition(this).X) / rowHeight), (int)((e.GetPosition(this).Y) / columnWidth))?.Color == nonPlayingColor && matrix[(int)((e.GetPosition(this).X) / rowHeight), (int)((e.GetPosition(this).Y) / columnWidth)] != 2) { MessageBox.Show("Opssss, it's not step of this color"); } else if (GetSelectedFigure((int)((e.GetPosition(this).X) / rowHeight), (int)((e.GetPosition(this).Y) / columnWidth))?.Color == nonPlayingColor && matrix[(int)((e.GetPosition(this).X) / rowHeight), (int)((e.GetPosition(this).Y) / columnWidth)] == 2) { clickedLeftButtonPosX = (int)((e.GetPosition(this).X) / rowHeight); clickedLeftButtonPosY = (int)((e.GetPosition(this).Y) / columnWidth); step = $"{clickedLeftButtonPosX} / {clickedLeftButtonPosY}"; endX = clickedLeftButtonPosX; endY = clickedLeftButtonPosY; if (currentColor == player1Color) { opponent_steps.Items.Clear(); opponentSelectedSteps.Clear(); if (!selectedSteps.Contains(qar + step)) { your_steps.Items.Add(qar + step); selectedSteps.Add(qar + step); } } else { your_steps.Items.Clear(); selectedSteps.Clear(); if (!opponentSelectedSteps.Contains(qar + step)) { opponent_steps.Items.Add(qar + step); opponentSelectedSteps.Add(qar + step); } } calculatedSteps.Add(new Steps(startX, startY, endX, endY)); step = ""; } else { clickedLeftButtonPosX = (int)((e.GetPosition(this).X) / rowHeight); clickedLeftButtonPosY = (int)((e.GetPosition(this).Y) / columnWidth); if (GetSelectedFigure(clickedLeftButtonPosX, clickedLeftButtonPosY) != null) { currentColor = GetSelectedFigure(clickedLeftButtonPosX, clickedLeftButtonPosY)?.Color; qar = $"{GetSelectedFigure(clickedLeftButtonPosX, clickedLeftButtonPosY)?.Name} - {clickedLeftButtonPosX} / {clickedLeftButtonPosY} to "; startX = clickedLeftButtonPosX; startY = clickedLeftButtonPosY; } if (matrix[clickedLeftButtonPosX, clickedLeftButtonPosY] != 2) { for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (matrix[i, j] == 2) { hint[i, j].Source = null; matrix[i, j] = 0; } } } } else { step = $"{clickedLeftButtonPosX} / {clickedLeftButtonPosY}"; endX = clickedLeftButtonPosX; endY = clickedLeftButtonPosY; if (currentColor == player1Color) { opponent_steps.Items.Clear(); opponentSelectedSteps.Clear(); if (!selectedSteps.Contains(qar + step)) { your_steps.Items.Add(qar + step); selectedSteps.Add(qar + step); } } else { your_steps.Items.Clear(); selectedSteps.Clear(); if (!opponentSelectedSteps.Contains(qar + step)) { opponent_steps.Items.Add(qar + step); opponentSelectedSteps.Add(qar + step); } } calculatedSteps.Add(new Steps(startX, startY, endX, endY)); step = ""; } if (GetSelectedFigure(clickedLeftButtonPosX, clickedLeftButtonPosY) != null) { clickedFigure = GetSelectedFigure(clickedLeftButtonPosX, clickedLeftButtonPosY); clickedFigure.AddHint(ref hint, ref matrix, figures, GetSelectedFigure(clickedLeftButtonPosX, clickedLeftButtonPosY)?.Color); } } }