We have added naive Artificial Intelligence. This time, you play against Robot Emil. He is quite naive – just plays randomly.
But, a lot has changed on the inside. I have structured all classes as they should be. For example this code:
class Player { #color; #printedScore; #name; constructor(name, color) { this.#color = color; this.#name = name; this.#printedScore = document.createElement("span"); const node = document.createElement("p"); node.style.color = color; node.appendChild(document.createTextNode(name + ": ")); node.appendChild(this.#printedScore); document.getElementById("atomy").appendChild(node); } getColor(){ return this.#color; } /* Definitions of other methods, inside the Class Player definition */ }
Instead of the older syntax:
var Player = function(name, color) { this._color = color; this._score = document.createElement("span"); var node = document.createElement("p"); node.style.color = color; node.appendChild(document.createTextNode(name + ": ")); node.appendChild(this._score); document.body.appendChild(node); } Player.prototype.getColor = function() { return this._color; } /*Definitions of other methods, using Player.prototype.function() syntax */
This time only 4 time 4 board (robot image from freepik). Enjoy.