public bool BulletCollision(Bullet bullet) { var position = GetPosition(bullet.GetPosition().Item1, bullet.GetPosition().Item2); if (!position.IsNull()) { _statistic.Score().SetScore(); return true; } for (var i = 0; i < ETankCount(); i++) { if (ETanks[i].GetPosition().Item1 == bullet.GetPosition().Item1 && ETanks[i].GetPosition().Item2 == bullet.GetPosition().Item2) { if(ETanks.Last().GetHealth() != 0 && !ETanks[i].Equals(ETanks.Last())) ETanks.RemoveAt(i); else ETanks.Last().ChangeHealth(-1); if (ETanks.Last().GetHealth() == 0) { Died = true; ETanks.RemoveAt(ETankCount()-1); } _statistic.Score().SetScore(); return true; } } return false; }
public bool BulletCollision(Bullet bullet) { if (_map.Bricks.Contains(new Map.Position(bullet.GetPosition().Item1, bullet.GetPosition().Item2, "W"))) { _map.Bricks.Remove(new Map.Position(bullet.GetPosition().Item1, bullet.GetPosition().Item2, "W")); statistic.Score().SetScore(); return true; } if (_map.Bricks.Contains(new Map.Position(bullet.GetPosition().Item1, bullet.GetPosition().Item2, "%"))) { _map.Bricks.Remove(new Map.Position(bullet.GetPosition().Item1, bullet.GetPosition().Item2, "%")); statistic.Score().SetScore(); return true; } if (ETanks.Contains(new EnemyTankOne(bullet.GetPosition().Item1, bullet.GetPosition().Item2))) { ETanks.Remove(new EnemyTankOne(bullet.GetPosition().Item1, bullet.GetPosition().Item2)); return true; } if (ETanks.Contains(new EnemyTankTwo(bullet.GetPosition().Item1, bullet.GetPosition().Item2))) { ETanks.Remove(new EnemyTankTwo(bullet.GetPosition().Item1, bullet.GetPosition().Item2)); return true; } if (ETanks.Contains(new Player(bullet.GetPosition().Item1, bullet.GetPosition().Item2))) { ETanks.Last().ChangeHealth(-1); if (ETanks.Last().GetHealth() == 0) ETanks.Remove(new Player(bullet.GetPosition().Item1, bullet.GetPosition().Item2)); return true; } for (var i = 0; i < ETankCount(); i++) { if (ETanks[i].GetPosition().Item1 == bullet.GetPosition().Item1 && ETanks[i].GetPosition().Item2 == bullet.GetPosition().Item2) { ETanks.RemoveAt(i); statistic.Score().SetScore(); return true; } } return false; }
public void MoveEnemy(Stopwatch sw) { for (var i = 0; i < collision.ETankCount() - 1; i++) { //pataisyt remote.MoveRandom(collision.ETanks[i]); if (collision.CanMove(collision.ETanks[i].GetPosition().Item1, collision.ETanks[i].GetPosition().Item2)) { view.RemoveObject(collision.ETanks[i].GetPosition().Item1, collision.ETanks[i].GetPosition().Item2); collision.ETanks[i].Move(); Console.SetCursorPosition(collision.ETanks[i].GetPosition().Item1, collision.ETanks[i].GetPosition().Item2); Console.Write(collision.ETanks[i].GetSymbol()); if (sw.ElapsedMilliseconds > 3500) { var bullet = new Bullet( collision.ETanks[i].GetPosition().Item1, collision.ETanks[i].GetPosition().Item2, collision.ETanks[i].GetDirection().Item1, collision.ETanks[i].GetDirection().Item2 ); collision.Bullets.Add(bullet); sw.Restart(); } } Thread.Sleep(70); } }
public void MovePlayer(ConsoleKeyInfo key) { var keyInfo = key; switch (keyInfo.Key) { case ConsoleKey.UpArrow: _remote.MoveUp(_collision.ETanks.Last()); break; case ConsoleKey.RightArrow: _remote.MoveRight(_collision.ETanks.Last()); break; case ConsoleKey.DownArrow: _remote.MoveDown(_collision.ETanks.Last()); break; case ConsoleKey.LeftArrow: _remote.MoveLeft(_collision.ETanks.Last()); break; case ConsoleKey.R: SavingMode(); ResetGame(); SinglePlayer(); break; case ConsoleKey.Spacebar: var bullet = new Bullet( _collision.ETanks.Last().GetPosition().Item1 + 2*_collision.ETanks.Last().GetDirection().Item1, _collision.ETanks.Last().GetPosition().Item2 + 2* _collision.ETanks.Last().GetDirection().Item2, _collision.ETanks.Last().GetDirection().Item1, _collision.ETanks.Last().GetDirection().Item2 ); _collision.Bullets.Add(bullet); break; } if (_collision.CanMove(_collision.ETanks.Last().GetPosition().Item1 + _collision.ETanks.Last().GetDirection().Item1, _collision.ETanks.Last().GetPosition().Item2 + +_collision.ETanks.Last().GetDirection().Item2, 1)) { _view.RemoveObject(_collision.ETanks.Last().GetPosition().Item1, _collision.ETanks.Last().GetPosition().Item2); _collision.ETanks.Last().Move(); Console.SetCursorPosition(_collision.ETanks.Last().GetPosition().Item1, _collision.ETanks.Last().GetPosition().Item2); Console.Write(_collision.ETanks.Last().GetSymbol()); } }
public void MovePlayer() { var shoot = false; if (Console.KeyAvailable) { var keyInfo = Console.ReadKey(); switch (keyInfo.Key) { case ConsoleKey.UpArrow: remote.MoveUp(collision.ETanks.Last()); break; case ConsoleKey.RightArrow: remote.MoveRight(collision.ETanks.Last()); break; case ConsoleKey.DownArrow: remote.MoveDown(collision.ETanks.Last()); break; case ConsoleKey.LeftArrow: remote.MoveLeft(collision.ETanks.Last()); break; case ConsoleKey.Q: statistic.Score().Run("save"); break; case ConsoleKey.R: ResetGame(); SinglePlayer(); break; case ConsoleKey.Spacebar: var bullet = new Bullet( collision.ETanks.Last().GetPosition().Item1 + collision.ETanks.Last().GetDirection().Item1, collision.ETanks.Last().GetPosition().Item2 + collision.ETanks.Last().GetDirection().Item2, collision.ETanks.Last().GetDirection().Item1, collision.ETanks.Last().GetDirection().Item2 ); collision.Bullets.Add(bullet); shoot = true; break; } if (!shoot && collision.CanMove(collision.ETanks.Last().GetPosition().Item1, collision.ETanks.Last().GetPosition().Item2)) { view.RemoveObject(collision.ETanks.Last().GetPosition().Item1, collision.ETanks.Last().GetPosition().Item2); collision.ETanks.Last().Move(); Console.SetCursorPosition(collision.ETanks.Last().GetPosition().Item1, collision.ETanks.Last().GetPosition().Item2); Console.Write(collision.ETanks.Last().GetSymbol()); } shoot = false; // cia tam, kad saudant tankiukas nejudetu } }
public bool BulletPositionCheck(Bullet bullet) { if (bullet.GetPosition().Item1 >= ScreenSizeX - 2 || bullet.GetPosition().Item2 >= ScreenSizeY - 2 || bullet.GetPosition().Item2 < 2 || bullet.GetPosition().Item1 < 2) return true; return false; }