Browse Source

fix mineurs et renommages

pull/1/head
Figg 11 months ago
parent
commit
16367a01e7
3 changed files with 19 additions and 23 deletions
  1. 3
    3
      js/drawer.js
  2. 15
    19
      js/game.js
  3. 1
    1
      js/tube.js

+ 3
- 3
js/drawer.js View File

@@ -17,7 +17,7 @@ class Drawer
17 17
 		this.tubeSize = _tubeSize;
18 18
 		
19 19
 		this.#canvasWidth = this.tubesNumbers * (this.tubeSize + this.padding) + this.padding;
20
-		this.#canvasHeight = 3 * this.padding + this.tubeLevels * this.tubeSize;
20
+		this.#canvasHeight = 2 * this.padding + (this.tubeLevels+1) * this.tubeSize;
21 21
 		
22 22
 		resizeCanvas(this.#canvasWidth, this.#canvasHeight);
23 23
 	}
@@ -29,7 +29,7 @@ class Drawer
29 29
 		
30 30
 		background('white');
31 31
 		
32
-		this.drawTubes(this.padding, 2*this.padding, tubes, selectedTube);
32
+		this.drawTubes(this.padding, this.padding+this.tubeSize, tubes, selectedTube);
33 33
 	}
34 34
 
35 35
 	drawTubes(x, y, tubes, selectedTube)
@@ -39,7 +39,7 @@ class Drawer
39 39
 		let selectionOffset = 0;
40 40
 		
41 41
 		tubes.forEach(tube => {
42
-			selectionOffset = (tube == selectedTube ? this.padding : 0);
42
+			selectionOffset = (tube == selectedTube ? this.tubeSize : 0);
43 43
 			
44 44
 			this.drawTube(tubeX, tubeY - selectionOffset, tube);
45 45
 			tubeX += this.padding + this.tubeSize;

+ 15
- 19
js/game.js View File

@@ -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);

+ 1
- 1
js/tube.js View File

@@ -8,7 +8,7 @@ class Tube {
8 8
 		this.#colors = [];
9 9
 	}
10 10
 	
11
-	addColor(color)
11
+	addColorLayer(color)
12 12
 	{
13 13
 		if (this.isFull()) return false;
14 14
 		

Loading…
Cancel
Save