Small changes to clean the code and differenciate between touchdragged and touchcard.
This commit is contained in:
@@ -16,6 +16,7 @@ public class Card {
|
|||||||
private Sprite cardSprite;
|
private Sprite cardSprite;
|
||||||
private float sizeX;
|
private float sizeX;
|
||||||
private float sizeY;
|
private float sizeY;
|
||||||
|
private int id;
|
||||||
//private boolean faceUp;
|
//private boolean faceUp;
|
||||||
//private boolean onTable;
|
//private boolean onTable;
|
||||||
//private float orientation;
|
//private float orientation;
|
||||||
@@ -42,7 +43,7 @@ public class Card {
|
|||||||
this.position = new Point(100f, 100f);
|
this.position = new Point(100f, 100f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Card(TextureRegion region) {
|
public Card(TextureRegion region, int id) {
|
||||||
|
|
||||||
this.card = region;
|
this.card = region;
|
||||||
this.cardSprite = new Sprite(region);
|
this.cardSprite = new Sprite(region);
|
||||||
@@ -51,6 +52,7 @@ public class Card {
|
|||||||
this.cardSprite.setSize(sizeX, sizeY);
|
this.cardSprite.setSize(sizeX, sizeY);
|
||||||
this.position = new Point(100f, 100f);
|
this.position = new Point(100f, 100f);
|
||||||
this.cardSprite.setPosition(position.getX(), position.getY());
|
this.cardSprite.setPosition(position.getX(), position.getY());
|
||||||
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawCardSprite(SpriteBatch batch,Point point, float sizeX, float sizeY){
|
public void drawCardSprite(SpriteBatch batch,Point point, float sizeX, float sizeY){
|
||||||
@@ -121,4 +123,8 @@ public class Card {
|
|||||||
public Sprite getCardSprite() {
|
public Sprite getCardSprite() {
|
||||||
return this.cardSprite;
|
return this.cardSprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package checamon.games.virtuacards;
|
package checamon.games.virtuacards;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
|
|
||||||
@@ -17,7 +16,6 @@ public class Deck {
|
|||||||
private ArrayList<Card> cards;
|
private ArrayList<Card> cards;
|
||||||
private HashMap<Integer,Integer> drawOrder;
|
private HashMap<Integer,Integer> drawOrder;
|
||||||
private int numberOfCards;
|
private int numberOfCards;
|
||||||
private Sprite result;
|
|
||||||
|
|
||||||
public Deck(Texture texture) {
|
public Deck(Texture texture) {
|
||||||
try {
|
try {
|
||||||
@@ -29,7 +27,7 @@ public class Deck {
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
for (int j = 0; j < 13; j++){
|
for (int j = 0; j < 13; j++){
|
||||||
this.cards.add(index, new Card(cc[i][j]));
|
this.cards.add(index, new Card(cc[i][j], index));
|
||||||
this.drawOrder.put(index, -1);
|
this.drawOrder.put(index, -1);
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
@@ -58,20 +56,14 @@ public class Deck {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawCards(SpriteBatch batch)
|
public void drawCards(SpriteBatch batch) {
|
||||||
{
|
|
||||||
boolean exit = false;
|
|
||||||
Sprite aux;
|
|
||||||
int i = 0;
|
|
||||||
while (i < numberOfCards && !exit){
|
|
||||||
if (drawOrder.get(i) > -1){
|
|
||||||
cards.get(drawOrder.get(i)).drawCardSprite(batch);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
exit = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
while (i <= numberOfCards){
|
||||||
|
if (drawOrder.get(i) > -1)
|
||||||
|
cards.get(drawOrder.get(i)).drawCardSprite(batch);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTouchingCard(float x, float y){
|
public boolean isTouchingCard(float x, float y){
|
||||||
@@ -80,16 +72,14 @@ public class Deck {
|
|||||||
boolean result = false;
|
boolean result = false;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
while (i < numberOfCards && !exit){
|
while (i <= numberOfCards && !exit){
|
||||||
if (drawOrder.get(i) > -1){
|
if (drawOrder.get(i) > -1){
|
||||||
if (cards.get(drawOrder.get(i)).isTouched(x,y)) {
|
if (cards.get(drawOrder.get(i)).isTouched(x, y)) {
|
||||||
result = true;
|
result = true;
|
||||||
exit = true;
|
exit = true;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
else
|
i++;
|
||||||
exit = true;
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -100,66 +90,63 @@ public class Deck {
|
|||||||
boolean result = false;
|
boolean result = false;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
while (i < numberOfCards && !exit){
|
while (i <= numberOfCards && !exit){
|
||||||
if (drawOrder.get(i) > -1){
|
if (drawOrder.get(i) > -1){
|
||||||
if (cards.get(drawOrder.get(i)).isTouchedDragged(x, y)) {
|
if (cards.get(drawOrder.get(i)).isTouchedDragged(x, y)) {
|
||||||
result = true;
|
result = true;
|
||||||
exit = true;
|
exit = true;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
else
|
i++;
|
||||||
exit = true;
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Card getTouchedDraggedCard(float x, float y){
|
public Card getTouchedDraggedCard(float x, float y){
|
||||||
|
|
||||||
boolean exit = false;
|
|
||||||
this.result = null;
|
|
||||||
Card cardResult = null;
|
Card cardResult = null;
|
||||||
int i = 0;
|
int i = numberOfCards;
|
||||||
|
boolean exit = false;
|
||||||
|
|
||||||
while (i < numberOfCards && !exit){
|
while (i >= 0 && !exit){
|
||||||
if (drawOrder.get(i) > -1){
|
|
||||||
if (cards.get(drawOrder.get(i)).isTouchedDragged(x, y)) {
|
if (cards.get(drawOrder.get(i)).isTouchedDragged(x, y)) {
|
||||||
|
|
||||||
this.result = cards.get(drawOrder.get(i)).getCardSprite();
|
|
||||||
cardResult = cards.get(drawOrder.get(i));
|
cardResult = cards.get(drawOrder.get(i));
|
||||||
exit = true;
|
exit = true;
|
||||||
|
}else {
|
||||||
|
i--;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
else
|
if (i < numberOfCards)
|
||||||
exit = true;
|
setCardDrawOrderOnTop(i);
|
||||||
}
|
|
||||||
return cardResult;
|
return cardResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Card getTouchedCard(float x, float y){
|
public Card getTouchedCard(float x, float y){
|
||||||
|
|
||||||
boolean exit = false;
|
|
||||||
this.result = null;
|
|
||||||
Card cardResult = null;
|
Card cardResult = null;
|
||||||
int i = 0;
|
int i = numberOfCards;
|
||||||
|
boolean exit = false;
|
||||||
|
|
||||||
while (i < numberOfCards && !exit){
|
while (i >= 0 && !exit){
|
||||||
if (drawOrder.get(i) > -1){
|
if (drawOrder.get(i) > -1 && cards.get(drawOrder.get(i)).isTouched(x, y)) {
|
||||||
if (cards.get(drawOrder.get(i)).isTouched(x, y)) {
|
|
||||||
|
|
||||||
this.result = cards.get(drawOrder.get(i)).getCardSprite();
|
|
||||||
cardResult = cards.get(drawOrder.get(i));
|
cardResult = cards.get(drawOrder.get(i));
|
||||||
exit = true;
|
exit = true;
|
||||||
|
}else{
|
||||||
|
i--;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
exit = true;
|
|
||||||
}
|
}
|
||||||
|
if (i < numberOfCards)
|
||||||
|
setCardDrawOrderOnTop(i);
|
||||||
|
|
||||||
return cardResult;
|
return cardResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setCardDrawOrderOnTop(int index){
|
||||||
|
int replace = drawOrder.get(numberOfCards);
|
||||||
|
drawOrder.put(numberOfCards,drawOrder.get(index));
|
||||||
|
drawOrder.put(index, replace);
|
||||||
|
}
|
||||||
|
|
||||||
public HashMap<Integer,Integer> getDrawOrder() {
|
public HashMap<Integer,Integer> getDrawOrder() {
|
||||||
return drawOrder;
|
return drawOrder;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user