Time for action – making the connection

  1. Add the PropagateWater() method to the GameBoard class:
      public void PropagateWater(int x, int y, string fromDirection)
      {
          if ((y >= 0) && (y < GameBoardHeight) &&
              (x >= 0) && (x < GameBoardWidth))
          {
              if (boardSquares[x,y].HasConnector(fromDirection) &&
                  !boardSquares[x,y].Suffix.Contains("W"))
              {
                  FillPiece(x, y);
                  WaterTracker.Add(new Vector2(x, y));
                  foreach (string end in
                           boardSquares[x,y].GetOtherEnds(fromDirection))
                      switch (end)
                            {
                          case "Left": PropagateWater(x - 1, y, "Right");
                              break;
                          case "Right": PropagateWater(x + 1, y, "Left");
                              break;
                          case "Top": PropagateWater(x, y - 1, "Bottom");
                              break;
                          case "Bottom": PropagateWater(x, y + 1, "Top");
                              break;
                      }
              }
          }
      }
  2. Add the GetWaterChain() method to the GameBoard class: ...

Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.