Browse Source

Post merge fixes

master
Figg 7 months ago
parent
commit
719be105ef
2 changed files with 31 additions and 27 deletions
  1. 29
    25
      js/controller.js
  2. 2
    2
      js/model/game.js

+ 29
- 25
js/controller.js View File

12
 	initializeGame() {
12
 	initializeGame() {
13
 		let params = this.gatherMenuValues();
13
 		let params = this.gatherMenuValues();
14
 		
14
 		
15
-		this.game = new Game(params.TUBESNUMBERS, params.TUBESLEVELS);
16
-		this.drawer = new Drawer(params.PADDING, params.SCALE);
15
+		this.#game = new Game(params.TUBESNUMBERS, params.TUBESLEVELS);
16
+		this.#drawer = new Drawer(params.PADDING, params.SCALE);
17
 		
17
 		
18
-		this.drawer.computeGameParams(params.TUBESNUMBERS, params.TUBESLEVELS);
19
-		this.width = 800
20
-		this.height = 600
21
-		this.ui = new UI(this.width, this.height);
18
+		this.#drawer.computeGameParams(params.TUBESNUMBERS, params.TUBESLEVELS);
19
+
20
+		this.ui = new UI(800, 600);
22
 		this.lastTime = 0;
21
 		this.lastTime = 0;
23
 		
22
 		
24
 		this.initializeColorTubes(params.TUBESLEVELS - 1);
23
 		this.initializeColorTubes(params.TUBESLEVELS - 1);
43
 	
42
 	
44
 	initializeColorTubes(LayersPerTube)
43
 	initializeColorTubes(LayersPerTube)
45
 	{
44
 	{
46
-		let nbTubes = this.game.tubesNumber() - 1;
45
+		let nbTubes = this.#game.tubesNumber() - 1;
47
 		let allColors = [];
46
 		let allColors = [];
48
 		
47
 		
49
 		for (let i = 0; i < nbTubes; i++)
48
 		for (let i = 0; i < nbTubes; i++)
59
 			let randomIndex = Math.floor(Math.random() * (index + 1));
58
 			let randomIndex = Math.floor(Math.random() * (index + 1));
60
 			let tubeIndex = Math.floor(index / LayersPerTube);
59
 			let tubeIndex = Math.floor(index / LayersPerTube);
61
 			
60
 			
62
-			this.game.tubeAt(tubeIndex).addColorLayer(allColors[randomIndex]);
61
+			this.#game.tubeAt(tubeIndex).addColorLayer(allColors[randomIndex]);
63
 			
62
 			
64
 			allColors[randomIndex] = allColors[index];
63
 			allColors[randomIndex] = allColors[index];
65
 		}
64
 		}
67
 	
66
 	
68
 	clickTube(tubeIndex)
67
 	clickTube(tubeIndex)
69
 	{
68
 	{
70
-		let _clickedTube = this.game.tubeAt(tubeIndex);
69
+		let _clickedTube = this.#game.tubeAt(tubeIndex);
71
 		if (_clickedTube == null) return;
70
 		if (_clickedTube == null) return;
72
 		
71
 		
73
-		if (_clickedTube == this.game.selectedTube())
74
-			this.game.unselectTube();
75
-		else if (this.canPourInto(this.game.selectedTube(), _clickedTube))
72
+		if (_clickedTube == this.#game.selectedTube())
73
+			this.#game.unselectTube();
74
+		else if (this.canPourInto(this.#game.selectedTube(), _clickedTube))
76
 		{
75
 		{
77
-			this.pourColorInto(this.game.selectedTube(), _clickedTube);
78
-			this.game.unselectTube();
76
+			this.pourColorInto(this.#game.selectedTube(), _clickedTube);
77
+			this.#game.unselectTube();
79
 		}
78
 		}
80
 		else if (!_clickedTube.isEmpty())
79
 		else if (!_clickedTube.isEmpty())
81
-			this.game.selectTubeAt(tubeIndex);
80
+			this.#game.selectTubeAt(tubeIndex);
82
 	}
81
 	}
83
 	
82
 	
84
 	canPourInto(sourceTube, targetTube)
83
 	canPourInto(sourceTube, targetTube)
86
 		return sourceTube != null && targetTube != null
85
 		return sourceTube != null && targetTube != null
87
 			&& sourceTube != targetTube
86
 			&& sourceTube != targetTube
88
 			&& (targetTube.isEmpty() || sourceTube.peekTopColor() == targetTube.peekTopColor())
87
 			&& (targetTube.isEmpty() || sourceTube.peekTopColor() == targetTube.peekTopColor())
89
-			&& !targetTube.isFull();
88
+			&& !targetTube.isFull() && !targetTube.isComplete();
90
 	}
89
 	}
91
 	
90
 	
92
 	pourColorInto(sourceTube, targetTube)
91
 	pourColorInto(sourceTube, targetTube)
104
 	{
103
 	{
105
 		if (tube.isComplete())
104
 		if (tube.isComplete())
106
 		{
105
 		{
107
-			this.game.removeTube(tube);
106
+			//this.#game.removeTube(tube);
108
 			this.checkGameCompletion();
107
 			this.checkGameCompletion();
109
 		}
108
 		}
110
 	}
109
 	}
111
 	
110
 	
112
 	checkGameCompletion()
111
 	checkGameCompletion()
113
 	{
112
 	{
114
-		if (this.game.tubesNumber() == 1 && this.game.tubeAt(0).isEmpty())
113
+		if (this.#game.tubesNumber() == 1 && this.#game.tubeAt(0).isEmpty())
115
 		{
114
 		{
116
-			this.game.clean();
115
+			this.#game.clean();
117
 		}
116
 		}
118
 	}
117
 	}
119
 
118
 
120
 	mousePressed(e) 
119
 	mousePressed(e) 
121
 	{
120
 	{
122
-		let clickedTubeId = this.drawer.getTubeIdAt(mouseX, mouseY);
121
+		let clickedTubeId = this.#drawer.getTubeIdAt(mouseX, mouseY);
123
 		this.clickTube(clickedTubeId);
122
 		this.clickTube(clickedTubeId);
124
 		
123
 		
125
 		this.needUpdate = true;
124
 		this.needUpdate = true;
127
 	
126
 	
128
 	runLoop()
127
 	runLoop()
129
 	{
128
 	{
130
-		const timeDelta = millis() - lastTime;
129
+		const timeDelta = millis() - this.lastTime;
131
 		// peut-être pas nécessaire de limiter le framerate
130
 		// peut-être pas nécessaire de limiter le framerate
132
 		if (timeDelta < 50)
131
 		if (timeDelta < 50)
133
 			return;
132
 			return;
134
 		this.lastTime = millis();
133
 		this.lastTime = millis();
135
 		
134
 		
136
 		const steps = [
135
 		const steps = [
137
-			(this.needUpdate || this.game.isCompleted) && drawGame,
138
-			this.game.isCompleted && drawUI
136
+			(this.needUpdate || this.#game.isCompleted) && this.drawGame,
137
+			this.#game.isCompleted && this.drawUI
139
 		]
138
 		]
140
 
139
 
141
-		steps.forEach(step => step && step());
140
+		steps.forEach(step => step && step.call(this));
141
+	}
142
+
143
+	drawGame()
144
+	{
145
+		this.#drawer.draw(this.#game);
142
 	}
146
 	}
143
 
147
 
144
-	function drawUI()
148
+	drawUI()
145
 	{
149
 	{
146
 		this.ui.drawWinView();
150
 		this.ui.drawWinView();
147
 	}
151
 	}

+ 2
- 2
js/model/game.js View File

4
 	
4
 	
5
 	constructor(nbTubes, tubeLevel)
5
 	constructor(nbTubes, tubeLevel)
6
 	{
6
 	{
7
-		this.tubes = [];
8
-		this.selectedTube = null;
7
+		this.#tubes = [];
8
+		this.#selectedTube = null;
9
 		this.isCompleted = false;
9
 		this.isCompleted = false;
10
 
10
 
11
 		for (let i = 0; i < nbTubes; i++)
11
 		for (let i = 0; i < nbTubes; i++)

Loading…
Cancel
Save