Practice
In this step, you studied reading from the console, converting from string to number, and functions. You will need this knowledge to implement the first player's move.
Requirements
Let the first player be named Julia. The tasks to complete in this practice are:
- Print an empty game board (this was done in the previous step)
- Print a message for Julia to make a move
- Read the index of the cell where Julia wants to move
- Record the move
- Print the game board again, now including Julia's move.
Implementation
The requirements are set and the tasks are defined — you can start implementing the move for the first player, whose name is Julia.
Line 1, Char 1
Exercises
- You probably noticed that printing the game board is used twice, and that is a great candidate for extracting into a separate function. Write your own function that accepts the game board as a parameter and prints it to the console. The function should have the following structure:
void PrintBoard(string[] board).
Line 1, Char 1
- Experiment: what happens if Julia enters an index that is not on the game board, for example 9? You will get a runtime error. Try to read the error message and understand what it means.
- Experiment: what happens if Julia enters not a number but a string, for example
qwe? You will also get a runtime error. Try to read the error message and understand what it means.
Working with errors is beyond the scope of this course and will be covered in other courses dedicated to C#.
Summary
Wow! We applied what we learned to implement a player's move. But there is still a lot of exciting work ahead!