try to work around overdeletion

noStream 0.1-test2
agp8x 2017-04-10 00:15:27 +02:00
parent 5932062e0c
commit 58f55f19bf
3 changed files with 20 additions and 27 deletions

View File

@ -207,17 +207,11 @@ public class FillGridView extends View {
private class FillGridTouchListener implements OnTouchListener { private class FillGridTouchListener implements OnTouchListener {
@Override @Override
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
System.out.println("EVENT!");
;
Log.d(TAG, "EVENT");
Pair<Float, Float> position = Util.event2pair(event); Pair<Float, Float> position = Util.event2pair(event);
boolean updated = false; boolean updated = false;
switch (event.getAction()) { switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_DOWN:
Log.d(TAG, "EVENT: AcitonDown");
if (Util.in(position, spawnBoundaries)) { if (Util.in(position, spawnBoundaries)) {
Log.d(TAG, " in boundary");
Log.d(TAG, "");
updated = handleStart(event, position); updated = handleStart(event, position);
} }
break; break;
@ -226,7 +220,6 @@ public class FillGridView extends View {
break; break;
case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_CANCEL:
//TODO: drop
updated = handleStop(event, position); updated = handleStop(event, position);
break; break;
} }
@ -250,13 +243,9 @@ public class FillGridView extends View {
return false; return false;
} }
boolean updated = 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)); // 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()) { for (Map.Entry<GridBlock<GroupCell>, Pair<Integer, Integer>> entry : spawnPositions.entrySet()) {
Log.d(TAG, "handleStart: "+position+"");
if (selects(position, entry.getValue())) { if (selects(position, entry.getValue())) {
Log.d(TAG, "handleStart: SELECTED");
Log.d(TAG, "now we drag");
dragging.object = entry.getKey(); dragging.object = entry.getKey();
dragging.xy = position; dragging.xy = position;
updated = true; updated = true;
@ -271,8 +260,6 @@ public class FillGridView extends View {
boolean updated = false; boolean updated = false;
if (dragging.object != null) { if (dragging.object != null) {
if (board.drop(coordinate2offset(position), dragging.object)) { 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 = spawnGrid.entrySet().stream().filter(entry -> entry==dragging.object).findFirst().get().getKey();
Offset key = null; Offset key = null;
for (Map.Entry<Offset, GridBlock<GroupCell>> entry : spawnGrid.entrySet()) { for (Map.Entry<Offset, GridBlock<GroupCell>> entry : spawnGrid.entrySet()) {
@ -288,11 +275,14 @@ public class FillGridView extends View {
if (spawnGrid.isEmpty()) { if (spawnGrid.isEmpty()) {
populateSpawnArea(); populateSpawnArea();
} }
score += board.collapseFilledLines(); int count = board.collapseFilledLines();
if (count > 0) {
score += count;
if (scoreView != null) { if (scoreView != null) {
scoreView.setText(String.valueOf(score)); scoreView.setText(String.valueOf(score));
} }
board.removeCollapsed(); board.removeCollapsed();
}
updated = true; updated = true;
} }
return updated; return updated;
@ -307,7 +297,6 @@ public class FillGridView extends View {
private boolean selects(Pair<Float, Float> eventPos, Pair<Integer, Integer> spawnPos) { private boolean selects(Pair<Float, Float> eventPos, Pair<Integer, Integer> spawnPos) {
float xdiff = Math.abs(eventPos.first - spawnPos.first); float xdiff = Math.abs(eventPos.first - spawnPos.first);
float ydiff = Math.abs(eventPos.second - spawnPos.second); float ydiff = Math.abs(eventPos.second - spawnPos.second);
System.out.println("diffs: " + xdiff + " --- " + ydiff);
return xdiff < 40 && ydiff < 40; return xdiff < 40 && ydiff < 40;
} }
} }
@ -315,6 +304,5 @@ public class FillGridView extends View {
private class Dragging { private class Dragging {
GridBlock<GroupCell> object; GridBlock<GroupCell> object;
Pair<Float, Float> xy; Pair<Float, Float> xy;
Offset key;
} }
} }

View File

@ -51,9 +51,11 @@ public class GridBoard<G extends GridObject<C>, C extends Cell> implements Grid<
} }
public void removeCollapsed() { 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.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() { public int collapseFilledLines() {
List<Offset> deletionQueue = findFullLines(); 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(); int count = deletionQueue.size();
System.out.println("DELETION QUEUE ("+count+"): "+deletionQueue);
deletionQueue.forEach(contents::remove);
deletionQueue.clear(); deletionQueue.clear();
return count; return count;
} }

View File

@ -28,12 +28,13 @@ public class GroupCell implements Cell {
@Override @Override
public void markCollapsed() { public void markCollapsed() {
System.out.println("DIE");
collapsionMark = true; collapsionMark = true;
} }
@Override @Override
public boolean isCollapsed() { public boolean isCollapsed() {
return collapsionMark; System.out.println("die? "+collapsionMark);return collapsionMark;
} }
} }