Exemplo n.º 1
0
 /// <summary>
 /// Blank Block Constructor
 /// </summary>
 /// <param name="isRandom"></param>
 public Block()
 {
     cells = new Cell[ROW_SIZE, COL_SIZE];
     for (int i = 0; i < ROW_SIZE; i++)
     {
         for (int j = 0; j < COL_SIZE; j++)
         {
             cells[i, j] = new BlankCell();
         }
     }
 }
Exemplo n.º 2
0
        // score table for chain removal
        // constructor: 1. initialize board with blank cells
        public Pile()
        {
            board = new Cell[ROW_SIZE+3, COL_SIZE];

            for (int i = 0; i < ROW_SIZE+3; i++)
            {
                for (int j = 0; j < COL_SIZE; j++)
                {
                    board[i, j] = new BlankCell();
                }
            }
        }
Exemplo n.º 3
0
        public Block(int blockCellCnt, int colorCnt)
        {
            if (blockCellCnt < 1 || ROW_SIZE * COL_SIZE < blockCellCnt)
            {
                throw new Exception("Can't MakeRandomBlock");
            }

            cells = new Cell[ROW_SIZE, COL_SIZE];

            int cnt = COL_SIZE * ROW_SIZE - 1;
            int remain = blockCellCnt - 1;

            int numberOfColors = 2;
            CellColor[] blockColorCand = new CellColor[numberOfColors];

            for (int i = 0; i < numberOfColors; i++)
            {
                bool dupFlg;
                do
                {
                    dupFlg = false;
                    blockColorCand[i] = (CellColor)Core.Random.rand(1, colorCnt + 1);
                    for (int j = 0; j < i; j++)
                    {
                        if (blockColorCand[i] == blockColorCand[j])
                        {
                            dupFlg = true;
                        }
                    }
                } while (dupFlg);
            }
            for (int i = 0; i < ROW_SIZE; i++)
            {
                for (int j = 0; j < COL_SIZE; j++)
                {
                    if (i == ROW_SIZE / 2 && j == COL_SIZE / 2)
                    {
                        cells[i, j] = new BlockCell(blockColorCand[Core.Random.rand(0, numberOfColors)]);
                        continue;
                    }
                    if (Core.Random.rand(cnt) < remain)
                    {
                        cells[i, j] = new BlockCell(blockColorCand[Core.Random.rand(0, numberOfColors)]);
                        remain--;
                    }
                    else
                    {
                        cells[i, j] = new BlankCell();
                    }
                    cnt--;
                }
            }
        }
Exemplo n.º 4
0
 private void RemoveBlock(int row, int col, Block block)
 {
     for (int i = 0; i < Block.ROW_SIZE; i++)
     {
         for (int j = 0; j < Block.COL_SIZE; j++)
         {
             if (!(block.IsEmpty(i,j)))
             {
                 board[row + i, col + j] = new BlankCell();
             }
         }
     }
 }
Exemplo n.º 5
0
        private bool CalcDrop(List<Animation.Drop> dropCells, Cell[,] board)
        {
            //(1) calculate drops
            bool retVal = false;
            bool[,] visit = new bool[ROW_SIZE + 3, COL_SIZE];//flood fill color array
            bool flgDown; // flag for gravity down

            do
            {
                flgDown = false;
                for (int i = 0; i < ROW_SIZE + 3; i++)
                {
                    for (int j = 0; j < COL_SIZE; j++)
                    {
                        visit[i, j] = false;
                    }
                }

                for (int j = 0; j < COL_SIZE; j++)
                {
                    FloodFill(0, j, visit, board[0, j].Color, board);
                }
                for (int i = 1; i < ROW_SIZE + 3; i++)
                {
                    for (int j = 0; j < COL_SIZE; j++)
                    {
                        if (visit[i, j] == false && ((board[i, j].IsEmpty) == false))
                        {
                            int k;
                            flgDown = true;
                            board[i - 1, j] = board[i, j];
                            board[i, j] = new BlankCell();

                            for (k = 0; k < dropCells.Count; k++)
                            {
                                if (dropCells[k].rowAfter == i && dropCells[k].col == j)
                                {
                                    Animation.Drop newdrop = new Animation.Drop();
                                    newdrop.rowBefore = dropCells[k].rowBefore;
                                    newdrop.rowAfter = i - 1;
                                    newdrop.col = j;
                                    dropCells[k] = newdrop;
                                    break;
                                }
                            }
                            if (k >= dropCells.Count)
                            {
                                Animation.Drop newdrop = new Animation.Drop();
                                newdrop.rowBefore = i;
                                newdrop.rowAfter = i - 1;
                                newdrop.col = j;
                                dropCells.Add(newdrop);
                            }
                        }
                    }
                }
                if (flgDown)
                {
                    retVal = true;
                }
            } while (flgDown);
            return retVal;
        }
Exemplo n.º 6
0
        public ChainResult SimulateChain()
        {
            ChainResult chainResult = new ChainResult();
            //initialize
            chainResult.SetOriginalBoard(board);
            chainResult.score = 0;

            bool flgContinue = false;
            do
            {
                List<int> removedLines = new List<int>();
                List<Animation.Drop> dropCells = new List<Animation.Drop>();

                flgContinue = CalcDrop(dropCells, board);
                //DONE : move all blocks down & add it to drop cells list

                //(2) clear full line
                for (int i = 0; i < ROW_SIZE + 3; i++)
                {
                    int cnt = 0;

                    for (int j = 0; j < COL_SIZE; j++)
                        if (IsCellEmpty(i, j))
                            cnt++;

                    if (cnt == 0)
                    {
                        for (int j = 0; j < COL_SIZE; j++)
                            board[i, j] = new BlankCell();
                        removedLines.Add(i);
                        flgContinue = true;
                    }
                }

                chainResult.Add(new Animation.EraseDropPair(removedLines, dropCells));
                //DONE : combine removedLines & drop cells list to make EraseDropPair
                //DONE : chainResult.animation 에 EraseDropPair 추가하기.

                chainResult.GetScore(removedLines.Count);
                //DONE : calculate score
            } while (flgContinue);

            return chainResult;
        }
Exemplo n.º 7
0
        /// <summary>
        /// 애니메이션 세팅.
        /// </summary>
        /// <param name="timeElapsed">애니메이션 시작 후 경과 시간(단위: 초)</param>
        /// <returns>returns true if animation ended</returns>
        public bool SetElapsedTime(double timeElapsed)
        {
            lock (thisLock)
            {
                rowDict = new Dictionary<Tuple<int, int>, double>();
                colorDict = new Dictionary<Tuple<int, int>, CellColor>();
                Cell[,] aniBoard = (Cell[,])copiedBoard.Clone();
                Cell[,] tmpBoard = (Cell[,])copiedBoard.Clone();
                foreach (Animation.EraseDropPair edp in animation)
                {
                    double largestGap = 0;
                    foreach (Animation.Drop drop in edp.dropCellList)
                    {
                        if (drop.rowBefore - drop.rowAfter > largestGap)
                        {
                            largestGap = drop.rowBefore - drop.rowAfter;
                        }
                    }
                    double timeSpan = GetTimeDown(largestGap);
                    if (timeSpan >= timeElapsed)
                    {
                        //drop 이전의 상태로 세팅
                        for (int i = 0; i < aniBoard.GetLength(0); i++)
                        {
                            for (int j = 0; j < aniBoard.GetLength(1); j++)
                            {
                                Tuple<int, int> pos = new Tuple<int, int>(i, j);
                                rowDict[pos] = i;
                                colorDict[pos] = aniBoard[i, j].Color;
                            }
                        }
                        //drop하는 도중의 위치를 시뮬레이트
                        foreach (Animation.Drop drop in edp.dropCellList)
                        {
                            Tuple<int, int> pos = new Tuple<int, int>(drop.rowBefore, drop.col);
                            double dist = drop.rowBefore - drop.rowAfter;
                            if (GetTimeDown(dist) >= timeElapsed)
                            {
                                // 아직 떨어지는 중
                                rowDict[pos] = drop.rowBefore - GetDistDown(timeElapsed);
                            }
                            else
                            {
                                // 완전히 떨어짐
                                rowDict[pos] = drop.rowAfter;
                            }
                        }
                        return false;
                    }
                    timeElapsed -= timeSpan;

                    //initialize temporary board
                    for (int i = 0; i < aniBoard.GetLength(0); i++)
                    {
                        for (int j = 0; j < aniBoard.GetLength(1); j++)
                        {
                            tmpBoard[i, j] = new BlankCell();
                        }
                    }
                    //moved cell to temp board
                    foreach (Animation.Drop drop in edp.dropCellList)
                    {
                        tmpBoard[drop.rowAfter, drop.col] = aniBoard[drop.rowBefore, drop.col];
                        aniBoard[drop.rowBefore, drop.col] = new BlankCell();
                    }
                    // store moved cell into original board
                    for (int i = 0; i < aniBoard.GetLength(0); i++)
                    {
                        for (int j = 0; j < aniBoard.GetLength(1); j++)
                        {
                            if (!(tmpBoard[i, j].IsEmpty))
                            {
                                //not blank cell
                                aniBoard[i, j] = tmpBoard[i, j];
                            }
                        }
                    }
                    //TODO: calculate bomb time & remove lines
                    if (edp.erasedLineList.Count > 0)
                    {
                        timeSpan = 0.5;
                    }
                    else
                    {
                        timeSpan = 0;
                    }
                    if (timeSpan >= timeElapsed)
                    {
                        for (int i = 0; i < aniBoard.GetLength(0); i++)
                        {
                            for (int j = 0; j < aniBoard.GetLength(1); j++)
                            {
                                Tuple<int, int> pos = new Tuple<int, int>(i, j);
                                rowDict[pos] = i;
                                colorDict[pos] = aniBoard[i, j].Color;
                            }
                        }
                        foreach (int i in edp.erasedLineList)
                        {
                            for (int j = 0; j < aniBoard.GetLength(1); j++)
                            {
                                Tuple<int, int> pos = new Tuple<int, int>(i, j);
                                if (((int)(timeElapsed / 0.06)) % 2 == 1)
                                {
                                    colorDict[pos] = aniBoard[i, j].Color;
                                }
                                else
                                {
                                    colorDict[pos] = CellColor.transparent;
                                }
                            }
                        }
                        return false;
                    }
                    timeElapsed -= timeSpan;
                    foreach (int i in edp.erasedLineList)
                    {
                        for (int j = 0; j < aniBoard.GetLength(1); j++)
                        {
                            aniBoard[i, j] = new BlankCell();
                        }
                    }
                }
                for (int i = 0; i < aniBoard.GetLength(0); i++)
                {
                    for (int j = 0; j < aniBoard.GetLength(1); j++)
                    {
                        Tuple<int, int> pos = new Tuple<int, int>(i, j);
                        rowDict[pos] = i;
                        colorDict[pos] = aniBoard[i, j].Color;
                    }
                }
                return true;
            }
        }