야구게임 수정 1
Form1.cs[디자인]
form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _2020._08._20_007
{
public partial class Form1 : Form
{
int[] intArray;
int Score; // 카운트 변수
//string input;
public Form1()
{
InitializeComponent();
}
private void Init()
{
Random aRandom = new Random();
intArray = new int[3] { 100, 100, 100 };
for (int Count = 0; Count < intArray.Length; ++Count)
{
int iTemp = aRandom.Next(0, 10);
int Count2;
for (Count2 = 0; Count2 < intArray.Length; ++Count2)
{
if (iTemp == intArray[Count2])
{
break;
}
}
if (Count2 < intArray.Length)
{
--Count;
continue;
}
intArray[Count] = iTemp;
}
lbRand1.Text = intArray[0].ToString();
lbRand2.Text = intArray[1].ToString();
lbRand3.Text = intArray[2].ToString();
//////////////지울 코드
label1.Text = intArray[0].ToString();
label3.Text = intArray[1].ToString();
label7.Text = intArray[2].ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
Init();
}
// 실행버튼
private void button1_Click(object sender, EventArgs e)
{
int[] InputArray = new int[intArray.Length];
int strikeCount = 0;
int ballCount = 0;
InputArray[0] = Convert.ToInt32(txtinput1.Text);
InputArray[1] = int.Parse(txtinput2.Text);
InputArray[2] = int.Parse(txtinput3.Text);
for (int Count1 = 0; Count1 < intArray.Length; ++Count1)
{
for (int Count2 = 0; Count2 < intArray.Length; ++Count2)
{ // 숫자 비교 if문
if (InputArray[Count1] == intArray[Count2])
{ // 위치 비교 if문
if (Count1 == Count2)
{
++strikeCount;
}
else
{
++ballCount;
}
break;
}
}
}
// 스트라이크, 볼 카운트 나타내기
lbStrike.Text = strikeCount.ToString();
lbBall.Text = ballCount.ToString();
// 카운트 증가 나타내기
++Score;
lbCount.Text = Score.ToString();
// 3스트라이크면 결과 레이블 보여주기
if (lbRand1.Text == txtinput1.Text && lbRand2.Text == txtinput2.Text && lbRand3.Text == txtinput3.Text)
{
lbRand1.Visible = true;
lbRand2.Visible = true;
lbRand3.Visible = true;
}
// 정답(3 Strike인 경우) 정답이라는 메세지 박스
// 리스트박스에 결과 나타내기
string[] str = new string[] { txtinput1.Text, txtinput2.Text, txtinput3.Text };
if (lbStrike.Text == "0" && lbBall.Text == "0")
{
foreach (var item in str)
{
listBox.Items.Add(item + ": 아웃");
}
}
else if (lbStrike.Text == 3.ToString())
{
MessageBox.Show("홈런", "정답");
}
else
{
foreach (var item in str)
{
listBox.Items.Add(item + ": 아웃");
}
}
}
// 다시시작 버튼
private void button2_Click(object sender, EventArgs e)
{
Init();
lbStrike.Text = "0";
lbBall.Text = "0";
txtinput1.Clear();
txtinput2.Clear();
txtinput3.Clear();
lbCount.Text = "0";
}
}
}
1. 처음에는 정답 레이블 가리고 > 정답을 맞춘 후에는 보여주기 (ok)
2. 3strike가 나오면 정답이라고 메세지 박스 띄우기 (OK)
3. 내가 입력한 숫자들을 기록해주는 textbox만들기 : 결과도 함께
'C#' 카테고리의 다른 글
2020.08.26(수) - C# (0) | 2020.08.26 |
---|---|
2020.08.25(화) - C# 윈폼 (0) | 2020.08.25 |
2020.08.21(금) - C# 윈폼 & C# (0) | 2020.08.21 |
2020.08.20(목) - C# 윈폼 & C# (0) | 2020.08.20 |
2020.08.19(수) - C# & 윈폼 (0) | 2020.08.19 |