static void Main() { Tile[,] gameBoard = new Tile[Constants.boardSize, Constants.boardSize]; var gameSettings = new Settings(); Board.InitializeBoard(gameBoard); while (!gameSettings.GameOver) { gameBoard = Action.SetPossibleActions(gameBoard); gameBoard = Turn.StartTurn(gameBoard, gameSettings.PlayerTurn); Board.RenderBoard(gameBoard); gameSettings.GameOver = Board.CheckGameOver(gameBoard); gameSettings.PlayerTurn = Turn.ChangeTurn(gameSettings.PlayerTurn); } Console.ReadLine(); }
static void Main(string[] args) { Board gameBoard = new Board(); bool game = true; bool initial; bool target; string cPair; string newGame = " "; string temp; while (game) { initial = false; target = false; while (!initial) { PrintBoard(gameBoard); gameBoard.GetRequiredJumps_Moves(); Console.WriteLine(gameBoard.Player + " player's turn: "); Console.WriteLine("Select a piece to move/jump by typing coordinates. (e.g. '5A')"); cPair = Console.ReadLine(); if (cPair.Length == 2) { try { gameBoard.Row = (int)Char.GetNumericValue(cPair[0]); gameBoard.Col = ((byte)Char.ToUpper(cPair[1])) - 65; } catch (Exception) { Console.WriteLine("Invalid entry."); Console.ReadLine(); continue; } if (!gameBoard.CheckValidPiece()) //do the coordinates fit and is current player piece { Console.WriteLine("Invalid entry."); Console.ReadLine(); } else if (gameBoard.MoveRequiresJump()) // if you need to jump first { Console.WriteLine("Invalid entry: You must select a piece that first must make a jump."); Console.ReadLine(); } else if (gameBoard.MoveNotPossible()) { Console.WriteLine("Invalid entry: You must select a piece that has moves or jumps."); Console.ReadLine(); } else { initial = true; } } else { Console.WriteLine("Invalid entry: Need a length of at least 2."); Console.ReadLine(); } } while (!target) { PrintBoard(gameBoard); Console.WriteLine(gameBoard.Player + " player's turn: "); Console.WriteLine("Select a target by typing coordinates. (e.g. '5A')"); cPair = Console.ReadLine(); if (cPair.Length == 2) { try { gameBoard.TargetRow = (int)Char.GetNumericValue(cPair[0]); gameBoard.TargetCol = ((byte)Char.ToUpper(cPair[1])) - 65; } catch (Exception) { Console.WriteLine("Invalid entry."); Console.ReadLine(); continue; } if (!gameBoard.IsTargetValid()) { Console.WriteLine("Target not valid."); Console.ReadLine(); } else { target = gameBoard.MoveJump(); if (gameBoard.CheckGameOver()) { break; } if (target) { gameBoard.Swap(); } } } } if (gameBoard.CheckGameOver()) { PrintBoard(gameBoard); gameBoard.CheckWinner(); Console.WriteLine(gameBoard.Player + " wins!!!\n"); while (newGame != "Y" || newGame != "N") { Console.WriteLine("Another game? Y/N"); temp = Console.ReadLine(); newGame = temp.ToUpper(); if (newGame != "Y" && newGame != "N") { Console.WriteLine("Invalid input. Please enter Y or N."); } } if (newGame == "N") { break; } if (newGame == "Y") { gameBoard.Reset(); } } } }