//показать все бомбы при взрыве void Explode(ButtonExtended button) { timer1.Enabled = false; MessageBox.Show("Вы проиграли"); OpenBomb(); loser = true; }
/// <summary> /// Add button to form and add them to array. Also to some buttons add bombs. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Form1_Load(object sender, EventArgs e) { AllButtons = new ButtonExtended[widht, height]; Random rand = new Random(); for (int y = 0; y < CountButton; y++) { for (int x = 0; x < CountButton; x++) { ButtonExtended button = new ButtonExtended { TabStop = false }; if (rand.Next(1, 100) < 20) // 20% that button will with bomb { BoombsSet++; button.Isbomb = true; } button.Location = new Point(10 + x * DistanceButtonWidht, 37 + y * DistanceButtonHeight); // it's a constant to place the button(this's not correct, but without it looks ugly) button.Size = new Size(DistanceButtonWidht, DistanceButtonHeight); Controls.Add(button); button.MouseDown += new MouseEventHandler(this.Button_RightClick); // subscribe to event(right and left click) button.Click += new EventHandler(ClickEvent); AllButtons[x, y] = button; button.xb = x; button.yb = y; } } }
public void FillWithButtons(Grid grid, GameGrid gameGrid, bool addContent, RoutedEventHandler eh) { CoordinateTranslationService CTS = new CoordinateTranslationService(); int x = gameGrid.Width; int y = gameGrid.Height; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { ButtonExtended btnToAdd = new ButtonExtended(i, j); btnToAdd.Height = 30; btnToAdd.Width = 30; if (addContent) { btnToAdd.Content = $"{CTS.Translate(new Coordinate(i, j))}"; } if (!addContent) { btnToAdd.Background = Brushes.LightGray; btnToAdd.Click += eh; } Grid.SetColumn(btnToAdd, i); Grid.SetRow(btnToAdd, j); grid.Children.Add(btnToAdd); } } }
/// <summary> /// /// </summary> /// <param name="button"></param> /// <returns>return false if it's not number</returns> bool CheckBut(ButtonExtended button) { for (int j = 0; j < 10; j++) { if (button.Text.Equals(j.ToString())) { return(false); } } return(true); }
private void EmptyFieldClick(ButtonExtended button) { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (allButtons[x, y] == button) { button.Text = "" + CountBombsAround(x, y); } } } }
void FieldClick(object sender, EventArgs e) { ButtonExtended button = (ButtonExtended)sender; if (button.isBomb) { Explore(button); } else { EmptyFieldClick(button); } }
//Event handlers are down here public void SetShipClick(object sender, RoutedEventArgs args) { try { if (CoordinateTask != null) { ButtonExtended btn = (ButtonExtended)sender; CoordinateTask.SetResult(btn.Coordinate); } } catch (InvalidOperationException) { MessageBox.Show("You cannot click here at the moment."); } }
private void Explore(ButtonExtended button) { button.BackColor = Color.Red; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (allButtons[x, y].isBomb) { allButtons[x, y].Text = "💣"; } } } MessageBox.Show("You lose"); Application.Restart(); }
/// <summary> /// Event if have clicked right button.(change color (it's flag)) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void Button_RightClick(object sender, MouseEventArgs e) { ButtonExtended button = (ButtonExtended)sender; if (e.Button == MouseButtons.Right && CheckBut(button)) { if (button.BackColor == Color.Yellow) { button.BackColor = default(Color); button.Text = ""; } else { button.Text = "L"; button.BackColor = Color.Yellow; } } }
private void GenerateField() { allButtons = new ButtonExtended[width, height]; Random rng = new Random(); for (int x = 10; (x - 10) < width * distanceBetweenButtons; x += distanceBetweenButtons) { for (int y = 30; (y - 30) < height * distanceBetweenButtons; y += distanceBetweenButtons) { ButtonExtended button = new ButtonExtended(); button.Location = new Point(x, y); button.Size = new Size(30, 30); if (rng.Next(0, 101) < 20) { button.isBomb = true; } allButtons[(x - 10) / distanceBetweenButtons, (y - 30) / distanceBetweenButtons] = button; Controls.Add(button); button.Click += new EventHandler(FieldClick); } } }
//генерируем поле и время private void GenerateField(int widht, int height) { //показываем таймер ShowTimer(); allButtons = new ButtonExtended[widht, height]; for (int x = 10; (x - 10) < widht * distanceBetweenButtons; x += distanceBetweenButtons) { for (int y = 60; (y - 60) < height * distanceBetweenButtons; y += distanceBetweenButtons) { ButtonExtended button = new ButtonExtended(); button.BackColor = Color.Blue; button.Location = new Point(x, y); button.Size = new Size(30, 30); allButtons[(x - 10) / distanceBetweenButtons, (y - 60) / distanceBetweenButtons] = button; Controls.Add(button); button.MouseClick += new MouseEventHandler(FieldClick); } } }
//выводим тескстовое сообщение с количеством бомб рядом с данной кнопкой void EmptyFieldClick(ButtonExtended button) { for (int x = 0; x < widht; x++) { for (int y = 0; y < height; y++) { if (allButtons[x, y] == button) { if (CountBombAround(x, y) == 0) { allButtons[x, y].BackColor = Color.White; OpenButtonsZero(x, y); } else { button.Text = "" + CountBombAround(x, y); // подсчёт количества бомб рядом с нажатой клеткой allButtons[x, y].BackColor = Color.White; } return; } } } }
public SplashPage() : base(typeof(SplashViewModel), typeof(SplashContentUI)) { NavigationPage.SetHasNavigationBar(this, false); BackgroundColor = MainStyles.MainBackgroundColor.FromResources <Color>(); var layoutSplash = new AbsoluteLayout { VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand }; var boxBackOpacity = new BoxView { Color = MainStyles.MainBackgroundColor.FromResources <Color>() }; AbsoluteLayout.SetLayoutFlags(boxBackOpacity, AbsoluteLayoutFlags.All); AbsoluteLayout.SetLayoutBounds(boxBackOpacity, new Rectangle(0f, 0f, 1f, 1f)); layoutSplash.Children.Add(boxBackOpacity); var imgLogo = new Image { Source = contentUI.ImgLogo }; AbsoluteLayout.SetLayoutFlags(imgLogo, AbsoluteLayoutFlags.PositionProportional); AbsoluteLayout.SetLayoutBounds(imgLogo, new Rectangle(0.5, 0.4, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize)); layoutSplash.Children.Add(imgLogo); var activityIndicator = new ActivityIndicator { Color = Color.White }; activityIndicator.SetBinding(IsVisibleProperty, "IsShowLoading"); activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsShowLoading"); AbsoluteLayout.SetLayoutFlags(activityIndicator, AbsoluteLayoutFlags.PositionProportional); AbsoluteLayout.SetLayoutBounds(activityIndicator, new Rectangle(0.5, 0.8, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize)); layoutSplash.Children.Add(activityIndicator); var btnRetry = new ButtonExtended { Style = LabelStyles.ButtonStyle.FromResources <Style>(), Command = viewModel.RetryCommand, Text = contentUI.BtnTxtRetry.ToUpper() }; btnRetry.SetBinding(IsVisibleProperty, "IsRetry"); AbsoluteLayout.SetLayoutFlags(btnRetry, AbsoluteLayoutFlags.PositionProportional | AbsoluteLayoutFlags.WidthProportional); AbsoluteLayout.SetLayoutBounds(btnRetry, new Rectangle(0.5, 0.7, 0.5f, AbsoluteLayout.AutoSize)); layoutSplash.Children.Add(btnRetry); var btnSkip = new ButtonExtended { Style = LabelStyles.ButtonStyle.FromResources <Style>(), Command = viewModel.SkipCommand, Text = contentUI.BtnTxtSkip.ToUpper() }; btnSkip.SetBinding(IsVisibleProperty, "IsRetry"); AbsoluteLayout.SetLayoutFlags(btnSkip, AbsoluteLayoutFlags.PositionProportional | AbsoluteLayoutFlags.WidthProportional); AbsoluteLayout.SetLayoutBounds(btnSkip, new Rectangle(0.5, 0.8, 0.5f, AbsoluteLayout.AutoSize)); layoutSplash.Children.Add(btnSkip); var txtProgress = new Label { Style = LabelStyles.DescriptionStyle.FromResources <Style>(), LineBreakMode = LineBreakMode.WordWrap, HorizontalTextAlignment = TextAlignment.Center, TextColor = Color.White }; txtProgress.SetBinding(Label.TextProperty, "ProcessMessage"); AbsoluteLayout.SetLayoutFlags(txtProgress, AbsoluteLayoutFlags.PositionProportional | AbsoluteLayoutFlags.WidthProportional); AbsoluteLayout.SetLayoutBounds(txtProgress, new Rectangle(0f, 0.9, 1f, AbsoluteLayout.AutoSize)); layoutSplash.Children.Add(txtProgress); ContentLayout.Children.Add(layoutSplash); }
//результат после клика на кнопку поля void FieldClick(object sender, System.Windows.Forms.MouseEventArgs e) { if (e.Button == MouseButtons.Right) { MessageBox.Show("Нажата правая кнопка"); return; } ButtonExtended button = (ButtonExtended)sender; if (e.Button == MouseButtons.Right) { MessageBox.Show("Нажата правая кнопка"); for (int x = 0; x < widht; x++) { for (int y = 0; y < height; y++) { if (allButtons[x, y] == button) { allButtons[x, y].BackColor = Color.Red; } return; } } } if (win == false && loser == false) { if (timer1.Enabled == false) { timer1.Enabled = true; } if (e.Button == MouseButtons.Left) { if (!FirstClick) { FirstClick = true; for (int x = 0; x < widht; x++) { for (int y = 0; y < height; y++) { if (allButtons[x, y] == button) { GenerationRandomBomb(widht, height, x, y); } } } } button.flag = true; if (button.isBomb) //если бомба { Explode(button); } else { EmptyFieldClick(button); //если нет, то посчитать количество бомб рядом с данной клеткой int t = 0; for (int x = 0; x < widht; x++) { for (int y = 0; y < height; y++) { if (allButtons[x, y].isBomb || allButtons[x, y].flag == true) { t++; } } } if (t == widht * height) { timer1.Enabled = false; MessageBox.Show("Вы выиграли!"); win = true; } } } } }
private void свояИграToolStripMenuItem_Click_1(object sender, EventArgs e) { NewGame(); // Form Form2 = new Form(); // Form2.ShowDialog(); TextBox[,] tb = new TextBox[1, 5]; Label[,] l = new Label[1, 5]; for (int i = 0; i < 5; i++) { l[0, i] = new System.Windows.Forms.Label(); l[0, i].Location = new System.Drawing.Point(20, 70 + i * 23); l[0, i].Size = new System.Drawing.Size(75, 23); l[0, i].Text = "поле"; Controls.Add(l[0, i]); tb[0, i] = new System.Windows.Forms.TextBox(); tb[0, i].Location = new System.Drawing.Point(120, 70 + i * 23); tb[0, i].Size = new System.Drawing.Size(75, 23); Controls.Add(tb[0, i]); } l[0, 0].Text = "мины"; l[0, 1].Text = "ширина"; l[0, 2].Text = "длина"; l[0, 3].Text = "время мин"; l[0, 4].Text = "время сек"; ButtonExtended button1 = new ButtonExtended(); button1.Location = new Point(40, 200); button1.Size = new Size(30, 30); button1.Text = "OK"; Controls.Add(button1); button1.MouseClick += new MouseEventHandler(FieldClick1); void FieldClick1(object sender1, System.Windows.Forms.MouseEventArgs e1) { ButtonExtended button = (ButtonExtended)sender1; if (e1.Button == MouseButtons.Left) { //ф-ия, ф-ии обработки введённых полей if (tb[0, 0].Text == "" || tb[0, 1].Text == "" || tb[0, 2].Text == "" || (tb[0, 3].Text == "" && tb[0, 4].Text == "")) { MessageBox.Show("Не все поля введены"); return; } if (Convert.ToInt32(tb[0, 0].Text) >= (Convert.ToInt32(tb[0, 1].Text) * Convert.ToInt32(tb[0, 2].Text))) { MessageBox.Show("Количество бомб не может быть больше или равно размеру поля"); return; } FirstClick = false; sizebomb = Convert.ToInt32(tb[0, 0].Text); widht = Convert.ToInt32(tb[0, 1].Text); height = Convert.ToInt32(tb[0, 2].Text); if (tb[0, 4].Text == "") { tic = 0; } else { tic = Convert.ToInt32(tb[0, 4].Text); } if (tb[0, 3].Text != "") { tic = tic + 60 * Convert.ToInt32(tb[0, 3].Text); } for (int i = 0; i < 5; i++) { l[0, i].Dispose(); tb[0, i].Dispose(); } button1.Dispose(); GenerateField(widht, height); } } }
public SettingsPage() : base(typeof(SettingsViewModel), typeof(SettingsContentUI)) { BackgroundColor = MainStyles.StatusBarColor.FromResources <Color>(); Content.BackgroundColor = MainStyles.MainBackgroundColor.FromResources <Color>(); var loadingColor = MainStyles.LoadingColor.FromResources <Color>(); LoadingActivityIndicator.Color = loadingColor; LoadingActivityText.TextColor = loadingColor; var appBar = new TitleBar(this, TitleBar.BarBtnEnum.bbBack) { BarColor = MainStyles.StatusBarColor.FromResources <Color>(), TitleStyle = LabelStyles.PageTitleStyle.FromResources <Style>(), BtnBack = { Source = contentUI.IconBack } }; appBar.SetBinding(TitleBar.TitleProperty, "Title"); #region Language setting var txtLangTitle = new Label { Style = LabelStyles.SettingStyle.FromResources <Style>() }; txtLangTitle.SetBinding(Label.TextProperty, "CurrentLanguageTitle"); var txtLangValue = new Label { Style = LabelStyles.SettingHintStyle.FromResources <Style>() }; txtLangValue.SetBinding(Label.TextProperty, "CurrLanguageName"); var stackLang = new StackLayout { Children = { txtLangTitle, txtLangValue } }; var tapLang = new TapGestureRecognizer(); tapLang.Tapped += viewModel.LangSetting_Click; stackLang.GestureRecognizers.Add(tapLang); #endregion #region Push notifications setting var txtPushNotifications = new Label { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.Center, Style = LabelStyles.SettingStyle.FromResources <Style>() }; txtPushNotifications.SetBinding(Label.TextProperty, "PushNotificationsTitle"); var switchPushNotifications = new Switch { HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.Center, OnColor = MainStyles.SwitchColor.FromResources <Color>() }; switchPushNotifications.SetBinding(Switch.IsToggledProperty, "IsPushEnabled"); var stackPushNotifications = new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.FillAndExpand, Spacing = 0, Children = { txtPushNotifications, switchPushNotifications } }; var tapPushNotifications = new TapGestureRecognizer(); tapPushNotifications.Tapped += viewModel.SwitchPushNotifications_Toggled; stackPushNotifications.GestureRecognizers.Add(tapPushNotifications); #endregion var btnUpdateDb = new ButtonExtended { Style = LabelStyles.ButtonStyle.FromResources <Style>() }; btnUpdateDb.SetBinding(Button.TextProperty, "UpdateDbTitle"); btnUpdateDb.SetBinding(IsEnabledProperty, "IsNotLoading"); btnUpdateDb.Clicked += viewModel.BtnUpdateDb_Clicked; var activityIndicator = new ActivityIndicator { Color = loadingColor, HorizontalOptions = LayoutOptions.Center }; activityIndicator.SetBinding(IsVisibleProperty, "IsUpdating"); activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsUpdating"); var txtProgress = new Label { Style = LabelStyles.DescriptionLightStyle.FromResources <Style>(), HorizontalTextAlignment = TextAlignment.Center }; txtProgress.SetBinding(Label.TextProperty, "ProcessMessage"); var layoutSettings = new StackLayout { Spacing = 20, Padding = 24, Children = { stackLang, stackPushNotifications, btnUpdateDb, activityIndicator, txtProgress } }; var safeAreaHelper = new SafeAreaHelper(); safeAreaHelper.UseSafeArea(this, SafeAreaHelper.CustomSafeAreaFlags.Top); safeAreaHelper.UseSafeArea(appBar.BtnBack, SafeAreaHelper.CustomSafeAreaFlags.Left); safeAreaHelper.UseSafeArea(layoutSettings, SafeAreaHelper.CustomSafeAreaFlags.Horizontal); ContentLayout.Children.Add(appBar); ContentLayout.Children.Add(layoutSettings); }
public FeedbackPage() : base(typeof(FeedbackViewModel), typeof(FeedbackContentUI)) { BackgroundColor = MainStyles.StatusBarColor.FromResources <Color>(); Content.BackgroundColor = MainStyles.MainBackgroundColor.FromResources <Color>(); var loadingColor = MainStyles.LoadingColor.FromResources <Color>(); LoadingActivityIndicator.Color = loadingColor; LoadingActivityText.TextColor = loadingColor; var appBar = new TitleBar(this, TitleBar.BarBtnEnum.bbBack) { BarColor = MainStyles.StatusBarColor.FromResources <Color>(), TitleStyle = LabelStyles.PageTitleStyle.FromResources <Style>(), BtnBack = { Source = contentUI.IconBack } }; appBar.SetBinding(TitleBar.TitleProperty, "Title"); var txtNameTitle = new Label { Style = LabelStyles.FeedbackLabelStyle.FromResources <Style>(), Text = contentUI.TxtName }; _txtName = new Entry { Style = LabelStyles.FeedbackEntryStyle.FromResources <Style>(), MaxLength = 30 }; _txtName.SetBinding(Entry.TextProperty, "Name"); _txtName.SetBinding(IsEnabledProperty, "IsNotLoading"); var txtCommentTitle = new Label { Style = LabelStyles.FeedbackLabelStyle.FromResources <Style>(), Text = contentUI.TxtComment }; _txtComment = new Editor { Style = LabelStyles.FeedbackEditorStyle.FromResources <Style>(), VerticalOptions = LayoutOptions.FillAndExpand, MaxLength = 1000 }; _txtComment.SetBinding(Editor.TextProperty, "Comment"); _txtComment.SetBinding(IsEnabledProperty, "IsNotLoading"); var btnSubmit = new ButtonExtended { Style = LabelStyles.ButtonStyle.FromResources <Style>(), Text = contentUI.TxtSubmit.ToUpper(), HorizontalOptions = LayoutOptions.Center, WidthRequest = 150 }; btnSubmit.SetBinding(IsEnabledProperty, "IsValidFeedback"); btnSubmit.SetBinding(IsVisibleProperty, "IsNotLoading"); btnSubmit.Clicked += viewModel.BtnSubmit_Clicked; var activityIndicator = new ActivityIndicator { Color = loadingColor, HorizontalOptions = LayoutOptions.Center }; activityIndicator.SetBinding(IsVisibleProperty, "IsSubmitting"); activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsSubmitting"); _layoutFeedback = new KeyboardView { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Star }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto } } }; _layoutFeedback.Children.Add(txtNameTitle, 0, 0); _layoutFeedback.Children.Add(_txtName, 0, 1); _layoutFeedback.Children.Add(txtCommentTitle, 0, 2); _layoutFeedback.Children.Add(_txtComment, 0, 3); _layoutFeedback.Children.Add(btnSubmit, 0, 4); _layoutFeedback.Children.Add(activityIndicator, 0, 5); var layoutContainer = new ContentView { Padding = 24, Content = _layoutFeedback, VerticalOptions = LayoutOptions.FillAndExpand }; var safeAreaHelper = new SafeAreaHelper(); safeAreaHelper.UseSafeArea(this, SafeAreaHelper.CustomSafeAreaFlags.Top); safeAreaHelper.UseSafeArea(appBar.BtnBack, SafeAreaHelper.CustomSafeAreaFlags.Left); safeAreaHelper.UseSafeArea(layoutContainer, SafeAreaHelper.CustomSafeAreaFlags.Horizontal); ContentLayout.Children.Add(appBar); ContentLayout.Children.Add(layoutContainer); }
public SettingsPage() : base(typeof(SettingsViewModel), typeof(SettingsContentUI)) { BackgroundColor = MainStyles.StatusBarColor.FromResources <Color>(); Content.BackgroundColor = MainStyles.MainBackgroundColor.FromResources <Color>(); var appBar = new TitleBar(this, TitleBar.BarBtnEnum.bbBack) { BarColor = MainStyles.StatusBarColor.FromResources <Color>(), TitleStyle = LabelStyles.PageTitleStyle.FromResources <Style>(), BtnBack = { Source = contentUI.IconBack } }; appBar.SetBinding(TitleBar.TitleProperty, "Title"); #region Language setting var txtLangTitle = new Label { Style = LabelStyles.SettingStyle.FromResources <Style>() }; txtLangTitle.SetBinding(Label.TextProperty, "CurrentLanguageTitle"); var txtLangValue = new Label { Style = LabelStyles.SettingHintStyle.FromResources <Style>() }; txtLangValue.SetBinding(Label.TextProperty, "CurrLanguageName"); var stackLang = new StackLayout { Children = { txtLangTitle, txtLangValue } }; var tapGestureRecognizer = new TapGestureRecognizer(); tapGestureRecognizer.SetBinding(TapGestureRecognizer.CommandParameterProperty, "TypeName"); tapGestureRecognizer.Tapped += viewModel.LangSetting_Click; stackLang.GestureRecognizers.Add(tapGestureRecognizer); #endregion var btnUpdateDb = new ButtonExtended { Style = LabelStyles.ButtonStyle.FromResources <Style>() }; btnUpdateDb.SetBinding(Button.TextProperty, "UpdateDbTitle"); btnUpdateDb.SetBinding(IsEnabledProperty, "IsNotLoading"); btnUpdateDb.Clicked += viewModel.BtnUpdateDb_Clicked; var activityIndicator = new ActivityIndicator { Color = Color.White, HorizontalOptions = LayoutOptions.Center }; activityIndicator.SetBinding(IsVisibleProperty, "IsLoading"); activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsLoading"); var txtProgress = new Label { Style = LabelStyles.DescriptionStyle.FromResources <Style>(), LineBreakMode = LineBreakMode.WordWrap, HorizontalTextAlignment = TextAlignment.Center, TextColor = Color.White }; txtProgress.SetBinding(Label.TextProperty, "ProcessMessage"); var layoutSettings = new StackLayout { Spacing = 20, Padding = 24, Children = { stackLang, btnUpdateDb, activityIndicator, txtProgress } }; var safeAreaHelper = new SafeAreaHelper(); safeAreaHelper.UseSafeArea(this, SafeAreaHelper.CustomSafeAreaFlags.Top); safeAreaHelper.UseSafeArea(appBar.BtnBack, SafeAreaHelper.CustomSafeAreaFlags.Left); safeAreaHelper.UseSafeArea(layoutSettings, SafeAreaHelper.CustomSafeAreaFlags.Horizontal); ContentLayout.Children.Add(appBar); ContentLayout.Children.Add(layoutSettings); }