-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainClass.cs
66 lines (62 loc) · 2.2 KB
/
MainClass.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
using System.Windows.Forms;
using System.Drawing;
using System;
namespace CheckersSolver
{
public partial class MainClass : Form
{
//MAKE UI HANDLER PRIVATE
static UIHandler UI;
public static Cell[] displayedCells { get; set; }
public static int boardSize { get; private set; }
public MainClass()
{
InitializeComponent();
UI = new UIHandler(pictureBox, resultLabel);
}
private void SizeSelectionComboBox_SelectedIndexChanged(object sender, System.EventArgs e)
{
int size = -1;
if (SizeSelectionComboBox.SelectedIndex == 0)
{
size = 4;
}
else if (SizeSelectionComboBox.SelectedIndex == 1)
{
size = 6;
}
else if (SizeSelectionComboBox.SelectedIndex == 2)
{
size = 8;
}
UI.OnSizeChosen(size);
boardSize = size;
displayedCells = new Cell[size * size / 2];
CellMath.BuildCellArray(displayedCells);
}
private void pictureBox_Click(object sender, EventArgs e)
{
var mouseEventArgs = e as MouseEventArgs;
Point SelectedCellPos = UI.CellPosFromMousePos(mouseEventArgs.Location);
if (CellMath.PositionPlayable(SelectedCellPos, boardSize)) {
int SelectedCellIndex = CellMath.PlayableCellIndexFromPos(SelectedCellPos, boardSize);
displayedCells[SelectedCellIndex].NextState();
UI.UpdateCell(SelectedCellPos);
}
}
private void solveButton_Click(object sender, EventArgs e)
{
Cell[] InitialState = CellMath.DeepCloneCellArray(displayedCells);
Solver solver = new Solver(displayedCells, firstTurnCheckBox.Checked);
bool whiteDefinetlyWin = solver.Solve(visualizeCheckBox.Checked);
//RETURN TO INITIAL DISPLAY STATE
UI.DisplayResult(whiteDefinetlyWin);
displayedCells = InitialState;
UI.UpdateBoard();
}
public static void UpdateDisplay()
{
UI.UpdateBoard();
}
}
}