¿Estás disfrutando #SemanaBackend? Desbloquea Premium anual con precio especial
Clase 1
1.- Curso javaScript - Introducción, Hola Mundo y Variables
Clase 2
2.- Curso javaScript - Números y operaciones aritméticas
Clase 3
3.- Curso javaScript - Cadenas
Clase 4
4.- Curso javaScript - Condiciones
Clase 5
5.- Curso javaScript - Ciclo While
Clase 6
6.- Curso javaScript - Ciclo For
Clase 7
7.- Curso javaScript - typeof, null y undefined
Clase 8
8.- Curso javaScript - Práctica 1 - Número mágico
Clase 9
9.- Curso javaScript - Seleccionar elementos del DOM
Clase 10
10.- Curso javaScript - Eventos
Clase 11
11.- Curso javaScript - Arreglos
Clase 12
12.- Curso javaScript - Funciones
Clase 13
13.- Curso javaScript - Métodos para arreglos
Clase 14
14.- Curso javaScript - Filter ES5
Clase 15
15.- Curso javaScript - Map ES5
Clase 16
16.- Curso javaScript - forEach ES5
Clase 17
17.- Curso javaScript - reduce ES5
Clase 18
18.- Curso javaScript - Closures
Clase 19
19.- Curso javaScript - JSON
Clase 20
20.- Curso javaScript - Declarar objetos con funciones
Clase 21
21.- Curso javaScript - Prototype
Clase 22
22.- Curso javaScript - Getters y Setters
Clase 23
23.- Curso javaScript - Práctica MVC parte 1
Clase 24
24.- Curso javaScript - Práctica MVC parte 2
Clase 25
25.- Curso javaScript - Práctica MVC parte 3
Clase 26
26.- Curso JavaScript - Práctica MVC parte 4
Clase 27
27.- Curso javaScript - Práctica MVC parte 5
Clase 28
28.- Curso javaScript - Práctica MVC parte 6
Clase 29
29.- Curso javaScript -Template Strings (ES6)
Clase 30
30.- Curso javaScript - Arrow functions (ES6)
Clase 31
31.- Curso javaScript - Clases (ES6)
Clase 32
32.- Curso javaScript - let (ES6)
Clase 33
33.- Curso javaScript - Dom Crear y agregar nodos
Clase 34
34.- Curso javaScript - DOM (Hijos y padres)
12 comentario(s)
$(document).ready(function(){(function(){ //clase Board // se incicializa el width, height, dos variables para saber si se esta jugando o se a cabo y los elementos. self.Board = function(width,height) { this.width = width; this.height = height; this.playing = false; this.gameOver = false; this.bar = []; this.ball = null; } // constructor self.Board.prototype = { get elements() { var elements = this.bars; elements.push(this.ball); return elements; }
}
})();
(function(){ self.Bar = function(x,y,width,height,board) { this.x = x; this.y = y; this.width = width; this.height = height; this.board = board; this.board.bar.push(this); this.kind = 'rectangle'; }
self.Bar.prototype = { down : function(){
}, up : function(){ }
} })();
(function(){ self.BoardView = function(canvas,board) { this.canvas = canvas; this.canvas.width = board.width; this.canvas.height = board.height; this.board = board; this.ctx = canvas.getContext('2d'); }
self.BoardView.prototype = { draw : function(){ for (var i = 0; i <= this.board.elements.length -1; i++) { var el = this.Board.elements[i];
draw(this.ctx,el); }; }
}
function draw(ctx,element) { if (element !== null && element.hasOwnProperty('kind')) { switch(element.kind) { case 'rectangle' : ctx.fillRect(element.x,element.y,element.width,element.height); break; } }
} })();
main();
function main () { var board = new Board(500,200); var bar = new Bar(20,100,40,100,board); var canvas = document.getElementById('canvas'); var boardView = new BoardView(canvas,board); boardView.draw(); } });
Hola.
Siguiendo por completo el video, termine con este código en main.js :
(function(){ self.Board =function(width,height){ //pizarron this.width = width; this.height = height; this.playing = false; this.game_over = false; this.bars = []; this.ball = null; }
self.Board.prototype = { get elements(){ var elements = this.bars; elements.push(this.ball); return elements; } } })();
(function(){ self.Bar = function(x,y,width,height,board){ this.x = x; this.y = y; this.width = width; this.height = height; this.board = board; this.board.bars.push(this); this.kind = "rectangle"; }
self.Bar.prototype = { down: function(){
}, up: function(){
} } })();
(function(){ self.BoardView = function(canvas,board){ this.canvas = canvas; this.canvas.width = board.width; this.canvas.height = board.height; this.board = board; this.ctx = canvas.getContext("2d"); }
self.BoardView.prototype = { draw: function () { for (var i = this.board.elements.length - 1; i >= 0; i--) { var el = this.board.elements[i];
draw(this.ctx,el);
} } }
function draw(ctx,element){ if (element !== null && element.hasOwnProperty("kind")){ swith(element.kind){ case "rectangle": ctx.fillRect(element.x,element.y,element.height,element.width); break; } } } })();
self.addEventListener("load",main); function main (){ var board = new Board(800,400); var bar = new Bar(20,100,40,100,board); var canvas = document.getElementById('canvas'); var board_view = new BoardView(canvas,board); console.log(board); board_view.draw(); }
en index.html:
<!DOCTYPE html>
Ping Pong Álvaro
El problema lo tengo en main.js, en la linea 62 me devuelve un error que dice Uncaught SyntaxError: Unexpected token {
Que es en la linea que contiene lo siguiente:
function draw(ctx,element){ if (element !== null && element.hasOwnProperty("kind")){ swith(element.kind){ case "rectangle": ctx.fillRect(element.x,element.y,element.height,element.width); break; } } }
Ya me queme las pestañas y no encuentro el error...
hola buenas tardes estoy siguiendo la practica, no me manda error pero a la hora de mostrar el board me lo muestra cortado te pido me puedas apoyar por favor
Clase 24