Small changes to clean the code and differenciate between touchdragged and touchcard.

This commit is contained in:
2015-11-28 20:19:35 +00:00
parent c6298f9829
commit c76a2fba08
4 changed files with 50 additions and 16 deletions

View File

@@ -1,7 +1,10 @@
package checamon.games.virtuacards.android; package checamon.games.virtuacards.android;
import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.View;
import com.badlogic.gdx.backends.android.AndroidApplication; import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
@@ -12,9 +15,33 @@ public class AndroidLauncher extends AndroidApplication {
@Override @Override
protected void onCreate (Bundle savedInstanceState) { protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
hideVirtualButtons();
}
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new VirtuaCards(), config); initialize(new VirtuaCards(), config);
Log.e("Error", "Error Test"); Log.e("Error", "Error Test");
} }
@TargetApi(19)
private void hideVirtualButtons() {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
/* @Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
// In KITKAT (4.4) and next releases, hide the virtual buttons
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
hideVirtualButtons();
}
}
}*/
} }

View File

@@ -47,8 +47,8 @@ public class Card {
public Card(TextureRegion region, int id, TextureRegion backRegion) { public Card(TextureRegion region, int id, TextureRegion backRegion) {
this.card = region; this.card = region;
this.sizeX = 100f; this.sizeX = 150f;
this.sizeY = 130f; this.sizeY = 190f;
this.position = new Point(100f, 100f); this.position = new Point(100f, 100f);
this.cardSprite = new Sprite(region); this.cardSprite = new Sprite(region);
this.cardSprite.setSize(sizeX, sizeY); this.cardSprite.setSize(sizeX, sizeY);

View File

@@ -209,6 +209,7 @@ public class Deck {
subDeck.add(index,c.getId()); subDeck.add(index,c.getId());
top = c.getId() - 1; top = c.getId() - 1;
index++; index++;
i--;
} }
} }
@@ -221,4 +222,8 @@ public class Deck {
public HashMap<Integer,Integer> getDrawOrder() { public HashMap<Integer,Integer> getDrawOrder() {
return drawOrder; return drawOrder;
} }
public int getNumberOfCards() {
return numberOfCards;
}
} }

View File

@@ -1,7 +1,7 @@
package checamon.games.virtuacards; package checamon.games.virtuacards;
import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor; import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
@@ -10,16 +10,15 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import java.util.ArrayList; import java.util.ArrayList;
public class VirtuaCards extends Game implements InputProcessor {
public class VirtuaCards extends ApplicationAdapter implements InputProcessor {
private SpriteBatch batch; private SpriteBatch batch;
private int dragCounter; private int dragCounter;
private int cardCounter; private int cardCounter;
private ArrayList<Point> dragBuffer; private ArrayList<Point> dragBuffer;
private Deck fullDeck; private Deck fullDeck;
@Override @Override
public void create () { public void create () {
batch = new SpriteBatch(); batch = new SpriteBatch();
@@ -30,10 +29,10 @@ public class VirtuaCards extends ApplicationAdapter implements InputProcessor {
fullDeck = new Deck(new Texture("full_french_deck.png")); fullDeck = new Deck(new Texture("full_french_deck.png"));
//init drawn cards //init drawn cards
for (int i = 0; i <= 53; i++) for (int i = 0; i < fullDeck.getNumberOfCards(); i++)
fullDeck.getDrawOrder().put(i,i); fullDeck.getDrawOrder().put(i,i);
fullDeck.getCards().get(52).setPosition(new Point(300f,100f)); //fullDeck.getCards().get(52).setPosition(new Point(300f,100f));
fullDeck.shuffle(110f, 110f); fullDeck.shuffle(110f, 110f);
@@ -75,14 +74,13 @@ public class VirtuaCards extends ApplicationAdapter implements InputProcessor {
dragBuffer.add(dragCounter, new Point(screenX, Gdx.graphics.getHeight() - screenY)); dragBuffer.add(dragCounter, new Point(screenX, Gdx.graphics.getHeight() - screenY));
dragCounter++; dragCounter++;
cardCounter++;
} }
else { else {
dragCounter = 0; dragCounter = 0;
dragBuffer.clear(); dragBuffer.clear();
cardCounter = 0;
} }
cardCounter = 0;
return true; return true;
} }
@@ -129,7 +127,7 @@ public class VirtuaCards extends ApplicationAdapter implements InputProcessor {
dragCounter = 0; dragCounter = 0;
dragBuffer.clear(); dragBuffer.clear();
cardCounter = 0; cardCounter = 1;
return true; return true;
@@ -145,10 +143,14 @@ public class VirtuaCards extends ApplicationAdapter implements InputProcessor {
@Override @Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) { public boolean touchUp(int screenX, int screenY, int pointer, int button) {
if (Point.pointListInsideDoubleTouchedDrag(dragBuffer, 75, 120) && dragCounter > 0) { //flip card if (Point.pointListInsideDoubleTouchedDrag(dragBuffer, 75, 150) && dragCounter > 0) { //flip card
//fullDeck.getCards().get(52).setFaceUp(true); //fullDeck.getCards().get(52).setFaceUp(true);
fullDeck.getTouchedDraggedCard(screenX, Gdx.graphics.getHeight() - screenY).toggleFaceUp(); fullDeck.getTouchedDraggedCard(screenX, Gdx.graphics.getHeight() - screenY).toggleFaceUp();
} }
/*else// if (cardCounter == 1)
{
fullDeck.shuffle(screenX, Gdx.graphics.getHeight() - screenY);
}*/
dragCounter = 0; dragCounter = 0;
dragBuffer.clear(); dragBuffer.clear();
cardCounter = 0; cardCounter = 0;