Hibajavítás: Most már nem lehet többször ugyanoda lőni

This commit is contained in:
Norbi Peti 2016-05-24 22:06:28 +02:00
parent 23b79cd9e0
commit c4ee6e3bd5
4 changed files with 34 additions and 17 deletions

View file

@ -33,18 +33,26 @@ namespace Torpedo
x = rand.Next(Game.GameSize.Width);
y = rand.Next(Game.GameSize.Height);
} while (Player.Player2.Shots.Any(p => p.X == x && p.Y == y));
Ship ship = Ship.GetShipAtField(Player.CurrentEnemy, x, y);
if (ship == null)
{
Player.CurrentOwn.Shots.Add(new Point(x, y));
}
else
Ship ship = Ship.GetShipAtField(Player.CurrentEnemy, x, y);
if (Player.CurrentOwn.Shots.Any(s => s.X == x && s.Y == y))
return;
if (ship != null)
{
if (ship.Direction == ShipDirection.Horizontal)
ship.DamagedParts[x - ship.X] = true;
{
if (!ship.DamagedParts[x - ship.X])
ship.DamagedParts[x - ship.X] = true;
else
return;
}
else
ship.DamagedParts[y - ship.Y] = true;
{
if (!ship.DamagedParts[y - ship.Y])
ship.DamagedParts[y - ship.Y] = true;
else return;
}
}
Player.CurrentOwn.Shots.Add(new Point(x, y));
}
}
}

View file

@ -50,8 +50,8 @@ namespace Torpedo
public override void RenderGameField()
{
Player.CurrentEnemy.Ships.ForEach(s => RenderShip(s));
Player.CurrentOwn.Shots.ForEach(s => UpdateField(s.X, s.Y, FieldTypeEnemy.Missed));
Player.CurrentEnemy.Ships.ForEach(s => RenderShip(s));
}
}

View file

@ -141,17 +141,26 @@ namespace Torpedo
return;
Point clickedfield = GameRenderer.Enemy.PixelsToFields(enemyPanel.PointToClient(Cursor.Position));
Ship ship = Ship.GetShipAtField(Player.CurrentEnemy, clickedfield.X, clickedfield.Y);
if (ship == null)
{
Player.CurrentOwn.Shots.Add(clickedfield);
}
else
if (Player.CurrentOwn.Shots.Any(s => s.X == clickedfield.X && s.Y == clickedfield.Y))
return;
if (ship != null)
{
if (ship.Direction == ShipDirection.Horizontal)
ship.DamagedParts[clickedfield.X - ship.X] = true;
{
if (!ship.DamagedParts[clickedfield.X - ship.X]) //Felesleges, mivel a Shots már eltárolja a találatokat is...
ship.DamagedParts[clickedfield.X - ship.X] = true;
else
return;
}
else
ship.DamagedParts[clickedfield.Y - ship.Y] = true;
{
if (!ship.DamagedParts[clickedfield.Y - ship.Y])
ship.DamagedParts[clickedfield.Y - ship.Y] = true;
else
return;
}
}
Player.CurrentOwn.Shots.Add(clickedfield);
GameRenderer.Enemy.RenderGameField();
Game.NextTurn(ship != null);
}

View file

@ -48,8 +48,8 @@ namespace Torpedo
public override void RenderGameField()
{
Player.CurrentOwn.Ships.ForEach(s => RenderShip(s));
Player.CurrentEnemy.Shots.ForEach(s => UpdateField(s.X, s.Y, FieldTypeOwn.Missed));
Player.CurrentOwn.Ships.ForEach(s => RenderShip(s));
}
}