|
@@ -43,7 +43,7 @@ class Game {
|
43
|
43
|
for (let index = 0; index < allColors.length; index++)
|
44
|
44
|
{
|
45
|
45
|
let tubeIndex = Math.floor(index/(tubeLevel-1));
|
46
|
|
- this.tubes[tubeIndex].addColor(allColors[index]);
|
|
46
|
+ this.tubes[tubeIndex].addColorLayer(allColors[index]);
|
47
|
47
|
}
|
48
|
48
|
}
|
49
|
49
|
|
|
@@ -51,31 +51,27 @@ class Game {
|
51
|
51
|
{
|
52
|
52
|
let newSelectedTube = this.tubes[tubeId];
|
53
|
53
|
|
54
|
|
- if (this.selectedTube == null && newSelectedTube.isEmpty()) return;
|
55
|
|
-
|
56
|
|
- if(this.selectedTube == null && !newSelectedTube.isEmpty())
|
57
|
|
- {
|
58
|
|
- this.selectedTube = newSelectedTube;
|
59
|
|
- }
|
60
|
|
- else if (this.selectedTube == newSelectedTube)
|
61
|
|
- {
|
|
54
|
+ if (this.selectedTube == newSelectedTube)
|
62
|
55
|
this.selectedTube = null;
|
63
|
|
- }
|
64
|
|
- else if (newSelectedTube.isEmpty() || this.selectedTube.peekTopColor() == newSelectedTube.peekTopColor())
|
65
|
|
- {
|
|
56
|
+ else if (this.canPourInto(this.selectedTube, newSelectedTube))
|
66
|
57
|
this.pourColorInto(this.selectedTube, newSelectedTube);
|
67
|
|
- }
|
|
58
|
+ else if (!newSelectedTube.isEmpty())
|
|
59
|
+ this.selectedTube = newSelectedTube;
|
|
60
|
+ }
|
|
61
|
+
|
|
62
|
+ canPourInto(sourceTube, targetTube)
|
|
63
|
+ {
|
|
64
|
+ return sourceTube != null && targetTube != null
|
|
65
|
+ && sourceTube != targetTube
|
|
66
|
+ && (targetTube.isEmpty() || sourceTube.peekTopColor() == targetTube.peekTopColor())
|
|
67
|
+ && !targetTube.isFull();
|
68
|
68
|
}
|
69
|
69
|
|
70
|
70
|
pourColorInto(sourceTube, targetTube)
|
71
|
71
|
{
|
72
|
|
- if (sourceTube.isEmpty()) return;
|
73
|
|
-
|
74
|
|
- let pouringColor = sourceTube.peekTopColor();
|
75
|
|
-
|
76
|
|
- while (sourceTube.peekTopColor() == pouringColor && !targetTube.isFull() && !targetTube.isComplete())
|
|
72
|
+ while (this.canPourInto(sourceTube, targetTube))
|
77
|
73
|
{
|
78
|
|
- targetTube.addColor(sourceTube.removeColorLayer());
|
|
74
|
+ targetTube.addColorLayer(sourceTube.removeColorLayer());
|
79
|
75
|
}
|
80
|
76
|
|
81
|
77
|
this.checkTubeCompletion(sourceTube);
|