diff --git a/CheckersCheckpoint/.vscode/launch.json b/CheckersCheckpoint/.vscode/launch.json new file mode 100644 index 00000000..0e2310de --- /dev/null +++ b/CheckersCheckpoint/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.2/CheckersCheckpoint.dll", + "args": [], + "cwd": "${workspaceFolder}", + "console": "integratedTerminal", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} \ No newline at end of file diff --git a/CheckersCheckpoint/.vscode/tasks.json b/CheckersCheckpoint/.vscode/tasks.json new file mode 100644 index 00000000..c894cb0c --- /dev/null +++ b/CheckersCheckpoint/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/CheckersCheckpoint.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/CheckersCheckpoint/Board.cs b/CheckersCheckpoint/Board.cs new file mode 100644 index 00000000..917421dc --- /dev/null +++ b/CheckersCheckpoint/Board.cs @@ -0,0 +1,111 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace CheckersCheckpoint +{ + public class Board + { + public string[][] grid; + public List checkers; + + public Board() + { + this.Checkers = new List(); + this.CreateBoard(); + return; + } + public string[][] Grid { get; set; } + public List Checkers { get; set; } + + + public void CreateBoard() + { + this.Grid = new string[][] + { + new string[] {" ", " ", " ", " ", " ", " ", " ", " "}, + new string[] {" ", " ", " ", " ", " ", " ", " ", " "}, + new string[] {" ", " ", " ", " ", " ", " ", " ", " "}, + new string[] {" ", " ", " ", " ", " ", " ", " ", " "}, + new string[] {" ", " ", " ", " ", " ", " ", " ", " "}, + new string[] {" ", " ", " ", " ", " ", " ", " ", " "}, + new string[] {" ", " ", " ", " ", " ", " ", " ", " "}, + new string[] {" ", " ", " ", " ", " ", " ", " ", " "}, + }; + return; + } + + + public void GenerateCheckers() + { + int[][] whitePositions = new int[][] + { + new int[] { 0, 1 }, new int[] { 0, 3 }, new int[] { 0, 5 }, new int[] { 0, 7 }, + new int[] { 1, 0 }, new int[] { 1, 2 }, new int[] { 1, 4 }, new int[] { 1, 6 }, + new int[] { 2, 1 }, new int [] { 2, 3 }, new int[] { 2, 5 }, new int[] { 2, 7} + }; + + int[][] blackPositions = new int[][] + { + new int[] { 5, 0 }, new int[] { 5, 2 }, new int[] { 5, 4 }, new int[] { 5, 6 }, + new int[] { 6, 1 }, new int[] { 6, 3 }, new int[] { 6, 5 }, new int[] { 6, 7 }, + new int[] { 7, 0 }, new int[] { 7, 2 }, new int [] { 7, 4 }, new int[] { 7, 6 } + }; + + for (int i = 0; i < 12; i++) + + { + Checker white = new Checker("white", whitePositions[i]); + Checker black = new Checker("black", blackPositions[i]); + Checkers.Add(white); + Checkers.Add(black); + } + return; + } + + + + public void PlaceCheckers() + { + foreach (var checker in Checkers) + { + ; + this.Grid[checker.Position[0]][checker.Position[1]] = checker.Symbol; + } + return; + } + + + public void DrawBoard() + { + CreateBoard(); + PlaceCheckers(); + Console.WriteLine(" 0 1 2 3 4 5 6 7 "); + Console.OutputEncoding = System.Text.Encoding.UTF8; + for (int i = 0; i < 8; i++) + { + Console.WriteLine(i + " " + String.Join(" ", this.Grid[i])); + } + return; + } + + + public Checker SelectChecker(int row, int column) + { + return Checkers.Find(x => x.Position.SequenceEqual(new List { row, column })); + } + + + public void RemoveChecker(Checker checker) + { + Checkers.Remove(checker); + return; + } + + + public bool CheckForWin() + { + return Checkers.All(x => x.Color == "white") || !Checkers.Exists(x => x.Color == "white"); + } + } +} \ No newline at end of file diff --git a/CheckersCheckpoint/Checker.cs b/CheckersCheckpoint/Checker.cs new file mode 100644 index 00000000..6b687ce0 --- /dev/null +++ b/CheckersCheckpoint/Checker.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace CheckersCheckpoint +{ + public class Checker + { + public string symbol; + public int[] position; + public string color; + + + public Checker(string color, int[] position) + { + int circleId; + + if (color == "white") + { + circleId = int.Parse("25CE", System.Globalization.NumberStyles.HexNumber); + Color = "white"; + } + else + { + circleId = int.Parse("25C9", System.Globalization.NumberStyles.HexNumber); + Color = "black"; + } + this.Symbol = char.ConvertFromUtf32(circleId); + this.Position = position; + } + + public string Symbol + { + get; + set; + } + + public int[] Position + { + get; + set; + } + + public string Color + { + get; + set; + } + } +} \ No newline at end of file diff --git a/CheckersCheckpoint/CheckersCheckpoint.csproj b/CheckersCheckpoint/CheckersCheckpoint.csproj new file mode 100644 index 00000000..21dff5ca --- /dev/null +++ b/CheckersCheckpoint/CheckersCheckpoint.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.2 + + + diff --git a/CheckersCheckpoint/Game.cs b/CheckersCheckpoint/Game.cs new file mode 100644 index 00000000..27da0253 --- /dev/null +++ b/CheckersCheckpoint/Game.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace CheckersCheckpoint +{ + public class Game + { + public Game() + { + Board board = new Board(); + board.GenerateCheckers(); + board.DrawBoard(); + + Console.WriteLine("\nIf you want to move a checker one space diagonally forward, enter 'move'."); + Console.WriteLine("\nIf a jump is available for one of your checker, you must enter 'jump'."); + + string choice = Console.ReadLine(); + + do + { + switch (choice) + { + case "move": + + Console.WriteLine("Enter checker Row to move:"); + int row = int.Parse(Console.ReadLine()); + Console.WriteLine("Enter checker Column:"); + int column = int.Parse(Console.ReadLine()); + + if (board.SelectChecker(row, column) != null) + { + Checker checker = board.SelectChecker(row, column); + Console.WriteLine("Move to which Row: "); + int newRow = int.Parse(Console.ReadLine()); + Console.WriteLine("Move to which Column: "); + int newColumn = int.Parse(Console.ReadLine()); + checker.Position = new int[] { newRow, newColumn }; + board.DrawBoard(); + } + else + { + Console.WriteLine("Invalid input"); + Console.WriteLine("Enter a valid checker Row:"); + row = int.Parse(Console.ReadLine()); + Console.WriteLine("Enter a valid checker Column:"); + column = int.Parse(Console.ReadLine()); + } + break; + + case "jump": + + Console.WriteLine("Select checker Row to remove:"); + int removeRow = int.Parse(Console.ReadLine()); + Console.WriteLine("Select checker Column to remove:"); + int removeColumn = int.Parse(Console.ReadLine()); + Checker changeChecker = board.SelectChecker(removeRow, removeColumn); + board.RemoveChecker(changeChecker); + board.DrawBoard(); + break; + + default: + + Console.WriteLine("Invalid input."); + break; + } + } + while (board.CheckForWin() != true); + } + } +} \ No newline at end of file diff --git a/CheckersCheckpoint/Program.cs b/CheckersCheckpoint/Program.cs new file mode 100644 index 00000000..6b7c027e --- /dev/null +++ b/CheckersCheckpoint/Program.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace CheckersCheckpoint +{ + public class Program + { + public static void Main(string[] args) + { + new Game(); + } + + } +} \ No newline at end of file diff --git a/CheckersCheckpoint/bash.exe.stackdump b/CheckersCheckpoint/bash.exe.stackdump new file mode 100644 index 00000000..4bc86685 --- /dev/null +++ b/CheckersCheckpoint/bash.exe.stackdump @@ -0,0 +1,16 @@ +Stack trace: +Frame Function Args +00180328AF0 0018006021E (00180247D00, 001802340B9, 00000000058, 000FFFFB740) +00180328AF0 00180048859 (00180236765, 00100000000, 00000000000, 00000000001) +00180328AF0 00180048892 (00000000000, 00000000000, 00000000058, 00180328950) +00180328AF0 0018006C179 (0000000000A, 00000000000, 0000000000A, 00000000000) +00180328AF0 0018006C342 (00000000003, 00000000000, 00180044EEF, 000FFFFCB30) +00000000000 0018006D3A8 (0000000000D, 000FFFFC920, 001800E4CF6, 000FFFFC920) +00000000000 00180058816 (000FFFF0000, 00000000000, 00000000000, 006FFFFFFFF) +00000000000 001800590A9 (000FFFFCAF0, 00600040000, 00000000000, 000FFFFCB80) +00180325CF8 001800595BA (001800C0322, 00000000000, 00000000000, 00000000000) +000FFFFCCD0 00180059937 (000FFFFCDF0, 000FFFFCCD0, FFFFFFFFFFFFFFD1, 00000000000) +000FFFFCCD0 00180048FE1 (00000000000, 00000000000, 00000000000, 00000000000) +00000000000 00180047963 (00000000000, 00000000000, 00000000000, 00000000000) +000FFFFFFF0 00180047A14 (00000000000, 00000000000, 00000000000, 00000000000) +End of stack trace diff --git a/NewCheckers/.vscode/launch.json b/NewCheckers/.vscode/launch.json new file mode 100644 index 00000000..d3ae507e --- /dev/null +++ b/NewCheckers/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.2/NewCheckers.dll", + "args": [], + "cwd": "${workspaceFolder}", + "console": "integratedTerminal", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} \ No newline at end of file diff --git a/NewCheckers/.vscode/tasks.json b/NewCheckers/.vscode/tasks.json new file mode 100644 index 00000000..ab83386f --- /dev/null +++ b/NewCheckers/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/NewCheckers.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/NewCheckers/Board.cs b/NewCheckers/Board.cs new file mode 100644 index 00000000..4fc5b7ce --- /dev/null +++ b/NewCheckers/Board.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using System.Threading; + +namespace NewCheckers +{ + public class Board + { + public Dictionary pieces { get; set; } + + public Board() + { + pieces = new Dictionary(); + for (int i = 0; i < 8; i++) + { + for (int j = 0; j < 8; j++) + { + Coordinates cord = new Coordinates(i, j); + Checker check = null; + switch (i) + { + case 0: + if (j % 2 == 0 || j == 0) + { + check = new Checker("black"); + pieces.Add(cord, check); + } + else + { + pieces.Add(cord, null); + } + break; + case 1: + if (j % 2 == 0 || j == 0) + { + pieces.Add(cord, null); + } + else + { + check = new Checker("black"); + pieces.Add(cord, check); + } + break; + case 2: + if (j % 2 == 0 || j == 0) + { + check = new Checker("black"); + pieces.Add(cord, check); + } + else + { + pieces.Add(cord, null); + } + break; + case 5: + if (j % 2 == 0 || j == 0) + { + pieces.Add(cord, null); + } + else + { + check = new Checker("white"); + pieces.Add(cord, check); + } + break; + case 6: + if (j % 2 == 0 || j == 0) + { + check = new Checker("white"); + pieces.Add(cord, check); + } + else + { + pieces.Add(cord, null); + } + break; + case 7: + if (j % 2 == 0 || j == 0) + { + pieces.Add(cord, null); + } + else + { + check = new Checker("white"); + pieces.Add(cord, check); + } + break; + default: + pieces.Add(cord, null); + break; + } + } + } + } + } +} + diff --git a/NewCheckers/CheckLanding.cs b/NewCheckers/CheckLanding.cs new file mode 100644 index 00000000..f692633f --- /dev/null +++ b/NewCheckers/CheckLanding.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; + +namespace NewCheckers +{ + public class CheckLanding + { + public Coordinates Remove { get; set; } + public bool Jumped { get; set; } = false; + + + public CheckLanding() + { + Jumped = false; + } + public bool Run(Coordinates from, Coordinates to, Dictionary curBoard) + { + int x = from.X; + int y = from.Y; + int toX = to.X; + int toY = to.Y; + + List possibles = new List(); + possibles.Add(new Coordinates(x - 1, y - 1)); + possibles.Add(new Coordinates(x - 2, y - 2)); + possibles.Add(new Coordinates(x + 1, y + 1)); + possibles.Add(new Coordinates(x + 2, y + 2)); + possibles.Add(new Coordinates(x - 1, y + 1)); + possibles.Add(new Coordinates(x - 2, y + 2)); + possibles.Add(new Coordinates(x + 1, y - 1)); + possibles.Add(new Coordinates(x + 2, y - 2)); + + bool isValidLanding = false; + bool twoSpaces = false; + + foreach (var item in possibles) + { + if (item.X == to.X && item.Y == to.Y) + { + isValidLanding = true; + if (item.X - 2 == x || item.X + 2 == x) + { + twoSpaces = true; + } + } + } + Checker occupied; + if (curBoard.TryGetValue(to, out occupied)) + { + if (occupied != null) + { + isValidLanding = false; + } + } + + if (isValidLanding) + { + if (twoSpaces) + { + if (toX - 2 == x) + { + if (toY - 2 == y) + { + Jumped = true; + Remove = new Coordinates(toX - 1, toY - 1); + } + else + { + Jumped = true; + Remove = new Coordinates(toX - 1, toY + 1); + } + } + else if (toX + 2 == x) + { + if (toY - 2 == y) + { + Jumped = true; + Remove = new Coordinates(toX + 1, toY - 1); + } + else + { + Jumped = true; + Remove = new Coordinates(toX + 1, toY + 1); + } + } + else + { + twoSpaces = true; + Jumped = false; + } + } + + } + bool returnMe = isValidLanding ? true : false; + + return returnMe; + } + } +} \ No newline at end of file diff --git a/NewCheckers/Checker.cs b/NewCheckers/Checker.cs new file mode 100644 index 00000000..a4bfb23b --- /dev/null +++ b/NewCheckers/Checker.cs @@ -0,0 +1,31 @@ +using System; + +namespace NewCheckers +{ + public class Checker + { + public string Color { get; private set; } + public string ColorAbs { get; private set; } + public bool King { get; private set; } + public Checker(string color) + { + int circleId; + + if (color == "white") + { + circleId = int.Parse("25CE", System.Globalization.NumberStyles.HexNumber); + ColorAbs = "white"; + } + else + { + circleId = int.Parse("25CF", System.Globalization.NumberStyles.HexNumber); + ColorAbs = "black"; + } + this.Color = char.ConvertFromUtf32(circleId); + } + public void MakeKing() + { + this.King = true; + } + } +} diff --git a/NewCheckers/Coordinates.cs b/NewCheckers/Coordinates.cs new file mode 100644 index 00000000..ff0b1818 --- /dev/null +++ b/NewCheckers/Coordinates.cs @@ -0,0 +1,15 @@ +using System; + +namespace NewCheckers +{ + public struct Coordinates + { + public int X { get; private set; } + public int Y { get; private set; } + public Coordinates(int x, int y) + { + this.X = x; + this.Y = y; + } + } +} diff --git a/NewCheckers/CreateCheckers.cs b/NewCheckers/CreateCheckers.cs new file mode 100644 index 00000000..5ec70267 --- /dev/null +++ b/NewCheckers/CreateCheckers.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace NewCheckers +{ + class CreateCheckers + { + Dictionary initialSetup = new Dictionary(); + //public Dictionary InitialCheckers() + //{ + + //} + } +} \ No newline at end of file diff --git a/NewCheckers/Display.cs b/NewCheckers/Display.cs new file mode 100644 index 00000000..ed37e5ca --- /dev/null +++ b/NewCheckers/Display.cs @@ -0,0 +1,337 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace NewCheckers +{ + public class Display + { + public Dictionary pieces { get; set; } + private int index = 0; + private Boolean Second = false; + private Coordinates cordsPrior; + public Display(Dictionary board) + { + pieces = new Dictionary(); + Coordinates cord; + for (int i = 0; i < 8; i++) + { + for (int j = 0; j < 8; j++) + { + cord = new Coordinates(i, j); + Checker c; + if (board.TryGetValue(cord, out c)) + { + if (c != null) + { + this.pieces.Add(cord, c.Color); + } + } + else + { + this.pieces.Add(cord, " "); + } + } + } + } + public int ChooseX(int player, string one, string two)//ChooseX + { + if (one != null && two != null) + { + int x = Convert.ToInt32(one); + int y = Convert.ToInt32(two); + cordsPrior = new Coordinates(x, y); + string testMe = ""; + if (pieces.TryGetValue(cordsPrior, out testMe)) + { + Second = testMe == null ? false : true; + } + } + Console.Clear(); + Coordinates cord; + string returnMe = ""; + Console.CursorVisible = false; + while (returnMe == "") + { + Console.WriteLine("Player " + player + " Choose A Row."); + Console.WriteLine(); + for (int i = 0; i < 8; i++) + { + if (index == i) + { + Console.BackgroundColor = ConsoleColor.Black; + Console.ForegroundColor = ConsoleColor.Green; + Console.Write(i); + Console.Write(" "); + } + else + { + Console.BackgroundColor = ConsoleColor.Black; + Console.ForegroundColor = ConsoleColor.White; + Console.Write(i); + Console.Write(" "); + } + for (int j = 0; j < 8; j++) + { + cord = new Coordinates(i, j); + if (i == 0 || i % 2 == 0) + { + if (j == 0 || j % 2 == 0) + { + Console.BackgroundColor = ConsoleColor.White; + if (Second) + { + if (cord.X == cordsPrior.X && cord.Y == cordsPrior.Y) + { + Console.BackgroundColor = ConsoleColor.Blue; + } + } + } + else + { + Console.BackgroundColor = ConsoleColor.Black; + if (Second) + { + if (cord.X == cordsPrior.X && cord.Y == cordsPrior.Y) + { + Console.BackgroundColor = ConsoleColor.Blue; + } + } + } + } + else + { + if (j == 0 || j % 2 == 0) + { + Console.BackgroundColor = ConsoleColor.Black; + if (Second) + { + if (cord.X == cordsPrior.X && cord.Y == cordsPrior.Y) + { + Console.BackgroundColor = ConsoleColor.Blue; + } + } + } + else + { + Console.BackgroundColor = ConsoleColor.White; + if (Second) + { + if (cord.X == cordsPrior.X && cord.Y == cordsPrior.Y) + { + Console.BackgroundColor = ConsoleColor.Blue; + } + } + } + } + string value = ""; + if (pieces.TryGetValue(cord, out value)) + { + Console.OutputEncoding = System.Text.Encoding.UTF8; + Console.Write(" "); + if (value == char.ConvertFromUtf32(int.Parse("25CE", System.Globalization.NumberStyles.HexNumber))) + { + value = char.ConvertFromUtf32(int.Parse("25CF", System.Globalization.NumberStyles.HexNumber)); + Console.ForegroundColor = ConsoleColor.Red; + + Console.Write(value); + Console.Write(" "); + } + else + { + Console.ForegroundColor = ConsoleColor.Black; + Console.Write(value); + Console.Write(" "); + } + } + else + { + Console.Write(" "); + } + Console.ResetColor(); + } + Console.WriteLine(); + } + List items = new List { "0", "1", "2", "3", "4", "5", "6", "7" }; + returnMe = MenuControllerX(items); + } + index = 0; + return Convert.ToInt32(returnMe); + } + private string MenuControllerX(List items) + { + ConsoleKeyInfo userInput = Console.ReadKey(); + + if (userInput.Key == ConsoleKey.DownArrow) + { + index = index == items.Count - 1 ? 0 : index + 1; + } + else if (userInput.Key == ConsoleKey.UpArrow) + { + index = index <= 0 ? items.Count - 1 : index - 1; + } + else if (userInput.Key == ConsoleKey.Enter) + { + return items[index]; + } + Console.Clear(); + return ""; + } + public int ChooseY(int player, int x, string one, string two)//PickY + { + if (one != null && two != null) + { + int z = Convert.ToInt32(one); + int y = Convert.ToInt32(two); + cordsPrior = new Coordinates(z, y); + string testMe = ""; + if (pieces.TryGetValue(cordsPrior, out testMe)) + { + Second = testMe == null ? false : true; + } + } + Console.Clear(); + Coordinates cord; + string returnMe = ""; + Console.CursorVisible = false; + while (returnMe == "") + { + Console.WriteLine("Player " + player + " Choose A Row."); + Console.WriteLine(); + for (int i = 0; i < 8; i++) + { + for (int j = 0; j < 8; j++) + { + cord = new Coordinates(i, j); + + if (i == 0 || i % 2 == 0) + { + if (j == 0 || j % 2 == 0) + { + Console.BackgroundColor = ConsoleColor.White; + if (Second) + { + if (cord.X == cordsPrior.X && cord.Y == cordsPrior.Y) + { + Console.BackgroundColor = ConsoleColor.Blue; + } + } + } + else + { + Console.BackgroundColor = ConsoleColor.Black; + if (Second) + { + if (cord.X == cordsPrior.X && cord.Y == cordsPrior.Y) + { + Console.BackgroundColor = ConsoleColor.Blue; + } + } + } + if (i == x && j == index) + { + Console.BackgroundColor = ConsoleColor.Green; + } + } + else + { + if (j == 0 || j % 2 == 0) + { + Console.BackgroundColor = ConsoleColor.Black; + if (Second) + { + if (cord.X == cordsPrior.X && cord.Y == cordsPrior.Y) + { + Console.BackgroundColor = ConsoleColor.Blue; + } + } + } + else + { + Console.BackgroundColor = ConsoleColor.White; + if (Second) + { + if (cord.X == cordsPrior.X && cord.Y == cordsPrior.Y) + { + Console.BackgroundColor = ConsoleColor.Blue; + } + } + } + if (i == x && j == index) + { + Console.BackgroundColor = ConsoleColor.Green; + } + } + string value = ""; + if (pieces.TryGetValue(cord, out value)) + { + Console.OutputEncoding = System.Text.Encoding.UTF8; + Console.Write(" "); + if (value == char.ConvertFromUtf32(int.Parse("25CE", System.Globalization.NumberStyles.HexNumber))) + { + value = char.ConvertFromUtf32(int.Parse("25CF", System.Globalization.NumberStyles.HexNumber)); + Console.ForegroundColor = ConsoleColor.Red; + Console.Write(value); + Console.Write(" "); + } + else + { + Console.ForegroundColor = ConsoleColor.Black; + Console.Write(value); + Console.Write(" "); + } + } + else + { + Console.Write(" "); + } + Console.ResetColor(); + } + Console.WriteLine(); + } + List items = new List { "0", "1", "2", "3", "4", "5", "6", "7" }; + for (int i = 0; i < items.Count; i++) + { + if (index == i) + { + Console.BackgroundColor = ConsoleColor.Black; + Console.ForegroundColor = ConsoleColor.Green; + Console.Write(" "); + Console.Write(items[i]); + Console.Write(" "); + } + else + { + Console.BackgroundColor = ConsoleColor.Black; + Console.ForegroundColor = ConsoleColor.White; + Console.Write(" "); + Console.Write(items[i]); + Console.Write(" "); + } + } + returnMe = MenuControllerY(items); + } + return Convert.ToInt32(returnMe); + } + private string MenuControllerY(List items) + { + ConsoleKeyInfo userInput = Console.ReadKey(); + + if (userInput.Key == ConsoleKey.RightArrow) + { + index = index == items.Count - 1 ? 0 : index + 1; + } + else if (userInput.Key == ConsoleKey.LeftArrow) + { + index = index <= 0 ? items.Count - 1 : index - 1; + } + else if (userInput.Key == ConsoleKey.Enter) + { + return items[index]; + } + Console.Clear(); + return ""; + } + + } +} diff --git a/NewCheckers/Game.cs b/NewCheckers/Game.cs new file mode 100644 index 00000000..e17f3317 --- /dev/null +++ b/NewCheckers/Game.cs @@ -0,0 +1,67 @@ +using System; + +namespace NewCheckers +{ + public class Game + { + //request both moves controle board + Board CurrentBoard; + public Game() + { + CurrentBoard = new Board(); + } + public int White = 0; + public int Black = 0; + public void Run() + { + int turn = 1; + bool GameOver = false; + int Winner; + while (!GameOver) + { + Select Choose = new Select(turn, CurrentBoard.pieces); + Coordinates moveFrom = Choose.From(); + Coordinates moveTo = Choose.To(moveFrom); + bool valid = Choose.CheckValidity(moveFrom, moveTo); + + if (valid) + { + CurrentBoard.pieces[moveTo] = CurrentBoard.pieces[moveFrom]; + CurrentBoard.pieces[moveFrom] = null; + if (moveTo.X == 0 && turn == 1) + { + this.CurrentBoard.pieces[moveTo].MakeKing(); + } + if (moveTo.X == 7 && turn == 2) + { + this.CurrentBoard.pieces[moveTo].MakeKing(); + } + if (Choose.Jumped == true) + { + bool addPoint = CurrentBoard.pieces[Choose.Remove].ColorAbs == "white" ? true : false; + this.CurrentBoard.pieces[Choose.Remove] = null; + if (addPoint) + { + this.White++; + } + else + { + this.Black++; + } + } + + turn = turn == 1 ? 2 : 1; + } + + GameOver = White == 12 || Black == 12 ? true : false; + if (GameOver) + { + Winner = White == 12 ? 1 : 2; + } + } + } + } +} +/*Display display = new Display(CurrentBoard.pieces); + int one = display.ChooseX(1); + int two = display.ChooseY(1, one); */ diff --git a/NewCheckers/IsValid.cs b/NewCheckers/IsValid.cs new file mode 100644 index 00000000..bdb5a0c9 --- /dev/null +++ b/NewCheckers/IsValid.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; + +namespace NewCheckers +{ + public class IsValid + { + private int Turn; + private Dictionary CurBoard; + private Coordinates From; + private Coordinates To; + public bool Valid = false; + public Coordinates Remove; + public bool Jumped = false; + public IsValid(int turn, Dictionary curBoard, Coordinates from, Coordinates to) + { + this.CurBoard = curBoard; + this.Turn = turn; + this.From = from; + this.To = to; + } + public bool Run() + { + bool isFromValid = false; + bool isToValid = false; + isFromValid = CheckFrom(); + isToValid = CheckTo(); + this.Valid = isFromValid && isToValid ? true : false; + return Valid; + } + private bool CheckFrom() + { + bool from; + if (Turn == 1 && CurBoard[From] != null && CurBoard[From].ColorAbs == "white") + { + from = true; + } + else if (Turn == 2 && CurBoard[From] != null && CurBoard[From].ColorAbs == "black") + { + from = true; + } + else + { + from = false; + } + return from; + } + private bool CheckTo() + { + bool to = false; + CheckLanding land = new CheckLanding(); + to = land.Run(From, To, CurBoard); + if (land.Jumped) + { + this.Remove = land.Remove; + this.Jumped = true; + } + if (Turn == 1 && (From.X - To.X) < 0) + { + Checker tryMe; + if (CurBoard.TryGetValue(From, out tryMe)) + { + if (tryMe != null) + { + if (!tryMe.King) + { + to = false; + } + } + } + else + { + to = false; + } + } + if (Turn == 2 && (To.X - From.X) < 0) + { + Checker tryMe; + if (CurBoard.TryGetValue(From, out tryMe)) + { + if (tryMe != null && !tryMe.King) + if (tryMe != null) + { + if (!tryMe.King) + { + to = false; + } + } + } + else + { + to = false; + } + } + return to; + } + + } +} diff --git a/NewCheckers/NewCheckers.csproj b/NewCheckers/NewCheckers.csproj new file mode 100644 index 00000000..21dff5ca --- /dev/null +++ b/NewCheckers/NewCheckers.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.2 + + + diff --git a/NewCheckers/Program.cs b/NewCheckers/Program.cs new file mode 100644 index 00000000..99a62ada --- /dev/null +++ b/NewCheckers/Program.cs @@ -0,0 +1,13 @@ +using System; + +namespace NewCheckers +{ + class Program + { + static void Main(string[] args) + { + Game game = new Game(); + game.Run(); + } + } +} diff --git a/NewCheckers/Select.cs b/NewCheckers/Select.cs new file mode 100644 index 00000000..05f35731 --- /dev/null +++ b/NewCheckers/Select.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Threading; + +namespace NewCheckers +{ + public class Select + { + private Dictionary CurBoard; + private int Turn; + public bool Jumped = false; + public Coordinates Remove; + public Select(int currentTurn, Dictionary CurrentBoard) + { + CurBoard = CurrentBoard; + Turn = currentTurn; + } + public Coordinates From() + { + Display display = new Display(CurBoard); + int row = display.ChooseX(Turn, null, null); + int column = display.ChooseY(Turn, row, null, null); + return new Coordinates(row, column); + } + public Coordinates To(Coordinates old) + { + string x = old.X.ToString(); + string y = old.Y.ToString(); + Display display = new Display(CurBoard); + int row = display.ChooseX(Turn, x, y); + int column = display.ChooseY(Turn, row, x, y); + return new Coordinates(row, column); + } + public bool CheckValidity(Coordinates from, Coordinates to) + { + IsValid isValid = new IsValid(Turn, CurBoard, from, to); + bool valid = isValid.Run(); + if (isValid.Jumped) + { + this.Jumped = true; + this.Remove = isValid.Remove; + } + return valid; + } + } +} \ No newline at end of file