Az AI teljesen működőképes; javítások
git-tfs-id: [https://sznp.visualstudio.com/DefaultCollection/]$/Torpedo;C14
This commit is contained in:
parent
d6fe86e650
commit
a2cb6590ae
4 changed files with 46 additions and 7 deletions
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -26,7 +27,24 @@ namespace Torpedo
|
|||
|
||||
public static void Attack()
|
||||
{
|
||||
//TODO
|
||||
int x, y;
|
||||
do
|
||||
{
|
||||
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
|
||||
{
|
||||
if (ship.Direction == ShipDirection.Horizontal)
|
||||
ship.DamagedParts[x - ship.X] = true;
|
||||
else
|
||||
ship.DamagedParts[y - ship.Y] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,12 +114,20 @@ namespace Torpedo
|
|||
GameForm.Instance.Reset();
|
||||
return;
|
||||
}
|
||||
if (Player.CurrentOwn.Ships.All(s => s.DamagedParts.All(d => d)))
|
||||
{
|
||||
MessageBox.Show("Vereség!");
|
||||
GameForm.Instance.Reset();
|
||||
return;
|
||||
}
|
||||
if (Type == GameType.Singleplayer)
|
||||
{
|
||||
GameForm.Instance.SetPanelsEnabled(false);
|
||||
Player.SwapPlayers();
|
||||
if (Player.CurrentOwn == Player.Player2)
|
||||
AIPlayer.PlaceShips();
|
||||
AIPlayer.Attack();
|
||||
Player.SwapPlayers();
|
||||
GameForm.Instance.SetPanelsEnabled(true);
|
||||
}
|
||||
else if (Type == GameType.Multiplayer)
|
||||
{
|
||||
|
|
|
@ -98,6 +98,8 @@ namespace Torpedo
|
|||
{
|
||||
int width = Parent.Width / Game.GameSize.Width;
|
||||
int height = Parent.Height / Game.GameSize.Height;
|
||||
if (x > Game.GameSize.Width || x < 0 || y > Game.GameSize.Height || y < 0)
|
||||
throw new InvalidOperationException("A koordináták a játéktéren kívül esnek.");
|
||||
gr.FillRectangle(new SolidBrush(color), x * width, y * height, width, height);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,8 +18,10 @@ namespace Torpedo
|
|||
|
||||
private static ReadOnlyDictionary<FieldTypeOwn, Color> FieldTypes = new ReadOnlyDictionary<FieldTypeOwn, Color>(new Dictionary<FieldTypeOwn, Color>()
|
||||
{
|
||||
{FieldTypeOwn.OwnShip, Color.LightGray},
|
||||
{FieldTypeOwn.OwnShipDamaged, Color.DarkRed}
|
||||
{ FieldTypeOwn.OwnShip, Color.LightGray },
|
||||
{ FieldTypeOwn.OwnShipDamaged, Color.DarkRed },
|
||||
{ FieldTypeOwn.OwnShipDestroyed, Color.Black },
|
||||
{ FieldTypeOwn.Missed, Color.LightBlue }
|
||||
});
|
||||
|
||||
public void UpdateField(int x, int y, FieldTypeOwn fieldtype)
|
||||
|
@ -30,12 +32,18 @@ namespace Torpedo
|
|||
public override void RenderShip(Ship ship)
|
||||
{
|
||||
//TODO: Képek az egyes hajótípusokhoz
|
||||
bool destroyed = ship.DamagedParts.All(p => p);
|
||||
for (int i = 0; i < ship.Size; i++)
|
||||
{
|
||||
FieldTypeOwn fto = FieldTypeOwn.OwnShip;
|
||||
if (destroyed)
|
||||
fto = FieldTypeOwn.OwnShipDestroyed;
|
||||
else if (ship.DamagedParts[i])
|
||||
fto = FieldTypeOwn.OwnShipDamaged;
|
||||
if (ship.Direction == ShipDirection.Horizontal)
|
||||
UpdateField(ship.X + i, ship.Y, FieldTypeOwn.OwnShip);
|
||||
UpdateField(ship.X + i, ship.Y, fto);
|
||||
else
|
||||
UpdateField(ship.X, ship.Y + i, FieldTypeOwn.OwnShip);
|
||||
UpdateField(ship.X, ship.Y + i, fto);
|
||||
}
|
||||
//TODO: Rárajzolni a képet a mezőkre
|
||||
}
|
||||
|
@ -43,12 +51,15 @@ 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));
|
||||
}
|
||||
}
|
||||
|
||||
public enum FieldTypeOwn
|
||||
{
|
||||
OwnShip,
|
||||
OwnShipDamaged
|
||||
OwnShipDamaged,
|
||||
OwnShipDestroyed,
|
||||
Missed
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue