KODLAR
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 WindowsFormsApp2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Graphics tuval; Pen kalem = new Pen(Color.Black , 3 ); int x, y, x1=0, y1=0, x2 = 0, y2 = 0,xk; bool atis = false; int px1, px2, px3, px4; int py1, py2, py3, py4; Random Rastgele = new Random(); int puanlama = 0; private void pictureBox1_Click(object sender, EventArgs e) { x = Cursor.Position.X; y = Cursor.Position.Y; Point P = PointToScreen(new Point(pictureBox1.Bounds.Left, pictureBox1.Bounds.Top)); xk = x - P.X; x1 = Convert.ToInt16( Math.Abs(450 - (x - P.X)) / 5 ); y1 = Convert.ToInt16( Math.Abs(400 - (y - P.Y)) / 5); x2 = 450; y2 = 400; atis = true; } private void Form1_Load(object sender, EventArgs e) { pictureBox2.Parent = pictureBox1; pictureBox2.BackColor = Color.Transparent; pictureBox3.Parent = pictureBox1; pictureBox3.BackColor = Color.Transparent; pictureBox4.Parent = pictureBox1; pictureBox4.BackColor = Color.Transparent; pictureBox5.Parent = pictureBox1; pictureBox5.BackColor = Color.Transparent; tuval = pictureBox1.CreateGraphics(); } private void button1_Click(object sender, EventArgs e) { timer1.Interval = 100; timer1.Start(); px1 = Rastgele.Next(50,850); py1 = 0; pictureBox2.Location = new Point(px1,py1); px2 = Rastgele.Next(50, 850); py2 = 0; pictureBox3.Location = new Point(px2, py2); px3 = Rastgele.Next(50, 850); py3 = 0; pictureBox4.Location = new Point(px3, py3); px4 = Rastgele.Next(50, 850); py4 = 0; pictureBox5.Location = new Point(px4, py4); } private void timer1_Tick(object sender, EventArgs e) { pictureBox1.Refresh(); x = Cursor.Position.X; y = Cursor.Position.Y; Point P = PointToScreen(new Point(pictureBox1.Bounds.Left, pictureBox1.Bounds.Top)); x = x - P.X; y = y - P.Y; if (atis) { if (xk < 450) { x2 = x2 - x1; } else { x2 = x2 + x1; } y2 = y2 - y1; tuval.DrawRectangle(kalem, x2, y2, 5, 5); } tuval.DrawLine(kalem, 450 , 400 , x , y); tuval.DrawLine(kalem, x - 25 , y , x + 25 , y); tuval.DrawLine(kalem, x , y - 25 , x , y + 25); tuval.DrawEllipse(kalem , x - 10 , y - 10 , 20 , 20); tuval.DrawArc(kalem , 425 , 375 , 50 , 50 , 270 , 360); //nesnelerin hareketinin saglanması py1 = py1 + Rastgele.Next(5,20); pictureBox2.Location = new Point(px1,py1); py2 = py2 + Rastgele.Next(5, 20); pictureBox3.Location = new Point(px2, py2); py3 = py3 + Rastgele.Next(5, 20); pictureBox4.Location = new Point(px3, py3); py4 = py4 + Rastgele.Next(5, 20); pictureBox5.Location = new Point(px4, py4); //oyun dışına çıkan nesnelerin başlangıç noktasından tekrar başlatılması if (py1 > 400) { py1 = -30; px1 = Rastgele.Next(50,850); } if (py2 > 400) { py2 = -30; px2 = Rastgele.Next(50, 850); } if (py3 > 400) { py3 = -30; px3 = Rastgele.Next(50, 850); } if (py4 > 400) { py4 = -30; px4 = Rastgele.Next(50, 850); } //vurma olayının gerçekleştirilmesi if (x2 > px1 && y2 > py1 && x2 < px1 + 30 && y2 < py1 + 30 ) { py1 = -30; px1 = Rastgele.Next(50, 850); puanlama = puanlama + 10; } if (x2 > px2 && y2 > py2 && x2 < px2 + 30 && y2 < py2 + 30) { py2 = -30; px2 = Rastgele.Next(50, 850); puanlama = puanlama + 10; } if (x2 > px3 && y2 > py3 && x2 < px3 + 30 && y2 < py3 + 30) { py3 = -30; px3 = Rastgele.Next(50, 850); puanlama = puanlama + 10; } if (x2 > px4 && y2 > py4 && x2 < px4 + 30 && y2 < py4 + 30) { py4 = -30; px4 = Rastgele.Next(50, 850); puanlama = puanlama + 10; } label2.Text = Convert.ToString(puanlama); } } }
Yorumlar
Yorum Gönder