- 1
namespace NardeGame { public class NardeGame { static void Main() { Console.WriteLine("Welcome to Narde Game!"); NardeGame game = new(); game.Play(); Console.WriteLine("Thank you for playing Narde Game! Press any key to exit..."); Console.ReadKey(); } private readonly Player player1; private readonly Player player2; private readonly Board board; public NardeGame() { player1 = new Player("Armen"); player2 = new Player("Suren"); board = new Board(); } public void Play() { while (!board.IsGameOver()) { Player currentPlayer = board.GetTurn() == Turn.WHITE ? player1 : player2; Console.WriteLine("It's " + currentPlayer.GetName() + "'s turn."); Console.WriteLine(board); int from, to; do { Console.Write("Enter the starting point of your move: "); from = int.Parse(Console.ReadLine()); Console.Write("Enter the ending point of your move: "); to = int.Parse(Console.ReadLine()); } while (!Board.IsValidMove(from, to, currentPlayer.GetColor())); Board.MakeMove(from, to); board.NextTurn(); } Console.WriteLine("Game over."); Console.WriteLine(board); Console.WriteLine(board.GetWinner().GetName() + " won!"); } } public enum Color { WHITE, BLACK } public enum Turn { WHITE, BLACK } public class Player { private readonly string name; private readonly Color color; public Player(string name) { this.name = name; color = name == "Armen" ? Color.WHITE : Color.BLACK; } public string GetName() { return name; } public Color GetColor() { return color; } } public class Board { private readonly int[] points; private Turn turn; public Board() { points = new int[24] { 2, 0, 0, 0, 0, -5, 0, 3, 0, 0, 0, -5, 5, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, -2 }; turn = Turn.WHITE; } public bool IsGameOver() { int whiteCount = 0; int blackCount = 0; for (int i = 0; i < 24; i++) { if (points[i] > 0) { whiteCount += points[i]; } else if (points[i] < 0) { blackCount -= points[i]; } } return whiteCount == 0 || blackCount == 0; } public Player? GetWinner() { int whiteCount = 0; int blackCount = 0; for (int i = 0; i < 24; i++) { if (points[i] > 0) { whiteCount += points[i]; } else if (points[i] < 0) { blackCount -= points[i]; } } if (whiteCount > blackCount) { return new Player("Armen"); } else if (blackCount > whiteCount) { return new Player("Suren"); } else { return null; } } public Turn GetTurn() { return turn; } public void NextTurn() { turn = turn == Turn.WHITE ? Turn.BLACK : Turn.WHITE; } public static bool IsValidMove(int from, int to, Color color) { return true; } public static void MakeMove(int from, int to) { } public override string ToString() { string output = ""; for (int i = 0; i < 24; i++) { output += points[i] + " "; } return output.TrimEnd(); } } }
Армяне играют в однострочные нарды... :)