private void ActivateCurrentSquare()
 {
     if (curX == startX && curY == startY)
     {
         if (startLevel == null)
         {
             startLevel = (GameSquare)Instantiate(startLevelPrefab, Vector3.zero, Quaternion.identity);
             startLevel.SetRunes(mainRune, runes[0], runes[0], runes[0]);
             startLevel.Activate();
         }
         else
         {
             startLevel.Activate();
         }
     }
     else
     {
         if (currentSquare() == null)
         {
             gameBoard[curX, curY] = (GameSquare)Instantiate(genericLevel, Vector3.zero, Quaternion.identity);
             if (maze.end[0] == curX && maze.end[1] == curY)
             {
                 InstantiateGoalObject(currentSquare());
             }
             gameBoard[curX, curY].difficulty = maze.maze[curX, curY];
             gameBoard[curX, curY].StartSpawners();
             gameBoard[curX, curY].SetRunes(RuneForDirection(Directions.North), RuneForDirection(Directions.South), RuneForDirection(Directions.East), RuneForDirection(Directions.West));
         }
         currentSquare().Activate();
     }
 }
Exemplo n.º 2
0
 public GameGrid( )
 {
     for (int i = 0; i <= 8; i++)
     {
         grid[i] = new GameSquare( );
     }
 }
    private void InstantiateGoalObject(GameSquare endSqaure)
    {
        Transform clonedObject = (Transform)Instantiate(goalObject);

        goalObject.transform.position = new Vector3(0, 1, 0);
        clonedObject.transform.parent = endSqaure.transform;
    }
Exemplo n.º 4
0
        //Calculates and advances the generation
        private void advanceGeneration()
        {
            int neighbors;
            GameSquare[,] gameBoardTemp = new GameSquare[col, row];
            for (int y = 0; y < row; y++)
                for (int x = 0; x < col; x++)
                {
                    neighbors = 0;
                    if (gameBoard[(x + col - 1) % col, y].populated) neighbors++;
                    if (gameBoard[(x + col - 1) % col, (y + row - 1) % row].populated) neighbors++;
                    if (gameBoard[x, (y + row - 1) % row].populated) neighbors++;
                    if (gameBoard[(x + 1) % col, (y + row - 1) % row].populated) neighbors++;
                    if (gameBoard[(x + 1) % col, y].populated) neighbors++;
                    if (gameBoard[(x + 1) % col, (y + 1) % row].populated) neighbors++;
                    if (gameBoard[x, (y + 1) % row].populated) neighbors++;
                    if (gameBoard[(x + col - 1) % col, (y + 1) % row].populated) neighbors++;
                    if (gameBoard[x, y].populated) gameBoard[x, y].willBePopulated = (neighbors >= SMIN && neighbors <= SMAX);
                    else gameBoard[x, y].willBePopulated = (neighbors >= BMIN && neighbors <= BMAX);

                }
            for (int y = 0; y < row; y++)
                for (int x = 0; x < col; x++)
                    gameBoard[x, y].populated = gameBoard[x, y].willBePopulated;
            Invalidate();
        }
        public ConsoleGameBuilder(IConsoleUI ui) : base(ui)
        {
            ui.DisplayStartScreen();
            bool startGame = false;

            while (startGame == false)
            {
                startGame = ui.DisplayReadyScreen();
            }
            List <IGamePlayer> players = ui.DisplayEnterPlayersScreen();
            NoughtCrossToken   token   = ui.DisplayEnterPlayerOneTokenScreen();

            IGameSquare[][] squares = new GameSquare[3][];
            for (int i = 0; i < 3; i++)
            {
                squares[i] = new GameSquare[3];
                for (int j = 0; j < 3; j++)
                {
                    squares[i][j] = new GameSquare();
                }
            }
            IGameBoard board = new GameBoard(squares);

            _gameEngine = new GameEngine(players, board, players[0].Id, token, new GameVictoryCalculator(GameWinStates.GetStates()));
        }
Exemplo n.º 6
0
        public void InitiateGameResources()
        {
            _squares = new GameSquare[3][];
            for (int i = 0; i < 3; i++)
            {
                _squares[i] = new GameSquare[3];
                for (int j = 0; j < 3; j++)
                {
                    _squares[i][j] = new GameSquare();
                }
            }

            _board = new GameBoard(_squares);

            _playerOne = new GamePlayer("Alice");

            _players = new List <IGamePlayer>()
            {
                _playerOne,
                new GamePlayer("Bob")
            };
            var playerOneToken = NoughtCrossToken.X;

            _victoryCalculator = new GameVictoryCalculator(GameWinStates.GetStates());
            _Game = new GameEngine(_players, _board, _playerOne.Id, playerOneToken, _victoryCalculator);
            _playerOne.SetPlayerToken(playerOneToken);
        }
    public void InitGame()
    {
        // First reset anything that already exists
        if (player)
        {
            player.goalAcheived = false;
        }
        if (startLevel != null)
        {
            Destroy(startLevel.gameObject);
            startLevel = null;
        }
        if (mainRune != null)
        {
            runes.Add(mainRune);
        }
        if (gameBoard != null)
        {
            for (int i = 0; i < gameBoard.GetLength(0); i++)
            {
                for (int j = 0; j < gameBoard.GetLength(1); j++)
                {
                    if (gameBoard[i, j] != null)
                    {
                        Destroy(gameBoard[i, j].gameObject);
                        gameBoard[i, j] = null;
                    }
                }
            }
        }

        if (player == null)
        {
            player = (Player)Instantiate(playerCharacter, Vector3.zero, Quaternion.Euler(0, -90, 0));
        }
        gameBoard = new GameSquare[size, size];
        maze      = new MazeCreator(size, 3, new int[] { startX, startY - 1 });
        Debug.Log("Start at " + maze.start[0].ToString() + " " + maze.start[1].ToString());
        Debug.Log("End at " + maze.end[0].ToString() + " " + maze.end[1].ToString());
        for (int i = 0; i < 10; i++)
        {
            string test = "";
            for (int j = 0; j < 10; j++)
            {
                test += maze.maze[j, i].ToString();
            }
            Debug.Log(test);
        }
        curX = startX;
        curY = startY;
        int runeIndex = Random.Range(0, runes.Count - 1);

        mainRune = runes[runeIndex];
        runes.RemoveAt(runeIndex);
        ActivateCurrentSquare();
        MovePlayerToSpawn(Directions.North);
    }
Exemplo n.º 8
0
 public void ChangeGridSize(int width, int height)
 {
     Grid = new GameSquare[width, height];
     for (int i = 0; i < width; i++)
     {
         for (int j = 0; j < height; j++)
         {
             Grid[i, j] = new GameSquare();
         }
     }
 }
Exemplo n.º 9
0
 private static void MoveSquare(string name, int x1, int y1)
 {
     for (int i = 0; i < list.Count; i++)
     {
         if (list[i].Name == name)
         {
             list[i] = new GameSquare(name, x1, y1);
             break;
         }
     }
 }
Exemplo n.º 10
0
        //Check if this square can be clicked, update square
        //Given x and y indexes in the board array and what mouse button was pressed
        private void ProcessUserInput(int x, int y, int button)
        {
            const int RIGHT = 1;
            const int LEFT  = 2;

            GameSquare current = mineBoard.GetGameSquare(x, y);

            //No action if square is already clicked
            if (current.Clicked != GameLogic.GameSquare.CLICKED)
            {
                //Action if square is already flagged, and right clicked
                if (button == RIGHT)
                {
                    if (current.Clicked == GameLogic.GameSquare.FLAGGED)
                    {
                        current.Clicked = GameLogic.GameSquare.UNCLICKED;
                        mineBoard.SetGameSquare(x, y, current);
                    }
                    else
                    {
                        current.Clicked = GameLogic.GameSquare.FLAGGED;
                        mineBoard.SetGameSquare(x, y, current);
                    }
                }

                //Left mouse button, no action if square is flagged
                if (button == LEFT)
                {
                    if (current.Clicked == GameLogic.GameSquare.UNCLICKED)
                    {
                        current.Clicked = GameLogic.GameSquare.CLICKED;
                        mineBoard.SetGameSquare(x, y, current);


                        //CHECK IF CLICKED SQUARE IS A BOMB
                        //End game if necessary
                        if (current.SquareValue == GameLogic.GameSquare.BOMB)
                        {
                            current.SquareValue = GameLogic.GameSquare.REDBOMB;
                            mineBoard.GameOver  = true;
                        }


                        //CHECK IF CLICKED SQUARE IS BLANK
                        //Reveal other blank squares
                        if (current.SquareValue == GameLogic.GameSquare.BLANK)
                        {
                            CheckBlank(x, y);
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
 public void InitiateBoardResources()
 {
     _squares = new GameSquare[3][];
     for (int i = 0; i < 3; i++)
     {
         _squares[i] = new GameSquare[3];
         for (int j = 0; j < 3; j++)
         {
             _squares[i][j] = new GameSquare();
         }
     }
 }
        private static GameSquare[,] InitGameSquareArray()
        {
            var gameState = new GameSquare[3, 3];

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    gameState[i, j] = new GameSquare();
                }
            }
            return(gameState);
        }
Exemplo n.º 13
0
 public void InitiateBoardResources()
 {
     _squares = new GameSquare[3][];
     for (int i = 0; i < 3; i++)
     {
         _squares[i] = new GameSquare[3];
         for (int j = 0; j < 3; j++)
         {
             _squares[i][j] = new GameSquare();
         }
     }
     _victoryCalculator = new GameVictoryCalculator(GameWinStates.GetStates());
 }
Exemplo n.º 14
0
    Sprite GetSprite(GameSquare square)
    {
        if (square == null)
        {
            return(blank);
        }
        if (square.type == Type.VIRUS)
        {
            switch (square.color)
            {
            case Color.RED:
                return(redVirus);

            case Color.BLUE:
                return(blueVirus);

            case Color.YELLOW:
                return(yellowVirus);
            }
        }
        else if (square.joinedAt == JoinDirection.NONE)
        {
            switch (square.color)
            {
            case Color.RED:
                return(redPillNone);

            case Color.BLUE:
                return(bluePillNone);

            case Color.YELLOW:
                return(yellowPillNone);
            }
        }
        else
        {
            switch (square.color)
            {
            case Color.RED:
                return(redPillJoined);

            case Color.BLUE:
                return(bluePillJoined);

            case Color.YELLOW:
                return(yellowPillJoined);
            }
        }
        return(blank);
    }
        public static BombedGuessResponseMessage fromJSON(string message) {
            JObject o = JObject.Parse(message);
            int id = (int) o["id"];
            int scoreYou = -1, scoreOpponent = -1, length;
            int[] bombs, selectionPath;
            int player_index = (int)o["player_id"];
            ePlayer player;
            Word word;
            GameSquare[] squares;

            if (Globals.PlayerIndex == player_index)
                player = ePlayer.You;
            else
                player = ePlayer.Opponent;

            if (Globals.PlayerIndex == 0)
            {
                scoreYou = (int)o["scores"][0];
                scoreOpponent = (int)o["scores"][1];
            }
            else if (Globals.PlayerIndex == 1)
            {
                scoreYou = (int)o["scores"][1];
                scoreOpponent = (int)o["scores"][0];
            }

            JArray bombsJson = (JArray) o["bombs"];
            length = bombsJson.Count;
            bombs = new int[length];
            for(int i = 0; i < length; i++) {
                bombs[i] = (int) bombsJson[i] ;
            }

            JArray selectionJson = (JArray)o["selection"];
            length = selectionJson.Count;
            selectionPath = new int[length];
            for (int i = 0; i < length; i++)
            {
                selectionPath[i] = (int)selectionJson[i];
            }

            squares = new GameSquare[selectionPath.Length];

            for (int i = 0; i < squares.Length; i++)
                squares[i] = WordGame.squares2[selectionPath[i]];

            word = new Word(id, selectionPath, squares);
            return new BombedGuessResponseMessage(scoreYou, scoreOpponent, word, bombs, player);
        }
Exemplo n.º 16
0
    public static GameSquare[,] CloneGrid(GameSquare[,] grid)
    {
        int cols = grid.GetLength(0);
        int rows = grid.GetLength(1);

        GameSquare[,] clonedGrid = new GameSquare[cols, rows];
        for (int i = 0; i < cols; i++)
        {
            for (int j = 0; j < rows; j++)
            {
                clonedGrid[i, j]            = new GameSquare();
                clonedGrid[i, j].isExplored = grid[i, j].isExplored;
            }
        }
        return(clonedGrid);
    }
Exemplo n.º 17
0
        private void CreatePawnAt(int columnIndex, int rowIndex)
        {
            Piece piece = new Pawn();

            piece.CurrentLocation = new Vector2(columnIndex, rowIndex);
            if (rowIndex == 1)
            {
                piece.PlayerIndex    = 2;
                player2[columnIndex] = piece;
            }
            else
            {
                piece.PlayerIndex    = 1;
                player1[columnIndex] = piece;
            }
            board[columnIndex, rowIndex] = new GameSquare(piece);
        }
Exemplo n.º 18
0
        public void ThrowErrorOnWrongBoard()
        {
            var playerOneToken = NoughtCrossToken.X;

            var squares = new GameSquare[4][];

            for (int i = 0; i < 4; i++)
            {
                squares[i] = new GameSquare[4];
                for (int j = 0; j < 4; j++)
                {
                    squares[i][j] = new GameSquare();
                }
            }
            var board = new GameBoard(squares);

            _Game = new GameEngine(_players, board, _playerOne.Id, playerOneToken, _victoryCalculator);
        }
Exemplo n.º 19
0
        private void CreateBackRowPeiceAt(int columnIndex, int rowIndex)
        {
            Piece piece;

            switch (columnIndex)
            {
            case 0:
            case 7:
                piece = new Rook();
                break;

            case 1:
            case 6:
                piece = new Knight();
                break;

            case 2:
            case 5:
                piece = new Bishop();
                break;

            case 3:
                piece = new Queen();
                break;

            default:
                piece = new King();
                break;
            }
            piece.CurrentLocation = new Vector2(columnIndex, rowIndex);
            if (rowIndex == 0)
            {
                piece.PlayerIndex        = 2;
                player2[8 + columnIndex] = piece;
            }
            else
            {
                piece.PlayerIndex        = 1;
                player1[8 + columnIndex] = piece;
            }
            board[columnIndex, rowIndex] = new GameSquare(piece);
        }
Exemplo n.º 20
0
    // Use this for initialization
    void Start()
    {
        //Subscribe to game events
        GameSquare.OnGameSquareHover     += highlightGameSpace;
        GameSquare.OnGameSquareHoverExit += dimGameSpace;
        GameSquare.OnGameSquareClicked   += selectTile;

        for (int x = 0; x < board.GetLength(0); x++)
        {
            for (int y = 0; y < board.GetLength(1); y++)
            {
                GameSquare s = t_spawn.SpawnGameSquare(square);
                //s.Initialize(new Vector2(x, y));
                s.name = "(" + x + "," + y + ")";
                s.transform.SetParent(gameObject.transform);
                s.SetCoordinates(new Vector2(x, y));
                board[x, y] = s;
            }
        }
    }
        public static GoodGuessResponseMessage fromJSON(string json) {
            JObject o = JObject.Parse(json);
            int length, id = (int)o["id"];
            int[] selectionPath;
            GameSquare[] squares;
            int scoreYou = -1, scoreOpponent = -1;
            Word word;
            ePlayer player;

            if ((int)o["player_id"] == Globals.PlayerIndex)
                player = ePlayer.You;
            else
                player = ePlayer.Opponent;

            if (Globals.PlayerIndex == 0)
            {
                scoreYou = (int)o["scores"][0];
                scoreOpponent = (int)o["scores"][1];
            }
            else if (Globals.PlayerIndex == 1)
            {
                scoreYou = (int)o["scores"][1];
                scoreOpponent = (int)o["scores"][0];
            }

            JArray selectionJson = (JArray)o["selection"];
            length = selectionJson.Count;
            selectionPath = new int[length];
            for (int i = 0; i < length; i++)
            {
                selectionPath[i] = (int)selectionJson[i];
            }

            squares = new GameSquare[selectionPath.Length];

            for (int i = 0; i < squares.Length; i++)
                squares[i] = WordGame.squares2[selectionPath[i]];

            word = new Word(id, selectionPath, squares);
            return new GoodGuessResponseMessage(scoreYou, scoreOpponent, player, word);
        }
Exemplo n.º 22
0
        public void Creating_GameSquare_Sets_Corners_And_Middle()
        {
            // top corner
            var testGameSquare = new GameSquare(0, 3, 7, 7);

            Assert.True(testGameSquare.IsTopCorner);

            // top corner
            testGameSquare = new GameSquare(6, 3, 7, 7);
            Assert.True(testGameSquare.IsBottomCorner);

            // left corner
            testGameSquare = new GameSquare(3, 0, 7, 7);
            Assert.True(testGameSquare.IsLeftCorner);

            // right corner
            testGameSquare = new GameSquare(3, 6, 7, 7);
            Assert.True(testGameSquare.IsRightCorner);

            // middle
            testGameSquare = new GameSquare(3, 3, 7, 7);
            Assert.True(testGameSquare.IsMiddle);
        }
Exemplo n.º 23
0
    Vector3 GetEulerRotation(GameSquare square)
    {
        if (square == null || square.type == Type.VIRUS || (square.type == Type.PILL && square.joinedAt == JoinDirection.NONE))
        {
            return(Vector3.zero);
        }
        float z = 0;

        switch (square.joinedAt)
        {
        case JoinDirection.UP:
            z = 90;
            break;

        case JoinDirection.LEFT:
            z = 180;
            break;

        case JoinDirection.DOWN:
            z = 270;
            break;
        }
        return(new Vector3(0, 0, z));
    }
Exemplo n.º 24
0
 public void highlightGameSpace(GameSquare s)
 {
     s.setShader(squareHighlight);
 }
Exemplo n.º 25
0
        public ChessBoard(InputHandler inp)
        {
            isHelpOpen            = false;
            isOptionsOpen         = false;
            isGameQuit            = false;
            gameMessage           = string.Empty;
            winnerMessage         = string.Empty;
            playerTurn            = WHITE + TURN;
            input                 = inp;
            currentPlayersTurn    = 1;
            selectedSpaceLocation = new Vector2(-1, -1);
            spaceSelected         = false;
            isGameOver            = false;
            Color gameSpaceColor = Color.White;

            board   = new GameSquare[8, 8];
            player1 = new Piece[16];
            player2 = new Piece[16];

            //Create All the GameSquares
            for (int y = 0; y < 8; y++)
            {
                for (int x = 0; x < 8; x++)
                {
                    if (y == 0 || y == 7) //create back row of characters
                    {
                        CreateBackRowPeiceAt(x, y);
                    }
                    else if (y == 1 || y == 6)
                    {
                        CreatePawnAt(x, y);
                    }
                    else
                    {
                        board[x, y] = new GameSquare(null);
                    }
                    board[x, y].DefaultColor = gameSpaceColor;
                    if (x != 7)
                    {
                        if (gameSpaceColor == Color.White)
                        {
                            gameSpaceColor = Color.Gray;
                        }
                        else
                        {
                            gameSpaceColor = Color.White;
                        }
                    }
                }
            }

            //Move the kings to the end of the array
            Piece temp = player1[15];

            player1[15] = player1[12];
            player1[12] = temp;

            temp        = player2[15];
            player2[15] = player2[12];
            player2[12] = temp;
        }
Exemplo n.º 26
0
        //Recursive method to reveal blank squares
        public void CheckBlank(int x, int y)
        {
            if (x >= 0 && x < mineBoard.Width && y >= 0 && y <= mineBoard.Height)
            {
                GameSquare current = mineBoard.GetGameSquare(x, y);
                current.Clicked = GameLogic.GameSquare.CLICKED;

                //All squares around this one are also clicked
                if (x - 1 >= 0)
                {
                    mineBoard.GetGameSquare(x - 1, y).Clicked = GameLogic.GameSquare.CLICKED;

                    if (y - 1 >= 0)
                    {
                        mineBoard.GetGameSquare(x - 1, y - 1).Clicked = GameLogic.GameSquare.CLICKED;
                    }
                }
                if (y - 1 >= 0)
                {
                    mineBoard.GetGameSquare(x, y - 1).Clicked = GameLogic.GameSquare.CLICKED;

                    if (x + 1 < mineBoard.Width)
                    {
                        mineBoard.GetGameSquare(x + 1, y - 1).Clicked = GameLogic.GameSquare.CLICKED;
                    }
                }
                if (x + 1 < mineBoard.Width)
                {
                    mineBoard.GetGameSquare(x + 1, y).Clicked = GameLogic.GameSquare.CLICKED;

                    if (y + 1 < mineBoard.Height)
                    {
                        mineBoard.GetGameSquare(x + 1, y + 1).Clicked = GameLogic.GameSquare.CLICKED;
                    }
                }
                if (y + 1 < mineBoard.Height)
                {
                    mineBoard.GetGameSquare(x, y + 1).Clicked = GameLogic.GameSquare.CLICKED;

                    if (x - 1 >= 0)
                    {
                        mineBoard.GetGameSquare(x - 1, y + 1).Clicked = GameLogic.GameSquare.CLICKED;
                    }
                }

                mineBoard.SetGameSquare(x, y, current);

                if ((y - 1) >= 0)
                {
                    if (mineBoard.GetGameSquare(x, y - 1).SquareValue == GameLogic.GameSquare.BLANK && mineBoard.GetGameSquare(x, y - 1).Searched == false)
                    {
                        mineBoard.GetGameSquare(x, y - 1).Searched = true;
                        CheckBlank(x, y - 1);
                    }
                }
                if ((y + 1) < mineBoard.Height)
                {
                    if (mineBoard.GetGameSquare(x, y + 1).SquareValue == GameLogic.GameSquare.BLANK && mineBoard.GetGameSquare(x, y + 1).Searched == false)
                    {
                        mineBoard.GetGameSquare(x, y + 1).Searched = true;
                        CheckBlank(x, y + 1);
                    }
                }
                if ((x - 1) >= 0)
                {
                    if (mineBoard.GetGameSquare(x - 1, y).SquareValue == GameLogic.GameSquare.BLANK && mineBoard.GetGameSquare(x - 1, y).Searched == false)
                    {
                        mineBoard.GetGameSquare(x - 1, y).Searched = true;
                        CheckBlank(x - 1, y);
                    }
                }
                if ((x + 1) < mineBoard.Width)
                {
                    if (mineBoard.GetGameSquare(x + 1, y).SquareValue == GameLogic.GameSquare.BLANK && mineBoard.GetGameSquare(x + 1, y).Searched == false)
                    {
                        mineBoard.GetGameSquare(x + 1, y).Searched = true;
                        CheckBlank(x + 1, y);
                    }
                }
            }

            return;
        }
Exemplo n.º 27
0
 public void dimGameSpace(GameSquare s)
 {
     s.setShader(Shader.Find("Sprites/Default"));
 }
Exemplo n.º 28
0
 private static bool CheckY(GameSquare current, GameSquare another)
 {
     return(current.Y1 <= another.Y2 && current.Y2 >= another.Y1);
 }
Exemplo n.º 29
0
    public int CompareTo(GameSquare another)
    {
        int cmpX = X1.CompareTo(another.X1);

        return(cmpX);
    }
Exemplo n.º 30
0
 public GameSquare SpawnGameSquare(GameSquare prototype)
 {
     m_Copy = prototype.Copy();
     return((GameSquare)m_Copy);
 }
Exemplo n.º 31
0
 public void selectTile(Vector2 coord)
 {
     selectedSquare = board[(int)coord.x, (int)coord.y];
     Debug.Log("Selected Square: " + selectedSquare.name);
 }