private static char GetChar(BoardModel boardModel, int index) { var cell = boardModel.Cells[index]; if (cell.IsEmpty()) { return(' '); } return(cell.IsPlayer1() ? 'x' : 'o'); }
public static void Show(BoardModel bm) { Console.Clear(); Console.WriteLine($" a b c"); Console.WriteLine(" ┌─────┐"); Console.WriteLine($"1│{bm.Content[0]} {bm.Content[1]} {bm.Content[2]}│"); Console.WriteLine($"2│{bm.Content[3]} {bm.Content[4]} {bm.Content[5]}│"); Console.WriteLine($"3│{bm.Content[6]} {bm.Content[7]} {bm.Content[8]}│"); Console.WriteLine(" └─────┘"); }
public static void Show(BoardModel m) { Console.Clear(); Console.WriteLine( " a b c\n" + " ┌─────┐\n" + "1│" + GetChar(m, 0) + " " + GetChar(m, 1) + " " + GetChar(m, 2) + "│\n" + "2│" + GetChar(m, 3) + " " + GetChar(m, 4) + " " + GetChar(m, 5) + "│\n" + "3│" + GetChar(m, 6) + " " + GetChar(m, 7) + " " + GetChar(m, 8) + "│\n" + " └─────┘"); }
public static void Show(BoardModel boardModel) { var content = BoardModel.Content; Console.Clear(); Console.WriteLine(" a b c"); Console.WriteLine(" ┌─────┐"); showline(0, content); showline(3, content); showline(6, content); Console.WriteLine(" └─────┘"); }
static bool CheckWinner(BoardModel bm) { GameLogic checkWinz = new GameLogic(); var checkWin = checkWinz.CheckVictoryCondition(bm); if (!checkWin) { return(false); } BoardView.Show(bm); Console.WriteLine(""); Console.WriteLine($"{GameLogic.Winner} won!"); return(true); }
static void Main(string[] args) { var boardModel = new BoardModel(); while (true) { BoardView.Show(boardModel); Console.Write("Skriv inn hvor du vil sette kryss (f.eks. \"a2\"): "); var position = Console.ReadLine(); boardModel.SetCross(position); BoardView.Show(boardModel); Thread.Sleep(2000); boardModel.SetRandomCircle(); } }
public static void Show(BoardModel boardModel) { Console.Clear(); var winningSymbol = boardModel.IsWinning(); var content = boardModel.Content; Console.WriteLine(" a b c"); Console.WriteLine(" ┌─────┐"); ShowOneLine(0, content); ShowOneLine(3, content); ShowOneLine(6, content); Console.WriteLine(" └─────┘"); if (winningSymbol != CellContent.None) { var symbol = winningSymbol == CellContent.Circle ? "Datamaskinen" : "Du"; Console.WriteLine("\n" + symbol + " har vunnet!"); Environment.Exit(0); } ; }
static void Main(string[] args) { var boardModel = new BoardModel(); while (true) { BoardView.Show(boardModel); Console.Write("Skriv inn hvor du vil sette kryss (f.eks. \"a2\"): "); var position = Console.ReadLine(); var col = position[0] - 'a'; var row = position[1] - '1'; var index = row * 3 + col; boardModel.SetPlayer1(index); BoardView.Show(boardModel); Thread.Sleep(700); var success = boardModel.SetRandomPlayer2(); if (!success) { return; } } }