Hibajavítás: Most már nem lehet többször ugyanoda lőni
This commit is contained in:
parent
23b79cd9e0
commit
c4ee6e3bd5
4 changed files with 34 additions and 17 deletions
|
@ -34,17 +34,25 @@ namespace Torpedo
|
|||
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
|
||||
if (Player.CurrentOwn.Shots.Any(s => s.X == x && s.Y == y))
|
||||
return;
|
||||
if (ship != null)
|
||||
{
|
||||
if (ship.Direction == ShipDirection.Horizontal)
|
||||
{
|
||||
if (!ship.DamagedParts[x - ship.X])
|
||||
ship.DamagedParts[x - ship.X] = true;
|
||||
else
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ship.DamagedParts[y - ship.Y])
|
||||
ship.DamagedParts[y - ship.Y] = true;
|
||||
}
|
||||
else return;
|
||||
}
|
||||
}
|
||||
Player.CurrentOwn.Shots.Add(new Point(x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
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
|
||||
ship.DamagedParts[clickedfield.Y - ship.Y] = true;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue