public Game100(byte ssize = 5) { this.size = ssize; //crosimg = Device.OnPlatform<string>(null, "@drawable/cross.jpg", "Assets/cross.jpg"); //zeroimg = Device.OnPlatform<string>(null, "@drawable/zero.jpg", "Assets/zero.jpg"); cross = new ClickedImage { image = new Image { Source = "cross.png" } }; zero = new ClickedImage { image = new Image { Source = "zero.png" } }; Content = CreateField(); }
private void MainForm_MouseDown(object sender, MouseEventArgs e) { // Get (x, y) of mouse click. Point mousePt = new Point(e.X, e.Y); // See if the mouse is anywhere in the 3 Rectangles. if (imageRects[0].Contains(mousePt)) { isImageClicked = true; imageClicked = ClickedImage.ImageA; this.Text = "You clicked image A"; } else if (imageRects[1].Contains(mousePt)) { isImageClicked = true; imageClicked = ClickedImage.ImageB; this.Text = "You clicked image B"; } else if (imageRects[2].Contains(mousePt)) { isImageClicked = true; imageClicked = ClickedImage.ImageC; this.Text = "You clicked image C"; } else if (myPath.IsVisible(mousePt)) { isImageClicked = true; imageClicked = ClickedImage.StrangePath; this.Text = "You clicked the strange shape..."; } else // Not in any shape, set defaults. { isImageClicked = false; this.Text = "Hit Testing Images"; } // Redraw the client area. Invalidate(); }
public Grid CreateField() { //add field Field = new Grid { ColumnSpacing = 2, RowSpacing = 2, BackgroundColor = Color.Transparent, VerticalOptions = LayoutOptions.Fill, HorizontalOptions = LayoutOptions.Fill, }; for (byte i = 0; i < size; i++) { Field.RowDefinitions.Add(new RowDefinition { Height = new GridLength(2, GridUnitType.Star) }); Field.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(2, GridUnitType.Star) }); } //create cells ImcelList = new ClickedImage[size + 3, size + 3]; for (int i = 0; i < size + 3; i++) //fix exception { for (int j = 0; j < size + 3; j++) //fix exception { ImcelList[i, j] = new ClickedImage(); ImcelList[i, j].TtapGesture.Tapped += StepOnClick; } } //add cells to field for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { Field.Children.Add(ImcelList[i, j].image, i, j); } } ////create state info ////add state row Field.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); current_s = new ClickedImage { image = new Image { Source = cross.image.Source, HorizontalOptions = LayoutOptions.CenterAndExpand }, TtapGesture = new TapGestureRecognizer() }; //curent player current_s.TtapGesture.Tapped += (sender, args) => { if (step != 0) { return; } current_s.image.Source = current_s.image.Source == zero.image.Source ? cross.image.Source : zero.image.Source; }; current_s.image.GestureRecognizers.Add(current_s.TtapGesture); Field.Children.Add(current_s.image, 1, size);//add current player image to row inf //var btnRestart = new Button //{ // Text = "Restart", //}; //Field.Children.Add(btnRestart,2,size); //Grid.SetColumnSpan(btnRestart,2); return(Field); }