-
Notifications
You must be signed in to change notification settings - Fork 0
/
Balloon.cs
68 lines (59 loc) · 1.42 KB
/
Balloon.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
using System;
using System.Drawing;
namespace Typo_PoP
{
public class Balloon
{
private Image image;
private Bitmap popImage;
private string word;
private Rectangle frame = new Rectangle ( 0, 0, 32, 48 );
private static Random random = new Random ( DateTime.Now.Second );
public Balloon ( int xPos, int yPos, string word )
{
int randomInt = random.Next ( 5 ) + 1;
image = Image.FromFile ( "Images/Balloon" +
randomInt + ".gif" );
popImage = ( Bitmap ) Image.FromFile ( "Images//Pop" +
randomInt + ".gif" );
this.word = word.ToUpper();
setLocation ( xPos, yPos );
}
public void draw ( Graphics graphics )
{
graphics.DrawImage ( image, frame );
SolidBrush brush = new SolidBrush ( Color.WhiteSmoke );
Font font = new Font ( new FontFamily ( "Arial" ),
9, FontStyle.Bold );
double length = word.Length / 18.0;
length *= 116;
int xOffset = ( int ) ( ( 0.539 * ( length ) ) - 17.5 );
graphics.DrawString ( word, font, brush,
frame.X - xOffset, frame.Y + 48 );
}
public void pop ( int popFrame )
{
image = popImage.Clone ( new Rectangle ( ( popFrame * 99 ) + 1, 1, 98, 148 ),
System.Drawing.Imaging.PixelFormat.DontCare );
}
public Rectangle Frame
{
get
{
return frame;
}
}
public void setLocation ( int xPos, int yPos )
{
frame.X = xPos;
frame.Y = yPos;
}
public string Word
{
get
{
return word;
}
}
}
}