public static bool ChooseStartingPlayer(IGameBoard gameBoard, IInputOutput printer) { printer.Print("\nWhich player starts first O or X\n\n>>> "); var choice = 'E'; bool completed; try { choice = (char)Convert.ChangeType(printer.Read(), typeof(char)); if (char.ToUpper(choice) == 'O' || char.ToUpper(choice) == 'X') { completed = true; ((IGameBoardWinning)gameBoard).PlayerStarts(char.ToUpper(choice)); } else { gameBoard.PrintBoard(); printer.Print("\nPlease choose either O or X", true); completed = false; } } catch { gameBoard.PrintBoard(); printer.Print("\nPlease choose either O or X", true); completed = false; } return(completed); }
public Controller( IInputOutput io, IPhraseProvider phraseProvider, GameSettings gs, ITraderService traderService, IShareService shareService, ITransactionService transactionService, ITraderRepository traderRep, IShareRepository shareRep, ITransactionRepository transactionRep) { this.io = io; this.phraseProvider = phraseProvider; this.traderService = traderService; this.shareService = shareService; this.transactionService = transactionService; this.traderRep = traderRep; this.shareRep = shareRep; this.transactionRep = transactionRep; Point start = (0, 0); int whidth = gs.whidthWindow; int height = gs.heightWindow; if (whidth < 160) { io.Print("Window whidth is low" + Environment.NewLine); throw new Exception(); } if (height < 30) { io.Print("Window height is low" + Environment.NewLine); throw new Exception(); } this.io.SetWindowSize(whidth + 4, height); terminal = new Terminal( (whidth / 2 + 1, start.y), whidth / 2, 5, io, phraseProvider); menu = new Menu( start, whidth / 2, height, io, phraseProvider); }
public int[] UserInputTile() { _printer.Print("\nInput X coordinate of tile\n\n>>> "); int tileX = Int32.Parse(_printer.Read()); _printer.Print("Input Y coordinate of tile\n\n>>> "); int tileY = Int32.Parse(_printer.Read()); int[] TileCoords = new int[] { tileX, tileY }; if (tileX < Math.Sqrt(board.Length) && tileY < Math.Sqrt(board.Length)) { if (board[tileX, tileY] == 'E') { return(TileCoords); } else { return(null); } } else { return(null); } }
public static void UserMove(IGameBoard thisboard, IInputOutput printer) { int[] tileCoords = thisboard.UserInputTile(); if (tileCoords == null) { printer.Print("\nInvalid input!", true); } if (tileCoords[0] == 10) { thisboard.PrintBoard(); printer.Print("\nYou must enter 2 numbers!", true); } else if (tileCoords[0] == 20) { thisboard.PrintBoard(); printer.Print("\nYou can't play there!", true); } else if (tileCoords[0] == 30) { thisboard.PrintBoard(); printer.Print("\nYou can't play there!", true); } else { char value = thisboard.UserInputValue(); thisboard.SetValue(tileCoords[0], tileCoords[1], value); thisboard.PrintBoard(); } /// Implement in version 2.0 //for (int i = 0; i < Math.Sqrt(board.Length); i++) //{ // for (int j = 0; j < Math.Sqrt(board.Length); j++) // { // if (j == 0) // { // thisboard.SetValue(board, tile, j, value); // } // else if (j == 1) // { // thisboard.SetValue(board, tile - j * int(Math.Sqrt(board.Length)), j, value); // } // else // { // thisboard.SetValue(board, tile) // } // } //} }
static void Main(string[] args) { StartIoC(); IGameBoard gameBoard = _container.Resolve <IGameBoard>(); IInputOutput printer = _container.Resolve <IInputOutput>(); gameBoard = GameManager.StartGame(gameBoard); while (true) { if (GameManager.ChooseStartingPlayer(gameBoard, printer)) { break; } } bool IsFinished = false; while (IsFinished == false) { GameManager.UserMove(gameBoard, printer); IsFinished = gameBoard.ValidateGame(); if (((IGameBoardWinning)gameBoard).IsDraw()) { break; } } if (((IGameBoardWinning)gameBoard).GetWinner() == 'x') { printer.Print("\nCrosses Wins!", true); } else if (((IGameBoardWinning)gameBoard).GetWinner() == 'o') { printer.Print("\nNoughts Wins!", true); } else { printer.Print("\nDraw!", true); } Console.ReadKey(); }
public int[] UserInputTile() { string TestCoordsString; char TestCoordX; char TestCoordY; char WhichGo; try { if (!userx.IsMyGo == true) { WhichGo = 'O'; } else { WhichGo = 'X'; } _printer.Print($"\n{WhichGo}'s turn, Enter coordinates of tile\n\n>>> "); TestCoordsString = _printer.Read(); TestCoordX = TestCoordsString.First(); TestCoordY = TestCoordsString.Last(); Convert.ChangeType(Convert.ChangeType(TestCoordX, typeof(string)), typeof(int)); Convert.ChangeType(Convert.ChangeType(TestCoordY, typeof(string)), typeof(int)); int[] TestCoords = { (int)Convert.ChangeType(Convert.ChangeType(TestCoordX, typeof(string)), typeof(int)), (int)Convert.ChangeType(Convert.ChangeType(TestCoordY, typeof(string)), typeof(int)) }; } catch { int[] incorrectcode = { 10, 10 }; return(incorrectcode); } int[] TileCoords = { (int)Convert.ChangeType(Convert.ChangeType(TestCoordX, typeof(string)), typeof(int)), (int)Convert.ChangeType(Convert.ChangeType(TestCoordY, typeof(string)), typeof(int)) }; if (TileCoords[0] < Math.Sqrt(GetBoard().Length) && TileCoords[1] < Math.Sqrt(GetBoard().Length)) { if (GetBoard()[TileCoords[0], TileCoords[1]] == 'E') { return(TileCoords); } else { int[] incorrectcode = { 20, 20 }; return(incorrectcode); } } else { int[] incorrectcode = { 30, 30 }; return(incorrectcode); } }
private string GetValidUserInput(string request) { string input; do { _io.Print($"Please input {request}: "); input = _io.Input(); } while (!IsValidOrderInput(input, request)); return(input); }
public void PrintHeader() { io.Clear(start, (start.x + whidth, start.y + height)); io.CursorPosition = start; io.Print(page.Header + Environment.NewLine); }
public Controller( IInputOutput io, IPhraseProvider phraseProvider, GameSettings gs) { this.io = io; this.phraseProvider = phraseProvider; Point start = (0, 0); int whidth = gs.whidthWindow; int height = gs.heightWindow; if (whidth < 160) { io.Print("Window width is low" + Environment.NewLine); throw new Exception(); } if (height < 30) { io.Print("Window height is low" + Environment.NewLine); throw new Exception(); } this.io.SetWindowSize(whidth + 4, height); terminal = new Terminal( (whidth / 2 + 1, start.y), whidth / 2, 5, io, phraseProvider); menu = new Menu( start, whidth / 2, height, io, phraseProvider); }
private void Init() { var temp = this.io.CursorPosition; for (int i = start.y; i < height; i++) { this.io.CursorPosition = (start.x - 1, i); io.Print(">"); this.io.CursorPosition = (start.x + whidth, i); io.Print("<"); } this.io.CursorPosition = temp; }
private void ShowHistory() { io.Print(Environment.NewLine); Point start = io.CursorPosition; int y = start.y; foreach (var t in this.transactionRep.GetTransactions()) { this.io.CursorPosition = (start.x, y); io.Print($" {t.seller.name} {t.seller.surname}"); this.io.CursorPosition = (start.x + 20, y); io.Print($"{phraseProvider.GetPhrase(Phrase.Sold)} {t.sellerShare.quantity}"); this.io.CursorPosition = (start.x + 20 + 8, y); io.Print($"{phraseProvider.GetPhrase(Phrase.SharesOf)} {t.sellerShare.name}"); this.io.CursorPosition = (start.x + 20 + 8 + 30, y); io.Print($" {phraseProvider.GetPhrase(Phrase.To)} {t.buyer.name} {t.buyer.surname}"); y++; } io.Print(Environment.NewLine); }
private void ShowHistory() { io.Print(Environment.NewLine); Point start = io.CursorPosition; int y = start.y; foreach (var t in JsonConvert.DeserializeObject <List <Transaction> >(Http.Get($"localhost/transaction/list"))) { this.io.CursorPosition = (start.x, y); io.Print($" {t.seller.name} {t.seller.surname}"); this.io.CursorPosition = (start.x + 20, y); io.Print($"{phraseProvider.GetPhrase(Phrase.Sold)} {t.sellerShare.quantity}"); this.io.CursorPosition = (start.x + 20 + 8, y); io.Print($"{phraseProvider.GetPhrase(Phrase.SharesOf)} {t.sellerShare.name}"); this.io.CursorPosition = (start.x + 20 + 8 + 30, y); io.Print($" {phraseProvider.GetPhrase(Phrase.To)} {t.buyer.name} {t.buyer.surname}"); y++; } io.Print(Environment.NewLine); }