-
Notifications
You must be signed in to change notification settings - Fork 0
/
Renderer.cs
44 lines (43 loc) · 1.4 KB
/
Renderer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using System.Collections.Generic;
using System.Text;
namespace TicTacToe
{
public class Renderer
{
public void Render(Board board)
{
char[,] symbols = new char[3, 3];
for (int row = 0; row < 3; row++)
for (int column = 0; column < 3; column++)
symbols[row, column] = SymbolFor(board.GetState(new Position(row, column)));
Console.WriteLine($" {symbols[0, 0]} | {symbols[0, 1]} | {symbols[0, 2]} ");
Console.WriteLine("---+---+---");
Console.WriteLine($" {symbols[1, 0]} | {symbols[1, 1]} | {symbols[1, 2]} ");
Console.WriteLine("---+---+---");
Console.WriteLine($" {symbols[2, 0]} | {symbols[2, 1]} | {symbols[2, 2]} ");
}
private char SymbolFor(State state)
{
switch (state)
{
case State.O: return 'O';
case State.X: return 'X';
default: return ' ';
}
}
public void RenderResults(State winner)
{
switch (winner)
{
case State.O:
case State.X:
Console.WriteLine(SymbolFor(winner) + " Wins!");
break;
case State.Undecided:
Console.WriteLine("Draw!");
break;
}
}
}
}