I was working on a small JavaScript project to make a tile based game (not homework, don't worry!), however I ran into a problem with my 'tile' class.
Each 'tile' has an X and a Y property, for its X and Y position on a grid. The grid is stored as a 2 dimensional array of these tiles. The tiles are constructed like so:
class tile {
constructor(x,y) {
this.x = x;
this.y = y;
console.log(`Genned Tile: ${x} , ${y}`);
}
}
There's also a small logging message contained
So then, I wrote a small loop to fill an array with 'tile' objects:
for (var x = 0; x < width; x++) {
for (var y = 0; y < height; y++) {
tiles[x,y] = new tile(x,y);
}
}
width and height are both set to 5. This should fill slots 0-4.
However, when displaying the tiles, the X coord is wrong! I'll attach a snippet to show you what I mean
// tile class
class tile {
constructor(x,y) {
this.x = x;
this.y = y;
console.log(`Genned Tile: ${x} , ${y}`);
}
}
var width = 5;
var height = 5;
var tiles = new Array(width,height);
// populates array
for (var x = 0; x < width; x++) {
for (var y = 0; y < height; y++) {
tiles[x,y] = new tile(x,y);
}
}
// displays each item in the array
for (var x = 0; x < width; x++) {
for (var y = 0; y < height; y++) {
let tile = tiles[x,y];
console.log(`Checked Tile: ${tile.x} , ${tile.y}`);
}
}
I'm using Ramda as my functional programming helper library to build a React app. I'm trying to build myself whereAny. Ramda exposes where which checks if every prop it is given satisfies the ...
I'm using Ramda as my functional programming helper library to build a React app. I'm trying to build myself whereAny. Ramda exposes where which checks if every prop it is given satisfies the ...
I have a form on a PHP page : <form name="SendEmail01" method="post"> form items here... </form> I then process it like this: if(isset($_POST["Submit"])) { All tasks here... $...
I have a form on a PHP page : <form name="SendEmail01" method="post"> form items here... </form> I then process it like this: if(isset($_POST["Submit"])) { All tasks here... $...
the problem is simple, document.getElementsByTagName('*') does not select the SVG tag and in the console it gives an error. But if I erase the SVG labels, works correctly. My Code: var Master = ...
the problem is simple, document.getElementsByTagName('*') does not select the SVG tag and in the console it gives an error. But if I erase the SVG labels, works correctly. My Code: var Master = ...
There is a function that returns an array according to the second argument (if the country is Japan, it will return only brands of cars from Japan). Is it possible to improve the function using only ...
There is a function that returns an array according to the second argument (if the country is Japan, it will return only brands of cars from Japan). Is it possible to improve the function using only ...