debut du code des deck et de la main
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme">
|
||||||
|
<activity android:name=".Game.HandActivity"></activity>
|
||||||
<activity android:name=".MainActivity">
|
<activity android:name=".MainActivity">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.iutlaval.myapplication.Game.Decks;
|
||||||
|
|
||||||
|
import com.iutlaval.myapplication.Game.Cards.Card;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TOUT DECK CREE DOIT ETRE AJOUTER A DECKREGISTER
|
||||||
|
*/
|
||||||
|
public abstract class Deck {
|
||||||
|
public abstract Stack<Card> getCards();
|
||||||
|
|
||||||
|
public void suffle()
|
||||||
|
{
|
||||||
|
Collections.shuffle(getCards());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* retourne le nom du deck ex: ww2 , science
|
||||||
|
* ce nom doit être unique
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract String getDeckName();
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.iutlaval.myapplication.Game.Decks;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.iutlaval.myapplication.Game.Cards.Card;
|
||||||
|
import com.iutlaval.myapplication.Game.Cards.DemoCard;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
|
public class DeckDemo extends Deck{
|
||||||
|
|
||||||
|
Stack<Card> cards;
|
||||||
|
|
||||||
|
public DeckDemo(String id, Context constext)
|
||||||
|
{
|
||||||
|
cards = new Stack<>();
|
||||||
|
|
||||||
|
//generating cards randomly
|
||||||
|
for(int i = 0 ; i < 50 ; i++)
|
||||||
|
{
|
||||||
|
cards.add(new DemoCard(id +"_card_"+ i,constext));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stack<Card> getCards() {
|
||||||
|
return cards;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeckName() {
|
||||||
|
return "demo";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.iutlaval.myapplication.Game.Decks;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.iutlaval.myapplication.Game.HandActivity;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class DeckRegister {
|
||||||
|
public static Deck getClassFromName(String name, Context context)
|
||||||
|
{
|
||||||
|
//switch case non utilisable MAIS c'est pas important car c'ette foction n'est que pour
|
||||||
|
//HandActivity
|
||||||
|
|
||||||
|
if(name.equals("demo"))
|
||||||
|
{
|
||||||
|
return new DeckDemo(name,context);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,17 @@
|
|||||||
package com.iutlaval.myapplication.Game;
|
package com.iutlaval.myapplication.Game;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
import com.iutlaval.myapplication.Game.Cards.Card;
|
import com.iutlaval.myapplication.Game.Cards.Card;
|
||||||
import com.iutlaval.myapplication.Game.Cards.DemoCard;
|
import com.iutlaval.myapplication.Game.Cards.DemoCard;
|
||||||
|
import com.iutlaval.myapplication.Game.Decks.Deck;
|
||||||
|
import com.iutlaval.myapplication.Game.Decks.DeckDemo;
|
||||||
import com.iutlaval.myapplication.GameActivity;
|
import com.iutlaval.myapplication.GameActivity;
|
||||||
import com.iutlaval.myapplication.MainActivity;
|
|
||||||
import com.iutlaval.myapplication.R;
|
import com.iutlaval.myapplication.R;
|
||||||
import com.iutlaval.myapplication.Video.Drawables.Drawable;
|
import com.iutlaval.myapplication.Video.Drawables.Drawable;
|
||||||
import com.iutlaval.myapplication.Video.Drawables.DrawableCard;
|
import com.iutlaval.myapplication.Video.Drawables.DrawableCard;
|
||||||
@@ -20,14 +23,24 @@ public class GameLogicThread extends Thread{
|
|||||||
private Renderer renderer;
|
private Renderer renderer;
|
||||||
private boolean ready;
|
private boolean ready;
|
||||||
private TouchHandler touch;
|
private TouchHandler touch;
|
||||||
|
private GameActivity gameActivity;
|
||||||
|
|
||||||
public GameLogicThread(Context cont, Renderer renderer)
|
private Deck localPlayerDeck;
|
||||||
|
private Hand localPlayerHand;
|
||||||
|
|
||||||
|
|
||||||
|
public GameLogicThread(GameActivity gameActivity, Renderer renderer)
|
||||||
{
|
{
|
||||||
ready=false;
|
ready=false;
|
||||||
this.cont = cont;
|
this.cont = gameActivity;
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
renderer.setEngine(this);
|
renderer.setEngine(this);
|
||||||
touch = new TouchHandler(renderer);
|
touch = new TouchHandler(renderer);
|
||||||
|
localPlayerDeck = new DeckDemo("local",cont);
|
||||||
|
localPlayerDeck.suffle();
|
||||||
|
localPlayerHand = new Hand();
|
||||||
|
localPlayerHand.fillHand(localPlayerDeck);
|
||||||
|
this.gameActivity=gameActivity;
|
||||||
}
|
}
|
||||||
|
|
||||||
private float i=0;
|
private float i=0;
|
||||||
@@ -36,31 +49,39 @@ public class GameLogicThread extends Thread{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
//affichage de l'arriere plan
|
||||||
//renderer.addToDraw(new Drawable(new Rectangle(0,0,100,100),"background", Color.BLUE));
|
|
||||||
Bitmap bitmap= BitmapFactory.decodeResource(cont.getResources(), R.drawable.t_b_board_background);
|
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 Drawable(bitmap, 0,0, "background", 100, 100 ));
|
||||||
|
|
||||||
//renderer.addToDraw(new Drawable(bm,0.0F,0.0F,"running",8F,16F));
|
//renderer.addToDraw(new Drawable(bm,0.0F,0.0F,"running",8F,16F));
|
||||||
//renderer.addToDraw(new DrawableCard(new DemoCard(),0.0F,0.0F,"card2",cont));
|
//renderer.addToDraw(new DrawableCard(new DemoCard(),0.0F,0.0F,"card2",cont));
|
||||||
Card card2 = new DemoCard("card3",cont);
|
/*Card card2 = new DemoCard("card3",cont);
|
||||||
renderer.addToDraw(card2.getDrawableCard());
|
renderer.addToDraw(card2.getDrawableCard());
|
||||||
Card card1 = new DemoCard("card1",cont);
|
Card card1 = new DemoCard("card1",cont);
|
||||||
renderer.addToDraw(card1.getDrawableCard());
|
renderer.addToDraw(card1.getDrawableCard());*/
|
||||||
|
|
||||||
|
|
||||||
|
drawHandPreview();
|
||||||
|
|
||||||
ready=true;
|
ready=true;
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
//Do Stuff
|
//Do Stuff
|
||||||
renderer.moveToDraw(20,20,"card1");
|
|
||||||
renderer.moveToDraw(40,20,"card3");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
((DrawableCard)renderer.getDrawAble("card3")).setOnBoard(false);
|
|
||||||
renderer.updateFrame();
|
renderer.updateFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void drawHandPreview() {
|
||||||
|
int i = 0;
|
||||||
|
for(Card c : localPlayerHand.getHand())
|
||||||
|
{
|
||||||
|
renderer.addToDraw(c.getDrawableCard());
|
||||||
|
renderer.moveToDraw(i*DrawableCard.CARD_WITH,90F,c.getDrawableCard().getName());
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cette fonction est appeller a chaque fin de frame
|
* 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 DIRRECT SUR LES FPS ELLE SE DOIT D'être OPTIMAL
|
||||||
@@ -69,27 +90,10 @@ public class GameLogicThread extends Thread{
|
|||||||
* TOUT APELLE DE CETTE FONCTION SE DOIT D'ÊTRE PROTEGER PAR isReady()
|
* TOUT APELLE DE CETTE FONCTION SE DOIT D'ÊTRE PROTEGER PAR isReady()
|
||||||
*
|
*
|
||||||
* /!\ renderer.updateFrame(); va forcer le system a redessiner l'afficher qui ensuite reappelera onFrameDoneRendering() ce qui peut causer si le updateFrame() n'est pas proteger
|
* /!\ renderer.updateFrame(); va forcer le system a redessiner l'afficher qui ensuite reappelera onFrameDoneRendering() ce qui peut causer si le updateFrame() n'est pas proteger
|
||||||
* une utilisation de la batterie massivz
|
* une utilisation de la batterie massive
|
||||||
*/
|
*/
|
||||||
public void onFrameDoneRendering()
|
public void onFrameDoneRendering()
|
||||||
{
|
{
|
||||||
if(i < 100)
|
|
||||||
{
|
|
||||||
i+=increm;
|
|
||||||
//((DrawableCard)renderer.getDrawAble("card3")).setOnBoard(increm <= 0);
|
|
||||||
}else{
|
|
||||||
increm=-increm;
|
|
||||||
i+=increm;
|
|
||||||
//((DrawableCard)renderer.getDrawAble("card3")).setOnBoard(increm > 0);
|
|
||||||
}
|
|
||||||
if(i==0)increm=-increm;
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
//TODO get x,y coordinate form name
|
|
||||||
//r.moveToDraw(i,i,"card2");
|
|
||||||
//renderer.moveToDraw(i,i,"card3");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -106,6 +110,30 @@ public class GameLogicThread extends Thread{
|
|||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
public void onTouchEvent(MotionEvent event) {
|
public void onTouchEvent(MotionEvent event) {
|
||||||
if(isReady())touch.onTouchEvent(event);
|
if(isReady()){
|
||||||
|
float unscalled_Y = event.getY() / GameActivity.screenHeight * 100;
|
||||||
|
if(unscalled_Y >= 90F) {
|
||||||
|
float unscalled_X = event.getX() / GameActivity.screenWidth * 100;
|
||||||
|
//TODO : display fullscreen cards
|
||||||
|
Intent HandActivity = new Intent(gameActivity, HandActivity.class);
|
||||||
|
String[] serializedHand = new String[localPlayerHand.getHand().size() +1];
|
||||||
|
int i = 0;
|
||||||
|
serializedHand[i] = localPlayerDeck.getDeckName();
|
||||||
|
for(Card c : localPlayerHand.getHand())
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
serializedHand[i] = c.getName();
|
||||||
|
|
||||||
|
}
|
||||||
|
HandActivity.putExtra("hand",serializedHand);
|
||||||
|
Bundle cardSelectedBundle = new Bundle();
|
||||||
|
gameActivity.startActivity(HandActivity,cardSelectedBundle);
|
||||||
|
|
||||||
|
|
||||||
|
}else{
|
||||||
|
touch.onTouchEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.iutlaval.myapplication.Game;
|
||||||
|
|
||||||
|
import com.iutlaval.myapplication.Game.Cards.Card;
|
||||||
|
import com.iutlaval.myapplication.Game.Decks.Deck;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Hand {
|
||||||
|
|
||||||
|
private static final int NUMBER_OF_CARDS_IN_STARTING_HAND = 5;
|
||||||
|
|
||||||
|
private List<Card> hand;
|
||||||
|
|
||||||
|
public Hand()
|
||||||
|
{
|
||||||
|
hand = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void pickCardFromDeck(Deck deck,int amount)
|
||||||
|
{
|
||||||
|
for(int i = 0 ; i < NUMBER_OF_CARDS_IN_STARTING_HAND;i++)
|
||||||
|
{
|
||||||
|
hand.add(deck.getCards().pop());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillHand(Deck deck)
|
||||||
|
{
|
||||||
|
pickCardFromDeck(deck,NUMBER_OF_CARDS_IN_STARTING_HAND);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Card> getHand() {
|
||||||
|
return hand;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.iutlaval.myapplication.Game;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import com.iutlaval.myapplication.Game.Decks.Deck;
|
||||||
|
import com.iutlaval.myapplication.Game.Decks.DeckRegister;
|
||||||
|
import com.iutlaval.myapplication.R;
|
||||||
|
|
||||||
|
public class HandActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_hand);
|
||||||
|
|
||||||
|
String[] serializedHand = getIntent().getStringArrayExtra("hand");
|
||||||
|
Deck d = DeckRegister.getClassFromName(serializedHand[0],this);
|
||||||
|
|
||||||
|
|
||||||
|
Intent data = new Intent();
|
||||||
|
String text = "Result to be returned....";
|
||||||
|
//---set the data to pass back---
|
||||||
|
data.setData(Uri.parse(text));
|
||||||
|
setResult(RESULT_OK, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +1,19 @@
|
|||||||
package com.iutlaval.myapplication.Game;
|
package com.iutlaval.myapplication.Game;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
import com.iutlaval.myapplication.GameActivity;
|
import com.iutlaval.myapplication.GameActivity;
|
||||||
|
import com.iutlaval.myapplication.MainActivity;
|
||||||
import com.iutlaval.myapplication.Video.Drawables.DrawableCard;
|
import com.iutlaval.myapplication.Video.Drawables.DrawableCard;
|
||||||
import com.iutlaval.myapplication.Video.Renderer;
|
import com.iutlaval.myapplication.Video.Renderer;
|
||||||
|
|
||||||
public class TouchHandler {
|
public class TouchHandler {
|
||||||
|
|
||||||
//TODO mettre sa dans une classe isolé
|
private float TouchDeltaX = 0;
|
||||||
private float deltaX = 0;
|
private float TouchDeltaY = 0;
|
||||||
private float deltaY = 0;
|
private float originalPositionX = 0;
|
||||||
|
private float originalPositionY = 0;
|
||||||
private DrawableCard moveEventCard = null;
|
private DrawableCard moveEventCard = null;
|
||||||
private Renderer renderer;
|
private Renderer renderer;
|
||||||
|
|
||||||
@@ -28,17 +31,23 @@ public class TouchHandler {
|
|||||||
float unscalled_Y = event.getY() / GameActivity.screenHeight * 100;
|
float unscalled_Y = event.getY() / GameActivity.screenHeight * 100;
|
||||||
|
|
||||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||||
|
if(unscalled_Y <= 90F) {
|
||||||
moveEventCard = renderer.getCardOn(unscalled_X, unscalled_Y);
|
moveEventCard = renderer.getCardOn(unscalled_X, unscalled_Y);
|
||||||
if(moveEventCard != null) {
|
if (moveEventCard != null) {
|
||||||
deltaY = unscalled_Y - moveEventCard.getY();
|
TouchDeltaY = unscalled_Y - moveEventCard.getY();
|
||||||
deltaX = unscalled_X - moveEventCard.getX();
|
TouchDeltaX = unscalled_X - moveEventCard.getX();
|
||||||
|
originalPositionX = moveEventCard.getX();
|
||||||
|
originalPositionY = moveEventCard.getY();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (event.getAction() == MotionEvent.ACTION_UP) {
|
} else if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||||
|
TouchDeltaY = 0;
|
||||||
|
TouchDeltaX = 0;
|
||||||
|
//TODO detect zones
|
||||||
|
if(moveEventCard != null)renderer.moveToDraw(originalPositionX,originalPositionY,moveEventCard.getName());
|
||||||
moveEventCard = null;
|
moveEventCard = null;
|
||||||
deltaY = 0;
|
|
||||||
deltaX = 0;
|
|
||||||
} else if (moveEventCard != null) {
|
} else if (moveEventCard != null) {
|
||||||
moveEventCard.setCoordinates(unscalled_X - deltaX, unscalled_Y - deltaY);
|
moveEventCard.setCoordinates(unscalled_X - TouchDeltaX, unscalled_Y - TouchDeltaY);
|
||||||
renderer.updateFrame();
|
renderer.updateFrame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import com.iutlaval.myapplication.Video.Rectangle;
|
|||||||
*/
|
*/
|
||||||
public class DrawableCard extends Drawable{
|
public class DrawableCard extends Drawable{
|
||||||
|
|
||||||
private static final int CARD_WITH = 14;
|
public static final int CARD_WITH = 14;
|
||||||
private static final int CARD_HEIGHT = 40;
|
private static final int CARD_HEIGHT = 40;
|
||||||
private static final float HP_ATK_FONT_SIZE_BIG_CARD =30F;
|
private static final float HP_ATK_FONT_SIZE_BIG_CARD =30F;
|
||||||
private static final float HP_ATK_FONT_SIZE_BOARD =70F;
|
private static final float HP_ATK_FONT_SIZE_BOARD =70F;
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".Game.HandActivity">
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
Reference in New Issue
Block a user