public List <CellOption> GetSortedList(List <CellOption> inputOptionList) { List <CellOption> myCellOptions = new List <CellOption>(); int numOptions = inputOptionList.Count; for (int i = 0; i < numOptions; i++) { int highestValue = 99; CellOption lowestValueOption = null; foreach (CellOption co in inputOptionList) { CellData cd = co.GetCellData(); if (cd != null) { if ((cd.cellValue < highestValue) && !myCellOptions.Contains(co)) { lowestValueOption = co; highestValue = cd.cellValue; } } } myCellOptions.Add(lowestValueOption); } return(myCellOptions); }
public void MarkCell(CellOption playerSymbol) { if (IsEmpty()) { cellState = playerSymbol; } }
public GameBoard() { BOARD_SIZE = _minimuBoardSize; _matchLength = _minimuBoardSize; CurrentSymbol = CellOption.CrossCell; _moveStack = new Stack <Cell>(); InitializeBoard(); }
public void MarkCell(CellOption playerSymbol, int cNum) { var getCoord = GetCoordinates(cNum); Board[getCoord.Key, getCoord.Value].MarkCell(playerSymbol); RecordMove(cNum); ChangePlayers(); }
public CellOption GetOpponentSymbol(CellOption currentPlayerSymbol) { if (currentPlayerSymbol == CellOption.CrossCell) { return(CellOption.NoughtCell); } else { return(CellOption.CrossCell); } }
public GameBoard(int size) { BOARD_SIZE = size; _matchLength = _minimuBoardSize; if (BOARD_SIZE > _minimuBoardSize) { _matchLength = _minimuBoardSize + 1; } CurrentSymbol = CellOption.CrossCell; _moveStack = new Stack <Cell>(); InitializeBoard(); }
void Start() { if (FindObjectOfType <BoardEditor>() != null) { cellOptionList = new List <CellOption>(); optionSort = GetComponent <LibraryOptionSort>(); libraryCanvasGroup = libraryTransform.GetComponent <CanvasGroup>(); informationCanvasGroup = informationTransform.GetComponent <CanvasGroup>(); informationPanel = GetComponentInChildren <InformationPanel>(); boardEditor = GetComponent <BoardEditor>(); EnableInformation(false); int numCells = allCells.Length; for (int i = 0; i < numCells; i++) { CellOption cellOption = Instantiate(optionPrefab, libraryTransform); if ((allCells.Length > i) && (allCells[i] != null)) { CellData cellData = allCells[i]; cellOption.LoadCell(cellData); cellOptionList.Add(cellOption); } } /// sort options by cell value if (optionSort != null) { List <CellOption> sortedOptionList = new List <CellOption>(); sortedOptionList = optionSort.GetSortedList(cellOptionList); foreach (CellOption co in cellOptionList) { co.transform.SetParent(null); } foreach (CellOption sortedOption in sortedOptionList) { sortedOption.transform.SetParent(libraryTransform); } cellOptionList = sortedOptionList; } } }
public void ResetCell() { cellState = CellOption.EmptyCell; }
public Cell(int row, int col) { Row = row; Col = col; cellState = CellOption.EmptyCell; }
public void ChangePlayers() { CurrentSymbol = (CurrentSymbol == CellOption.CrossCell ? CellOption.NoughtCell : CellOption.CrossCell); }
public virtual IPlayer GetPlayer(CellOption symbol) { return(players.SingleOrDefault(x => x.PreferredSymbol == symbol)); }
/// <summary> /// Initializes Maze and World /// </summary> public static void SetupMaze() { int interiorScale = -1; int boundScale = -1; int openingScale = -1; int[] dInfo; GenOption genOption = GetGenOption(); CellOption cellOption = GetCellOption(); //Get input Console.WriteLine("Please input:"); switch (genOption) { case GenOption.userDefined: dInfo = DSizeAndCountByInput(); break; case GenOption.defineDNum: dInfo = InputDCount(); break; case GenOption.maxCellsDNum: dInfo = InputMaxCellsAndCount(); break; case GenOption.maxCells: dInfo = InputMaxCellsAndGenCount(); break; default: dInfo = GenDCountAndSizes(); break; } if (cellOption == CellOption.predefined) { interiorScale = DefaultInteriorScale; boundScale = DefaultBoundScale; openingScale = DefaultOpeningScale; goto Initialize; } //Get interior scale while (interiorScale < 2) { try { Console.Write(" Cell Interior Scale: "); interiorScale = Convert.ToInt32(Console.ReadLine()); if (interiorScale < 2) { Console.WriteLine("Please input an integer greater than 1."); } } catch (FormatException e) { Console.WriteLine("Please input an integer greater than 1."); } } //Get bound scale while (boundScale <= 0) { try { Console.Write(" Cell Bound Scale: "); boundScale = Convert.ToInt32(Console.ReadLine()); if (boundScale <= 0) { Console.WriteLine("Please input a positive numerical value."); } } catch (FormatException e) { Console.WriteLine("Please input a positive numerical value."); } } //Get opening scale while (openingScale <= 0) { try { Console.Write(" Cell Opening Scale "); openingScale = Convert.ToInt32(Console.ReadLine()); if (openingScale <= 0) { Console.WriteLine("Please input a positive numerical value."); } } catch (FormatException e) { Console.WriteLine("Please input a positive numerical value."); } } Initialize: //Initialize maze, or world, or both, depending World.Initialize(dInfo, interiorScale, boundScale, openingScale); //Clear and Wait to start Console.Clear(); Console.WriteLine("Press [enter] to begin.\n"); while (ConsoleKey.Enter != Console.ReadKey().Key) { //Spinning while input not [enter] } }
/// <summary> /// Gets cell scale option from user /// </summary> /// <returns>Cell scale option</returns> public static CellOption GetCellOption() { CellOption _selected = CellOption.predefined; Console.Clear(); Console.ResetColor(); /*Console.SetCursorPosition(0, 0); * Console.Write("Choose cell scaling method:"); * Console.SetCursorPosition(0, OptionLinesDisplayed + 2); * Console.Write("Use arrow keys to select option. [Enter] to confirm selection.");*/ while (true) { Console.Clear(); Console.SetCursorPosition(0, 0); Console.Write("Choose cell scaling method:"); Console.SetCursorPosition(0, OptionLinesDisplayed + 2); Console.Write("Use arrow keys to select option. [Enter] to confirm selection."); //Write Options int _start = (CellOptionCount - 1) - (int)_selected < OptionLinesDisplayed ? ((CellOptionCount - 1) - OptionLinesDisplayed < 0 ? 0 : (CellOptionCount - 1) - OptionLinesDisplayed) : (int)_selected; int _end = (CellOptionCount - 1) - (int)_selected > OptionLinesDisplayed ? (int)_selected + OptionLinesDisplayed : (CellOptionCount - 1); int _lineCount = 0; for (int _i = (int)_selected; _i < ((int)_selected + OptionLinesDisplayed < CellOptionCount ? (int)_selected + OptionLinesDisplayed : CellOptionCount); _i++) { if (_i == (int)_selected) { Console.ForegroundColor = HighlightFG; Console.BackgroundColor = HighlightBG; } else { Console.ResetColor(); } Console.SetCursorPosition(0, 1 + _i - (int)_selected); Console.Write(" {0}", CellOptionString[_i]); _lineCount++; Console.ResetColor(); if (_lineCount >= OptionLinesDisplayed) { goto Input; } /*for (int _j = 0; _j <= CellOptionString[_i].Length / (Console.BufferWidth - 6); _j++) * { * Console.SetCursorPosition(0, 1 + _i + _j - (int)_selected); * Console.Write(" {0}", CellOptionString[_i].Substring(_j * (Console.BufferWidth - 6), (Console.BufferWidth - 6))); * _lineCount++; * if (_lineCount >= OptionLinesDisplayed) * goto Input; * }*/ } Input: //Get input switch (Console.ReadKey().Key) { case ConsoleKey.Enter: goto Done; case ConsoleKey.UpArrow: if ((int)_selected != 0) { _selected = (CellOption)((int)_selected - 1); } break; case ConsoleKey.DownArrow: if ((int)_selected != CellOptionCount - 1) { _selected = (CellOption)((int)_selected + 1); } break; } } Done: Console.Clear(); Console.ResetColor(); return(_selected); }