export const BarcoTipo = Object.freeze({ FRAGATA: 1, DESTRUCTOR: 2, ACORAZADO: 3, PORTAAVIONES: 4, }); class Barco { constructor(x, y, longitud, orientacion) { this.xIni = this.x = x; this.yIni = this.y = y; this.longitud = longitud; this.orientacion = orientacion; this.seleccionado = false; this.superpuesto = false; } clickado(clickX, clickY) { if (this.orientacion === "VERTICAL") { return ( clickX === this.x && clickY >= this.y && clickY < this.y + this.longitud ); } else { return ( clickY === this.y && clickX >= this.x && clickX < this.x + this.longitud ); } } saveIniPos() { this.xIni = this.x; this.yIni = this.y; } restoreIniPos() { this.x = this.xIni; this.y = this.yIni; } setXY(x, y) { this.x = x; this.y = y; } giraBarco() { this.orientacion === "VERTICAL" ? (this.orientacion = "HORIZONTAL") : (this.orientacion = "VERTICAL"); } draw(ctx) { ctx.fillStyle = this.seleccionado ? "green" : "red"; this.orientacion === "VERTICAL" ? ctx.fillRect(this.x * 64, this.y * 64, 64, 64 * this.longitud) : ctx.fillRect(this.x * 64, this.y * 64, 64 * this.longitud, 64); } } export default Barco;