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
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace IntroEkranKoruyucu
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
bool sola; // içeriği eğer true ise sinek sola, false ise sağa gidecektir..
bool yukari; // içeriği eğer true ise sinek yukarı false ise aşağı gider..
private void Form1_Load(object sender, EventArgs e)
{
// cismin hareket edeceği yönü rasgele atayalım:
// sola ve yukari içerisine rasgele değerler atalım..
Random rnd = new Random();
int sayi = rnd.Next(0, 2);
if (sayi == 0)
sola = false;// tek satırlık işlem yapılacaksa "{}" gerek yoktur..
else
sola = true;
sayi = rnd.Next(0, 2);
if (sayi == 0)
yukari = false;
else
yukari = true;
// mouse simgesini gizleyelim :
Cursor.Hide();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (sola == true)
{
pbSinek.Left--;// sinek sola gider..
// eğer sineğin soldan uzaklığı 0 ise yani limite erişmişse yön değiştirsin :
if (pbSinek.Left == 0)
{
sola = false; // cisim sağa gitsin..
}
}
else
{
pbSinek.Left++; // sinek sağa gider..
if (pbSinek.Left == (this.Width - pbSinek.Width))// cisim sağa dayandığı anda yön değiştirsin ve sola gitmeye başlasın..
sola = true;
}
// Y eksenindeki hareket için :
if (yukari) // yukari==true
{
pbSinek.Top--;// cisim yukarıya doğru ilerler..
if (pbSinek.Top == 0)
yukari = false;
}
else
{
pbSinek.Top++; // sinek aşağı doğru ilerler..
if (pbSinek.Top == (this.Height - pbSinek.Height-20))
yukari = true;
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
// mouse un her hareketinde tetiklenen olaydır..
pbCursor.Left = e.X; // cismin soldan uzaklığına mouse un soldan uzaklığına eşitledik..
pbCursor.Top = e.Y; // cismin yukardan uzaklığını mouse un yukardan uzaklığına eşitledik..
}
}
}
|