private void Canvas1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { name1 = Name1.Text; name2 = Name2.Text; Point p = Mouse.GetPosition(Canvas1); BlockX = p.X; BlockY = p.Y; CoordinatesXY(ref BlockX, ref BlockY); if (gameStop) { if (BlockX < 0) { BlockX = 0; } else if (BlockX >= 750) { BlockX = 675; } if (BlockY < 0) { BlockY = 0; } else if (BlockY >= 750) { BlockY = 675; } if (arr[Convert.ToInt32(Math.Floor(BlockX / Math.Round(CanvasX / CountOfCell))), Convert.ToInt32(Math.Floor(BlockY / Math.Round(CanvasY / CountOfCell)))] == 0) { if (Turn) { ArrowLeft.Visibility = Visibility.Hidden; ArrowRight.Visibility = Visibility.Visible; Turn = !Turn; Cross = graph.DrawCross(BlockX, BlockY, Canvas1.Width, Canvas1.Height, CountOfCell); for (int i = 0; i < Cross.Count; i++) { Canvas1.Children.Add(Cross[i]); } } else { ArrowLeft.Visibility = Visibility.Visible; ArrowRight.Visibility = Visibility.Hidden; Turn = !Turn; Canvas1.Children.Add(graph.DrawCircle(BlockX, BlockY, Canvas1.Width, Canvas1.Height, CountOfCell)); } if (Turn) { arr[Convert.ToInt32(Math.Floor(BlockX / Math.Round(CanvasX / CountOfCell))), Convert.ToInt32(Math.Floor(BlockY / Math.Round(CanvasY / CountOfCell)))] = 1; } else { arr[Convert.ToInt32(Math.Floor(BlockX / Math.Round(CanvasX / CountOfCell))), Convert.ToInt32(Math.Floor(BlockY / Math.Round(CanvasY / CountOfCell)))] = 2; } double[] Ansarr = trn.CheckTurn(arr); for (int t = 0; t < 4; t++) { if (Ansarr[t] != 0) { for (int l = 0; l < 4; l++) { Ansarr[l] *= Math.Round(CanvasX / CountOfCell); Ansarr[l] = Ansarr[l] + Math.Round(CanvasX / CountOfCell) / 2; } Canvas1.Children.Add(graph.DrawLine(Ansarr[0], Ansarr[1], Ansarr[2], Ansarr[3], Brushes.Green, 15)); Canvas1.Children.Add(graph.DrawLine(Ansarr[0], Ansarr[1], Ansarr[2], Ansarr[3], Brushes.Yellow, 7)); WinBox task1 = new WinBox(); if (Turn) { Pl1Count++; task1.nameSet(name1); } else { Pl2Count++; task1.nameSet(name2); } name1 = Name1.Text; name2 = Name2.Text; gameStop = false; task1.Show(); break; } } } } }
private void Canvas1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { name1 = Name1.Text; name2 = Name2.Text; Point p = Mouse.GetPosition(Canvas1); BlockX = p.X; BlockY = p.Y; CoordinatesXY(ref BlockX, ref BlockY); if (gameStop) { if (arr[Convert.ToInt32(Math.Floor(BlockX / Math.Round(CanvasX / CountOfCell))), Convert.ToInt32(Math.Floor(BlockY / Math.Round(CanvasY / CountOfCell)))] == 0) { if (Turn) { Turn = !Turn; Cross = graph.DrawCross(BlockX, BlockY, Canvas1.Width, Canvas1.Height, CountOfCell); for (int i = 0; i < Cross.Count; i++) { Canvas1.Children.Add(Cross[i]); } } else { Turn = !Turn; Canvas1.Children.Add(graph.DrawCircle(BlockX, BlockY, Canvas1.Width, Canvas1.Height, CountOfCell)); } } if (Turn) { arr[Convert.ToInt32(Math.Floor(BlockX / Math.Round(CanvasX / CountOfCell))), Convert.ToInt32(Math.Floor(BlockY / Math.Round(CanvasY / CountOfCell)))] = 1; } else { arr[Convert.ToInt32(Math.Floor(BlockX / Math.Round(CanvasX / CountOfCell))), Convert.ToInt32(Math.Floor(BlockY / Math.Round(CanvasY / CountOfCell)))] = 2; } int[] Ansarr = trn.CheckTurn(arr); for (int t = 0; t < 4; t++) { if (Ansarr[t] != 0) { WinBox task1 = new WinBox(); if (Turn) { Pl1Count++; task1.nameSet(name1); } else { Pl2Count++; task1.nameSet(name2); } name1 = Name1.Text; name2 = Name2.Text; gameStop = false; task1.Show(); break; } } } }