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

+ Recent posts