parent
5932062e0c
commit
58f55f19bf
|
|
@ -207,17 +207,11 @@ public class FillGridView extends View {
|
|||
private class FillGridTouchListener implements OnTouchListener {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
System.out.println("EVENT!");
|
||||
;
|
||||
Log.d(TAG, "EVENT");
|
||||
Pair<Float, Float> position = Util.event2pair(event);
|
||||
boolean updated = false;
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
Log.d(TAG, "EVENT: AcitonDown");
|
||||
if (Util.in(position, spawnBoundaries)) {
|
||||
Log.d(TAG, " in boundary");
|
||||
Log.d(TAG, "");
|
||||
updated = handleStart(event, position);
|
||||
}
|
||||
break;
|
||||
|
|
@ -226,7 +220,6 @@ public class FillGridView extends View {
|
|||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
//TODO: drop
|
||||
updated = handleStop(event, position);
|
||||
break;
|
||||
}
|
||||
|
|
@ -250,13 +243,9 @@ public class FillGridView extends View {
|
|||
return false;
|
||||
}
|
||||
boolean updated = false;
|
||||
Log.d(TAG, "no object dragged aleady");
|
||||
// spawnPositions.entrySet().stream().filter(entry -> selects(position, entry.getValue())).findFirst().ifPresent(entry -> startDragging(entry, position));
|
||||
for (Map.Entry<GridBlock<GroupCell>, Pair<Integer, Integer>> entry : spawnPositions.entrySet()) {
|
||||
Log.d(TAG, "handleStart: "+position+"");
|
||||
if (selects(position, entry.getValue())) {
|
||||
Log.d(TAG, "handleStart: SELECTED");
|
||||
Log.d(TAG, "now we drag");
|
||||
dragging.object = entry.getKey();
|
||||
dragging.xy = position;
|
||||
updated = true;
|
||||
|
|
@ -271,8 +260,6 @@ public class FillGridView extends View {
|
|||
boolean updated = false;
|
||||
if (dragging.object != null) {
|
||||
if (board.drop(coordinate2offset(position), dragging.object)) {
|
||||
System.out.println(spawnGrid);
|
||||
System.out.println(dragging.object);
|
||||
//Offset key = spawnGrid.entrySet().stream().filter(entry -> entry==dragging.object).findFirst().get().getKey();
|
||||
Offset key = null;
|
||||
for (Map.Entry<Offset, GridBlock<GroupCell>> entry : spawnGrid.entrySet()) {
|
||||
|
|
@ -288,11 +275,14 @@ public class FillGridView extends View {
|
|||
if (spawnGrid.isEmpty()) {
|
||||
populateSpawnArea();
|
||||
}
|
||||
score += board.collapseFilledLines();
|
||||
int count = board.collapseFilledLines();
|
||||
if (count > 0) {
|
||||
score += count;
|
||||
if (scoreView != null) {
|
||||
scoreView.setText(String.valueOf(score));
|
||||
}
|
||||
board.removeCollapsed();
|
||||
}
|
||||
updated = true;
|
||||
}
|
||||
return updated;
|
||||
|
|
@ -307,7 +297,6 @@ public class FillGridView extends View {
|
|||
private boolean selects(Pair<Float, Float> eventPos, Pair<Integer, Integer> spawnPos) {
|
||||
float xdiff = Math.abs(eventPos.first - spawnPos.first);
|
||||
float ydiff = Math.abs(eventPos.second - spawnPos.second);
|
||||
System.out.println("diffs: " + xdiff + " --- " + ydiff);
|
||||
return xdiff < 40 && ydiff < 40;
|
||||
}
|
||||
}
|
||||
|
|
@ -315,6 +304,5 @@ public class FillGridView extends View {
|
|||
private class Dragging {
|
||||
GridBlock<GroupCell> object;
|
||||
Pair<Float, Float> xy;
|
||||
Offset key;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,9 +51,11 @@ public class GridBoard<G extends GridObject<C>, C extends Cell> implements Grid<
|
|||
}
|
||||
|
||||
public void removeCollapsed() {
|
||||
List<Offset> removals = contents.entrySet().stream().filter(offsetCEntry -> offsetCEntry.getValue().isCollapsed()).map(Map.Entry::getKey).collect(Collectors.toList());
|
||||
/*List<Offset> removals = contents.entrySet().stream().filter(offsetCEntry -> offsetCEntry.getValue().isCollapsed()).map(Map.Entry::getKey).collect(Collectors.toList());
|
||||
System.out.println("REMOVALS QUEUE ("+removals.size()+"): "+removals);
|
||||
removals.forEach(contents::remove);
|
||||
removals.clear();
|
||||
removals.clear();*/
|
||||
System.err.println("!!! BUG ALERT !!!");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -63,8 +65,10 @@ public class GridBoard<G extends GridObject<C>, C extends Cell> implements Grid<
|
|||
*/
|
||||
public int collapseFilledLines() {
|
||||
List<Offset> deletionQueue = findFullLines();
|
||||
deletionQueue.stream().map(contents::get).forEach(Cell::markCollapsed);
|
||||
deletionQueue.stream().map(contents::get).distinct().forEach(Cell::markCollapsed);
|
||||
int count = deletionQueue.size();
|
||||
System.out.println("DELETION QUEUE ("+count+"): "+deletionQueue);
|
||||
deletionQueue.forEach(contents::remove);
|
||||
deletionQueue.clear();
|
||||
return count;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,12 +28,13 @@ public class GroupCell implements Cell {
|
|||
|
||||
@Override
|
||||
public void markCollapsed() {
|
||||
System.out.println("DIE");
|
||||
collapsionMark = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCollapsed() {
|
||||
return collapsionMark;
|
||||
System.out.println("die? "+collapsionMark);return collapsionMark;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue