Exemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        GameEngine.Instance = this;
        startGameState      = HerugolfGameState.CreateRandomGolfGrid(12, 9);
        currentGameState    = startGameState;

        gridBuilder.BuildGrid(currentGameState);
    }
Exemplo n.º 2
0
    public static HerugolfGameState CreateRandomGolfGrid(int width, int height)
    {
        HerugolfGameState game = new HerugolfGameState(width, height);

        int numberOfHoles = 0;

        for (int xi = 0; xi < width; xi++)
        {
            for (int yi = 0; yi < height; yi++)
            {
                int r = Random.Range(0, 10);
                if (r < 1)
                {
                    game.gridArray[xi, yi] = new GolfCell(xi, yi, CellType.HOLE_EMPTY);
                    numberOfHoles++;
                }
                else if (r < 3)
                {
                    game.gridArray[xi, yi] = new GolfCell(xi, yi, CellType.BUNKER);
                }
                else
                {
                    game.gridArray[xi, yi] = new GolfCell(xi, yi, CellType.GREEN);
                }
            }
        }

        int numberOfBalls = 0;

        while (numberOfBalls < numberOfHoles)
        {
            int  ballPosX = Random.Range(0, Mathf.RoundToInt(game.gridDimensions.x));
            int  ballPosY = Random.Range(0, Mathf.RoundToInt(game.gridDimensions.y));
            Ball ball     = new Ball(ballPosX, ballPosY, Random.Range(1, 6));

            if (game.GetCell(ball.positionOnGridX, ball.positionOnGridY).type.Equals(CellType.GREEN))
            {
                bool alreadyABallAtThisPosition = false;
                foreach (Ball otherBall in game.balls)
                {
                    alreadyABallAtThisPosition |= ((ballPosX == otherBall.positionOnGridX) && (ballPosY == otherBall.positionOnGridY));
                }

                if (!alreadyABallAtThisPosition)
                {
                    game.balls.Add(ball);
                    numberOfBalls++;
                }
            }
        }

        return(game);
    }
Exemplo n.º 3
0
    public static HerugolfGameState CreateEmptyGolfGrid(int width, int height)
    {
        HerugolfGameState game = new HerugolfGameState(width, height);

        for (int xi = 0; xi < width; xi++)
        {
            for (int yi = 0; yi < height; yi++)
            {
                game.gridArray[xi, yi] = new GolfCell(xi, yi, CellType.GREEN);
            }
        }

        return(game);
    }
Exemplo n.º 4
0
 public void BuildGrid(HerugolfGameState gridState)
 {
     gridWidth     = Mathf.RoundToInt(gridState.gridDimensions.x);
     gridHeight    = Mathf.RoundToInt(gridState.gridDimensions.y);
     displayedGrid = new GameObject[gridWidth, gridHeight];
     for (int xi = 0; xi < gridState.gridDimensions.x; xi++)
     {
         for (int yi = 0; yi < gridState.gridDimensions.y; yi++)
         {
             GolfCell cellData = gridState.GetCell(xi, yi);
             displayedGrid[xi, yi] = BuildSquare(xi, yi, cellData);
         }
     }
     foreach (Ball ball in gridState.balls)
     {
         AddBall(ball);
     }
 }