connection serveur + debut jeu
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.iutlaval.myapplication">
|
package="com.iutlaval.myapplication">
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.iutlaval.myapplication.Game.Cards;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CardRegistery {
|
||||||
|
public static List<Class> registry;
|
||||||
|
|
||||||
|
public CardRegistery()
|
||||||
|
{
|
||||||
|
registry = new ArrayList<>();
|
||||||
|
|
||||||
|
registry.add(DemoCard.class);
|
||||||
|
registry.add(DemoCard2.class);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int get(Class<? extends Card> class1) {
|
||||||
|
int a = registry.indexOf(class1);
|
||||||
|
return a != -1 ? a : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Class get(int index) {
|
||||||
|
return registry.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.iutlaval.myapplication.Game.Cards;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.iutlaval.myapplication.R;
|
||||||
|
|
||||||
|
public class DemoCard2 extends Card{
|
||||||
|
/**
|
||||||
|
* cree une carte est lui definit un drawable
|
||||||
|
*
|
||||||
|
* @param UID
|
||||||
|
* @param c
|
||||||
|
*/
|
||||||
|
public DemoCard2(String UID, Context c) {
|
||||||
|
super(UID, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCardPicture() {
|
||||||
|
return R.drawable.t_b_batiut;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return "usless demo";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAttack() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHealth() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "DEMO2";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
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,45 @@
|
|||||||
|
package com.iutlaval.myapplication.Game.Decks;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.iutlaval.myapplication.Game.Cards.Card;
|
||||||
|
import com.iutlaval.myapplication.Game.Cards.CardRegistery;
|
||||||
|
import com.iutlaval.myapplication.Game.Cards.DemoCard;
|
||||||
|
import com.iutlaval.myapplication.Game.Cards.DemoCard2;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
|
public class NetWorkDeck extends Deck{
|
||||||
|
Stack<Card> cards;
|
||||||
|
public NetWorkDeck(String deckstring, Context context)
|
||||||
|
{
|
||||||
|
cards = new Stack<>();
|
||||||
|
int nbcarte=0;
|
||||||
|
for(String s : deckstring.split(","))
|
||||||
|
{
|
||||||
|
Class c = CardRegistery.get(Integer.parseInt(s));
|
||||||
|
try {
|
||||||
|
//on utilise le bon constructeur
|
||||||
|
Constructor con = c.getConstructor(String.class, Context.class);
|
||||||
|
cards.add((Card) con.newInstance("nas"+nbcarte,context));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
cards.add(new DemoCard("nas"+nbcarte,context));
|
||||||
|
}
|
||||||
|
nbcarte++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stack<Card> getCards() {
|
||||||
|
return cards;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDeckName() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,15 +7,20 @@ import android.util.Log;
|
|||||||
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.CardRegistery;
|
||||||
import com.iutlaval.myapplication.Game.Decks.Deck;
|
import com.iutlaval.myapplication.Game.Decks.Deck;
|
||||||
import com.iutlaval.myapplication.Game.Decks.DeckDemo;
|
import com.iutlaval.myapplication.Game.Decks.NetWorkDeck;
|
||||||
import com.iutlaval.myapplication.GameActivity;
|
import com.iutlaval.myapplication.GameActivity;
|
||||||
import com.iutlaval.myapplication.R;
|
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.DrawableBitmap;
|
||||||
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;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.net.Socket;
|
||||||
|
|
||||||
public class GameLogicThread extends Thread{
|
public class GameLogicThread extends Thread{
|
||||||
|
|
||||||
private Context cont;
|
private Context cont;
|
||||||
@@ -33,15 +38,13 @@ public class GameLogicThread extends Thread{
|
|||||||
|
|
||||||
public GameLogicThread(GameActivity gameActivity, Renderer renderer)
|
public GameLogicThread(GameActivity gameActivity, Renderer renderer)
|
||||||
{
|
{
|
||||||
|
new CardRegistery();
|
||||||
Log.e("RESOLUTION:",""+GameActivity.screenWidth+"x"+GameActivity.screenHeight);
|
Log.e("RESOLUTION:",""+GameActivity.screenWidth+"x"+GameActivity.screenHeight);
|
||||||
ready=false;
|
ready=false;
|
||||||
this.cont = gameActivity;
|
this.cont = gameActivity;
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
touch = new TouchHandler(renderer);
|
touch = new TouchHandler(renderer);
|
||||||
localPlayerDeck = new DeckDemo("local",cont);
|
|
||||||
localPlayerDeck.shuffle();
|
|
||||||
localPlayerHand = new Hand();
|
localPlayerHand = new Hand();
|
||||||
localPlayerHand.fillHand(localPlayerDeck);
|
|
||||||
this.gameActivity=gameActivity;
|
this.gameActivity=gameActivity;
|
||||||
board=new Board();
|
board=new Board();
|
||||||
playableZonesHandler = new PlayableZonesHandler(board);
|
playableZonesHandler = new PlayableZonesHandler(board);
|
||||||
@@ -53,16 +56,55 @@ public class GameLogicThread extends Thread{
|
|||||||
//affichage de l'arriere plan
|
//affichage de l'arriere plan
|
||||||
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 DrawableBitmap(bitmap, 0,0, "background", 100, 100 ));
|
renderer.addToDraw(new DrawableBitmap(bitmap, 0,0, "background", 100, 100 ));
|
||||||
drawHandPreview();
|
//drawHandPreview();
|
||||||
//Rectangle pos = new Rectangle(0F,0F,100F,100F);
|
//Rectangle pos = new Rectangle(0F,0F,100F,100F);
|
||||||
|
|
||||||
|
//TODO : choix du deck avant de se co au serv
|
||||||
|
|
||||||
|
final String host = "4.tcp.ngrok.io";//192.168.43.251
|
||||||
|
final int port = 18567;
|
||||||
|
ObjectInputStream clientIn=null;
|
||||||
|
ObjectOutputStream clientOut=null;
|
||||||
|
try {
|
||||||
|
Socket client = new Socket(host, port);
|
||||||
|
clientIn = new ObjectInputStream(client.getInputStream());
|
||||||
|
clientOut = new ObjectOutputStream(client.getOutputStream());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e("ERROR SERVER DEAD","srv");
|
||||||
|
//TODO display error and don't crash the game;
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
renderer.updateFrame();
|
||||||
|
|
||||||
ready=true;
|
ready=true;
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
//Do Stuff
|
try {
|
||||||
break;
|
String serveurCmd = (String)clientIn.readObject();
|
||||||
|
switch (serveurCmd)
|
||||||
|
{
|
||||||
|
case "getDeck":
|
||||||
|
//TODO get deck from player
|
||||||
|
clientOut.writeObject("deckDemo");
|
||||||
|
//TODO assing this deck
|
||||||
|
String deckstr = (String)clientIn.readObject();
|
||||||
|
localPlayerDeck = new NetWorkDeck(deckstr,gameActivity.getBaseContext());
|
||||||
|
Log.e("got deck",deckstr);
|
||||||
|
|
||||||
|
Log.e("recived","getdeck");
|
||||||
|
break;
|
||||||
|
case "draw":
|
||||||
|
int nbcard = (Integer)clientIn.readObject();
|
||||||
|
localPlayerHand.pickCardFromDeck(localPlayerDeck,nbcard);
|
||||||
|
Log.e("picked",nbcard+"card");
|
||||||
|
drawHandPreview();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e("ERROR DURING COMS","SERVER DIED");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
renderer.updateFrame();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user