-
Notifications
You must be signed in to change notification settings - Fork 0
/
SudokuCell.cs
97 lines (84 loc) · 2.61 KB
/
SudokuCell.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
namespace Sudoku
{
class SudokuCell
{
const char EmptyCellDisplayChar = ' ';
public int value;
private bool isEditable;
public bool isCorrect;
protected int windowRowPosition;
protected int windowColPosition;
public int RowPosition
{
get { return windowRowPosition; }
set { windowRowPosition = value; }
}
public int ColumnPosition
{
get { return windowColPosition; }
set { windowColPosition = value; }
}
public SudokuCell(int value, bool isEditable, int windowRowPosition, int windowColPosition)
{
this.value = value;
this.isEditable = isEditable;
this.windowRowPosition = windowRowPosition;
this.windowColPosition = windowColPosition;
isCorrect = true;
}
public SudokuCell(int windowRowPosition, int windowColPosition)
{
this.windowRowPosition = windowRowPosition;
this.windowColPosition = windowColPosition;
}
public void Write(int newValue)
{
value = newValue;
Redraw();
}
public virtual void Redraw()
{
Console.SetCursorPosition(windowColPosition, windowRowPosition);
if (GameWindow.CurrentCell.HasSamePositionAs(this))
{
Console.BackgroundColor = GameWindow.HighlightBackGroundColor;
}
else
{
Console.BackgroundColor = GameWindow.BackgroundColor;
}
if (isEditable)
{
Console.ForegroundColor = GameWindow.EntryDigitColor;
}
else
{
Console.ForegroundColor = GameWindow.LockedEntryDigitColor;
}
if (!isCorrect && isEditable)
{
Console.ForegroundColor = GameWindow.WrongEntryBackGroundColor;
}
if (value != 0)
{
Console.Write(value);
}
else
Console.Write(EmptyCellDisplayChar);
}
public void RefreshValues(int value, bool isEditable)
{
this.value = value;
this.isEditable = isEditable;
}
public bool HasSamePositionAs(SudokuCell other)
{
if (this.windowRowPosition == other.windowRowPosition && this.windowColPosition == other.windowColPosition)
{
return true;
}
return false;
}
}
}