public void OnKeyPress(object sender, KeyEventArgs e) { if (sender is KolobokView) { switch (e.KeyData) { case Keys.Up: case Keys.W: { ((KolobokView)sender).IdentifyMovementDirection((int)Direction.UP); break; } case Keys.Down: case Keys.S: { ((KolobokView)sender).IdentifyMovementDirection((int)Direction.DOWN); break; } case Keys.Left: case Keys.A: { ((KolobokView)sender).IdentifyMovementDirection((int)Direction.LEFT); break; } case Keys.Right: case Keys.D: { ((KolobokView)sender).IdentifyMovementDirection((int)Direction.RIGHT); break; } case Keys.F: { Shooting?.Invoke(this); break; } default: break; } } }
//Старт игры public void StartGame() { ListParty = new List <ListUnit>(); ListParty.Add(new ListUnit(Color.Red, new Point(20, 20))); ListParty.Add(new ListUnit(Color.Blue, new Point(80, 80), 5, 5)); //ListParty.Add(new ListUnit()); //ListParty.Add(new ListUnit(new Point(80, 80), 5, 5)); //ListParty.Add(new ListUnit(Color.Yellow, new Point(20, 80), 5)); //SW(); Sound.Music(); listShot = new ListShot(); action = new Action(); shooting = new Shooting(); }
//Старт игры public void StartGame() { ListParty = new List <ListUnit>(); //Цвет█Позиция█Танки█Машинки█ // #1 ListParty.Add(new ListUnit()); // #2 ListParty.Add(new ListUnit(Color.Red, new Point(30, 20))); // #3 ListParty.Add(new ListUnit(Color.Blue, new Point(70, 20), 2, 1)); // #4 ListParty.Add(new ListUnit(new Point(70, 80), 2, 1)); // #5 ListParty.Add(new ListUnit(Color.Yellow, new Point(30, 80), 1)); listShot = new ListShot(); actions = new Actions(); shooting = new Shooting(); //Sound.Music(); }
public void Move(List <FixedObject> Obstacles, List <TankView> Tanks) { if (rnd.NextDouble() < 0.3) { IdentifyMovementDirection(MainForm.rnd.Next(0, 4)); } if (rnd.NextDouble() < 0.15) { Shooting?.Invoke(this); } switch (MovementDirection) { case (int)Direction.DOWN: { PrevY = Y; PrevX = X; Y++; if (CollideWithFixedObjects(Obstacles) || CollidesWithTanks(Tanks)) { Y--; IdentifyMovementDirection((int)Direction.UP); } break; } case (int)Direction.LEFT: { PrevY = Y; PrevX = X; X--; if (CollideWithFixedObjects(Obstacles) || CollidesWithTanks(Tanks)) { X++; IdentifyMovementDirection((int)Direction.RIGHT); } break; } case (int)Direction.RIGHT: { PrevY = Y; PrevX = X; X++; if (CollideWithFixedObjects(Obstacles) || CollidesWithTanks(Tanks)) { X--; IdentifyMovementDirection((int)Direction.LEFT); } break; } case (int)Direction.UP: { PrevY = Y; PrevX = X; Y--; if (CollideWithFixedObjects(Obstacles) || CollidesWithTanks(Tanks)) { Y++; IdentifyMovementDirection((int)Direction.DOWN); } break; } default: break; } ChangeImage(); }