Escolar Documentos
Profissional Documentos
Cultura Documentos
{
if (FileName == null)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Balloons doc file (*.bal)|*.bal";
saveFileDialog.Title = "Save balloons doc";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
FileName = saveFileDialog.FileName;
}
}
if (FileName != null)
{
using (FileStream fileStream = new FileStream(FileName, FileMode.Create))
{
IFormatter formatter = new BinaryFormatter();
formatter.Serialize(fileStream, balloonDoc);
}
}
}
private void openFile()
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Balloons doc file (*.bal)|*.bal";
openFileDialog.Title = "Open balloons file";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
FileName = openFileDialog.FileName;
try
{
using (FileStream fileStream = new FileStream(FileName, FileMode.Open))
{
IFormatter formater = new BinaryFormatter();
balloonDoc = (BalloonDoc)formater.Deserialize(fileStream);
}
}
catch (Exception ex)
{
MessageBox.Show("Could not read file: " + FileName);
FileName = null;
return;
}
Invalidate(true);
}
}
// kod za dvizenje na topce
public void Move(int left, int top, int width, int height)
{
float nextX = center.X + velocityX;
float nextY = center.Y + velocityY;
if (nextX - 20 <= left || nextX + 20 >= width + left)
{
velocityX = -velocityX;
}
if (nextY - 20 <= top || nextY + 20 >= height + top)
{
velocityY = -velocityY;
}
center = new Point((int)(center.X + velocityX), (int)(center.Y + velocityY));
}
// color dialog
polygonDoc.Draw(e.Graphics);
Pen squarePen = new Pen(Color.Black, 2);
squarePen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
Pen linePen = new Pen(Color.Black, 1);
linePen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
if (drawSquare)
{
e.Graphics.DrawRectangle(squarePen, startPoint.X - 5, startPoint.Y - 5, 10, 10);
}
namespace BlowingBalloons
[Serializable]
public class Balloon
{
public Point Center { get; set; }
public int Radius { get; set; }
public Color Color { get; set; }
public bool Flag { get; set; }
public Balloon(Point center, int radius)
{
Center = center;
Radius = radius;
Random r = new Random();
Color = Color.FromArgb(r.Next(255), r.Next(255), r.Next(255));
Flag = false;
}
namespace BlowingBalloons
{
[Serializable]
public class BalloonsDoc
{
public List<Balloon> Balloons { get; set; }
public BalloonsDoc()
{
Balloons = new List<Balloon>();
}
public void AddBalloon(Point point)
{
Random r = new Random();
Balloon balloon = new Balloon(point, r.Next(20, 30));
Balloons.Add(balloon);
}
public void BlowBalloons()