private NumBall Check(List <int> userIn) { NumBall nb = new NumBall() { Round = 0, Strike = 0, Ball = 0, Out = "Safe" }; nb.Input = number; nb.Round = ++round; foreach (int u in userIn) { foreach (int a in answer) { if (u == a) { if (userIn.IndexOf(u) == answer.IndexOf(a)) { nb.Strike++; } else { nb.Ball++; } break; } } } if (nb.Strike == 0 && nb.Ball == 0) { nb.Out = "Out"; } return(nb); }
private void check_answer(NumBall nb) { string msg = String.Format($"성공! {round}회차 만에 성공하셨습니다!"); MessageBox.Show(msg); // 경기결과 저장(캡쳐) if (check_capture.IsChecked) { string path = null; capturePlay(ref path); MessageBox.Show("기록이 저장되었습니다.\n저장위치: " + path); } // 세팅 초기화 round = 0; btnStart.IsEnabled = true; cbDim.IsEnabled = true; check_capture.IsChecked = false; name.IsEnabled = true; foreach (Control ctl in grid_num.Children) { if (ctl is CheckBox) { ((CheckBox)ctl).IsChecked = false; } } //resultView.Items.Clear(); }
private void Click_Enter(object sender, RoutedEventArgs e) { if (btnStart.IsEnabled == true) { MessageBox.Show("시작버튼을 먼저 눌러주세요!"); return; } if (numballValue.Text == "" || numballValue.Text.Length < dimension) { MessageBox.Show("숫자를 입력해주세요!"); return; } number = numballValue.Text; List <int> userIn = new List <int>(); // 중복검사 foreach (char c in number) { userIn.Add(int.Parse(c.ToString())); } if (Check_Dup(userIn)) { MessageBox.Show("Try Again!"); numballValue.Text = ""; return; } // update NumBall nb = updateData(userIn); // Add() // check for answer if (nb.Strike == dimension) { check_answer(nb); } }
private NumBall updateData(List <int> userIn) { NumBall nb = Check(userIn); resultView.Items.Add(nb); // list(DataGrid) 스크롤 아래로 내리기 if (resultView.Items.Count > 0) { var border = VisualTreeHelper.GetChild(resultView, 0) as Decorator; if (border != null) { var scroll = border.Child as ScrollViewer; if (scroll != null) { scroll.ScrollToEnd(); } } } // 입력창 리셋 numballValue.Text = ""; return(nb); }