반응형
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
반응형

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
int main()
{
 
    int a = 0;
 
    while (1) {
        printf("hello");
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                if (a == 0)
                    goto stop;
            }
        }
    }
    stop:
    printf("탈출\n");
    return 0;
}
 
cs

 

// goto 문이 실행되는 순간 stop:구문으로 이동하여 탈출 한다.

출력 결과  :

 

 

반응형
반응형
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
 
#include "stdafx.h"
#include <stdio.h>
#include <Windows.h>
#define MAX 3
 
struct st_info {
    char name[30];
    double lang=0.0f, eng = 0.0f, math = 0.0f;
    double total = 0.0f, avg = 0.0f, rank = 0.0f;
    char grade[3];
};
int main()
{
    typedef unsigned char byte;
 
    //구조체
    st_info clsA[MAX];
    for (int i = 0; i < MAX; i++) {
        system("cls");
        printf("%d번 학생\n이름 :", i + 1);
        scanf_s("%s", clsA[i].name, sizeof(clsA[i].name));
 
        printf("국어 :");
        scanf_s("%lf"&clsA[i].lang);
    
        printf("영어 :");
        scanf_s("%lf"&clsA[i].eng);
 
        printf("수학 :");
        scanf_s("%lf"&clsA[i].math);
    
        clsA[i].total = clsA[i].lang + clsA[i].eng + clsA[i].math;
        clsA[i].avg = (clsA[i].lang + clsA[i].eng + clsA[i].math) / 3;
    
        if (clsA[i].total > 95) sprintf_s(clsA[i].grade, "A+");
        else if (clsA[i].total > 90 && clsA[i].total <=95) sprintf_s(clsA[i].grade, "A0");
        else if (clsA[i].total > 85 && clsA[i].total <= 90) sprintf_s(clsA[i].grade, "B+");
        else if (clsA[i].total > 80 && clsA[i].total <= 85) sprintf_s(clsA[i].grade, "B0");
        else if (clsA[i].total > 75 && clsA[i].total <= 80) sprintf_s(clsA[i].grade, "C+");
        else if (clsA[i].total > 70 && clsA[i].total <= 75) sprintf_s(clsA[i].grade, "C0");
        else if (clsA[i].total > 65 && clsA[i].total <= 70) sprintf_s(clsA[i].grade, "D+");
        else if (clsA[i].total > 60 && clsA[i].total <= 65) sprintf_s(clsA[i].grade, "D0");
    }
 
    printf("------------------------------------------------------\n");
    printf("이    름 | 국어 | 영어 | 수학 | 총점| 평균 | 등급\n");
    for (int i = 0; i < MAX; i++) {
        printf("%s %0.1lf %0.1lf %0.1lf %0.1lf %0.1lf %s\n", clsA[i].name, clsA[i].lang,clsA[i].eng,clsA[i].math,clsA[i].total,clsA[i].avg, clsA[i].grade);
    }
    return 0;
}
 
 
cs

출력 결과

// 이름과 국, 영, 수 점수를 scanf으로 입력 받을 수 있고, 입력된 결과를 출력 한다.

 

*과제

// 1등과 꼴지  출력하기

// 등수대로 출력하기

반응형

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

C언어(자료구조) - Stack 구현  (0) 2018.09.06
C언어 - goto문  (0) 2018.08.29
C언어 - 2차원 배열과 포인터(빙고판 출력하기)  (0) 2018.08.29
C언어 - 2차원배열 과 포인터  (0) 2018.08.29
C언어 - 이중 포인터  (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
 
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#include <random>
    using namespace std;
#define MAX 5
 
void _swap(int *a, int *b) {
        int tmp = *a;
        *= *b;
        *= tmp;
}
int main()
{
    int bingo[MAX][MAX];
    int count = 0;
    int dice = 0;
    int d1, d2, d3, d4;
    d1 = d2 = d3 = d4 = 0;
 
 
    for (int i = 0; i < MAX; i++) {
        for (int j = 0; j < MAX; j++) {
            count++;
            *(*(bingo+i)+j) = count;
        }
    }
    for (int i = 0; i < 1000; i++) {
        d1 = rand() % 5;
        d2 = rand() % 5;
        d3 = rand() % 5;
        d4 = rand() % 5;
 
        _swap((*(*bingo + d1) + d2)),(*(*bingo + d3) + d4));
    }
    while (1) {
        system("cls");
        for (int i = 0; i < MAX; i++) {
            for (int j = 0; j < MAX; j++) {
                printf("%d "*(*(bingo+i)+j));
            }
            printf("\n");
        }
        Sleep(100);
    }
    return 0;
}
cs

 

// 미완성 

 

반응형

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

C언어 - goto문  (0) 2018.08.29
C언어 - 구조체(학생 성적 구조체 만들기)  (0) 2018.08.29
C언어 - 2차원배열 과 포인터  (0) 2018.08.29
C언어 - 이중 포인터  (0) 2018.08.29
C언어 - 비트연산3 (0을 이동시키기)  (0) 2018.08.29

+ Recent posts