-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBoardScene.cs
66 lines (57 loc) · 1.31 KB
/
BoardScene.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 Godot;
using System;
using System.Linq;
public class BoardScene : Spatial
{
ABoard _board;
public ABoard Board {
get { return _board; }
set {
_board = value;
Bind (_board);
}
}
public CardScene [,] CardScenes { get; set; }
void Bind (ABoard board)
{
if (board == null) {
return;
}
Reset ();
}
void Reset ()
{
if (CardScenes != null) {
for (var i = 0; i < Board.Width; i++) {
for (var j = 0; j < Board.Height; j++) {
if (CardScenes [i, j] != null) {
RemoveChild (CardScenes [i, j]);
}
}
}
}
CardScenes = new CardScene [Board.Width, Board.Height];
}
public void AddCardScene (CardScene cardScene, BoardCoords boardCoords)
{
cardScene.Translation = new Vector3 (
-(Const.CARD_WIDTH + Const.BOARD_GRID_SPACING) * (Board.Width - 1 - boardCoords.X * 2) / 2,
(Const.CARD_HEIGHT + Const.BOARD_GRID_SPACING) * (Board.Height - 1 - boardCoords.Y * 2) / 2,
0
);
cardScene.Rotation = Vector3.Zero;
AddChild (cardScene);
CardScenes [boardCoords.X, boardCoords.Y] = cardScene;
}
public CardScene GetCardScene (ACard card)
{
for (var i = 0; i < Board.Width; i++) {
for (var j = 0; j < Board.Height; j++) {
if (CardScenes [i, j] != null && CardScenes [i, j].Card == card) {
return CardScenes [i, j];
}
}
}
return null;
}
}