C# 구구단 게임 만들기
C# 구구단 게임 만들기
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 구구단게임
{
public partial class Form1 : Form
{
int x;
int y;
int z;
Random r = new Random();
public Form1()
{
InitializeComponent();
Question();
}
private void Question()
{
r.Next();
x = r.Next(2, 9); //2~9 random
r.Next();
y = r.Next(1, 9); // 1~9 random
z = x * y;
lbl_num1.Text = x.ToString();
lbl_num2.Text = y.ToString();
numAnswer.Value = 0;
}
private void numAnswer_KeyDown(object sender, KeyEventArgs e)
{
//엔터키를 누를경우
if(e.KeyCode == Keys.Enter)
{
if (numAnswer.Value == z)
{
MessageBox.Show("정답입니다.", "정답", MessageBoxButtons.OK, MessageBoxIcon.Information);
Question();
}
else
{
MessageBox.Show("오답입니다.", "오답", MessageBoxButtons.OK, MessageBoxIcon.Error);
Question();
}
}
}
private void button1_Click(object sender, EventArgs e)
{
if(numAnswer.Value == z)
{
MessageBox.Show("정답입니다.", "정답", MessageBoxButtons.OK, MessageBoxIcon.Information);
Question();
}
else
{
MessageBox.Show("오답입니다.", "오답", MessageBoxButtons.OK, MessageBoxIcon.Error);
Question();
}
}
}
}