-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectFourManager.cs
More file actions
64 lines (56 loc) · 1.78 KB
/
ConnectFourManager.cs
File metadata and controls
64 lines (56 loc) · 1.78 KB
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
using UnityEngine;
namespace ConnectFourGame
{
public class ConnectFourManager : MonoBehaviour
{
private Board board;
private Player player1;
private Player player2;
private Player curr;
void Start()
{
board = new Board();
player1 = new Player();
player2 = new Player();
player1.SetID(1);
player2.SetID(2);
curr = player1;
// TODO: Initialize your Unity board UI here
}
// This method should be called from Unity UI when a player makes a move
public void OnPlayerMove(int col)
{
int row = board.Drop(curr.GetID(), col);
// TODO: Update board visuals in Unity here
if (board.IsWin(row, col))
{
// TODO: Show win message in Unity UI
Debug.Log($"\n\ncongratulations! player: {curr.GetID()} won\n\n\n");
// TODO: End game or restart
}
else if (board.IsDraw())
{
// TODO: Show draw message in Unity UI
Debug.Log("\n\nREALLY? A DRAW?!\n\n\n");
// TODO: End game or restart
}
else
{
curr = (curr == player1) ? player2 : player1;
// TODO: Update current player indicator in UI
}
}
public void OnUndo()
{
board.UnDo();
curr = (curr == player1) ? player2 : player1;
// TODO: Update board visuals and current player UI
}
public void OnRedo()
{
board.ReDo();
curr = (curr == player1) ? player2 : player1;
// TODO: Update board visuals and current player UI
}
}
}