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 {
@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,13 +260,11 @@ 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;
Offset key = null;
for (Map.Entry<Offset, GridBlock<GroupCell>> entry : spawnGrid.entrySet()) {
if (entry.getValue() == dragging.object){
key= entry.getKey();
if (entry.getValue() == dragging.object) {
key = entry.getKey();
break;
}
}
@ -285,14 +272,17 @@ public class FillGridView extends View {
spawnPositions.remove(dragging.object);
}
dragging.object = null;
if (spawnGrid.isEmpty()){
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;
}
}

View File

@ -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;
}

View File

@ -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;
}
}