refactor des drawable + debut du code des zones placable
This commit is contained in:
@@ -8,29 +8,53 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Board {
|
||||
private static final int MAX_CARD_ON_BOARD=10;
|
||||
private List<Card> advCardsOnBoard;
|
||||
private List<Card> playerCardsOnBoard;
|
||||
public static final int MAX_CARD_ON_BOARD=5;
|
||||
private Card[] advCardsOnBoard;
|
||||
private Card[] playerCardsOnBoard;
|
||||
|
||||
public Board()
|
||||
{
|
||||
advCardsOnBoard = new ArrayList<>();
|
||||
playerCardsOnBoard = new ArrayList<>();
|
||||
advCardsOnBoard = new Card[MAX_CARD_ON_BOARD];
|
||||
playerCardsOnBoard = new Card[MAX_CARD_ON_BOARD];
|
||||
}
|
||||
|
||||
/**
|
||||
* joue une carte et l'ajoute au terrain du joueur correspondant
|
||||
* si retourne faux alors la carte n'a pas éte joué
|
||||
* @param card
|
||||
* @param player
|
||||
* @return success/failure
|
||||
*/
|
||||
public void playCard(Card card,Player player)
|
||||
public boolean playCard(Card card,Player player)
|
||||
{
|
||||
boolean returnvalue = false;
|
||||
if(player instanceof PlayerLocal)
|
||||
{
|
||||
playerCardsOnBoard.add(card);
|
||||
for(Card c : playerCardsOnBoard)
|
||||
{
|
||||
if(c == null)
|
||||
{
|
||||
c=card;
|
||||
returnvalue=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
advCardsOnBoard.add(card);
|
||||
for(Card c : advCardsOnBoard)
|
||||
{
|
||||
if(c == null)
|
||||
{
|
||||
c=card;
|
||||
returnvalue=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
card.onCardPlayed(this,player);
|
||||
return returnvalue;
|
||||
}
|
||||
|
||||
public Card[] getPlayerCardsOnBoard() {
|
||||
return playerCardsOnBoard;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.iutlaval.myapplication.Game.Decks.DeckDemo;
|
||||
import com.iutlaval.myapplication.GameActivity;
|
||||
import com.iutlaval.myapplication.R;
|
||||
import com.iutlaval.myapplication.Video.Drawables.Drawable;
|
||||
import com.iutlaval.myapplication.Video.Drawables.DrawableBitmap;
|
||||
import com.iutlaval.myapplication.Video.Drawables.DrawableCard;
|
||||
import com.iutlaval.myapplication.Video.Renderer;
|
||||
|
||||
@@ -25,6 +26,7 @@ public class GameLogicThread extends Thread{
|
||||
|
||||
private Deck localPlayerDeck;
|
||||
private Hand localPlayerHand;
|
||||
private Board board;
|
||||
|
||||
public GameLogicThread(GameActivity gameActivity, Renderer renderer)
|
||||
{
|
||||
@@ -37,6 +39,7 @@ public class GameLogicThread extends Thread{
|
||||
localPlayerHand = new Hand();
|
||||
localPlayerHand.fillHand(localPlayerDeck);
|
||||
this.gameActivity=gameActivity;
|
||||
board=new Board();
|
||||
GameActivity.setGameEngine(this);
|
||||
}
|
||||
|
||||
@@ -49,7 +52,7 @@ public class GameLogicThread extends Thread{
|
||||
Log.e("RESOLUTION:",""+GameActivity.screenWidth+"x"+GameActivity.screenHeight);
|
||||
//affichage de l'arriere plan
|
||||
Bitmap bitmap= BitmapFactory.decodeResource(cont.getResources(), R.drawable.t_b_board_background);
|
||||
renderer.addToDraw(new Drawable(bitmap, 0,0, "background", 100, 100 ));
|
||||
renderer.addToDraw(new DrawableBitmap(bitmap, 0,0, "background", 100, 100 ));
|
||||
drawHandPreview();
|
||||
|
||||
ready=true;
|
||||
@@ -61,6 +64,9 @@ public class GameLogicThread extends Thread{
|
||||
renderer.updateFrame();
|
||||
}
|
||||
|
||||
/**
|
||||
* cette methode est UNIQUEMENT a bute de test elle ne sert a rien d'autre ne pas s'en servir
|
||||
*/
|
||||
private void drawHandPreview() {
|
||||
int i = 0;
|
||||
for(Card c : localPlayerHand.getHand())
|
||||
@@ -74,7 +80,7 @@ public class GameLogicThread extends Thread{
|
||||
|
||||
/**
|
||||
* cette fonction est appeller a chaque fin de frame
|
||||
* CETTE FONCTION A UN IMPACT DIRRECT SUR LES FPS ELLE SE DOIT D'être OPTIMAL
|
||||
* CETTE FONCTION A UN IMPACT DIRECT SUR LES FPS ELLE SE DOIT D'être OPTIMAL
|
||||
* TOUT CALCUL REDONDANT CE DOIT D'AVOIR ETE PRE FAIT
|
||||
*
|
||||
* TOUT APELLE DE CETTE FONCTION SE DOIT D'ÊTRE PROTEGER PAR isReady()
|
||||
@@ -105,10 +111,12 @@ public class GameLogicThread extends Thread{
|
||||
*/
|
||||
public void onTouchEvent(MotionEvent event) {
|
||||
if(isReady()){
|
||||
float unscalled_Y = event.getY() / GameActivity.screenHeight * 100;
|
||||
if(unscalled_Y >= 90F && event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
//calcul y sur une echelle de 0 a 100
|
||||
float scalled_Y = event.getY() / GameActivity.screenHeight * 100;
|
||||
//si on clique sur une carte dans la main
|
||||
if(event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
float unscalled_X = event.getX() / GameActivity.screenWidth * 100;
|
||||
DrawableCard smallCArd = renderer.getCardOn(unscalled_X,unscalled_Y);
|
||||
DrawableCard smallCArd = renderer.getCardOn(unscalled_X,scalled_Y);
|
||||
if(smallCArd !=null)
|
||||
{
|
||||
if(currentlySelected !=null)
|
||||
@@ -122,8 +130,8 @@ public class GameLogicThread extends Thread{
|
||||
renderer.addToDraw(bigCard);
|
||||
bigCard.setCoordinates(72F,10F);
|
||||
smallCArd.setCoordinates(smallCArd.getX(),smallCArd.getY() - SELECTING_OFFSET);
|
||||
touch.onTouchEvent(event);
|
||||
}
|
||||
touch.onTouchEvent(event);
|
||||
}else if(event.getAction() == MotionEvent.ACTION_UP){
|
||||
//currentlySelected.setCoordinates(currentlySelected.getX(),currentlySelected.getY() + SELECTING_OFFSET);
|
||||
touch.onTouchEvent(event);
|
||||
@@ -139,4 +147,19 @@ public class GameLogicThread extends Thread{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void displayPlayableZones()
|
||||
{
|
||||
Card[] cardsOnBoard = board.getPlayerCardsOnBoard();
|
||||
for(int i=0 ; i < cardsOnBoard.length ;i++)
|
||||
{
|
||||
if(cardsOnBoard[i] == null)
|
||||
{
|
||||
displayPlayableZoneOn(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void displayPlayableZoneOn(int i) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,8 +37,6 @@ public class GameActivity extends Activity {
|
||||
|
||||
renderer = new Renderer(getBaseContext(),this);
|
||||
|
||||
|
||||
|
||||
setContentView(renderer);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import com.iutlaval.myapplication.Video.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Drawable {
|
||||
public abstract class Drawable {
|
||||
|
||||
private float x,y;
|
||||
private String name;
|
||||
@@ -37,73 +37,6 @@ public class Drawable {
|
||||
this.name=name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param bitmap a dessiner
|
||||
* @param x_pos position en x du texte
|
||||
* @param y_pos position en y du texte
|
||||
* @param name nom du Drawable
|
||||
* @param x_size taille du drawable entre 0 et 100
|
||||
* @param y_size taille du drawable entre 0 et 100
|
||||
* @throws InvalidDataException
|
||||
*/
|
||||
public Drawable(@NonNull Bitmap bitmap, float x_pos, float y_pos, String name, float x_size, float y_size){
|
||||
this(x_pos,y_pos,name);
|
||||
|
||||
float x_scaled_size = x_size* GameActivity.screenWidth/100;
|
||||
float y_scaled_size = y_size* GameActivity.screenHeight/100;
|
||||
|
||||
if(x_scaled_size <=0 || y_scaled_size <=0)
|
||||
{
|
||||
Log.e("DRAWABLE_TEXTURE :","ERREUR DE MISE A L'ECHELLE");
|
||||
System.exit(ERROR_CODE.ERROR_TEXTURE_DIMENSIONS_INVALID.ordinal());
|
||||
}
|
||||
|
||||
this.bitmap = Bitmap.createScaledBitmap(bitmap, (int)x_scaled_size, (int)y_scaled_size, GameActivity.bilinearFiltering);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ce constructeur n'est pas rapide essayer de l'utiliser le moin possible
|
||||
* TODO : optimize it
|
||||
*
|
||||
* ce constructeur dessine un rectangle avec la texture donner en argument
|
||||
* @param rectangle recange cooresspondant a la surface a dessiner
|
||||
* @param name nom du drawable agit comme un identifiant mais doit être unique
|
||||
* @param color couleur du rectangle
|
||||
*/
|
||||
public Drawable(Rectangle rectangle, String name, int color) throws InvalidDataException {
|
||||
this(rectangle.getPositionX(),rectangle.getPositionY(),name);
|
||||
if(rectangle.getHeight() <= 0 || rectangle.getWidth() <=0)throw new InvalidDataException(name,rectangle);
|
||||
|
||||
rectangle.scaleRectangleToScreen();
|
||||
Bitmap bitmap = Bitmap.createBitmap((int)rectangle.getWidth(),(int)rectangle.getHeight(), Bitmap.Config.ARGB_8888);
|
||||
rectangle.bitmapRectangleBuilder(bitmap,color);
|
||||
|
||||
this.bitmap=bitmap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ce constructeur n'est pas tres rapide donc a eviter il utilse pas mal de ram mais sava encore le gc de java s'en ocupe vite
|
||||
* ce constructeur dessine un rectangle avec la texture donner en argument
|
||||
* @param bitmap
|
||||
* @param rectangle recange cooresspondant a la surface a dessiner
|
||||
* @param name nom du drawable agit comme un identifiant mais doit être unique
|
||||
* @param color couleur du rectangle
|
||||
* @throws InvalidDataException
|
||||
*/
|
||||
//TODO verifier l'utiliter de ce constructeur
|
||||
@Deprecated
|
||||
public Drawable(Bitmap bitmap,Rectangle rectangle, String name, int color) throws InvalidDataException {
|
||||
this(rectangle.getPositionX(),rectangle.getPositionY(),name);
|
||||
if(rectangle.getHeight() <= 0 || rectangle.getWidth() <=0 || bitmap == null)throw new InvalidDataException(name,rectangle);
|
||||
|
||||
rectangle.scaleRectangleToScreen();
|
||||
rectangle.bitmapRectangleBuilder(bitmap,color);
|
||||
this.bitmap = bitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* NE PAS UTLISER CETTE FONCTION EST RESERVER AU FONCTIONNEMENT DU MOTEUR GRAPHIQUE
|
||||
* SI VOUS EN AVEZ BESOIN ENTRE EN CONTACT AVEC MARC POUR AJOUTER AU MOTEUR LA FONCTIONNALITER QUE VOUS AVEZ BESOIN
|
||||
@@ -168,40 +101,6 @@ public class Drawable {
|
||||
p = new Paint();
|
||||
}
|
||||
|
||||
/**
|
||||
* coupe le texte a une certaine longeur
|
||||
* @param charPerLines nombre de caractére par lignes
|
||||
* @param text texte a afficher
|
||||
* @return liste de lignes de texte
|
||||
*/
|
||||
protected List<String> cutText(int charPerLines,String text)
|
||||
{
|
||||
List<String> output = new ArrayList<>();
|
||||
//TODO cut text in lines
|
||||
StringBuilder nextLine = new StringBuilder(charPerLines);
|
||||
for (String word : text.split(" ")) {
|
||||
if(word.length() < charPerLines)
|
||||
{
|
||||
if(word.length() + nextLine.toString().length() +1 < charPerLines)
|
||||
{
|
||||
nextLine.append(" " + word);
|
||||
}else{
|
||||
//fillWithSpace(nextLine,charPerLines);
|
||||
output.add(nextLine.toString());
|
||||
nextLine.delete(0,charPerLines-1);
|
||||
}
|
||||
}else{
|
||||
Log.e("TextRender","ERROR WORD TOO LONG :" + word);
|
||||
}
|
||||
}
|
||||
if(!nextLine.toString().equals(""))
|
||||
{
|
||||
//fillWithSpace(nextLine,charPerLines);
|
||||
output.add(nextLine.toString());
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
protected void scale(float i) {
|
||||
bitmap = Bitmap.createScaledBitmap(this.bitmap,(int)(bitmap.getWidth()*i),(int)(bitmap.getHeight()*i),GameActivity.bilinearFiltering);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.iutlaval.myapplication.Video.Drawables;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.iutlaval.myapplication.ERROR_CODE;
|
||||
import com.iutlaval.myapplication.GameActivity;
|
||||
import com.iutlaval.myapplication.InvalidDataException;
|
||||
|
||||
public class DrawableBitmap extends Drawable{
|
||||
/**
|
||||
* @param bitmap a dessiner
|
||||
* @param x_pos position en x du texte
|
||||
* @param y_pos position en y du texte
|
||||
* @param name nom du Drawable
|
||||
* @param x_size taille du drawable entre 0 et 100
|
||||
* @param y_size taille du drawable entre 0 et 100
|
||||
* @throws InvalidDataException
|
||||
*/
|
||||
public DrawableBitmap(@NonNull Bitmap bitmap, float x_pos, float y_pos, String name, float x_size, float y_size){
|
||||
super(x_pos,y_pos,name);
|
||||
|
||||
float x_scaled_size = x_size* GameActivity.screenWidth/100;
|
||||
float y_scaled_size = y_size* GameActivity.screenHeight/100;
|
||||
|
||||
if(x_scaled_size <=0 || y_scaled_size <=0)
|
||||
{
|
||||
Log.e("DRAWABLE_TEXTURE :","ERREUR DE MISE A L'ECHELLE");
|
||||
System.exit(ERROR_CODE.ERROR_TEXTURE_DIMENSIONS_INVALID.ordinal());
|
||||
}
|
||||
|
||||
setBitmap(Bitmap.createScaledBitmap(bitmap, (int)x_scaled_size, (int)y_scaled_size, GameActivity.bilinearFiltering));
|
||||
}
|
||||
}
|
||||
@@ -151,7 +151,7 @@ public class DrawableCard extends Drawable{
|
||||
this.ratio=ratio;
|
||||
this.card=c;
|
||||
|
||||
frameDrawable = new Drawable(c.getFrameBitmap(context),0,0,name+"frame",CARD_WITH*ratio,CARD_HEIGHT*ratio);
|
||||
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);
|
||||
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);
|
||||
@@ -160,8 +160,8 @@ public class DrawableCard extends Drawable{
|
||||
Bitmap pictureBitmap = BitmapFactory.decodeResource(context.getResources(),c.getCardPicture());
|
||||
|
||||
try {
|
||||
opacityRectangleDrawable = new Drawable(opacityRect,toString()+"Opacity", Color.parseColor(c.getColor()));
|
||||
pictureDrawable = new Drawable(pictureBitmap,0,0,toString()+"Picture",PICTURE_WIDTH*ratio,PICTURE_HEIGHT*ratio);
|
||||
opacityRectangleDrawable = new DrawableRectangle(opacityRect,toString()+"Opacity", Color.parseColor(c.getColor()));
|
||||
pictureDrawable = new DrawableBitmap(pictureBitmap,0,0,toString()+"Picture",PICTURE_WIDTH*ratio,PICTURE_HEIGHT*ratio);
|
||||
} catch (InvalidDataException e) {
|
||||
e.printStackTrace();
|
||||
Log.e("CARTE :","forme de la carte invalide !");
|
||||
@@ -187,7 +187,7 @@ public class DrawableCard extends Drawable{
|
||||
cardOnBoardAtk.bitmapRectangleBuilder(cardOnBoardBitmap,Color.parseColor("#FFFF0000"));
|
||||
cardOnBoardHp.bitmapRectangleBuilder(cardOnBoardBitmap,Color.parseColor("#FF00FF00"));
|
||||
|
||||
cardOnBoardDrawable = new Drawable(cardOnBoardBitmap,x,y,toString()+"BOARD",CARD_ON_BOARD_DRAWABLE_WIDTH*ratio,CARD_ON_BOARD_DRAWABLE_HEIGHT*ratio);
|
||||
cardOnBoardDrawable = new DrawableBitmap(cardOnBoardBitmap,x,y,toString()+"BOARD",CARD_ON_BOARD_DRAWABLE_WIDTH*ratio,CARD_ON_BOARD_DRAWABLE_HEIGHT*ratio);
|
||||
|
||||
c.setDrawableCard(this);
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.iutlaval.myapplication.Video.Drawables;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import com.iutlaval.myapplication.InvalidDataException;
|
||||
import com.iutlaval.myapplication.Video.Rectangle;
|
||||
|
||||
public class DrawableRectangle extends Drawable{
|
||||
/**
|
||||
* ce constructeur n'est pas rapide essayer de l'utiliser le moin possible
|
||||
* TODO : optimize it
|
||||
*
|
||||
* ce constructeur dessine un rectangle avec la couleur donné en argument
|
||||
* @param rectangle recange cooresspondant a la surface a dessiner
|
||||
* @param name nom du drawable agit comme un identifiant mais doit être unique
|
||||
* @param color couleur du rectangle
|
||||
*/
|
||||
public DrawableRectangle(Rectangle rectangle, String name, int color) throws InvalidDataException {
|
||||
super(rectangle.getPositionX(),rectangle.getPositionY(),name);
|
||||
if(rectangle.getHeight() <= 0 || rectangle.getWidth() <=0)throw new InvalidDataException(name,rectangle);
|
||||
|
||||
rectangle.scaleRectangleToScreen();
|
||||
Bitmap bitmap = Bitmap.createBitmap((int)rectangle.getWidth(),(int)rectangle.getHeight(), Bitmap.Config.ARGB_8888);
|
||||
rectangle.bitmapRectangleBuilder(bitmap,color);
|
||||
|
||||
setBitmap(bitmap);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ce constructeur n'est pas tres rapide donc a eviter il utilse pas mal de ram mais sava encore le gc de java s'en ocupe vite
|
||||
* ce constructeur dessine un rectangle avec la couleur donné" en argument
|
||||
* @param bitmap
|
||||
* @param rectangle recange cooresspondant a la surface a dessiner
|
||||
* @param name nom du drawable agit comme un identifiant mais doit être unique
|
||||
* @param color couleur du rectangle
|
||||
* @throws InvalidDataException
|
||||
*/
|
||||
//TODO verifier l'utiliter de ce constructeur
|
||||
@Deprecated
|
||||
public DrawableRectangle(Bitmap bitmap,Rectangle rectangle, String name, int color) throws InvalidDataException {
|
||||
super(rectangle.getPositionX(),rectangle.getPositionY(),name);
|
||||
if(rectangle.getHeight() <= 0 || rectangle.getWidth() <=0 || bitmap == null)throw new InvalidDataException(name,rectangle);
|
||||
|
||||
rectangle.scaleRectangleToScreen();
|
||||
rectangle.bitmapRectangleBuilder(bitmap,color);
|
||||
setBitmap(bitmap);
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,11 @@ package com.iutlaval.myapplication.Video.Drawables;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.util.Log;
|
||||
|
||||
import com.iutlaval.myapplication.GameActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DrawableText extends Drawable{
|
||||
@@ -47,4 +49,38 @@ public class DrawableText extends Drawable{
|
||||
|
||||
setBitmap(Bitmap.createScaledBitmap(bitmap,scalled_x_size,scalled_y_size,GameActivity.bilinearFiltering));
|
||||
}
|
||||
|
||||
/**
|
||||
* coupe le texte a une certaine longeur
|
||||
* @param charPerLines nombre de caractére par lignes
|
||||
* @param text texte a afficher
|
||||
* @return liste de lignes de texte
|
||||
*/
|
||||
private List<String> cutText(int charPerLines,String text)
|
||||
{
|
||||
List<String> output = new ArrayList<>();
|
||||
//TODO cut text in lines
|
||||
StringBuilder nextLine = new StringBuilder(charPerLines);
|
||||
for (String word : text.split(" ")) {
|
||||
if(word.length() < charPerLines)
|
||||
{
|
||||
if(word.length() + nextLine.toString().length() +1 < charPerLines)
|
||||
{
|
||||
nextLine.append(" " + word);
|
||||
}else{
|
||||
//fillWithSpace(nextLine,charPerLines);
|
||||
output.add(nextLine.toString());
|
||||
nextLine.delete(0,charPerLines-1);
|
||||
}
|
||||
}else{
|
||||
Log.e("TextRender","ERROR WORD TOO LONG :" + word);
|
||||
}
|
||||
}
|
||||
if(!nextLine.toString().equals(""))
|
||||
{
|
||||
//fillWithSpace(nextLine,charPerLines);
|
||||
output.add(nextLine.toString());
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user