90 lines
2.9 KiB
C#
Raw Normal View History

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;
using WarmlyLocomotive.Drawnings;
namespace WarmlyLocomotive
{
2024-02-09 00:09:15 +03:00
public partial class FormWarmlyLocomotive : Form
{
2024-02-17 14:03:31 +03:00
private DrawningWarmlyLocomotive? _drawningWarmlyLocomotive;
2024-02-09 00:09:15 +03:00
public FormWarmlyLocomotive()
{
InitializeComponent();
}
2024-02-17 14:03:31 +03:00
private void Draw()
{
if (_drawningWarmlyLocomotive == null)
{
return;
}
Bitmap bmp = new(pictureBoxWarmlyLocomotive.Width,
pictureBoxWarmlyLocomotive.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningWarmlyLocomotive.DrawTransport(gr);
pictureBoxWarmlyLocomotive.Image = bmp;
}
private void createButton_Click(object sender, EventArgs e){
Random random = new();
_drawningWarmlyLocomotive = new DrawningWarmlyLocomotive();
_drawningWarmlyLocomotive.Init(
random.Next(100, 300),
random.Next(1000,3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)));
2024-02-17 14:35:37 +03:00
_drawningWarmlyLocomotive.SetPictureSize(
pictureBoxWarmlyLocomotive.Width,
pictureBoxWarmlyLocomotive.Height);
_drawningWarmlyLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
2024-02-17 14:03:31 +03:00
Draw();
}
private void moveButton_Click(object sender, EventArgs e)
{
if (_drawningWarmlyLocomotive == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
bool result = false;
switch (name)
{
case "buttonUp":
result =
_drawningWarmlyLocomotive.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
result =
_drawningWarmlyLocomotive.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
result =
_drawningWarmlyLocomotive.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
result =
_drawningWarmlyLocomotive.MoveTransport(DirectionType.Right);
break;
}
if (result)
{
Draw();
}
}
}
}