티스토리 뷰

프로그래밍/C#

C# 구구단 게임 만들기

뽀로로친구에디 2019. 2. 28. 13:51

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();

            }

        }

    }

}



댓글
최근에 달린 댓글
글 보관함
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Total
Today
Yesterday
    뽀로로친구에디
    최근에 올라온 글