Ejemplo n.º 1
0
        private void strpBoardType_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem strp = (ToolStripMenuItem)sender;

            if (strp.Checked)
            {
                return;
            }
            try
            {
                gameBoard.RemovePiece(this.Controls);
            }
            catch { }

            BoardOption option = gameBoard.Option;

            gameBoard = new Board(option);
            string str = strp.Name;

            str = str.Substring(13, (str.Length == 16) ? 1 : 2);
            int num = Convert.ToInt32(str);

            gameBoard.Type = (BoardType)(num - 2);

            strpBoardType_Change();
            this.strpNew_Click(sender, e);
        }
Ejemplo n.º 2
0
        private BoardOption PickBoardOption()
        {
            bool        isValidOption = false;
            BoardOption boardOption   = BoardOption.Flag;

            while (!isValidOption)
            {
                OptionHelper.PrintOption('r', "Reveal Tile");
                OptionHelper.PrintOption('f', "Flag Tile");
                string input  = Console.ReadLine();
                bool   isChar = char.TryParse(input.Trim(), out char inputChar);
                if (isChar)
                {
                    if (char.ToUpper(inputChar) == 'R')
                    {
                        isValidOption = true;
                        boardOption   = BoardOption.Reveal;
                    }
                    else if (char.ToUpper(inputChar) == 'F')
                    {
                        isValidOption = true;
                        boardOption   = BoardOption.Flag;
                    }
                }
                if (!isValidOption)
                {
                    Console.WriteLine("You didn't pick one of the listed options. Please try again.");
                }
            }

            return(boardOption);
        }
Ejemplo n.º 3
0
 public void ChangeOption(BoardOption opt)
 {
     if (CurrentOption == BoardOption.NO_VAL)
     {
         CurrentOption = opt;
     }
     Ref.sprite    = Options[(int)opt];
     CurrentOption = opt;
     GetComponent <Button>().enabled = false;
 }
Ejemplo n.º 4
0
        private void RequestUserInput()
        {
            BoardOption boardOption = PickBoardOption();
            int         inputRow    = InputLoop("Enter row number (Vertical):");
            int         inputColumn = InputLoop("Enter Column Number (Horizontal): ");

            lastRow    = inputRow;
            lastColumn = inputColumn;
            // Takeaway 1 from inputs because the board array is zero-indexed
            HandlePositionInput(inputRow - 1, inputColumn - 1, boardOption);
        }
Ejemplo n.º 5
0
        private void HandlePositionInput(int rowNumber, int columnNumber, BoardOption boardOption)
        {
            switch (boardOption)
            {
            case BoardOption.Flag:
                lastTileChange = gameBoard.FlagTile(rowNumber, columnNumber);
                break;

            case BoardOption.Reveal:
                lastTileChange = gameBoard.RevealTile(rowNumber, columnNumber);
                break;
            }
        }
Ejemplo n.º 6
0
        public bool PlaceMove(int x, int y, BoardOption opt)
        {
            //Debug.Log("Model Cord:" + x + ", " + y);
            if (BoardData[y, x] == BoardOption.NO_VAL)
            {
                BoardData[y, x] = opt;
                currentPlayer   = (opt == BoardOption.X)? PlayerIndex.PLAYER1:PlayerIndex.PLAYER2;
                //printBoardDebug();


                return(true);
            }

            return(false);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Finds the smallest or largest chessboard in the image. Returns null if no image was found.
        /// </summary>
        public Rectangle?FindChessboard(BoardOption option)
        {
            Rectangle[] chessboards = FindChessboards();
            if (chessboards.Length == 0)
            {
                return(null);
            }

            IOrderedEnumerable <Rectangle> sizeSortedChessboards = chessboards.OrderByDescending(b => b.Width + b.Height);

            return(option switch
            {
                BoardOption.Largest => sizeSortedChessboards.First(),
                BoardOption.Smallest => sizeSortedChessboards.Last(),
                _ => throw new ArgumentException("Invalid board option."),
            });
Ejemplo n.º 8
0
        public WinnerStripeIndex GetWinMove()
        {
            BoardOption temp = (currentPlayer == PlayerIndex.PLAYER1) ? BoardOption.X : BoardOption.O;

            //check rows
            if (getBoardValue(0, 0) == temp && getBoardValue(0, 1) == temp && getBoardValue(0, 2) == temp)
            {
                return(WinnerStripeIndex.HT);
            }
            if (getBoardValue(1, 0) == temp && getBoardValue(1, 1) == temp && getBoardValue(1, 2) == temp)
            {
                return(WinnerStripeIndex.HC);
            }
            if (getBoardValue(2, 0) == temp && getBoardValue(2, 1) == temp && getBoardValue(2, 2) == temp)
            {
                return(WinnerStripeIndex.HB);
            }

            //check colums
            if (getBoardValue(0, 0) == temp && getBoardValue(1, 0) == temp && getBoardValue(2, 0) == temp)
            {
                return(WinnerStripeIndex.VL);
            }
            if (getBoardValue(0, 1) == temp && getBoardValue(1, 1) == temp && getBoardValue(2, 1) == temp)
            {
                return(WinnerStripeIndex.VC);
            }
            if (getBoardValue(0, 2) == temp && getBoardValue(1, 2) == temp && getBoardValue(2, 2) == temp)
            {
                return(WinnerStripeIndex.VR);
            }

            //check diagonals
            if (getBoardValue(0, 0) == temp && getBoardValue(1, 1) == temp && getBoardValue(2, 2) == temp)
            {
                return(WinnerStripeIndex.DL);
            }
            if (getBoardValue(0, 2) == temp && getBoardValue(1, 1) == temp && getBoardValue(2, 0) == temp)
            {
                return(WinnerStripeIndex.DR);
            }

            return(WinnerStripeIndex.NULL);
        }
Ejemplo n.º 9
0
 private void ModifyOptionView(int x, int y, BoardOption opt)
 {
     GridRef[x, y].GetComponent <OptionController>().ChangeOption(opt);
 }
Ejemplo n.º 10
0
        private BoardOption initBoard()
        {
            StreamReader sr          = null;
            string       tmp         = "";
            BoardOption  boardOption = new BoardOption();

            try
            {
                sr = new StreamReader("option.ini");
            }
            catch
            {
                OptionSaver();
                sr = new StreamReader("option.ini");
            }

            while (true)
            {
                tmp = sr.ReadLine();
                if (tmp.Length > 7)
                {
                    switch (tmp.Substring(3, 4))
                    {
                    //PuzzleImage//
                    case "name":
                        boardOption.puzzleImage.name = tmp.Substring(8, tmp.Length - 8);
                        break;

                    case "desc":
                        boardOption.puzzleImage.desc = tmp.Substring(8, tmp.Length - 8);
                        break;

                    case "Type":
                        boardOption.puzzleImage.boardType = this.ExtractToBoardType(tmp.Substring(8, tmp.Length - 8));
                        break;

                    case "file":
                        boardOption.puzzleImage.file = tmp.Substring(8, tmp.Length - 8);
                        break;

                    //BoardOption//
                    case "prev":
                        boardOption.previewHint = (tmp.Substring(8, tmp.Length - 8) == "True") ? true : false;
                        break;

                    case "draw":
                        boardOption.drawNum = (tmp.Substring(8, tmp.Length - 8) == "True") ? true : false;
                        break;

                    case "dTyp":
                        boardOption.drawNumType = this.DrawNumTypeChange(tmp.Substring(8, tmp.Length - 8));
                        break;

                    case "font":
                        boardOption.fontColor = this.ColorChange(tmp.Substring(8, tmp.Length - 8));
                        break;

                    case "igno":
                        boardOption.ignoreBoardType = (tmp.Substring(8, tmp.Length - 8) == "True") ? true : false;
                        break;
                    }
                }
                if (sr.EndOfStream)
                {
                    break;
                }
            }
            sr.Close();
            boardOption.puzzleImage.image = Image.FromFile(boardOption.puzzleImage.file);

            return(boardOption);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// 생성자: 보드타입을 사용자가 정의하고 세팅합니다.
 /// </summary>
 /// <param name="type">BoardType 형태의 열거형</param>
 public Board(BoardType type)
 {
     this.boardOption = initBoard();
     this.boardOption.puzzleImage.boardType = type;
     this.setPieceWidth();
 }
Ejemplo n.º 12
0
 /// <summary>
 /// 생성자: 보드타입을 Type4x4를 기본으로 잡고 세팅합니다.
 /// </summary>
 public Board()
 {
     this.boardOption = initBoard();
     //this.Type = BoardType.Type4x4;
     this.setPieceWidth();
 }
Ejemplo n.º 13
0
 /// <summary>
 /// 현재 퍼즐 보드의 옵션을 저장합니다.
 /// </summary>
 /// <param name="option">사용자 임의의 BoardOption 형태의 구조체</param>
 public void OptionSaver(BoardOption option)
 {
     option_ini_Creator(option.puzzleImage.name, option.puzzleImage.desc, option.puzzleImage.boardType,
                        option.puzzleImage.file, option.previewHint, option.drawNum,
                        option.drawNumType, this.ColorChange(option.fontColor), option.ignoreBoardType);
 }
Ejemplo n.º 14
0
        private static BoardDetail ParseDetails(string json)
        {
            var boardDetail = new BoardDetail();

            string[] lines = json.Replace("\"", "").Split('\n');

            BoardOption      boardOption      = null;
            BoardOptionValue boardOptionValue = null;

            foreach (string line in lines)
            {
                var cleanLine = line.Trim();

                if (cleanLine.StartsWith("option: "))
                {
                    boardOption        = new BoardOption();
                    boardOption.Option = cleanLine.Replace("option: ", "").Replace(",", "").Replace(",", "");
                }
                else if (cleanLine.StartsWith("option_label: "))
                {
                    if (boardOption != null)
                    {
                        boardOption.Option_Label = cleanLine.Replace("option_label: ", "").Replace(",", "");
                    }
                }
                else if (cleanLine.StartsWith("value: "))
                {
                    boardOptionValue       = new BoardOptionValue();
                    boardOptionValue.Value = cleanLine.Replace("value: ", "").Replace(",", "").Replace(",", "");
                }
                else if (cleanLine.StartsWith("value_label: "))
                {
                    if (boardOptionValue != null)
                    {
                        boardOptionValue.Value_Label = cleanLine.Replace("value_label: ", "").Replace(",", "");
                    }
                }
                else if (cleanLine.StartsWith("selected: "))
                {
                    if (boardOptionValue != null)
                    {
                        boardOptionValue.Selected = true;
                    }
                }
                else if (cleanLine.StartsWith("}"))
                {
                    if (boardOptionValue != null)
                    {
                        boardOption?.Values.Add(boardOptionValue);
                        boardOptionValue = null;
                    }
                    else if (boardOption != null)
                    {
                        boardDetail.Options.Add(boardOption);
                        boardOption = null;
                    }
                }
            }

            return(boardDetail);
        }
Ejemplo n.º 15
0
 public void setBoard(BoardOption option)
 {
     gameBoard.Option = option;
 }
Ejemplo n.º 16
0
 public Board(BoardOption option)
 {
     this.boardOption = option;
     this.setPieceWidth();
 }
Ejemplo n.º 17
0
 public void Init()
 {
     CurrentOption = BoardOption.NO_VAL;
     Ref.sprite    = Options[(int)BoardOption.NO_VAL];
     GetComponent <Button>().enabled = true;
 }