namespace Ballistika
{
public partial class Form1 : Form
{
int x_fly = 0, y_fly = 0;
int x_st = 0, y_st = 0, def1=0,def2=0;
int c_m = 0, fl_im=1, gamer=0, angle =0, n_sh=0, mas_kern=0, c1=0,c2=0;
double V0 = 165;
Random rnd = new Random();
string[] type_kern ={"бронебойный", "легкий", "коммулятивный", "разрывной", "реактивный", "болванка"};
int[] stac1 = new int [8];
int[] stac2 = new int[8];
int[,] stat_kern = { {3, 25}, {2, 20}, {6,25}, {3, 38}, {6, 32}, {1, 20}};
public Form1()
{
InitializeComponent();
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
label1.Parent = pictureBox1;
label1.BackColor = Color.Transparent;
label2.Parent = pictureBox1;
label2.BackColor = Color.Transparent;
label3.Parent = pictureBox1;
label3.BackColor = Color.Transparent;
label4.Parent = pictureBox4;
label4.BackColor = Color.Transparent;
label5.Parent = pictureBox4;
label5.BackColor = Color.Transparent;
label6.Parent = pictureBox4;
label6.BackColor = Color.Transparent;
for (int i = 0; i < 8; i++)
{
int id = rnd.Next(5);
StacG1.Items.Add(type_kern[id]);
stac1[i] = id;
id = rnd.Next(5);
StacG2.Items.Add(type_kern[id]);
stac2[i] = id;
}
gamer = 1;
c1 = 8;
c2 = 8;
}
public int GetIndexKernel(string n)
{
return Array.IndexOf(type_kern, n);
}
public int Y_change(int Xf, int angle, double Vf)
{
return (int)Math.Floor(Math.Tan((Math.PI * angle) / 180) * Xf - (9.8 / (2 * Vf * Vf * Math.Cos((Math.PI * angle) / 180) * Math.Cos((Math.PI * angle) / 180))) * Xf * Xf);
}
public int GetLengthShot(double Vf, int angle)
{
return (int) Math.Floor(V0*V0*Math.Sin(2*(Math.PI*angle)/180)/9.8);
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (c1 == 0)
{
MessageBox.Show("Заряды закончились");
}
if (def1!=0)
{
StacG1.Items.Remove(StacG1.SelectedItem);
StacG1.SelectedIndex = -1;
x_st = 110;
y_st = 455;
x_fly = 0;
angle = (int)UgG1.Value;
V0 = (double)FG1.Value * 5 / mas_kern;
gamer = 2;
n_sh = 1;
pictureBox3.Load(@"br.png");
button1.Visible = false;
button2.Visible = true;
//y_fly = 455;
fl_im = 1;
c_m = 0;
lb_bullet.Location = new Point(x_fly + x_st, y_st);
Protocol.AppendText("Выстрел- Танк1" + Environment.NewLine);
Protocol.AppendText("Дальность: " + GetLengthShot(V0, angle).ToString() + Environment.NewLine);
c1--;
lb_bullet.Visible = true;
tmr_fly.Enabled = true;
}
}
private void tmr_fly_Tick(object sender, EventArgs e)
{
y_fly = -(Y_change(x_fly, angle, V0));
if ((y_fly + y_st > 428) && (n_sh * x_fly + x_st >= 385) && (n_sh * x_fly + x_st <= 415))
{
tmr_fly.Enabled = false;
pictureBox3.Load(@"brf.png");
//MessageBox.Show("Boobooch!!!");
}
if ((n_sh * x_fly + x_st > 800) || (n_sh * x_fly + x_st < 0))
{
tmr_fly.Enabled = false;
//MessageBox.Show("Boobooch!!!");
}
if (y_fly + y_st > 510)
{
if ((n_sh*x_fly + x_st)>10 && (n_sh*x_fly + x_st)<115)
{
if (HPL.Value <= def2)
{
HPL.Value = 0;
Protocol.AppendText("Победил Танк2!!!" + Environment.NewLine);
}
else
HPL.Value -= def2;
targPl.Enabled = true;
}
if ((n_sh*x_fly + x_st)>665 && (n_sh*x_fly + x_st)<770)
{
if (HPR.Value <= def1)
{
HPR.Value = 0;
Protocol.AppendText("Победил Танк1!!!" + Environment.NewLine);
}
else
HPR.Value -= def1;
targPl.Enabled =true;
}
def1 = 0;
def2 = 0;
tmr_fly.Enabled = false;
}
lb_bullet.Location = new Point(n_sh*x_fly + x_st, y_fly + y_st);
x_fly+=5;
}
private void targPl_Tick(object sender, EventArgs e)
{
tmr_fly.Enabled = false;
if (gamer == 2)
{
if (fl_im == 1)
{
tankG2.Load(@"targR.png");
fl_im = 2;
}
else
{
tankG2.Load(@"TR.png");
fl_im = 1;
}
}
if (gamer == 1)
{
if (fl_im == 1)
{
tankG1.Load(@"targL.png");
fl_im = 2;
}
else
{
tankG1.Load(@"TL.png");
fl_im = 1;
}
}
c_m++;
if (c_m == 8)
{ targPl.Enabled = false; }
}
private void button2_Click(object sender, EventArgs e)
{
if (c2 == 0)
{
MessageBox.Show("Заряды закончились");
}
if (def2!= 0)
{
StacG2.Items.Remove(StacG2.SelectedItem);
StacG2.SelectedIndex = -1;
angle = (int)UgG2.Value;
V0 = (double)FG2.Value * 5 / mas_kern;
x_fly = 0;
x_st = 660;
y_st = 455;
n_sh = -1;
gamer = 1;
Protocol.AppendText("Выстрел- Танк2" + Environment.NewLine);
Protocol.AppendText("Дальность: " + GetLengthShot(V0, angle).ToString() + Environment.NewLine);
pictureBox3.Load(@"br.png");
button2.Visible = false;
button1.Visible = true;
//y_fly = 455;
fl_im = 1;
c_m = 0;
lb_bullet.Location = new Point(x_st, y_st);
c2--;
lb_bullet.Visible = true;
tmr_fly.Enabled = true;
}
}
private void label5_Click(object sender, EventArgs e)
{
}
private void StacG1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void StacG2_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void StacG1_SelectionChangeCommitted(object sender, EventArgs e)
{
if (StacG2.SelectedItem != "")
{
int i = GetIndexKernel(StacG1.SelectedItem.ToString());
def1 = stat_kern[i, 0];
mas_kern = stat_kern[i, 1];
Protocol.AppendText("Снаряд: " + StacG1.SelectedItem + " def=" + def1.ToString() + " mas=" + mas_kern.ToString() + Environment.NewLine);
}
}
private void StacG2_SelectionChangeCommitted(object sender, EventArgs e)
{
if (StacG2.SelectedItem != "")
{
int i = GetIndexKernel(StacG2.SelectedItem.ToString());
def2 = stat_kern[i, 0];
mas_kern = stat_kern[i, 1];
Protocol.AppendText("Снаряд: " + StacG2.SelectedItem + " def=" + def2.ToString() + " mas=" + mas_kern.ToString() + Environment.NewLine);
}
}
private void выходToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void новаяToolStripMenuItem1_Click(object sender, EventArgs e)
{
StacG1.Items.Clear();
StacG2.Items.Clear();
Protocol.Clear();
HPR.Value = 10;
HPL.Value = 10;
button1.Visible = true;
button2.Visible = false;
for (int i = 0; i < 8; i++)
{
int id = rnd.Next(5);
StacG1.Items.Add(type_kern[id]);
stac1[i] = id;
id = rnd.Next(5);
StacG2.Items.Add(type_kern[id]);
stac2[i] = id;
}
gamer = 1;
c1 = 8;
c2 = 8;
}
}
}```