Я установил все числовое изображение в сетке изображений, теперь проблема состоит в том, как переместить числовое изображение с помощью «модуля» размером 50 пикселей (размер сетки из одной ячейки), туда, где есть свободная ячейка?
Я использую Andengine, и каждое числовое изображение - это спрайт, а также сеточное изображение.
РЕДАКТИРОВАТЬ: Я работаю таким образом:
Я устанавливаю позицию плитки с помощью этих двух функций:
private void getGrid()
{
boolean end = false;
Random random = new Random();
int x = 0;
while( ALDef.size() < 15 && x < 100 )
{
// Genera un numero a caso, da 1 a 15
int numRandom = random.nextInt( 15 );
System.out.println( x++ + ") Scelgo un numero RANDOM:" + numRandom );
// il numero e' gia' presente in array?
if ( !memory.contains( numRandom ) )
{
System.out.println( "ADD " + numRandom );
// Non e' presente...
ALDef.add( numRandom );
memory.add( numRandom );
}
else
{
System.out.println( "ESISTE " + numRandom );
memory.add( numRandom );
}
}
System.out.println( "------------------------------" );
}
// ===========================================================
// Restituisce le coordinate
// ===========================================================
public HashMap getCoordinates( int numInArray )
{
// Ottiene l'integer corrispondente a numInArray, ovvero il tasto
Integer value = ALDef.get( numInArray );
int row = 0; // riga della tabella
int position = 0; // posizione
// Definisce la riga
if ( numInArray <= 3 )
{
row = 0;
position = 3 - ( 3 - numInArray );
}
else if ( numInArray >= 4 && numInArray <= 7 )
{
row = 1;
position = numInArray - 4;
}
else if ( numInArray >= 8 && numInArray <= 11 )
{
row = 2;
position = numInArray - 8;
}
else if ( numInArray >= 12 && numInArray <= 15 )
{
row = 3;
position = numInArray - 12;
}
HashMap HM = new HashMap();
HM.put( "btn" , value );
HM.put( "x" , width * position );
HM.put( "y" , height * row );
System.out.println( "Colloco il numero " + ( value ) + " nella casella " + numInArray + "(ROW=" + row + ",POS=" + position + ")" );
return HM;
}
Логика этих двух функций заключается в том, что getGrid помещает в ArrayList случайные числа (от 0 до 15), соответствующие изображению с номером плитки.
С getCoordinates функция возвращает координату (в строке - 0, 1, 2, 3 - и положение - 0, 1, 2, 3) тайла для определения спрайта.