public void CreateShotTank(MovingObject sender) { switch (sender.MovementDirection) { case (int)Direction.DOWN: { ShotsTanks.Add(new ShotView(sender.X, sender.Y + 1, sender.MovementDirection, sender)); break; } case (int)Direction.LEFT: { ShotsTanks.Add(new ShotView(sender.X - 1, sender.Y, sender.MovementDirection, sender)); break; } case (int)Direction.RIGHT: { ShotsTanks.Add(new ShotView(sender.X + 1, sender.Y, sender.MovementDirection, sender)); break; } case (int)Direction.UP: { ShotsTanks.Add(new ShotView(sender.X, sender.Y - 1, sender.MovementDirection, sender)); break; } default: break; } var index = ShotsTanks.Last().InteractWithFixedObjects(Obstacles); if (index > 0) { mapGraphics.FillRectangle(Brushes.Black, Obstacles[index].X * MainForm.sizeCell, Obstacles[index].Y * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell); Obstacles.RemoveAt(index); ShotsTanks.RemoveAt(ShotsTanks.Count - 1); } }
public void CreateShotTank(MovebleObj sender) { switch (sender.DirectionTo) { case (int)Direction.Down: { ShotsTanks.Add(new Shot(sender.X, sender.Y + 1, sender.DirectionTo, sender)); break; } case (int)Direction.Left: { ShotsTanks.Add(new Shot(sender.X - 1, sender.Y, sender.DirectionTo, sender)); break; } case (int)Direction.Right: { ShotsTanks.Add(new Shot(sender.X + 1, sender.Y, sender.DirectionTo, sender)); break; } case (int)Direction.Up: { ShotsTanks.Add(new Shot(sender.X, sender.Y - 1, sender.DirectionTo, sender)); break; } default: break; } if (ShotsTanks.Last().CollidesWithWalls(Walls)) { ShotsTanks.RemoveAt(ShotsTanks.Count - 1); } }
public void StepOfShots() { while (DeltaShots != MainForm.sizeCell + 5) { for (int i = 0; i < ShotsKolobok.Count; i++) { Move(ShotsKolobok[i], DeltaShots); } for (int i = 0; i < ShotsTanks.Count; i++) { Move(ShotsTanks[i], DeltaShots); } for (int i = 0; i < Apples.Count; i++) { mapGraphics.DrawImage(Apples[i].Img, Apples[i].X * MainForm.sizeCell, Apples[i].Y * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell); } for (int i = 0; i < Obstacles.Count; i++) { if (Obstacles[i].Ability == 1) { mapGraphics.DrawImage(Obstacles[i].Img, Obstacles[i].X * MainForm.sizeCell, Obstacles[i].Y * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell); } } DeltaShots += 5; map.Image = backgroundMap; return; } DeltaShots = 5; for (int j = 0; j < ShotsTanks.Count; j++) { if (kolobok.Collide(ShotsTanks[j])) { gameOver = true; break; } } for (int i = 0; i < Tanks.Count; i++) { for (int j = 0; j < ShotsKolobok.Count; j++) { if (Tanks[i].Collide(ShotsKolobok[j])) { mapGraphics.FillRectangle(Brushes.Black, Tanks[i].PrevX * MainForm.sizeCell, Tanks[i].PrevY * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell); mapGraphics.FillRectangle(Brushes.Black, ShotsKolobok[j].X * MainForm.sizeCell, ShotsKolobok[j].Y * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell); mapGraphics.FillRectangle(Brushes.Black, Tanks[i].X * MainForm.sizeCell, Tanks[i].Y * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell); mapGraphics.FillRectangle(Brushes.Black, ShotsKolobok[j].PrevX * MainForm.sizeCell, ShotsKolobok[j].PrevY * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell); Tanks.RemoveAt(i); ShotsKolobok.RemoveAt(j); i--; j--; break; } } } for (int i = 0; i < ShotsKolobok.Count; i++) { ShotsKolobok[i].Move(); var index = ShotsKolobok[i].InteractWithFixedObjects(Obstacles); if (index > 0) { mapGraphics.FillRectangle(Brushes.Black, ShotsKolobok[i].PrevX * MainForm.sizeCell, ShotsKolobok[i].PrevY * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell); mapGraphics.FillRectangle(Brushes.Black, Obstacles[index].X * MainForm.sizeCell, Obstacles[index].Y * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell); Obstacles.RemoveAt(index); ShotsKolobok.RemoveAt(i); } } for (int i = 0; i < ShotsTanks.Count; i++) { ShotsTanks[i].Move(); /*if (ShotsTanks[i].CollideWithFixedObjects(Obstacles)) * { * mapGraphics.FillRectangle(Brushes.Black, ShotsTanks[i].PrevX * MainForm.sizeCell, ShotsTanks[i].PrevY * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell); * ShotsTanks.RemoveAt(i); * i--; * continue; * }*/ var index = ShotsTanks[i].InteractWithFixedObjects(Obstacles); if (index > 0) { mapGraphics.FillRectangle(Brushes.Black, ShotsTanks[i].PrevX * MainForm.sizeCell, ShotsTanks[i].PrevY * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell); mapGraphics.FillRectangle(Brushes.Black, Obstacles[index].X * MainForm.sizeCell, Obstacles[index].Y * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell); Obstacles.RemoveAt(index); ShotsTanks.RemoveAt(i); i--; continue; } if (kolobok.Collide(ShotsTanks[i])) { gameOver = true; break; } } for (int i = 0; i < Tanks.Count; i++) { for (int j = 0; j < ShotsKolobok.Count; j++) { if (Tanks[i].Collide(ShotsKolobok[j])) { mapGraphics.FillRectangle(Brushes.Black, Tanks[i].PrevX * MainForm.sizeCell, Tanks[i].PrevY * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell); mapGraphics.FillRectangle(Brushes.Black, ShotsKolobok[j].X * MainForm.sizeCell, ShotsKolobok[j].Y * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell); mapGraphics.FillRectangle(Brushes.Black, Tanks[i].X * MainForm.sizeCell, Tanks[i].Y * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell); mapGraphics.FillRectangle(Brushes.Black, ShotsKolobok[j].PrevX * MainForm.sizeCell, ShotsKolobok[j].PrevY * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell); Tanks.RemoveAt(i); ShotsKolobok.RemoveAt(j); i--; j--; break; } } } for (int i = 0; i < Apples.Count; i++) { if (Apples[i].Collide(kolobok)) { Apples.RemoveAt(i); Score++; break; } mapGraphics.DrawImage(Apples[i].Img, Apples[i].X * MainForm.sizeCell, Apples[i].Y * MainForm.sizeCell, MainForm.sizeCell, MainForm.sizeCell); } RespOfApples(); DeltaShots += 5; map.Image = backgroundMap; }
public void StepOfShots() { while (DeltaShots != TanksForm.sizeCell + 5) { for (int i = 0; i < ShotsKolobok.Count; i++) { Move(ShotsKolobok[i], DeltaShots); } for (int i = 0; i < ShotsTanks.Count; i++) { Move(ShotsTanks[i], DeltaShots); } for (int i = 0; i < Apples.Count; i++) { mapGraphics.DrawImage(Apples[i].Img, Apples[i].X * TanksForm.sizeCell, Apples[i].Y * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell); } DeltaShots += 5; map.Image = backgroundMap; return; } DeltaShots = 5; for (int j = 0; j < ShotsTanks.Count; j++) { if (kolobok.CollidesWith(ShotsTanks[j])) { gameOver = true; break; } } for (int i = 0; i < Tanks.Count; i++) { for (int j = 0; j < ShotsKolobok.Count; j++) { if (Tanks[i].CollidesWith(ShotsKolobok[j])) { mapGraphics.FillRectangle(Brushes.Black, Tanks[i].OldX * TanksForm.sizeCell, Tanks[i].OldY * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell); mapGraphics.FillRectangle(Brushes.Black, ShotsKolobok[j].X * TanksForm.sizeCell, ShotsKolobok[j].Y * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell); mapGraphics.FillRectangle(Brushes.Black, Tanks[i].X * TanksForm.sizeCell, Tanks[i].Y * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell); mapGraphics.FillRectangle(Brushes.Black, ShotsKolobok[j].OldX * TanksForm.sizeCell, ShotsKolobok[j].OldY * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell); Tanks.RemoveAt(i); ShotsKolobok.RemoveAt(j); i--; j--; break; } } } for (int i = 0; i < ShotsKolobok.Count; i++) { ShotsKolobok[i].Move(); if (ShotsKolobok[i].CollidesWithWalls(Walls)) { mapGraphics.FillRectangle(Brushes.Black, ShotsKolobok[i].OldX * TanksForm.sizeCell, ShotsKolobok[i].OldY * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell); ShotsKolobok.RemoveAt(i); i--; } } for (int i = 0; i < ShotsTanks.Count; i++) { ShotsTanks[i].Move(); if (ShotsTanks[i].CollidesWithWalls(Walls)) { mapGraphics.FillRectangle(Brushes.Black, ShotsTanks[i].OldX * TanksForm.sizeCell, ShotsTanks[i].OldY * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell); ShotsTanks.RemoveAt(i); i--; continue; } if (kolobok.CollidesWith(ShotsTanks[i])) { gameOver = true; break; } } for (int i = 0; i < Tanks.Count; i++) { for (int j = 0; j < ShotsKolobok.Count; j++) { if (Tanks[i].CollidesWith(ShotsKolobok[j])) { mapGraphics.FillRectangle(Brushes.Black, Tanks[i].OldX * TanksForm.sizeCell, Tanks[i].OldY * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell); mapGraphics.FillRectangle(Brushes.Black, ShotsKolobok[j].X * TanksForm.sizeCell, ShotsKolobok[j].Y * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell); mapGraphics.FillRectangle(Brushes.Black, Tanks[i].X * TanksForm.sizeCell, Tanks[i].Y * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell); mapGraphics.FillRectangle(Brushes.Black, ShotsKolobok[j].OldX * TanksForm.sizeCell, ShotsKolobok[j].OldY * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell); Tanks.RemoveAt(i); ShotsKolobok.RemoveAt(j); i--; j--; break; } } } for (int i = 0; i < Apples.Count; i++) { if (Apples[i].CollidesWith(kolobok)) { Apples.RemoveAt(i); Score++; break; } mapGraphics.DrawImage(Apples[i].Img, Apples[i].X * TanksForm.sizeCell, Apples[i].Y * TanksForm.sizeCell, TanksForm.sizeCell, TanksForm.sizeCell); } SpawnApples(); DeltaShots += 5; map.Image = backgroundMap; }