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);
|
y = rand.Next(Game.GameSize.Height);
|
||||||
} while (Player.Player2.Shots.Any(p => p.X == x && p.Y == y));
|
} while (Player.Player2.Shots.Any(p => p.X == x && p.Y == y));
|
||||||
Ship ship = Ship.GetShipAtField(Player.CurrentEnemy, x, y);
|
Ship ship = Ship.GetShipAtField(Player.CurrentEnemy, x, y);
|
||||||
if (ship == null)
|
if (Player.CurrentOwn.Shots.Any(s => s.X == x && s.Y == y))
|
||||||
{
|
return;
|
||||||
Player.CurrentOwn.Shots.Add(new Point(x, y));
|
if (ship != null)
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (ship.Direction == ShipDirection.Horizontal)
|
if (ship.Direction == ShipDirection.Horizontal)
|
||||||
|
{
|
||||||
|
if (!ship.DamagedParts[x - ship.X])
|
||||||
ship.DamagedParts[x - ship.X] = true;
|
ship.DamagedParts[x - ship.X] = true;
|
||||||
else
|
else
|
||||||
ship.DamagedParts[y - ship.Y] = true;
|
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()
|
public override void RenderGameField()
|
||||||
{
|
{
|
||||||
Player.CurrentEnemy.Ships.ForEach(s => RenderShip(s));
|
|
||||||
Player.CurrentOwn.Shots.ForEach(s => UpdateField(s.X, s.Y, FieldTypeEnemy.Missed));
|
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;
|
return;
|
||||||
Point clickedfield = GameRenderer.Enemy.PixelsToFields(enemyPanel.PointToClient(Cursor.Position));
|
Point clickedfield = GameRenderer.Enemy.PixelsToFields(enemyPanel.PointToClient(Cursor.Position));
|
||||||
Ship ship = Ship.GetShipAtField(Player.CurrentEnemy, clickedfield.X, clickedfield.Y);
|
Ship ship = Ship.GetShipAtField(Player.CurrentEnemy, clickedfield.X, clickedfield.Y);
|
||||||
if (ship == null)
|
if (Player.CurrentOwn.Shots.Any(s => s.X == clickedfield.X && s.Y == clickedfield.Y))
|
||||||
{
|
return;
|
||||||
Player.CurrentOwn.Shots.Add(clickedfield);
|
if (ship != null)
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (ship.Direction == ShipDirection.Horizontal)
|
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;
|
ship.DamagedParts[clickedfield.X - ship.X] = true;
|
||||||
else
|
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();
|
GameRenderer.Enemy.RenderGameField();
|
||||||
Game.NextTurn(ship != null);
|
Game.NextTurn(ship != null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,8 +48,8 @@ namespace Torpedo
|
||||||
|
|
||||||
public override void RenderGameField()
|
public override void RenderGameField()
|
||||||
{
|
{
|
||||||
Player.CurrentOwn.Ships.ForEach(s => RenderShip(s));
|
|
||||||
Player.CurrentEnemy.Shots.ForEach(s => UpdateField(s.X, s.Y, FieldTypeOwn.Missed));
|
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