Exemplo n.º 1
0
        } //Chord 함수 종료

        //게임 오버처리. 지뢰를 밟은 셀의 좌표를 가져온다.
        private void ProcessGameOver(int mineX, int mineY)
        {
            fieldState = ConstantsPack.gameState.gameState_GameOver;
            //밟은 셀은 빨간 지뢰 표시
            fieldGrid[mineY, mineX].openValue = (sbyte)ConstantsPack.openCellValue.cellValue_minePressed;
            //나머지 셀들 중 깃발 표시된 셀을 체크, 지뢰가 없었다면 X 표시
            int x = 0, y = 0;

            for (y = 0; y < fieldHeight; ++y)
            {
                for (x = 0; x < fieldWidth; ++x)
                {
                    if ((fieldGrid[y, x].closeValue == (sbyte)ConstantsPack.closeCellValue.cellValue_closed ||
                         fieldGrid[y, x].closeValue == (sbyte)ConstantsPack.closeCellValue.cellValue_dontknow) &&
                        fieldGrid[y, x].openValue == (sbyte)ConstantsPack.openCellValue.cellValue_mine)
                    {
                        fieldGrid[y, x].closeValue = (sbyte)ConstantsPack.closeCellValue.cellValue_opened;
                    }
                    else if (fieldGrid[y, x].closeValue == (sbyte)ConstantsPack.closeCellValue.cellValue_flaged &&
                             fieldGrid[y, x].openValue != (sbyte)ConstantsPack.openCellValue.cellValue_mine)
                    {
                        fieldGrid[y, x].closeValue = (sbyte)ConstantsPack.closeCellValue.cellValue_opened;
                        fieldGrid[y, x].openValue  = (sbyte)ConstantsPack.openCellValue.cellValue_flagFailed;
                    }
                }
            }
        } //ProcessGameOver 함수 종료
Exemplo n.º 2
0
        //주어진 필드의 크기와 지뢰 갯수로 필드 생성
        public void InitMineField(int width = ConstantsPack.minWidthCells, int height = ConstantsPack.minHeightCells, int mines = ConstantsPack.minMines)
        {
            fieldState      = ConstantsPack.gameState.gameState_Init;
            fieldWidth      = width; fieldHeight = height; fieldMines = mines;
            remainSafeCells = (fieldWidth * fieldHeight) - fieldMines;
            fieldGrid       = new FieldCell[fieldHeight, fieldWidth];

            PcgRandom randObj = new PcgRandom();

            //주어진 지뢰 갯수로 필드에 지뢰를 임의로 배치시킨다.
            int remainMines = fieldMines;

            while (remainMines > 0)
            {
                int setX = randObj.Next(0, fieldWidth);
                int setY = randObj.Next(0, fieldHeight);

                if (fieldGrid[setY, setX].openValue == (sbyte)ConstantsPack.openCellValue.cellValue_mine)
                {
                    continue;
                }

                fieldGrid[setY, setX].openValue = (sbyte)ConstantsPack.openCellValue.cellValue_mine;
                remainMines--;
            }

            //배치가 끝나면 빈 칸들을 탐색하여 주변 지뢰가 있으면 그 갯수를 체크한다.
            int x = 0, y = 0, k = 0;

            for (y = 0; y < fieldHeight; ++y)
            {
                for (x = 0; x < fieldWidth; ++x)
                {
                    FieldCell curCell = fieldGrid[y, x];
                    if (curCell.openValue == (sbyte)ConstantsPack.openCellValue.cellValue_blank)
                    {
                        //빈 칸 주변 8셀에 지뢰가 있는지 체크하여 카운팅
                        sbyte totalAdjMines = 0;
                        for (k = 0; k < 8; ++k)
                        {
                            int adjX = x + adjDx[k], adjY = y + adjDy[k];
                            if (!CellRangeCheck(adjX, adjY))
                            {
                                continue;
                            }
                            if (fieldGrid[adjY, adjX].openValue == (sbyte)ConstantsPack.openCellValue.cellValue_mine)
                            {
                                totalAdjMines++;
                            }
                        }
                        //카운팅된 값을 셀에 대입
                        fieldGrid[y, x].openValue = totalAdjMines;
                    }
                }
            }

            //필드 생성 끝나면 인게임 상태로 전환
            fieldState = ConstantsPack.gameState.gameState_InGame;
        } //InitMineField 함수 끝
Exemplo n.º 3
0
        } //ProcessGameOver 함수 종료

        //게임 클리어 체크 (업데이트 루프 내에서 호출)
        private void ProcessGameClear()
        {
            if (fieldState == ConstantsPack.gameState.gameState_InGame &&
                remainSafeCells <= 0)
            {
                fieldState = ConstantsPack.gameState.gameState_Clear;
                //열리지 않은 셀들 다 열어준다. 어차피 지뢰만 남았음.
                int x = 0, y = 0;
                for (y = 0; y < fieldHeight; ++y)
                {
                    for (x = 0; x < fieldWidth; ++x)
                    {
                        if (fieldGrid[y, x].closeValue != (sbyte)ConstantsPack.closeCellValue.cellValue_opened)
                        {
                            fieldGrid[y, x].closeValue = (sbyte)ConstantsPack.closeCellValue.cellValue_opened;
                        }
                    }
                }
            }
        } //ProcessGameClear 함수 종료