-
Notifications
You must be signed in to change notification settings - Fork 0
Checkpoint2 #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Checkpoint2 #14
Changes from all commits
c4b21c4
8091add
9dec5fa
1ef1583
cacb3e7
b2a16a5
41194d0
abfef1c
8cd423e
a8e94a3
7363468
c1804f9
bb0af5a
329981b
2337d6f
2d4debc
aea114a
5eb441f
124fb23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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}" | ||
| } | ||
| ] | ||
| } |
| 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" | ||
| } | ||
| ] | ||
| } |
| 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"); | ||
| } | ||
| } | ||
| } |
| 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; | ||
| } | ||
| } | ||
| } |
| 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> |
| 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(); | ||
|
|
||
| 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()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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).
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| } | ||
| } | ||
| } | ||
| 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(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| } | ||
|
|
||
| } | ||
| } | ||
| 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 |
| 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}" | ||
| } | ||
| ] | ||
| } |
| 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" | ||
| } | ||
| ] | ||
| } |
There was a problem hiding this comment.
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?