Example #1
0
    Road PickRoad(Road r, bool up, bool down, bool left, bool right)
    {
        switch (r.GetType().ToString())
        {
        case "NarrowRoad": {
            if (r.up)
            {
                return(RoadFactory.CreateT((int)weavingPosition.x, (int)weavingPosition.y, true, true, left, right));
            }
            else
            {
                return(RoadFactory.CreateT((int)weavingPosition.x, (int)weavingPosition.y, up, down, true, true));
            }
        }

        case "CrossTRoad": {
            return(RoadFactory.CreateQCrossroad((int)weavingPosition.x, (int)weavingPosition.y));
        }

        case "EndRoad": {
            if (r.up)
            {
                return(RoadFactory.CreateTwoSided((int)weavingPosition.x, (int)weavingPosition.y, true, down, left, right));
            }
            else if (r.down)
            {
                return(RoadFactory.CreateTwoSided((int)weavingPosition.x, (int)weavingPosition.y, up, true, left, right));
            }
            else if (r.left)
            {
                return(RoadFactory.CreateTwoSided((int)weavingPosition.x, (int)weavingPosition.y, up, down, true, right));
            }
            else
            {
                return(RoadFactory.CreateTwoSided((int)weavingPosition.x, (int)weavingPosition.y, up, down, left, true));
            }
        }
        }
        return(null);
    }
Example #2
0
    private Road ChooseSprite(int x, int y, RoadStub[,] roads, int mapX, int mapY)
    {
        //check surrounding

        bool down      = false;
        bool up        = false;
        bool left      = false;
        bool right     = false;
        int  numAround = 0;

        try { if (roads[y, x + 1] != null)
              {
                  numAround++; right = true;
              }
        }
        catch (System.IndexOutOfRangeException) {}
        try { if (roads[y, x - 1] != null)
              {
                  numAround++; left = true;
              }
        }
        catch (System.IndexOutOfRangeException) {}
        try { if (roads[y + 1, x] != null)
              {
                  numAround++; down = true;
              }
        }
        catch (System.IndexOutOfRangeException) {}
        try { if (roads[y - 1, x] != null)
              {
                  numAround++; up = true;
              }
        }
        catch (System.IndexOutOfRangeException) {}

        Road     result = null;
        RoadStub stub   = roads[y, x];

        //Choose correct road
        //Could just use RoadFactory.CreateGeneralRoad, but at the time of writing this,
        //that function did not exist
        switch (numAround)
        {
        case 0: {
            throw new System.ArgumentException();
        }

        case 1: {
            if (stub.type == RoadStub.RoadType.ChargingSpot)
            {
                result = RoadFactory.CreateChargeSpot(mapX, mapY, up, down, left, right);
            }
            else if (stub.type == RoadStub.RoadType.Regular)
            {
                result = RoadFactory.CreateEnd(mapX, mapY, up, down, left, right);
            }
            else if (stub.type == RoadStub.RoadType.ParkingSpot)
            {
                result = RoadFactory.CreateParkingSpot(mapX, mapY, up, down, left, right);
            }
            break;
        }

        case 2: {
            result = RoadFactory.CreateTwoSided(mapX, mapY, up, down, left, right);
            break;
        }

        case 3: {
            result = RoadFactory.CreateT(mapX, mapY, up, down, left, right);
            break;
        }

        case 4: {
            result = RoadFactory.CreateQCrossroad(mapX, mapY);
            break;
        }
        }
        return(result);
    }
Example #3
0
    private Road CreateRoad(int gridx, int gridy, int mapx, int mapy)
    {
        bool down      = false;
        bool up        = false;
        bool left      = false;
        bool right     = false;
        int  numAround = 0;

        try { if (roadGrid[gridy, gridx + 1] != null)
              {
                  numAround++; right = true;
              }
        }
        catch (System.IndexOutOfRangeException) {}
        try { if (roadGrid[gridy, gridx - 1] != null)
              {
                  numAround++; left = true;
              }
        }
        catch (System.IndexOutOfRangeException) {}
        try { if (roadGrid[gridy + 1, gridx] != null)
              {
                  numAround++; down = true;
              }
        }
        catch (System.IndexOutOfRangeException) {}
        try { if (roadGrid[gridy - 1, gridx] != null)
              {
                  numAround++; up = true;
              }
        }
        catch (System.IndexOutOfRangeException) {}

        Road result = null;

        switch (numAround)
        {
        case 0: {
            throw new System.ArgumentException();
        }

        case 1: {
            throw new System.ArgumentException("1 road around fixee?");
        }

        case 2: {
            result = RoadFactory.CreateTwoSided(mapx, mapy, up, down, left, right);
            break;
        }

        case 3: {
            result = RoadFactory.CreateT(mapx, mapy, up, down, left, right);
            break;
        }

        case 4: {
            result = RoadFactory.CreateQCrossroad(mapx, mapy);
            break;
        }
        }
        return(result);
    }