refactor touchHandler + repensé dekc + renpensé carte + suprimé code inutile + ajouter d'event carte
This commit is contained in:
@@ -8,16 +8,16 @@ import android.view.MotionEvent;
|
||||
|
||||
import com.iutlaval.myapplication.Game.Cards.Card;
|
||||
import com.iutlaval.myapplication.Game.Cards.CardRegistery;
|
||||
import com.iutlaval.myapplication.Game.Decks.Deck;
|
||||
import com.iutlaval.myapplication.Game.Decks.NetWorkDeck;
|
||||
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.Drawables.DrawableSelfRemoving;
|
||||
import com.iutlaval.myapplication.Video.Renderer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.net.Socket;
|
||||
@@ -29,14 +29,15 @@ public class GameLogicThread extends Thread{
|
||||
private boolean ready;
|
||||
private TouchHandler touch;
|
||||
private GameActivity gameActivity;
|
||||
private ObjectInputStream clientIn=null;
|
||||
private ObjectOutputStream clientOut=null;
|
||||
|
||||
private Deck localPlayerDeck;
|
||||
private Hand localPlayerHand;
|
||||
private NetworkDeck deck;
|
||||
private Hand hand;
|
||||
private Board board;
|
||||
|
||||
|
||||
|
||||
private boolean isYourTurn;
|
||||
private boolean cancelled;
|
||||
private Socket client;
|
||||
|
||||
public GameLogicThread(GameActivity gameActivity, Renderer renderer)
|
||||
{
|
||||
@@ -45,12 +46,13 @@ public class GameLogicThread extends Thread{
|
||||
ready=false;
|
||||
this.cont = gameActivity;
|
||||
this.renderer = renderer;
|
||||
touch = new TouchHandler(renderer,this,gameActivity);
|
||||
localPlayerHand = new Hand();
|
||||
this.gameActivity=gameActivity;
|
||||
board=new Board();
|
||||
touch = new TouchHandler(renderer,this,gameActivity);
|
||||
hand = new Hand();
|
||||
this.gameActivity=gameActivity;
|
||||
GameActivity.setGameEngine(this);
|
||||
isYourTurn=false;
|
||||
cancelled=false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,14 +66,15 @@ public class GameLogicThread extends Thread{
|
||||
//drawHandPreview();
|
||||
//Rectangle pos = new Rectangle(0F,0F,100F,100F);
|
||||
|
||||
ready=true;
|
||||
|
||||
//TODO : choix du deck avant de se co au serv
|
||||
|
||||
final String host = "4.tcp.ngrok.io";//192.168.43.251tcp://2.tcp.ngrok.io:
|
||||
final int port = 17531;
|
||||
ObjectInputStream clientIn=null;
|
||||
ObjectOutputStream clientOut=null;
|
||||
|
||||
try {
|
||||
Socket client = new Socket(host, port);
|
||||
client = new Socket(host, port);
|
||||
clientIn = new ObjectInputStream(client.getInputStream());
|
||||
clientOut = new ObjectOutputStream(client.getOutputStream());
|
||||
} catch (IOException e) {
|
||||
@@ -83,8 +86,8 @@ public class GameLogicThread extends Thread{
|
||||
|
||||
//principe de fonctionnement : on attends une comande du server et on l'execute
|
||||
//si quelquechose se passe alors c'est le server qu'il l'a dit
|
||||
ready=true;
|
||||
while(true)
|
||||
|
||||
while(ready && !cancelled)
|
||||
{
|
||||
try {
|
||||
String serveurCmd = (String)clientIn.readObject();
|
||||
@@ -95,14 +98,14 @@ public class GameLogicThread extends Thread{
|
||||
clientOut.writeObject("deckDemo");
|
||||
//TODO assing this deck
|
||||
String deckstr = (String)clientIn.readObject();
|
||||
localPlayerDeck = new NetWorkDeck(deckstr,gameActivity.getBaseContext());
|
||||
deck = new NetworkDeck(deckstr,gameActivity.getBaseContext());
|
||||
Log.e("got deck",deckstr);
|
||||
|
||||
Log.e("recived","getdeck");
|
||||
break;
|
||||
case COMMAND.DRAW:
|
||||
int nbcard = (Integer)clientIn.readObject();
|
||||
localPlayerHand.pickCardFromDeck(localPlayerDeck,nbcard);
|
||||
hand.pickCardFromDeck(deck,nbcard);
|
||||
Log.e("picked",nbcard+"card");
|
||||
drawHandPreview();
|
||||
break;
|
||||
@@ -111,12 +114,18 @@ public class GameLogicThread extends Thread{
|
||||
isYourTurn=true;
|
||||
renderer.addToDraw(new DrawableSelfRemoving(new DrawableBitmap(bitmapYourTurn,0,0,"yourTurn",100F,50F),1));
|
||||
break;
|
||||
|
||||
default:
|
||||
Log.e("UNKOWN COMMAND",serveurCmd);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}catch (InterruptedIOException e)
|
||||
{
|
||||
Log.e("Stopping","dead thread");
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.e("ERROR DURING COMS","SERVER DIED");
|
||||
e.printStackTrace();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,7 +135,7 @@ public class GameLogicThread extends Thread{
|
||||
*/
|
||||
private void drawHandPreview() {
|
||||
int i = 0;
|
||||
for(Card c : localPlayerHand.getHand())
|
||||
for(Card c : hand.getHand())
|
||||
{
|
||||
renderer.addToDraw(c.getDrawableCard());
|
||||
renderer.moveToDraw(i* DrawableCard.getCardWith(),90F,c.getDrawableCard().getName());
|
||||
@@ -135,6 +144,16 @@ public class GameLogicThread extends Thread{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* cette evenement est appelé par le touchHandler et permet d'envoyer au serveur le fait qu'un carte a été jouer
|
||||
* @param card la carte jouer
|
||||
* @param zone ou elle a été joué sur le terrain
|
||||
*/
|
||||
protected void onCardPlayed(Drawable card,int zone)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* cette fonction est appeller a chaque fin de frame
|
||||
* CETTE FONCTION A UN IMPACT DIRECT SUR LES FPS ELLE SE DOIT D'être OPTIMAL
|
||||
@@ -163,7 +182,7 @@ public class GameLogicThread extends Thread{
|
||||
* @param event
|
||||
*/
|
||||
public void onTouchEvent(MotionEvent event) {
|
||||
//if(isReady())touch.onTouchEvent(event);
|
||||
if(isReady())touch.onTouchEvent(event);
|
||||
}
|
||||
|
||||
public boolean isYourTurn() {
|
||||
@@ -174,4 +193,17 @@ public class GameLogicThread extends Thread{
|
||||
public Board getBoard() {
|
||||
return board;
|
||||
}
|
||||
|
||||
public void terminate() {
|
||||
ready=false;
|
||||
try {
|
||||
if(clientOut != null)clientOut.close();
|
||||
if(clientIn != null)clientIn.close();
|
||||
if(client != null)client.close();
|
||||
} catch (IOException e) {}
|
||||
cancelled=true;
|
||||
|
||||
interrupt();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user