88 lines
2.7 KiB
C#
88 lines
2.7 KiB
C#
|
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;
|
|||
|
|
|||
|
namespace CruiserMech
|
|||
|
{
|
|||
|
public partial class DrawingCanvas : Form
|
|||
|
{
|
|||
|
|
|||
|
private DrawingCruiser? _DrCruiser;
|
|||
|
|
|||
|
public DrawingCanvas()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
}
|
|||
|
|
|||
|
//private DrawingCanvas_Load(object sender, EventArgs e);
|
|||
|
|
|||
|
private void Draw()
|
|||
|
{
|
|||
|
if (_DrCruiser == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
Bitmap bmp = new(pictureBox1.Width, pictureBox1.Height);
|
|||
|
Graphics gr = Graphics.FromImage(bmp);
|
|||
|
_DrCruiser.DrawTransport(gr);
|
|||
|
pictureBox1.Image = bmp;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void buttonCr_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
Random rn = new();
|
|||
|
|
|||
|
Class_CruiserEntity CruiserEntity = new Class_CruiserEntity();
|
|||
|
CruiserEntity.Init(rn.Next(100, 300), rn.Next(1000, 3000),
|
|||
|
Color.FromArgb(rn.Next(0, 256), rn.Next(0, 256), rn.Next(0, 256)),
|
|||
|
Color.FromArgb(rn.Next(0, 256), rn.Next(0, 256), rn.Next(0, 256)),
|
|||
|
Convert.ToBoolean(rn.Next(0, 2)), Convert.ToBoolean(rn.Next(0, 2)),
|
|||
|
Convert.ToBoolean(rn.Next(0, 2)), rn.Next(1, 4), rn.Next(5, 10), rn.Next(1, 3));
|
|||
|
|
|||
|
_DrCruiser = new DrawingCruiser();
|
|||
|
_DrCruiser.Init(CruiserEntity);
|
|||
|
// 32, 44
|
|||
|
_DrCruiser.SetPicSize(pictureBox1.Width, pictureBox1.Height);
|
|||
|
_DrCruiser.SetPos(rn.Next(pictureBox1.Width - 600, pictureBox1.Width - _DrCruiser._CruiserMaxW), rn.Next(0, 100));
|
|||
|
|
|||
|
Draw();
|
|||
|
}
|
|||
|
|
|||
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (_DrCruiser == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|||
|
bool result = false;
|
|||
|
switch (name)
|
|||
|
{
|
|||
|
case "buttonUp":
|
|||
|
result = _DrCruiser.MoveTransport(DirectionType.Up);
|
|||
|
break;
|
|||
|
case "buttonDown":
|
|||
|
result = _DrCruiser.MoveTransport(DirectionType.Down);
|
|||
|
break;
|
|||
|
case "buttonLeft":
|
|||
|
result = _DrCruiser.MoveTransport(DirectionType.Left);
|
|||
|
break;
|
|||
|
case "buttonRight":
|
|||
|
result = _DrCruiser.MoveTransport(DirectionType.Right);
|
|||
|
break;
|
|||
|
}
|
|||
|
if (result)
|
|||
|
{
|
|||
|
Draw();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|