tiles-game

Correct tile movement for a 2048 game

心不动则不痛 提交于 2021-02-04 18:30:37
问题 I decided to make a 2048 Command Line Edition but I'm having trouble getting the right tile movement... My current structure is that the board is a 2D array (4x4) of ints. When an input is received, it will try to push every tile in that direction (ignoring tiles with value 0), if it notices a change it will start over (Because a tile on the bottom row will have to go all the way up, not just one step up). However, a side effect of this is the following problem: [2][2][4] with the command ->

Correct tile movement for a 2048 game

▼魔方 西西 提交于 2021-02-04 18:30:30
问题 I decided to make a 2048 Command Line Edition but I'm having trouble getting the right tile movement... My current structure is that the board is a 2D array (4x4) of ints. When an input is received, it will try to push every tile in that direction (ignoring tiles with value 0), if it notices a change it will start over (Because a tile on the bottom row will have to go all the way up, not just one step up). However, a side effect of this is the following problem: [2][2][4] with the command ->

getting rectangular coordinates of tiles of a 2D map

不羁的心 提交于 2021-01-29 17:41:00
问题 I have a 2D tile map (made of 25 tiles, each 30*30 pixels) drawn on a JPanel . How can I get the rectangular coordinates of each tile? 回答1: The "basic" approach might be do something like... int tileWidth = 30; int tileHeight = 30; // Coordinates in the physical world, like a mouse point for example... int x = ...; int y = ...; int col = (int)Math.floor(x / (double)tileWidth); int row = (int)Math.floor(y / (double)tileHeight); This will return the virtual grid x/y position of each tile based