Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions CheckersCheckpoint/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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}"
}
]
}
15 changes: 15 additions & 0 deletions CheckersCheckpoint/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/CheckersCheckpoint.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
111 changes: 111 additions & 0 deletions CheckersCheckpoint/Board.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace CheckersCheckpoint
{
public class Board
{
public string[][] grid;
public List<Checker> checkers;

public Board()
{
this.Checkers = new List<Checker>();
this.CreateBoard();
return;
}
public string[][] Grid { get; set; }
public List<Checker> 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<int> { 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");
}
}
}
50 changes: 50 additions & 0 deletions CheckersCheckpoint/Checker.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
8 changes: 8 additions & 0 deletions CheckersCheckpoint/CheckersCheckpoint.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

</Project>
71 changes: 71 additions & 0 deletions CheckersCheckpoint/Game.cs
Original file line number Diff line number Diff line change
@@ -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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I always have to move or jump, I cannot switch between the two during game play?


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());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every time you use just Parse and not TryParse a QA person cries 😭

You should be doing input validation (checking what the user typed in matches what is acceptable).

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you graded the wrong thing, that was my mockup.


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);
}
}
}
15 changes: 15 additions & 0 deletions CheckersCheckpoint/Program.cs
Original file line number Diff line number Diff line change
@@ -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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might look like clean code, but doing a bunch of work in a constructor is a bad idea. You should have a method called Play or something like that. This becomes a problem when someone (could be you or someone else or a framework) want to figure out how this class works and this constructor calls never returns. In the next class you will use an DI framework and if it runs into a class like this, your program will just hang and there is not an easy way to figure out what is happening.

}

}
}
16 changes: 16 additions & 0 deletions CheckersCheckpoint/bash.exe.stackdump
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions NewCheckers/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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}"
}
]
}
15 changes: 15 additions & 0 deletions NewCheckers/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/NewCheckers.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
Loading