コード例 #1
0
ファイル: Game.cs プロジェクト: epicvrvs/Shashkrid
 List<Hex> GetZoneOfControl(Player player)
 {
     int initial;
     int direction;
     if (player.Colour == PlayerColour.Black)
     {
         initial = 0;
         direction = 1;
     }
     else
     {
         initial = GameConstants.GridSizeY - 1;
         direction = -1;
     }
     List<Hex> zone = new List<Hex>();
     for (int x = 0; x < GameConstants.GridSizeX; x++)
     {
         int? maximum = null;
         for (int y = initial; y >= 0 && y < GameConstants.GridSizeY; y += direction)
         {
             Position position = new Position(x, y);
             if (!position.IsValid())
                 break;
             Hex hex = GetHex(position);
             Piece piece = hex.Piece;
             if (piece == null)
                 continue;
             else if (object.ReferenceEquals(piece.Owner, player))
                 maximum = y;
             else
                 break;
         }
         if (maximum == null)
             continue;
         for (int y = initial; ; y += direction)
         {
             Position position = new Position(x, y);
             Hex hex = GetHex(position);
             zone.Add(hex);
             if (y == maximum)
                 break;
         }
     }
     return zone;
 }
コード例 #2
0
ファイル: Game.cs プロジェクト: epicvrvs/Shashkrid
 void CreateGrid()
 {
     _Grid = new List<Hex>();
     for (int y = 0; y < GameConstants.GridSizeY; y++)
     {
         for (int x = 0; x < GameConstants.GridSizeX; x++)
         {
             Position position = new Position(x, y);
             Hex hex = new Hex(position);
             _Grid.Add(hex);
         }
     }
     foreach (Hex hex in _Grid)
     {
         foreach (Position offset in Position.NeighbourOffsets)
         {
             Position position = hex.Position + offset;
             if (position.IsValid())
             {
                 Hex neighbour = GetHex(position);
                 hex.Neighbours.Add(hex);
             }
         }
     }
 }