patch divers + patch crash quand on joue une carte
This commit is contained in:
@@ -2,6 +2,8 @@ package com.iutlaval.myapplication.Game;
|
||||
|
||||
public final class Command {
|
||||
|
||||
public static final String UPDATE = "update";
|
||||
|
||||
private Command(){} // pas de contructor public on ne veut pas instancier cette classe
|
||||
public static final String YOURTURN="yourturn";
|
||||
public static final String DRAW = "draw";
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.io.OptionalDataException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketTimeoutException;
|
||||
|
||||
public class GameLogicThread extends Thread{
|
||||
|
||||
@@ -89,11 +90,10 @@ public class GameLogicThread extends Thread{
|
||||
renderer.addToDraw(new DrawableBitmap(bitmap, 0,0, "background", 100, 100 ));
|
||||
//drawHandPreview();
|
||||
//Rectangle pos = new Rectangle(0F,0F,100F,100F);
|
||||
|
||||
ready=true;
|
||||
|
||||
final String host = "0.tcp.ngrok.io";//192.168.43.251tcp://2.tcp.ngrok.io:
|
||||
final int port = 11601;
|
||||
final String host = "4.tcp.ngrok.io";//192.168.43.251tcp://2.tcp.ngrok.io:
|
||||
final int port = 19165;
|
||||
|
||||
try {
|
||||
client = new Socket(host, port);
|
||||
@@ -118,6 +118,7 @@ public class GameLogicThread extends Thread{
|
||||
requestResult = onCardPlayed(requestCard,requestZone);
|
||||
requestZone=-1;
|
||||
requestCard=null;
|
||||
Log.e("request","done");
|
||||
requestDone=true;
|
||||
}
|
||||
|
||||
@@ -197,6 +198,9 @@ public class GameLogicThread extends Thread{
|
||||
clientOut.writeObject("pong");
|
||||
break;
|
||||
|
||||
case Command.UPDATE:
|
||||
renderer.updateFrame();
|
||||
|
||||
case Command.PUT_ENEMY_CARD:
|
||||
int cardId = (int)clientIn.readObject();
|
||||
int zone = (int)clientIn.readObject();
|
||||
@@ -217,10 +221,15 @@ public class GameLogicThread extends Thread{
|
||||
default:
|
||||
Log.e("UNKOWN COMMAND",serveurCmd);
|
||||
}
|
||||
}catch (InterruptedIOException e)
|
||||
}catch (SocketTimeoutException e){}
|
||||
catch (InterruptedIOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
Log.e("Stopping","dead thread");
|
||||
if(e.getStackTrace().length != 0)
|
||||
{
|
||||
e.printStackTrace();
|
||||
Log.e("Stopping","dead thread");
|
||||
}
|
||||
|
||||
}catch(IOException e)
|
||||
{
|
||||
}
|
||||
@@ -275,7 +284,9 @@ public class GameLogicThread extends Thread{
|
||||
clientOut.writeObject(cardId);
|
||||
clientOut.writeObject(zone);
|
||||
|
||||
Log.e("waiting","for ok");
|
||||
if (clientIn.readObject().equals(Command.OK)) {
|
||||
Log.e("waiting","done");
|
||||
board.setCard(zone, card.getCard());
|
||||
return true;
|
||||
}
|
||||
@@ -284,19 +295,27 @@ public class GameLogicThread extends Thread{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean setOnCardPlayedRequest(DrawableCard card,int zone)
|
||||
protected synchronized boolean setOnCardPlayedRequest(DrawableCard card,int zone)
|
||||
{
|
||||
//on ne peut pas avoir 2 requette simultané
|
||||
while(!requestDone);
|
||||
if(!requestDone)return false;
|
||||
|
||||
this.requestCard=card;
|
||||
this.requestZone=zone;
|
||||
requestDone=false;
|
||||
|
||||
//on attends la fin de la requette
|
||||
while(!requestDone);
|
||||
while(!requestDone) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Log.e("card play","sending to render");
|
||||
return requestResult;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ public class NetworkDeck{
|
||||
int nbcarte=0;
|
||||
for(String s : deckstring.split(","))
|
||||
{
|
||||
if(s.equals(""))break;
|
||||
Class c = CardRegistery.get(Integer.parseInt(s));
|
||||
try {
|
||||
//on utilise le bon constructeur
|
||||
|
||||
@@ -156,7 +156,8 @@ public class DrawableCard extends Drawable{
|
||||
|
||||
frameDrawable = new DrawableBitmap(c.getFrameBitmap(context),0,0,name+"frame",CARD_WITH*ratio,CARD_HEIGHT*ratio);
|
||||
//to string retourne le hash code de l'objet qui est donc unique ce qui fait de lui un id parfait
|
||||
cardDescription = new DrawableText(c.getDescription(),0,0,toString()+"description",DESCRIPTION_WIDTH*ratio,DESCRIPTION_HEIGHT*ratio,DESCRIPTION_FONT_SIZE,DESCRIPTION_TEXT_X_RES,DESCRIPTION_TEXT_Y_RES);
|
||||
if(c.getDescription() != null)
|
||||
cardDescription = new DrawableText(c.getDescription(),0,0,toString()+"description",DESCRIPTION_WIDTH*ratio,DESCRIPTION_HEIGHT*ratio,DESCRIPTION_FONT_SIZE,DESCRIPTION_TEXT_X_RES,DESCRIPTION_TEXT_Y_RES);
|
||||
cardTitle = new DrawableText(c.getName(),0,0,toString()+"name",TITLE_WIDTH*ratio,TITLE_HEIGHT*ratio,TITLE_FONT_SIZE,TEXT_TITLE_X_RES,TEXT_TITLE_Y_RES);
|
||||
|
||||
Rectangle opacityRect = new Rectangle(x,y,OPACITY_RECT_WIDTH*ratio+x,OPACITY_RECT_HEIGHT*ratio+x);
|
||||
@@ -278,7 +279,7 @@ public class DrawableCard extends Drawable{
|
||||
|
||||
//dessine le texte
|
||||
cardTitle.drawOn(c,p);
|
||||
cardDescription.drawOn(c,p);
|
||||
if(cardDescription != null)cardDescription.drawOn(c,p);
|
||||
cardHpDrawable.drawOn(c,p);
|
||||
cardAtkDrawable.drawOn(c,p);
|
||||
}
|
||||
@@ -306,7 +307,7 @@ public class DrawableCard extends Drawable{
|
||||
pictureDrawable.setCoordinates(x + OFFBOARD_PICTURE_X*ratio, y + OFFBOARD_PICTURE_Y*ratio);
|
||||
|
||||
//les textes ce dessines depuis leur base et non depuis le coin haut gauche
|
||||
cardDescription.setCoordinates(x+OFFBOARD_DESCRIPTION_X*ratio,y+OFFBOARD_DESCRIPTION_Y*ratio);
|
||||
if(cardDescription != null)cardDescription.setCoordinates(x+OFFBOARD_DESCRIPTION_X*ratio,y+OFFBOARD_DESCRIPTION_Y*ratio);
|
||||
cardAtkDrawable.setCoordinates(x + OFFBOARD_ATK_X*ratio,y + OFFBOARD_ATK_HP_Y*ratio);
|
||||
cardHpDrawable.setCoordinates(x + OFFBOARD_HP_X*ratio,y +OFFBOARD_ATK_HP_Y*ratio);
|
||||
cardTitle.setCoordinates(x+OFFBOARD_TITLE_X*ratio,y - OFFBOARD_TITLE_Y*ratio);
|
||||
|
||||
Reference in New Issue
Block a user