반응형

인터넷에 떠도는 C# 메모장 프로그램이다...

 

생각보다 간단하네...?

 

MemoEx.zip
0.78MB

 

반응형

'Study > C#' 카테고리의 다른 글

C# - 활쏘기 게임  (0) 2018.08.31
C# - 닷지 게임 만들기 결과  (2) 2018.08.31
C# - 닷지 게임 만들기  (0) 2018.08.30
C# - 비행기 자유롭게 움직이기  (0) 2018.08.30
C# - 공튀기기 (particles.js)  (0) 2018.08.30
반응형
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
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 WindowsFormsApp1
{
    struct s_watch
    {
        public int milisec;
        public bool status;
    }
    public partial class Form1 : Form
    {
        int board_x = 0;
        int board_y = 0;
        int board_size_x = 0;
        int board_size_y = 0;
 
        int arrow_x = 0;
        int arrow_y = 0;
        int arrow_size_x = 0;
        int arrow_size_y = 0;
 
        int gagebar_x = 0;
        int gagebar_y = 0;
        int gagebar_size_x = 0;
        int gagebar_size_y = 0;
 
        int gagepoint_x = 0;
        int gagepoint_y = 0;
        int gagepoint_size_x = 0;
        int gagepoint_size_y = 0;
 
       
        int powerCount = 0;
        int power = 0;
        bool powermax = false;
        bool gamestate = false;
 
        int highlow_x = 0;
        int highlow_y = 0;
        int highlow_size_x = 0;
        int highlow_size_y = 0;
 
        bool resultState = false;
        s_watch Watch;
        
        public Form1()
        {
            InitializeComponent();
            board_x = (pictureBox1.Width/2 -100- board_size_x;
            board_y = (pictureBox1.Height*(1/17)) - board_size_y;
            board_size_x = 200;
            board_size_y = 200;
 
            arrow_x = (pictureBox1.Width / 2 - 30);
            arrow_y = (pictureBox1.Height -100- arrow_size_y;
            arrow_size_x = 50;
            arrow_size_y = 100;
 
            gagebar_x = pictureBox1.Width - 100;
            gagebar_y = pictureBox1.Height - 500;
            gagebar_size_x = 50;
            gagebar_size_y = 500;
 
            gagepoint_x = pictureBox1.Width - 160;
            gagepoint_y = pictureBox1.Height- 30;
            gagepoint_size_x = 60;
            gagepoint_size_y = 30;
 
        }
 
        
 
        private void Form1_Load(object sender, EventArgs e)
        {
 
        }
 
        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            Image board = Bitmap.FromFile("board.png"); // 이미지로 가져오는 소스
            e.Graphics.DrawImage(board, board_x, board_y, board_size_x, board_size_y);
 
            Image arrow = Bitmap.FromFile("arrow2.png"); // 이미지로 가져오는 소스
            e.Graphics.DrawImage(arrow, arrow_x, arrow_y, arrow_size_x, arrow_size_y);
 
            Image gagebar = Bitmap.FromFile("gagebar.png"); // 이미지로 가져오는 소스
            e.Graphics.DrawImage(gagebar, gagebar_x, gagebar_y, gagebar_size_x, gagebar_size_y);
            
            Image gagepoint = Bitmap.FromFile("gagepoint4.png"); // 이미지로 가져오는 소스
            e.Graphics.DrawImage(gagepoint, gagepoint_x, gagepoint_y , gagepoint_size_x, gagepoint_size_y);
 
            Image highlow = Bitmap.FromFile("highlow.png"); // 이미지로 가져오는 소스
            e.Graphics.DrawImage(highlow, highlow_x, highlow_y, highlow_size_x, highlow_size_y);
 
        }
 
        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            if (Watch.status == false)
            {
                timer1.Enabled = true;
                power = 0;
                powerCount = 0;
                Watch.status = true;
                
            }
            timer2.Enabled = true;
            arrow_y = (pictureBox1.Height) - arrow_size_y;
            gamestate = false;
        }
 
 
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            
            Watch.milisec++;
            if (Watch.milisec > 2)
            {
                Watch.milisec = 0;
                powerCount++;
                power = powerCount * 20;
                if (power > 460) { 
                powerCount = 0;
                powermax = true;
                }
            }
         
            gagepoint_y = pictureBox1.Height -30 - power;
            
            pictureBox1.Invalidate();
 
        }
 
        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            arrow_y = (pictureBox1.Height-350- arrow_size_y;
            pictureBox1.Invalidate();
            if (Watch.status == true)
            {
                timer1.Enabled=false;
                Watch.milisec = 0;
                power = powerCount ;
                
                Watch.status = false;
                
            }
            textBox1.Text = "Power = " + power;
            if (resultState == true)
            {
                resultState = false;
                timer2.Enabled = false;
                if (power == 11 && gamestate == false)
                {
                    gamestate = true;
                    MessageBox.Show("10점");       
                }
                else if ((power == 9 || power == 10 || power == 12 || power == 13&& gamestate == false)
                {
                    gamestate = true;
                    MessageBox.Show("8점");
                }
                else if ((power == 7 || power == 8 || power == 14 || power == 15&& gamestate == false)
                {
                    gamestate = true;
                    MessageBox.Show("6점");
                }
                else if ((power == 5 || power == 6 || power == 16 || power == 17&& gamestate == false)
                {
                    gamestate = true;
                    MessageBox.Show("4점");
                }
                else if ((power == 3 || power == 4 || power == 18 || power == 19&& gamestate == false)
                {
                    gamestate = true;
                    MessageBox.Show("2점");
                }
                else  
                {
                    gamestate = true;
                    MessageBox.Show("장외");
                }
                
            }
 
        }
 
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
           
        }
 
        private void timer2_Tick(object sender, EventArgs e)
        {
          
            resultState = true;
            pictureBox1.Invalidate();
 
        }
    }
}
 
cs

 

// 마우스를 누르면 power 게이지가 올라가며, 뗄경우 화살이 날라가며 점수가 출력 된다.

 

 

반응형

'Study > C#' 카테고리의 다른 글

C# 메모장 프로그램  (0) 2021.01.22
C# - 닷지 게임 만들기 결과  (2) 2018.08.31
C# - 닷지 게임 만들기  (0) 2018.08.30
C# - 비행기 자유롭게 움직이기  (0) 2018.08.30
C# - 공튀기기 (particles.js)  (0) 2018.08.30
반응형
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
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 WindowsFormsApp3
{
    public partial class Form1 : Form
    {
        Random rs = new Random(); // 랜덤 함수 출력
                                  // 볼 갯수 
        const int missile_quantity = 100;
 
        
        // 볼 사이즈와 컬러 구조체 선언
        Point[] ballPoint = new Point[missile_quantity];
        int sizePoint_x = 5;
        int sizePoint_y = 5;
        // 비행기컬러 , 비행기 사이즈 구조체 선언
        int ship_x = 0;
        int ship_y = 0;
        int shipsize = 25;
 
        int ready_x = 0;
        int ready_y = 0;
        int readysize_x = 200;
        int readysize_y = 200;
 
        int gameover_x = 0;
        int gameover_y = 0;
        int gameover_size_x = 200;
        int gameover_size_y = 200;
 
        int space_x = 0;
        int space_y = 0;
        int space_size_x = 200;
        int space_size_y = 200;
 
        int gameState = 0;
        
        // 볼 속도 선언
        int[] x_speed = new int[100];
        int[] y_speed = new int[100];
 
        // 위치판단
        Rectangle rt = new Rectangle();
 
        public Form1()
        {
            InitializeComponent();
 
            rt.X = ship_x;
            rt.Y = ship_y;
            rt.Width = shipsize;
            rt.Height = shipsize;
 
 
            ship_x = (pictureBox1.Width / 2);
            ship_y = (pictureBox1.Height / 2);
 
            ready_x = (pictureBox1.Width/2- (readysize_x/2);
            ready_y = (pictureBox1.Height*1/3- (readysize_y /2);
 
            gameover_x = (pictureBox1.Width / 2- (gameover_size_x/2);
            gameover_y = (pictureBox1.Height / 2- (gameover_size_x / 2);
 
            space_x = (pictureBox1.Width / 2- (space_size_x / 2);
            space_y = (pictureBox1.Height*2 / 3- (space_size_y / 2);
 
            for (int i = 0; i < missile_quantity; i++)
            {
                ballPoint[i].X = rs.Next(0, pictureBox1.Width);
                ballPoint[i].Y = rs.Next(0, pictureBox1.Height);
                x_speed[i] = rs.Next(-22);
                y_speed[i] = rs.Next(-22);
                if (x_speed[i] == 0)
                    x_speed[i] = 1;
                else if (y_speed[i] == 0)
                    y_speed[i] = 1;
            }
        }
 
        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
 
            if (gameState == 0)
            {
                Image ready = Bitmap.FromFile("ready.png"); // 이미지로 가져오는 소스
                e.Graphics.DrawImage(ready, ready_x, ready_y, readysize_x, readysize_y);
 
                Image space = Bitmap.FromFile("space.png"); // 이미지로 가져오는 소스
                e.Graphics.DrawImage(space, space_x, space_y, space_size_x, space_size_y);
 
            }
            else if (gameState == 3)
            {
                Image gameover = Bitmap.FromFile("gameover.png"); // 이미지로 가져오는 소스
                e.Graphics.DrawImage(gameover, gameover_x, gameover_y, gameover_size_x, gameover_size_y);
            }
            else if (gameState == 1)
            {
                //비행기 그리는 소스
                Image ship = Bitmap.FromFile("ship.png"); // 이미지로 가져오는 소스
                e.Graphics.DrawImage(ship, ship_x, ship_y, shipsize, shipsize);
                //
               // e.Graphics.FillRectangle(Brushes.Orange, rt);
            }
           
            for (int i = 0; i < missile_quantity; i++)
            {
                if (i % 2 == 0) e.Graphics.FillEllipse(Brushes.Blue,ballPoint[i].X,ballPoint[i  ].Y, sizePoint_x, sizePoint_y);
                else e.Graphics.FillEllipse(Brushes.Purple,ballPoint[i].X,ballPoint[i].Y, sizePoint_x, sizePoint_y);
 
            }
 
 
        }
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (gameState == 1)
            {
                for (int i = 0; i < missile_quantity; i++)
                {
                    // 볼을 이동시키는 소스
                    ballPoint[i].X += x_speed[i];
                    ballPoint[i].Y += y_speed[i];
                    pictureBox1.Invalidate(); // 화면 갱신
 
                    // 벽을 만나면 튕기는 소스
                    if (ballPoint[i].X < 0) x_speed[i] *= -1;
                    if (ballPoint[i].X > pictureBox1.Width) x_speed[i] *= -1;
                    if (ballPoint[i].Y < 0) y_speed[i] *= -1;
                    if (ballPoint[i].Y > pictureBox1.Height) y_speed[i] *= -1;
                }
                
            }
 
        }
        
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            
        }
  
        class Watch
        {
            static public int milisec = 0;
            static public int sec = 0;
 
            static public bool status = false;
        }
        
        private void timer3_Tick(object sender, EventArgs e)
        {
            Watch.milisec++;
            if (Watch.milisec > 59)
            {
                Watch.milisec = 0;
                Watch.sec++;
                if (Watch.sec > 59)
                    Watch.sec = 0;
            }
            textBox1.Text = Watch.sec + ":" + Watch.milisec+"초";
        }
 
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
 
        }
 
        private void Form1_Click(object sender, EventArgs e)
        {
 
        }
 
        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            //키코드를 뗄 때 입력받는 함수
           
                if (e.KeyCode == Keys.Right) bright = false;
                if (e.KeyCode == Keys.Left) bleft = false;
                if (e.KeyCode == Keys.Down) bdown = false;
                if (e.KeyCode == Keys.Up) bup = false;
 
            if (e.KeyCode == Keys.Space) gameState = 1;
               
                 
               
                
 
            
                //
            if (Watch.status == false && gameState == 1)
            {
                timer3.Start();
                timer3.Interval = 10;
                Watch.status = true;
            }
            else if (Watch.status == true && gameState == 3)
            {
                timer3.Stop();
                Watch.status = false;
                Watch.milisec = 0;
                Watch.sec = 0;
                gameState = 0;
                
            }
            else if (gameState == 0)
            {
                Watch.milisec = 0;
                Watch.sec = 0;
                Watch.status = false;
                textBox1.Text = Watch.sec + ":" + Watch.milisec +"초";
                timer3.Stop();
            }
           
        }
        // 키보드 이동용 bool변수
        bool bleft = false, bright = false, bup = false, bdown = false, bspace = false;
 
        private void timer2_Tick(object sender, EventArgs e)
        {
            if (gameState == 1)
            {
 
                // 비행기 움직임
                if (bright) { if (ship_x < pictureBox1.Width - 30) ship_x += 5; }
                if (bleft) { if (ship_x > 0) ship_x -= 5; }
                if (bup) { if (ship_y > 0) ship_y -= 5; }
                if (bdown) { if (ship_y < pictureBox1.Height - 30) ship_y += 5; }
 
                for (int i = 0; i < missile_quantity; i++)
                {
                    if (rt.Contains(ballPoint[i].X  , ballPoint[i].Y) == true)
                    {
                        gameState = 3;
                        textBox1.Text = Watch.sec + ":" + Watch.milisec + "초";
                        timer3.Stop();
                        MessageBox.Show("기록 : "+Watch.sec + ":" + Watch.milisec + "초");
                        break;
 
                    }
                }
            }
            else if (gameState == 3)
            {
                Watch.status = false;
                bleft = false;
                bright = false;
                bup = false;
                bdown = false;
                if (bspace) gameState = 0;
                for (int i =0; i<missile_quantity; i++)
                {
                    ballPoint[i].X += x_speed[i];
                    ballPoint[i].Y += y_speed[i];
                    pictureBox1.Invalidate();
                }
            }
            else if (gameState == 0)
            {
                Watch.status = false;
               
            }
            pictureBox1.Invalidate();
 
        }
 
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
 
             // 키코드를 누를 때 입력 받는 함수
            if (e.KeyCode == Keys.Right) bright = true;
            if (e.KeyCode == Keys.Left) bleft = true;
            if (e.KeyCode == Keys.Down) bdown = true;
            if (e.KeyCode == Keys.Up) bup = true;
            
 
        }
    }
 
    
    
}
 
cs

 

 

 

 

WindowsFormsApp3.zip

WindowsFormsApp3.sln

 

반응형

'Study > C#' 카테고리의 다른 글

C# 메모장 프로그램  (0) 2021.01.22
C# - 활쏘기 게임  (0) 2018.08.31
C# - 닷지 게임 만들기  (0) 2018.08.30
C# - 비행기 자유롭게 움직이기  (0) 2018.08.30
C# - 공튀기기 (particles.js)  (0) 2018.08.30
반응형
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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 WindowsFormsApp3
{
    public partial class Form1 : Form
    {
        Random rs = new Random(); // 랜덤 함수 출력
                                  // 볼 갯수 
        const int missile_quantity = 100;
 
        int randnumber = 0;
        // 볼 사이즈와 컬러 구조체 선언
        Point[] ballPoint = new Point[missile_quantity];
        int sizePoint_x = 5;
        int sizePoint_y = 5;
        // 비행기컬러 , 비행기 사이즈 구조체 선언
        int ship_x = 300;
        int ship_y = 300;
        int shipsize = 25;
 
     
 
        // 볼 속도 선언
        int[] x_speed = new int[100];
        int[] y_speed = new int[100];
        
 
        public Form1()
        {
            InitializeComponent();
           
            for (int i = 0; i < missile_quantity; i++)
            {
                ballPoint[i].X = rs.Next(0, pictureBox1.Width);
                ballPoint[i].Y = rs.Next(0, pictureBox1.Height);
                x_speed[i] = rs.Next(-33);
                y_speed[i] = rs.Next(-33);
                if (x_speed[i] == 0)
                    x_speed[i] = 1;
                else if (y_speed[i] == 0)
                    y_speed[i] = 1;
            }
        }
 
        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
         
            //비행기 그리는 소스
            Image ship = Bitmap.FromFile("ship.png"); // 이미지로 가져오는 소스
            e.Graphics.DrawImage(ship, ship_x, ship_y, shipsize, shipsize);
       
           
            for (int i = 0; i < missile_quantity; i++)
            {
                if (i % 2 == 0) e.Graphics.FillEllipse(Brushes.Blue,ballPoint[i].X,ballPoint[i].Y, sizePoint_x, sizePoint_y);
                else e.Graphics.FillEllipse(Brushes.Purple,ballPoint[i].X,ballPoint[i].Y, sizePoint_x, sizePoint_y);
 
            }
 
 
        }
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            for (int i = 0; i < missile_quantity; i++)
            {
                // 볼을 이동시키는 소스
                ballPoint[i].X += x_speed[i];
                ballPoint[i].Y += y_speed[i];
                pictureBox1.Invalidate(); // 화면 갱신
 
                // 벽을 만나면 튕기는 소스
                if (ballPoint[i].X < 0) x_speed[i] *= -1;
                if (ballPoint[i].X > pictureBox1.Width) x_speed[i] *= -1;
                if (ballPoint[i].Y < 0) y_speed[i] *= -1;
                if (ballPoint[i].Y > pictureBox1.Height) y_speed[i] *= -1;
            }
         
 
        }
        // 키보드 이동용 bool변수
        bool bleft = false, bright = false, bup = false, bdown = false;
 
        private void pictureBox1_Click(object sender, EventArgs e)
        {
 
 
        }
        
 
        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            //키코드를 뗄 때 입력받는 함수
            if (e.KeyCode == Keys.Right) bright = false;
            if (e.KeyCode == Keys.Left) bleft = false;
            if (e.KeyCode == Keys.Down) bdown = false;
            if (e.KeyCode == Keys.Up) bup = false;
 
            
        }
 
        private void timer2_Tick(object sender, EventArgs e)
        {
            // 비행기 움직임
            if (bright) { if (ship_x < pictureBox1.Width-30) ship_x += 5; }
            if (bleft) { if (ship_x > 0) ship_x -= 5; }
            if (bup) { if (ship_y > 0) ship_y -= 5; }
            if (bdown) { if (ship_y < pictureBox1.Height -30) ship_y += 5; }
 
            pictureBox1.Invalidate();
 
        }
 
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
 
            // 키코드를 누를 때 입력 받는 함수
            if (e.KeyCode == Keys.Right) bright = true;
            if (e.KeyCode == Keys.Left) bleft = true;
            if (e.KeyCode == Keys.Down) bdown = true;
            if (e.KeyCode == Keys.Up) bup = true;
            
 
        }
    }
 
    
    
}
 
cs

 

 

 

 

// 수정 코드

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
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 WindowsFormsApp3
{
    public partial class Form1 : Form
    {
        Random rs = new Random(); // 랜덤 함수 출력
                                  // 볼 갯수 
        const int missile_quantity = 100;
 
        int randnumber = 0;
        // 볼 사이즈와 컬러 구조체 선언
        Point[] ballPoint = new Point[missile_quantity];
        int sizePoint_x = 5;
        int sizePoint_y = 5;
        // 비행기컬러 , 비행기 사이즈 구조체 선언
        int ship_x = 0;
        int ship_y = 0;
        int shipsize = 25;
 
        int ready_x = 0;
        int ready_y = 0;
        int readysize_x = 200;
        int readysize_y = 100;
 
        int gameover_x = 0;
        int gameover_y = 0;
        int gameover_size_x = 0;
        int gameover_size_y = 0;
 
        int gameState = 0;
 
        // 볼 속도 선언
        int[] x_speed = new int[100];
        int[] y_speed = new int[100];
        
 
        public Form1()
        {
            InitializeComponent();
            ship_x = (pictureBox1.Width / 2);
            ship_y = (pictureBox1.Height / 2);
 
            ready_x = (pictureBox1.Width/2- (readysize_x/2);
            ready_y = (pictureBox1.Height/2- (readysize_y /2);
 
            gameover_x = (pictureBox1.Width / 2- (gameover_size_x/2);
            gameover_y = (pictureBox1.Height / 2- (gameover_size_y / 2);
 
 
            for (int i = 0; i < missile_quantity; i++)
            {
                ballPoint[i].X = rs.Next(0, pictureBox1.Width);
                ballPoint[i].Y = rs.Next(0, pictureBox1.Height);
                x_speed[i] = rs.Next(-33);
                y_speed[i] = rs.Next(-33);
                if (x_speed[i] == 0)
                    x_speed[i] = 1;
                else if (y_speed[i] == 0)
                    y_speed[i] = 1;
            }
        }
 
        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
 
            if (gameState == 0)
            {
                Image ready = Bitmap.FromFile("ready.png"); // 이미지로 가져오는 소스
                e.Graphics.DrawImage(ready, ready_x, ready_y, readysize_x, readysize_y);
            }
            else if (gameState == 3)
            {
                Image gameover = Bitmap.FromFile("gameover.png"); // 이미지로 가져오는 소스
                e.Graphics.DrawImage(gameover, gameover_x, gameover_y, gameover_size_x, gameover_size_y);
            }
            else if (gameState == 1)
            {
                //비행기 그리는 소스
                Image ship = Bitmap.FromFile("ship.png"); // 이미지로 가져오는 소스
                e.Graphics.DrawImage(ship, ship_x, ship_y, shipsize, shipsize);
            }
           
            for (int i = 0; i < missile_quantity; i++)
            {
                if (i % 2 == 0) e.Graphics.FillEllipse(Brushes.Blue,ballPoint[i].X,ballPoint[i  ].Y, sizePoint_x, sizePoint_y);
                else e.Graphics.FillEllipse(Brushes.Purple,ballPoint[i].X,ballPoint[i].Y, sizePoint_x, sizePoint_y);
 
            }
 
 
        }
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (gameState == 1)
            {
                for (int i = 0; i < missile_quantity; i++)
                {
                    // 볼을 이동시키는 소스
                    ballPoint[i].X += x_speed[i];
                    ballPoint[i].Y += y_speed[i];
                    pictureBox1.Invalidate(); // 화면 갱신
 
                    // 벽을 만나면 튕기는 소스
                    if (ballPoint[i].X < 0) x_speed[i] *= -1;
                    if (ballPoint[i].X > pictureBox1.Width) x_speed[i] *= -1;
                    if (ballPoint[i].Y < 0) y_speed[i] *= -1;
                    if (ballPoint[i].Y > pictureBox1.Height) y_speed[i] *= -1;
                }
            }
 
        }
        // 키보드 이동용 bool변수
        bool bleft = false, bright = false, bup = false, bdown = false;
 
        private void pictureBox1_Click(object sender, EventArgs e)
        {
 
 
        }
 
        class Watch
        {
            static public int milisec = 0;
            static public int sec = 0;
 
            static public bool status = false;
        }
        
        private void timer3_Tick(object sender, EventArgs e)
        {
            Watch.milisec++;
            if (Watch.milisec > 59)
            {
                Watch.milisec = 0;
                Watch.sec++;
                if (Watch.sec > 59)
                    Watch.sec = 0;
            }
            textBox1.Text = Watch.sec + ":" + Watch.milisec;
        }
 
        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            //키코드를 뗄 때 입력받는 함수
           
                if (e.KeyCode == Keys.Right) bright = false;
                if (e.KeyCode == Keys.Left) bleft = false;
                if (e.KeyCode == Keys.Down) bdown = false;
                if (e.KeyCode == Keys.Up) bup = false;   
             
                if (e.KeyCode == Keys.Space) gameState = 1;
            //
            if (Watch.status == false && gameState == 1)
            {
                timer3.Start();
                timer3.Interval = 10;
                Watch.status = true;
            }
            else if (Watch.status == true && gameState == 0 && gameState == 3)
            {
                timer3.Stop();
                Watch.status = false;
            }
 
        }
 
        private void timer2_Tick(object sender, EventArgs e)
        {
            if (gameState == 1)
            {
                // 비행기 움직임
                if (bright) { if (ship_x < pictureBox1.Width - 30) ship_x += 5; }
                if (bleft) { if (ship_x > 0) ship_x -= 5; }
                if (bup) { if (ship_y > 0) ship_y -= 5; }
                if (bdown) { if (ship_y < pictureBox1.Height - 30) ship_y += 5; }
            }
            pictureBox1.Invalidate();
        }
 
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
 
             // 키코드를 누를 때 입력 받는 함수
            if (e.KeyCode == Keys.Right) bright = true;
            if (e.KeyCode == Keys.Left) bleft = true;
            if (e.KeyCode == Keys.Down) bdown = true;
            if (e.KeyCode == Keys.Up) bup = true;
           
 
        }
    }
 
    
    
}
 
cs

// Timer 스톱워치 참고 자료

// http://baealex.tistory.com/89

 

반응형

'Study > C#' 카테고리의 다른 글

C# - 활쏘기 게임  (0) 2018.08.31
C# - 닷지 게임 만들기 결과  (2) 2018.08.31
C# - 비행기 자유롭게 움직이기  (0) 2018.08.30
C# - 공튀기기 (particles.js)  (0) 2018.08.30
C# - 이벤트  (0) 2018.08.30
반응형
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
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 WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        Random rs = new Random(); // 랜덤 함수 출력
 
        int randnumber = 0;
        // 볼 사이즈와 컬러 구조체 선언
        Point[] colorPoint = new Point[100];
        Point[] sizePoint = new Point[100];
 
        // 비행기컬러 , 비행기 사이즈 구조체 선언
        int ship_x = 300;
        int ship_y = 300;
       // int shipsize = 10;
 
        int count = 0;
        // 볼 속도 선언
        int[] x_speed = new int[100];
        int[] y_speed = new int[100];
 
       
        public Form1()
        {
            InitializeComponent();
 
            // x,y 속도를 랜덤하게 출력하게 하는 함수
            // 속도가 0 일경우 1로 설정됨.
            
            for (int i = 0; i < 100; i++)
            {
                x_speed[i]= rs.Next(-3,3);
                y_speed[i] = rs.Next(-33);
                if (x_speed[i] == 0)
                    x_speed[i] = 1;
                else if (y_speed[i] == 0)
                    y_speed[i] = 1;
            }
        }
 
        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            
            randnumber = rs.Next(520); // 랜덤수 출력
            // 마우스 클릭시 해당 좌표값 읽어오는 소스
            //textBox1.Text = e.X.ToString() + "," + e.Y.ToString() + "(" + randnumber.ToString() + ")";
 
            colorPoint[count].X = e.X;
            colorPoint[count].Y = e.Y;
 
            
 
            //볼 사이즈를 랜덤하게 설정 
            sizePoint[count].X = randnumber; 
            sizePoint[count].Y = randnumber;
 
            count++;
            pictureBox1.Invalidate(); // 화면 갱신
        }
 
        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            //비행기 그리는 소스
            Image ship = Bitmap.FromFile("ship.png"); // 이미지로 가져오는 소스
            e.Graphics.DrawImage(ship, ship_x, ship_y,25,25);
            //e.Graphics.FillEllipse(Brushes.Purple, ship_x, ship_y, shipsize, shipsize);
 
            for (int i = 0; i < count; i++)
            {
                //원을 그려주는 소스
                SolidBrush mybrush = new SolidBrush(Color.FromArgb(i + 10025500));
                e.Graphics.FillEllipse(mybrush, colorPoint[i].X - (sizePoint[i].X/2), colorPoint[i].Y-(sizePoint[i].Y/2), sizePoint[i].X, sizePoint[i].Y);
 
                
 
                for (int j =0; j<count; j++)
                {
                    // 선을 그려주는 소스
                   // Pen mypen = new Pen(Color.FromArgb(i + 5,255,255,255),0.1f) ;
                  //  e.Graphics.DrawLine(mypen, colorPoint[i], colorPoint[j]);
                    
                }
            }
            
        }
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            for (int i = 0; i<count; i++)
            {
                // 볼을 이동시키는 소스
                colorPoint[i].X += x_speed[i]; 
                colorPoint[i].Y += y_speed[i];
                pictureBox1.Invalidate(); // 화면 갱신
                // 벽을 만나면 튕기는 소스
                if (colorPoint[i].X < 0) x_speed[i] *=-1;
                if (colorPoint[i].X > pictureBox1.Width) x_speed[i] *= -1;
                if (colorPoint[i].Y < 0) y_speed[i] *= -1;
                if (colorPoint[i].Y > pictureBox1.Height) y_speed[i] *= -1;
            }
        }
 
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            // 키코드를 누를 때 입력 받는 함수
            if (e.KeyCode == Keys.Right) bright = true;
            if (e.KeyCode == Keys.Left) bleft = true;
            if (e.KeyCode == Keys.Down) bdown = true;
            if (e.KeyCode == Keys.Up) bup = true;
           
             
        }
        // 키보드 이동용 bool변수
        bool bleft = false,bright=false, bup =false,bdown =false;
 
        private void timer2_Tick(object sender, EventArgs e)
        {
            // 비행기 움직임
            if (bright) { if (ship_x < pictureBox1.Width-35) ship_x +=5; }
            if (bleft) { if (ship_x > 0) ship_x -=5; }
            if (bup) {if (ship_y > 0) ship_y -=5; }
            if (bdown) { if (ship_y < pictureBox1.Height -35)  ship_y +=5; }
 
            pictureBox1.Invalidate();
        }
 
        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            //키코드를 뗄 때 입력받는 함수
            if (e.KeyCode == Keys.Right)bright = false;
            if (e.KeyCode == Keys.Left)bleft = false;
            if (e.KeyCode == Keys.Down)bdown = false;
            if (e.KeyCode == Keys.Up)bup = false;
            
        }
    }
}
 
cs

 

반응형

'Study > C#' 카테고리의 다른 글

C# - 닷지 게임 만들기 결과  (2) 2018.08.31
C# - 닷지 게임 만들기  (0) 2018.08.30
C# - 공튀기기 (particles.js)  (0) 2018.08.30
C# - 이벤트  (0) 2018.08.30
C# - 계산기 만들기2  (0) 2018.08.30
반응형
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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 WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        Random rs = new Random(); // 랜덤 함수 출력
 
        int randnumber = 0;
        // 볼 사이즈와 컬러 구조체 선언
        Point[] colorPoint = new Point[100];
        Point[] sizePoint = new Point[100];
 
        int count = 0;
        // 볼 속도 선언
        int[] x_xpeed = new int[100];
        int[] y_xpeed = new int[100];
 
        public Form1()
        {
            InitializeComponent();
 
            // x,y 속도를 랜덤하ㅔ 출력하게 하는 함수
            // 속도가 0 일경우 1로 설정됨.
            for (int i = 0; i < 100; i++)
            {
                x_xpeed[i]= rs.Next(-3,3);
                y_xpeed[i] = rs.Next(-33);
                if (x_xpeed[i] == 0)
                    x_xpeed[i] = 1;
                else if (y_xpeed[i] == 0)
                    y_xpeed[i] = 1;
            }
        }
 
        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            
            randnumber = rs.Next(520); // 랜덤수 출력
            textBox1.Text = e.X.ToString() + "," + e.Y.ToString() + "(" + randnumber.ToString() + ")";
            colorPoint[count].X = e.X;
            colorPoint[count].Y = e.Y;
 
            //볼 사이즈를 랜덤하게 설정
            sizePoint[count].X = randnumber; 
            sizePoint[count].Y = randnumber;
 
            count++;
            pictureBox1.Invalidate(); // 화면 갱신
        }
 
        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            for (int i = 0; i < count; i++)
            {
                //원을 그려주는 소스
                SolidBrush mybrush = new SolidBrush(Color.FromArgb(i + 10025500));
                e.Graphics.FillEllipse(mybrush, colorPoint[i].X - (sizePoint[i].X/2), colorPoint[i].Y-(sizePoint[i].Y/2), sizePoint[i].X, sizePoint[i].Y);
                for (int j =0; j<count; j++)
                {
                    // 선을 그려주는 소스
                    Pen mypen = new Pen(Color.FromArgb(i + 5,255,255,255),0.1f) ;
                    e.Graphics.DrawLine(mypen, colorPoint[i], colorPoint[j]);
                    
                }
            }
            
        }
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            for (int i = 0; i<count; i++)
            {
                // 볼을 이동시키는 소스
                colorPoint[i].X += x_xpeed[i]; 
                colorPoint[i].Y += y_xpeed[i];
                pictureBox1.Invalidate(); // 화면 갱신
                // 벽을 만나면 튕기는 소스
                if (colorPoint[i].X < 0) x_xpeed[i] *=-1;
                if (colorPoint[i].X > pictureBox1.Width) x_xpeed[i] *= -1;
                if (colorPoint[i].Y < 0) y_xpeed[i] *= -1;
                if (colorPoint[i].Y > pictureBox1.Height) y_xpeed[i] *= -1;
            }
        }
 
       
    }
}
 
cs

 

 

 

 

 

 

반응형

'Study > C#' 카테고리의 다른 글

C# - 닷지 게임 만들기  (0) 2018.08.30
C# - 비행기 자유롭게 움직이기  (0) 2018.08.30
C# - 이벤트  (0) 2018.08.30
C# - 계산기 만들기2  (0) 2018.08.30
C# - WinForm 계산기 만들기1  (0) 2018.08.29
반응형
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
32
33
34
35
36
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 WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        int x = 0, y = 0;
 
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawRectangle(Pens.Orange, x, y, 100100); // 네모칸을 그린다.
            e.Graphics.FillRectangle(Brushes.Red, 100100100100); // 채워진 네모칸을 그린다.
            
        } // 그려주는함수
 
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            x = x + 10;
            y = y + 10;
            this.Invalidate(); // refresh 새로고침.
        }// 클릭할 경우 이벤트
    }
}
 
cs

 //마우스를 클릭 할 경우 네모칸이 움직 인다.

//e.Graphics.FillEllipse(Brushes.Purple, 200, 200, 100, 100); // 원을 그린다.
//e.Graphics.DrawString("hello", new Font("Arial", 16), Brushes.Blue, 300, 100); // 문자를 입력한다.

 

반응형

'Study > C#' 카테고리의 다른 글

C# - 닷지 게임 만들기  (0) 2018.08.30
C# - 비행기 자유롭게 움직이기  (0) 2018.08.30
C# - 공튀기기 (particles.js)  (0) 2018.08.30
C# - 계산기 만들기2  (0) 2018.08.30
C# - WinForm 계산기 만들기1  (0) 2018.08.29
반응형
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
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 WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        String oper="";
        double currentNumber = 0;
        double savedNumber = 0;
        public Form1()
        {
            InitializeComponent();
        }
        private void calcOper(ref String oper, ref double savedNumber, ref double currentNumber)
        {
           
                if (oper == "+") savedNumber += currentNumber;
                else if (oper == "-") savedNumber -= currentNumber;
                else if (oper == "*") savedNumber *= currentNumber;
                else if (oper == "/") savedNumber /= currentNumber;
                else savedNumber = currentNumber;
            
        }
        private void button1_Click(object sender, EventArgs e)
        {
            
            calcOper(ref oper, ref savedNumber, ref currentNumber);
            rbx1.Text = savedNumber.ToString();
            oper = "=";
          
            question.Text += currentNumber;
            currentNumber = 0;
            currentNumber = savedNumber;
 
        }
 
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
           
           
        }
 
        private void textBox1_TextChanged_1(object sender, EventArgs e)
        {
 
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            if (currentNumber != 0)
            {
                calcOper(ref oper, ref savedNumber, ref currentNumber);
 
                question.Text += currentNumber.ToString() + "+";
                rbx1.Text = savedNumber.ToString();
                currentNumber = 0;
                oper = "+";
            }
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
 
        }
 
        private void rbx1_TextChanged(object sender, EventArgs e)
        {
 
        }
 
        private void num1_Click(object sender, EventArgs e)
        {
 
            currentNumber = (currentNumber * 10+ 1;
            rbx1.Text = currentNumber.ToString();
           
        }
 
        private void minus_Click(object sender, EventArgs e)
        {
            if (currentNumber != 0)
            {
                calcOper(ref oper, ref savedNumber, ref currentNumber);
                question.Text += currentNumber.ToString() + "-";
                rbx1.Text = savedNumber.ToString();
                currentNumber = 0;
                oper = "-";
            }
        }
       
        private void clear_Click(object sender, EventArgs e)
        {
            rbx1.Clear();
            question.Clear();
            savedNumber = 0;
            currentNumber = 0;
        }
 
        private void mul_Click(object sender, EventArgs e)
        {
            if (currentNumber != 0)
            {
                calcOper(ref oper, ref savedNumber, ref currentNumber);
                question.Text += currentNumber.ToString() + "*";
                rbx1.Text = savedNumber.ToString();
                currentNumber = 0;
                oper = "*";
            }
        }
 
        private void div_Click(object sender, EventArgs e)
        {
            if (currentNumber != 0)
            {
                calcOper(ref oper, ref savedNumber, ref currentNumber);
                question.Text += currentNumber.ToString() + "/";
                rbx1.Text = savedNumber.ToString();
                currentNumber = 0;
                oper = "/";
            }
        }
 
        private void num3_Click(object sender, EventArgs e)
        {
            currentNumber = (currentNumber * 10+ 3;
            rbx1.Text = currentNumber.ToString();
        }
 
        private void num4_Click(object sender, EventArgs e)
        {
            currentNumber = (currentNumber * 10+ 4;
            rbx1.Text = currentNumber.ToString();
        }
 
        private void num5_Click(object sender, EventArgs e)
        {
            currentNumber = (currentNumber * 10+ 5;
            rbx1.Text = currentNumber.ToString();
        }
 
        private void num6_Click(object sender, EventArgs e)
        {
            currentNumber = (currentNumber * 10+ 6;
            rbx1.Text = currentNumber.ToString();
        }
 
        private void num7_Click(object sender, EventArgs e)
        {
            currentNumber = (currentNumber * 10+ 7;
            rbx1.Text = currentNumber.ToString();
        }
 
        private void num8_Click(object sender, EventArgs e)
        {
            currentNumber = (currentNumber * 10+ 8;
            rbx1.Text = currentNumber.ToString();
        }
 
        private void num9_Click(object sender, EventArgs e)
        {
            currentNumber = (currentNumber * 10+ 9;
            rbx1.Text = currentNumber.ToString();
        }
 
        private void num0_Click(object sender, EventArgs e)
        {
            currentNumber = (currentNumber * 10+ 0;
            rbx1.Text = currentNumber.ToString();
        }
 
        private void num2_Click(object sender, EventArgs e)
        {
            currentNumber = (currentNumber * 10+ 2;
            rbx1.Text = currentNumber.ToString();
 
        }
 
        private void question_TextChanged(object sender, EventArgs e)
        {
 
        }
    }
}
 
cs

 

 

 

 

>> 함수를 써서 간결화

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
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 WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        String oper="";
        double currentNumber = 0;
        double savedNumber = 0;
        public Form1()
        {
            InitializeComponent();
        }
        private void calcOper(string currentOper, ref String oper, ref double savedNumber, ref double currentNumber)
        {
           
                if (oper == "+") savedNumber += currentNumber;
                else if (oper == "-") savedNumber -= currentNumber;
                else if (oper == "*") savedNumber *= currentNumber;
                else if (oper == "/") savedNumber /= currentNumber;
                else savedNumber = currentNumber;
          
            question.Text += currentNumber.ToString() + ""+currentOper+"";
            rbx1.Text = savedNumber.ToString();
            oper = currentOper;
 
        }
        private void button1_Click(object sender, EventArgs e)
        {
            
            calcOper("=",ref oper, ref savedNumber, ref currentNumber);
            question.Text += currentNumber;
            currentNumber = 0;
            currentNumber = savedNumber;
 
        }
 
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
           
           
        }
 
        private void textBox1_TextChanged_1(object sender, EventArgs e)
        {
 
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            if (currentNumber != 0)
            {
                calcOper("+",ref oper, ref savedNumber, ref currentNumber);
                
                currentNumber = 0;
               
            }
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
 
        }
 
        private void rbx1_TextChanged(object sender, EventArgs e)
        {
 
        }
 
        private void num1_Click(object sender, EventArgs e)
        {
 
            currentNumber = (currentNumber * 10+ 1;
            rbx1.Text = currentNumber.ToString();
           
        }
 
        private void minus_Click(object sender, EventArgs e)
        {
            if (currentNumber != 0)
            {
                calcOper("-",ref oper, ref savedNumber, ref currentNumber);
               
                currentNumber = 0;
               
            }
        }
       
        private void clear_Click(object sender, EventArgs e)
        {
            rbx1.Clear();
            question.Clear();
            savedNumber = 0;
            currentNumber = 0;
            oper = "";
        }
 
        private void mul_Click(object sender, EventArgs e)
        {
            if (currentNumber != 0)
            {
                calcOper("*",ref oper, ref savedNumber, ref currentNumber);
              
                currentNumber = 0;
                
            }
        }
 
        private void div_Click(object sender, EventArgs e)
        {
            if (currentNumber != 0)
            {
                calcOper("/",ref oper, ref savedNumber, ref currentNumber);
              
                currentNumber = 0;
             
            }
        }
 
        private void num3_Click(object sender, EventArgs e)
        {
            currentNumber = (currentNumber * 10+ 3;
            rbx1.Text = currentNumber.ToString();
        }
 
        private void num4_Click(object sender, EventArgs e)
        {
            currentNumber = (currentNumber * 10+ 4;
            rbx1.Text = currentNumber.ToString();
        }
 
        private void num5_Click(object sender, EventArgs e)
        {
            currentNumber = (currentNumber * 10+ 5;
            rbx1.Text = currentNumber.ToString();
        }
 
        private void num6_Click(object sender, EventArgs e)
        {
            currentNumber = (currentNumber * 10+ 6;
            rbx1.Text = currentNumber.ToString();
        }
 
        private void num7_Click(object sender, EventArgs e)
        {
            currentNumber = (currentNumber * 10+ 7;
            rbx1.Text = currentNumber.ToString();
        }
 
        private void num8_Click(object sender, EventArgs e)
        {
            currentNumber = (currentNumber * 10+ 8;
            rbx1.Text = currentNumber.ToString();
        }
 
        private void num9_Click(object sender, EventArgs e)
        {
            currentNumber = (currentNumber * 10+ 9;
            rbx1.Text = currentNumber.ToString();
        }
 
        private void num0_Click(object sender, EventArgs e)
        {
            currentNumber = (currentNumber * 10+ 0;
            rbx1.Text = currentNumber.ToString();
        }
 
        private void num2_Click(object sender, EventArgs e)
        {
            currentNumber = (currentNumber * 10+ 2;
            rbx1.Text = currentNumber.ToString();
 
        }
 
        private void question_TextChanged(object sender, EventArgs e)
        {
 
        }
    }
}
 
cs

 

 

>> 참고 결과

 

wfCalc.zip

 

반응형

'Study > C#' 카테고리의 다른 글

C# - 닷지 게임 만들기  (0) 2018.08.30
C# - 비행기 자유롭게 움직이기  (0) 2018.08.30
C# - 공튀기기 (particles.js)  (0) 2018.08.30
C# - 이벤트  (0) 2018.08.30
C# - WinForm 계산기 만들기1  (0) 2018.08.29
반응형

//C# 윈도우 폼 계산기 만들기


        private void button1_Click(object sender, EventArgs e)
        {
            int a = int.Parse(tbxData1.Text);
            int b = int.Parse(tbxData2.Text);

            rbx1.Text = (a + b).ToString()   

   }

 

// 숫자 입력한 뒤 버튼을 누르면 더한 결과가 나온다.

 

 

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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 WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        int question_a = 0, question_b = 0;
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
 
            //int a = int.Parse(tbxData1.Text);
            //int b = int.Parse(tbxData2.Text);
 
            //rbx1.Text = (a + b).ToString();
 
            int a = question_a;
            int b = question_b;
            rbx1.Text =(a+b).ToString();
 
        }
 
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
           
           
        }
 
        private void textBox1_TextChanged_1(object sender, EventArgs e)
        {
 
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            question.Text = "+";
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
 
        }
 
        private void rbx1_TextChanged(object sender, EventArgs e)
        {
 
        }
 
        private void num1_Click(object sender, EventArgs e)
        {
            question.Text += 1.ToString();
           
        }
 
        private void minus_Click(object sender, EventArgs e)
        {
            question.Text = "-";
        }
 
        private void clear_Click(object sender, EventArgs e)
        {
            question.Clear();
        }
 
        private void mul_Click(object sender, EventArgs e)
        {
            question.Text = "*";
        }
 
        private void div_Click(object sender, EventArgs e)
        {
            question.Text = "/";
        }
 
        private void del_Click(object sender, EventArgs e)
        {
 
        }
 
        private void num3_Click(object sender, EventArgs e)
        {
            question.Text += 3.ToString();
        }
 
        private void num4_Click(object sender, EventArgs e)
        {
            question.Text += 4.ToString();
        }
 
        private void num5_Click(object sender, EventArgs e)
        {
            question.Text += 5.ToString();
        }
 
        private void num6_Click(object sender, EventArgs e)
        {
            question.Text += 6.ToString();
        }
 
        private void num7_Click(object sender, EventArgs e)
        {
            question.Text += 7.ToString();
        }
 
        private void num8_Click(object sender, EventArgs e)
        {
            question.Text += 8.ToString();
        }
 
        private void num9_Click(object sender, EventArgs e)
        {
            question.Text += 9.ToString();
        }
 
        private void num0_Click(object sender, EventArgs e)
        {
            question.Text += 0.ToString();
        }
 
        private void num2_Click(object sender, EventArgs e)
        {
            question.Text += 2.ToString();
 
        }
    }
}
 
cs

 

 

 

반응형

'Study > C#' 카테고리의 다른 글

C# - 닷지 게임 만들기  (0) 2018.08.30
C# - 비행기 자유롭게 움직이기  (0) 2018.08.30
C# - 공튀기기 (particles.js)  (0) 2018.08.30
C# - 이벤트  (0) 2018.08.30
C# - 계산기 만들기2  (0) 2018.08.30

+ Recent posts