Ejemplo n.º 1
0
    public void DeleteColumn(int x)
    {
        GameObject.Find("GameController").GetComponent <scoreManager> ().UpdateScore(100);         //add score, accomodate score modifer block
        for (int y = 0; y < 10; y++)
        {
            /*    Destroy(gameGridCol[x].row[y].gameObject);
             * gameGridCol[x].row[y] = null;*/
            Grid.grid [x, y] = null;

            /*
             * for (int i = 0; i < blocks.Length; i++) {
             *      if (blocks[i].xPos == x)
             *              Destroy(blocks[i].gameObject);
             * }
             */
            for (int i = 0; i < blockList.Count; i++)
            {
                if (blockList [i].xPos == x)
                {
                    //Debug.Log ("Destroying block at: " + x + "," + y);
                    PlacedBlock removeMe = blockList [i];
                    Debug.Log("I have " + removeMe.transform.childCount + " children.");
                    removeMe.transform.DetachChildren();
                    Destroy(removeMe.gameObject);
                    blockList.Remove(removeMe);
                    i--;
                }
            }
        }
        //Debug.Log ("Cleared Column: " + x);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Remove last block placed by PlaceBlock().
    /// </summary>
    public void RemoveLastBlock()
    {
        int len = m_blocks.Count;

        if (len == 0)
        {
            return;
        }
        PlacedBlock pb = m_blocks[len - 1];

        m_blocks.RemoveAt(len - 1);
        int x = pb.m_position.x;
        int y = pb.m_position.y;

        for (int i = 0; i < 4; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                if (x + i < 10 && y + j < 10 && pb[i, j] == 1)
                {
                    m_index[x + i, y + j] = 0;
                }
            }
        }
    }
Ejemplo n.º 3
0
    private void OnPlacedBlock(PlacedBlock msg)
    {
        Point3 worldCoord = msg.worldCoord;
        Voxel block = ChunkManager.GetBlock(worldCoord);
        if (block == null) {
            block = ChunkManager
                .AddChunk(worldCoord)
                .AddBlock(worldCoord.ToLocalBlockCoord());
        }

        int hash = ChunkManager.GetHash(worldCoord.ToChunkCoord());
        block.SetBlockType(msg.type);

        // Get neighbours, pass to surface manager
        Voxel[] neighbours = GetNeighbours(worldCoord);

        // Lookup mesh name and rotation based on neighbours
        BlockInfo bi =
            SurfaceManager.GetSurface(
                SurfaceManager.GetID(neighbours));

        block.SetRotation(bi.rotation);

        for (int i=0; i<neighbours.Length; i++) {
            if (neighbours[i] == null) {
                continue;
            }
            UpdateNeighbour(neighbours[i], worldCoord + checkSides[i]);
        }

        PlaceBlock(msg.worldCoord, hash, bi);
    }
Ejemplo n.º 4
0
        /// <summary>
        /// Draw block on game board.
        /// </summary>
        /// <param name="block"></param>
        private void DrawBlock(Canvas canvas, PlacedBlock pb)
        {
            Block    b   = pb.m_block;
            Position pos = pb.m_position;

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (pb[i, j] == 1)
                    {
                        int x = pos.x + i;
                        int y = pos.y + j;
                        DrawCircle(canvas, x, y, b.m_color);
                        if (i + 1 < 4 && pb[i + 1, j] == 1)
                        {
                            DrawLine(canvas, x, y, x + 1, y, b.m_color);
                        }
                        if (j + 1 < 4 && pb[i, j + 1] == 1)
                        {
                            DrawLine(canvas, x, y, x, y + 1, b.m_color);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
    /// <summary>
    /// Try place block at first empty cell, from top to bottom, from left to right, leave no empty cells.
    /// </summary>
    /// <param name="block">the block to place</param>
    /// <param name="varient">the block varient</param>
    /// <returns>A new game Board if block varient can be placed at first empty cell.</returns>
    private Board TryPlaceBlock(Block block, int varient)
    {
        Position boardEmptyPos = FindFirstEmptyPosition();

        if (boardEmptyPos == null)
        {
            return(null);
        }
        Position topRowLeftPos = FindTopRowLeft(block, varient);

        Debug.Assert(topRowLeftPos != null);

        int         x        = boardEmptyPos.x - topRowLeftPos.x;
        int         y        = boardEmptyPos.y - topRowLeftPos.y;
        PlacedBlock pb       = new PlacedBlock(block, varient, x, y);
        bool        canPlace = true;

        for (int i = 0; i < 4; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                if (pb[i, j] == 1)
                {
                    if ((x + i < 0) ||
                        (x + i > 9) ||
                        (y + j < 0) ||
                        (y + j > 9 - (x + i)) ||
                        (m_index[x + i, y + j] == 1))
                    {
                        //Debug.WriteLine("canPlace=false");
                        canPlace = false;
                        break;
                    }
                }
            }
        }
        if (canPlace)
        {
            Board newBoard = new Board(this);
            newBoard.m_blocks.Add(pb);
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (pb[i, j] == 1)
                    {
                        newBoard.m_index[x + i, y + j] = 1;
                    }
                }
            }
            return(newBoard);
        }
        return(null);
    }
Ejemplo n.º 6
0
    /// <summary>
    /// Place a block at given position. Do not check for collision.
    /// </summary>
    /// <param name="block">the block to add to board</param>
    /// <param name="x">row number</param>
    /// <param name="y">column number</param>
    public void PlaceBlock(Block block, int x, int y, int varient)
    {
        PlacedBlock pb = new PlacedBlock(block, varient, x, y);

        m_blocks.Add(pb);

        for (int i = 0; i < 4; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                if (x + i < 10 && y + j < 10)
                {
                    m_index[x + i, y + j] += pb[i, j];
                }
            }
        }
    }
Ejemplo n.º 7
0
        /// <summary>
        /// If highlighted cells can form a block, add PlacedBlock in m_puzzle and clear m_highlightPositions.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NextBlockButton_Click(object sender, RoutedEventArgs e)
        {
            PlacedBlock pb = FindAndHighlightBlockMaybe();

            if (pb == null)
            {
                MsgBox.Text = "Invalid Block. Please double check highlighted cells.\n";
                return;
            }
            if (m_puzzle.m_blocks.Any(e => e.m_block.m_name == pb.m_block.m_name))
            {
                MsgBox.Text = "Duplicate Block. Please double check highlighted cells.\n";
                return;
            }
            Debug.WriteLine("Found {0}", pb);
            m_puzzle.PlaceBlock(pb.m_block, pb.m_position.x, pb.m_position.y, pb.m_varient);
            m_highlightPositions.Clear();
            DrawBoard(PuzzleCanvas, m_puzzle);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// If cells in m_highlightPositions forms one block, add block in m_puzzle, and draw the block. Otherwise, do nothing.
        /// </summary>
        /// <returns>PlacedBlock if block is found, null otherwise</returns>
        private PlacedBlock FindAndHighlightBlockMaybe()
        {
            if (m_highlightPositions.Count == 0)
            {
                return(null);
            }
            int minX = m_highlightPositions.Select(pos => pos.x).Min();
            int minY = m_highlightPositions.Select(pos => pos.y).Min();
            int maxX = m_highlightPositions.Select(pos => pos.x).Max();
            int maxY = m_highlightPositions.Select(pos => pos.y).Max();

            if (maxX - minX > 3 || maxY - minY > 3)
            {
                return(null);
            }
            int[,] hlBlockIndex = new int[4, 4];
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (m_highlightPositions.Contains(new Position(minX + i, minY + j)))
                    {
                        hlBlockIndex[i, j] = 1;
                    }
                }
            }
            foreach (string name in BlockFactory.m_blockNames)
            {
                Block b = BlockFactory.GetBlockByName(name);
                for (int i = 0; i < b.m_varients.Count; i++)
                {
                    if (BlockFactory.ArrayEquals(b.m_varients[i], hlBlockIndex))
                    {
                        PlacedBlock pb = new PlacedBlock(b, i, minX, minY);
                        return(pb);
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 9
0
 public void DeleteRow(int y)
 {
     GameObject.Find("GameController").GetComponent <scoreManager> ().UpdateScore(100);         //add score, accomodate score modifer block
     for (int x = 0; x < 10; x++)
     {
         /*    Destroy(gameGridCol[x].row[y].gameObject);
          *  gameGridCol[x].row[y] = null;*/
         for (int i = 0; i < blockList.Count; i++)
         {
             if (blockList[i].yPos == y)
             {
                 //Debug.Log ("Destroying block at: " + blockList[i].xPos + "," + blockList[i].yPos);
                 Grid.grid [blockList[i].xPos, blockList[i].yPos] = null;
                 PlacedBlock removeMe = blockList [i];
                 //Debug.Log (removeMe.transform.childCount);
                 Destroy(removeMe.gameObject);
                 blockList.Remove(removeMe);
                 i--;
             }
         }
     }
     //Debug.Log ("Cleared Row: " + y);
 }
Ejemplo n.º 10
0
    private void OnPlacedBlock(PlacedBlock msg)
    {
        Point3 worldCoord = msg.worldCoord;
        Voxel  block      = ChunkManager.GetBlock(worldCoord);

        if (block == null)
        {
            block = ChunkManager
                    .AddChunk(worldCoord)
                    .AddBlock(worldCoord.ToLocalBlockCoord());
        }

        int hash = ChunkManager.GetHash(worldCoord.ToChunkCoord());

        block.SetBlockType(msg.type);

        // Get neighbours, pass to surface manager
        Voxel[] neighbours = GetNeighbours(worldCoord);

        // Lookup mesh name and rotation based on neighbours
        BlockInfo bi =
            SurfaceManager.GetSurface(
                SurfaceManager.GetID(neighbours));

        block.SetRotation(bi.rotation);

        for (int i = 0; i < neighbours.Length; i++)
        {
            if (neighbours[i] == null)
            {
                continue;
            }
            UpdateNeighbour(neighbours[i], worldCoord + checkSides[i]);
        }

        PlaceBlock(msg.worldCoord, hash, bi);
    }