forked from AustinCodingAcademy/csharp-workbook
-
Notifications
You must be signed in to change notification settings - Fork 0
03week 1 #4
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
Open
jsnconnolly
wants to merge
9
commits into
master
Choose a base branch
from
03week-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
03week 1 #4
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,15 +10,18 @@ class Program | |
| new string[] {" ", " ", " "}, | ||
| new string[] {" ", " ", " "}, | ||
| new string[] {" ", " ", " "} | ||
|
|
||
| }; | ||
|
|
||
| public static void Main() | ||
| { | ||
| do | ||
| { | ||
| /*swap player turn ? Does this make sence to execute*/ | ||
|
|
||
| DrawBoard(); | ||
| GetInput(); | ||
|
|
||
| /*loop */ | ||
| } while (!CheckForWin() && !CheckForTie()); | ||
|
|
||
| // leave this command at the end so your program does not close automatically | ||
|
|
@@ -29,51 +32,141 @@ public static void GetInput() | |
| { | ||
| Console.WriteLine("Player " + playerTurn); | ||
| Console.WriteLine("Enter Row:"); | ||
| int row = int.Parse(Console.ReadLine()); | ||
|
|
||
| string input = Console.ReadLine(); | ||
| int row = 0; | ||
| // limits input to 0, 1, 2 | ||
| if(input == "0" || input == "1" || input == "2") | ||
| { | ||
| row = int.Parse(input); | ||
| } | ||
| else | ||
| { | ||
| Console.WriteLine("Invalid Input, Try Again"); | ||
| GetInput(); | ||
| } | ||
|
|
||
|
|
||
| Console.WriteLine("Enter Column:"); | ||
| int column = int.Parse(Console.ReadLine()); | ||
| string inputtwo = Console.ReadLine(); | ||
| int column = 0; | ||
| if(inputtwo == "0" || inputtwo == "1" || inputtwo == "2") | ||
| { | ||
| column = int.Parse(inputtwo); | ||
| } | ||
| else | ||
| { | ||
| Console.WriteLine("Invalid Input, Try Again"); | ||
| GetInput(); | ||
| } | ||
|
|
||
| PlaceMark(row,column); | ||
| if (playerTurn == "O") | ||
| { | ||
| playerTurn = "X"; | ||
| } | ||
| else | ||
| { | ||
| playerTurn ="O"; | ||
| } | ||
|
|
||
| DrawBoard(); | ||
| } | ||
|
|
||
| /*update board with correct value and position */ | ||
| public static void PlaceMark(int row, int column) | ||
| { | ||
| board[row][column] = playerTurn; | ||
| // your code goes here | ||
|
|
||
|
|
||
| } | ||
|
|
||
| public static bool CheckForWin() | ||
| { | ||
| // your code goes here | ||
| bool won = false; | ||
| if(HorizontalWin() || VerticalWin() || DiagonalWin()) | ||
| { | ||
| won = true; | ||
| Console.Write("You Won!"); | ||
| } | ||
|
|
||
| return false; | ||
| return won; | ||
| } | ||
|
|
||
| public static bool CheckForTie() | ||
| { | ||
| // your code goes here | ||
|
|
||
| return false; | ||
| // checking for Tie | ||
|
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. This is not really checking for a tie, its just checking that every position is played. |
||
| bool tie = false; | ||
| if(board [0][0] != " " && board [0][1] != " " && board [0][2] != " " && board [1][0] != " " && board [1][1] != " " && board [1][2] != " " && board [2][0] != " " && board [2][1] != " " && board [2][2] != " ") | ||
| { | ||
| tie = true; | ||
| Console.Write("Tie!"); | ||
| } | ||
| return tie; | ||
| } | ||
| /*this method will return true when any row has three of a kind in said row otherwise it will return false */ | ||
|
|
||
| public static bool HorizontalWin() | ||
| { | ||
| // your code goes here | ||
| /* if cells are empty what happens, make sure empty does not count as win */ | ||
|
|
||
| bool WonHorizontally = false; | ||
| if(board [0][0] == board[0][1] && board [0][1] == board [0][2] && board [0][0] != " " && board [0][1] != " " && board [0][2] != " ") | ||
| { | ||
| //Console.Write("Horizon one"); | ||
| WonHorizontally = true; | ||
| } | ||
| else if(board [1][0] == board[1][1] && board [1][1] == board [1][2] && board [1][0] != " " && board [1][1] != " " && board [1][2] != " ") | ||
| { | ||
| //Console.Write("Horizon two"); | ||
| WonHorizontally = true; | ||
| } | ||
| else if(board [2][0] == board[2][1] && board [2][1] == board [2][2] && board [2][0] != " " && board [2][1] != " " && board [2][2] != " ") | ||
| { | ||
| //Console.Write("Horizon three"); | ||
| WonHorizontally = true; | ||
| } | ||
| //Console.Write("Horizontal Won"); | ||
| return WonHorizontally; | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| public static bool VerticalWin() | ||
| { | ||
| // your code goes here | ||
|
|
||
| return false; | ||
| bool WonVertically = false; | ||
| if(board [0][0] == board[1][0] && board [1][0] == board [2][0] && board [0][0] != " " && board [1][0] != " " && board [2][0] != " ") | ||
| { | ||
| WonVertically = true; | ||
| } | ||
| else if(board [0][1] == board[1][1] && board [1][1] == board [2][1] && board [0][1] != " " && board [1][1] != " " && board [2][1] != " ") | ||
| { | ||
| WonVertically = true; | ||
| } | ||
| else if(board [0][2] == board[1][2] && board [1][2] == board [2][2] && board [0][2] != " " && board [1][2] != " " && board [2][2] != " ") | ||
| { | ||
| WonVertically = true; | ||
| } | ||
| //0Console.Write("Vertical Won"); | ||
| return WonVertically; | ||
| } | ||
|
|
||
| public static bool DiagonalWin() | ||
| { | ||
| // your code goes here | ||
|
|
||
| return false; | ||
| bool WonDiagonally = false; | ||
| if(board [0][0] == board[1][1] && board [1][1] == board [2][2] && board [0][0] != " " && board [1][1] != " " && board [2][2] != " ") | ||
| { | ||
| WonDiagonally = true; | ||
| } | ||
| else if(board [0][2] == board[1][1] && board [1][1] == board [2][0] && board [0][2] != " " && board [1][1] != " " && board [0][2] != " ") | ||
| { | ||
| WonDiagonally = true; | ||
| } | ||
| //Console.Write("Diagonal Won"); | ||
| return WonDiagonally; | ||
| } | ||
|
|
||
|
|
||
| public static void DrawBoard() | ||
| { | ||
| Console.WriteLine(" 0 1 2"); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
logic is slightly off, you draw the board before and after each player plays.
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.
Better comments on the methods would have been nice.