/
item.cs
176 lines (171 loc) · 7.1 KB
/
item.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace sosil3_homework
{
class item
{
public bool state;
public int type = 0;
Point location;
public PictureBox my_item;
public Task T_move;
public rabbit myrabbit;
public Label health_label;
public Label Star_label;
public Label Score_label;
public Label Level_label;
public Form1 Form1;
public PictureBox pic_rabbit;
public item(Form1 Form1, PictureBox parent, PictureBox Cloud,PictureBox pictureboxrabbit, rabbit rabbit, Label healtlabel, Label label_Star, Label label_score, Label label_level)
{
pic_rabbit = pictureboxrabbit;
Bitmap my_image = getMyImage(rabbit.score);
state = true;
location = Cloud.Location;
location.X = location.X + 35;
location.Y = location.Y + 50;
my_item = new PictureBox();
try
{
Form1.Invoke(new MethodInvoker(delegate ()
{
health_label = healtlabel;
Star_label = label_Star;
Score_label = label_score;
Level_label = label_level;
IntPtr x;
if (!my_item.IsHandleCreated)
x = my_item.Handle;
my_item.Parent = parent;
my_item.BackColor = Color.Transparent;
my_item.Name = "item";
my_item.Size = new Size(30, 30);
my_item.Location = location;
my_item.Image = my_image;
my_item.Visible = true;
my_item.SizeMode = PictureBoxSizeMode.StretchImage;
}));
this.myrabbit = rabbit;
this.Form1 = Form1;
T_move = new Task(new Action(move));
T_move.Start();
}
catch (Exception e) { }
}
public Rectangle getMyBound()
{
return my_item.Bounds;
}
private Bitmap getMyImage(int score)
{
Random r = new Random((int)DateTime.Now.Ticks);
int i = r.Next(0, 13 + (score / 300));
switch (i)
{
case 0:
return sosil3_homework.Properties.Resources.f_carrot;
case 1:
return sosil3_homework.Properties.Resources.f_apple;
case 2:
type = 2;
return sosil3_homework.Properties.Resources.f_bomb;
case 3:
return sosil3_homework.Properties.Resources.f_cherry;
case 4:
return sosil3_homework.Properties.Resources.f_grapes;
case 5:
type = 1;
return sosil3_homework.Properties.Resources.f_heart;
case 6:
return sosil3_homework.Properties.Resources.f_kiwi;
case 7:
return sosil3_homework.Properties.Resources.f_orange;
case 8:
return sosil3_homework.Properties.Resources.f_pear;
case 9:
return sosil3_homework.Properties.Resources.f_pineapple;
case 10:
type = 3;
return sosil3_homework.Properties.Resources.f_star;
case 11:
return sosil3_homework.Properties.Resources.f_strawberry;
case 12:
return sosil3_homework.Properties.Resources.f_watermelon;
}
type = 2;
return sosil3_homework.Properties.Resources.f_bomb;
}
public void move()
{
int a = 1;
try
{
while (state == true)
{
my_item.Invoke(new MethodInvoker(delegate ()
{
if (location.Y > 375)
{
if (type == 0 && myrabbit.over == false)
{
myrabbit.health--;
if (myrabbit.health < 1)
{
Application.Restart();
}
health_label.Text = "Health : " + myrabbit.health.ToString();
}
state = false;
if (my_item.IsDisposed == false)
{
my_item.Dispose();
}
}
else
{
for (int i = 0; i < 2 + a / 5; i++)
{
location.Y += 3;
my_item.SetBounds(location.X, location.Y, my_item.Width, my_item.Height);
}
if (pic_rabbit.Bounds.IntersectsWith(getMyBound()))
{
if (type == 1) myrabbit.health++;
else if (type == 2 && myrabbit.over == false)
{
myrabbit.health--;
if (myrabbit.health < 1)
{
Application.Restart();
}
}
else if (type == 3) myrabbit.star++;
else myrabbit.score = myrabbit.score + 10;
health_label.Text = "Health : " + myrabbit.health.ToString();
Score_label.Text = "Score : " + myrabbit.score.ToString();
Star_label.Text = "Star : " + myrabbit.star.ToString();
Level_label.Text = "Level : " + (myrabbit.score/100 + 1).ToString();
state = false;
my_item.Dispose();
}
}
a++;
}));
/*if (a > 20) a = a - 10;
else a = 10;*/
T_move.Wait(30);
}
}
catch (InvalidOperationException e)
{ }
}
}
}