fix nullpoint sur les description de carte + masque de log de timeout

This commit is contained in:
marc barbier
2020-12-16 17:32:29 +01:00
parent e76532ec72
commit 0c7e09249a
3 changed files with 27 additions and 15 deletions
@@ -30,10 +30,11 @@ import java.net.SocketTimeoutException;
public class GameLogicThread extends Thread{
public static final float BUTTON_Y_POS = 50F;
public static final float BUTTON_Y_POS = 45F;
public static final int BUTTON_X_POS = 0;
public static final float BUTTON_X_SIZE = 5F;
public static final float BUTTON_Y_SIZE = 2.5F;
public static final float BUTTON_X_SIZE = 20F;
public static final float BUTTON_Y_SIZE = 10F;
public static final String BUTTONTURN_DRAWABLE_NAME = "buttonturn";
private Context cont;
private Renderer renderer;
private boolean ready;
@@ -81,7 +82,7 @@ public class GameLogicThread extends Thread{
//loading textures
Bitmap bitmapYourTurn = BitmapFactory.decodeResource(renderer.getResources(),R.drawable.t_pb_your_turn);
Bitmap bitmapEnemyTurn = BitmapFactory.decodeResource(renderer.getResources(),R.drawable.t_pb_enemy_turn);
Bitmap bitmapButtonEnd = BitmapFactory.decodeResource(renderer.getResources(),R.drawable.t_pb_enemy_turn);
Bitmap bitmapButtonEnd = BitmapFactory.decodeResource(renderer.getResources(),R.drawable.t_btn_boutonfintour);
Bitmap bitmap= BitmapFactory.decodeResource(cont.getResources(), R.drawable.t_b_board_background);
//adding the background
@@ -125,7 +126,7 @@ public class GameLogicThread extends Thread{
coms.setLimitedTimeOut();
String serveurCmd = coms.recieve();
coms.setUnlimitedTimeOut();
Log.e("command",serveurCmd);
if(!serveurCmd.equals("timeout"))Log.e("command",serveurCmd);
switch (serveurCmd)
{
case Command.GET_DECK:
@@ -144,7 +145,7 @@ public class GameLogicThread extends Thread{
case Command.YOURTURN:
isYourTurn=true;
renderer.addToDraw(new DrawableSelfRemoving(new DrawableBitmap(bitmapYourTurn,0,0,"yourTurn",100F,50F),1));
renderer.addToDraw(new DrawableBitmap(bitmapButtonEnd, BUTTON_X_POS, BUTTON_Y_POS,"buttonturn", BUTTON_X_SIZE, BUTTON_Y_SIZE));
renderer.addToDraw(new DrawableBitmap(bitmapButtonEnd, BUTTON_X_POS, BUTTON_Y_POS, BUTTONTURN_DRAWABLE_NAME, BUTTON_X_SIZE, BUTTON_Y_SIZE));
break;
case Command.SETMANA:
@@ -154,6 +155,8 @@ public class GameLogicThread extends Thread{
break;
case Command.ENEMYTURN:
//on update pas vu que l'instruction suivante va le faire
renderer.removeToDrawWithoutUpdate(BUTTONTURN_DRAWABLE_NAME);
renderer.addToDraw(new DrawableSelfRemoving(new DrawableBitmap(bitmapEnemyTurn,0,0,"enemyTurn",100F,50F),1));
break;
@@ -207,6 +210,9 @@ public class GameLogicThread extends Thread{
//ajout la card au terain
board.setEnemyCard(zone,cardPlayed);
break;
case "timeout":
//ceci est une erreur et non une commande elle se doit donc de ne rien faire
break;
default:
Log.e("UNKOWN COMMAND",serveurCmd);
@@ -365,6 +371,7 @@ public class GameLogicThread extends Thread{
if(isYourTurn)
{
try {
Log.e("TURN","PASSED");
coms.send(Command.PASS_TURN);
} catch (IOException e) {
e.printStackTrace();
@@ -1,6 +1,7 @@
package com.iutlaval.myapplication.Game;
import android.content.Context;
import android.util.Log;
import android.view.MotionEvent;
import com.iutlaval.myapplication.GameActivity;
@@ -188,6 +189,7 @@ public class TouchHandler {
unScalled_X > GameLogicThread.BUTTON_X_POS && unScalled_X < GameLogicThread.BUTTON_X_POS + GameLogicThread.BUTTON_X_SIZE &&
unScalled_Y > GameLogicThread.BUTTON_Y_POS && unScalled_Y < GameLogicThread.BUTTON_Y_POS + GameLogicThread.BUTTON_Y_SIZE)
{
Log.e("push","detected");
gameLogic.onEndTurnButtonPushed();
}
}
@@ -35,21 +35,24 @@ public class DrawableText extends Drawable{
p.setAntiAlias(true);
p.setTextSize(textSize);
List<String> linesOfText = cutText(20,text);
//+10 permet d'e prendre en compte les p,q,j qui dessende plus bas que les autres
Bitmap bitmap = Bitmap.createBitmap(x_canvasRatio, y_canvasRatio, Bitmap.Config.ARGB_8888);
setBitmap(bitmap);
Canvas c = new Canvas(bitmap);
int index = 1;
for(String line : linesOfText)
//si on a une description
if(text != null)
{
//y_canvasRatio/linesOfText.size()
c.drawText(line ,0,index*textSize,p);
index++;
int index = 1;
List<String> linesOfText = cutText(20,text);
for(String line : linesOfText)
{
//y_canvasRatio/linesOfText.size()
c.drawText(line ,0,index*textSize,p);
index++;
}
}
int scalled_x_size = (int)(GameActivity.screenWidth*x_size/100);
int scalled_y_size = (int)(GameActivity.screenHeight*y_size/100);