ajout choix deck
This commit is contained in:
@@ -53,12 +53,6 @@ package Game <<Folder>> {
|
||||
- originalPositionX : float
|
||||
- originalPositionY : float
|
||||
}
|
||||
package Players <<Folder>> {
|
||||
class Player
|
||||
class PlayerBot
|
||||
class PlayerLocal
|
||||
class PlayerAdversary
|
||||
}
|
||||
class GameActivity
|
||||
{
|
||||
+ onCreate()
|
||||
@@ -215,10 +209,6 @@ Renderer "1" *-- DrawingThread : -drawingThread
|
||||
Renderer "1" *-- GameLogicThread : -engine
|
||||
Renderer "*" *-- Drawable : toDraw
|
||||
|
||||
Player <|-- PlayerBot
|
||||
Player <|-- PlayerLocal
|
||||
Player <|-- PlayerAdversary
|
||||
|
||||
DrawableCard o-- Drawable : frameDrawable
|
||||
DrawableCard *-- Drawable : OpacityRectangleDrawable
|
||||
DrawableCard *-- Drawable : PictureDrawable
|
||||
@@ -257,9 +247,6 @@ GameLogicThread *-- Hand : fillHand
|
||||
GameLogicThread *-- PlayableZonesHandler : playableZonesHandler
|
||||
GameLogicThread *-- GameActivity : gameActivity
|
||||
|
||||
Board *-- PlayerLocal : player
|
||||
Board *-- Player : adversary
|
||||
|
||||
Deck <|-- DeckDemo
|
||||
|
||||
Renderer o-- GameLogicThread
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.iutlaval.myapplication;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
public class DeckPickDialogue extends DialogFragment {
|
||||
Context context;
|
||||
public DeckPickDialogue(@NonNull Context context) {
|
||||
this.context=context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setTitle(R.string.pickdeck)
|
||||
.setItems(R.array.decks, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// The 'which' argument contains the index position
|
||||
// of the selected item
|
||||
String[] mTestArray = getResources().getStringArray(R.array.decks);
|
||||
|
||||
Intent gameActivity = new Intent(context, GameActivity.class);
|
||||
gameActivity.putExtra("DECK", mTestArray[which]);
|
||||
gameActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
|
||||
startActivity(gameActivity);
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,20 @@
|
||||
package com.iutlaval.myapplication.Game;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
import com.iutlaval.myapplication.DeckPickDialogue;
|
||||
import com.iutlaval.myapplication.Game.Cards.Card;
|
||||
import com.iutlaval.myapplication.Game.Cards.CardRegistery;
|
||||
import com.iutlaval.myapplication.GameActivity;
|
||||
import com.iutlaval.myapplication.MainActivity;
|
||||
import com.iutlaval.myapplication.R;
|
||||
import com.iutlaval.myapplication.Video.Drawables.Drawable;
|
||||
import com.iutlaval.myapplication.Video.Drawables.DrawableBitmap;
|
||||
@@ -38,10 +44,12 @@ public class GameLogicThread extends Thread{
|
||||
private boolean isYourTurn;
|
||||
private boolean cancelled;
|
||||
private Socket client;
|
||||
private String deckName;
|
||||
|
||||
public GameLogicThread(GameActivity gameActivity, Renderer renderer)
|
||||
public GameLogicThread(GameActivity gameActivity, String deckName, Renderer renderer)
|
||||
{
|
||||
new CardRegistery();
|
||||
this.deckName=deckName;
|
||||
Log.e("RESOLUTION:",""+GameActivity.screenWidth+"x"+GameActivity.screenHeight);
|
||||
ready=false;
|
||||
this.cont = gameActivity;
|
||||
@@ -57,6 +65,8 @@ public class GameLogicThread extends Thread{
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
//pickDeck();
|
||||
|
||||
//loading textures
|
||||
Bitmap bitmapYourTurn = BitmapFactory.decodeResource(renderer.getResources(),R.drawable.t_pb_your_turn);
|
||||
Bitmap bitmap= BitmapFactory.decodeResource(cont.getResources(), R.drawable.t_b_board_background);
|
||||
@@ -71,7 +81,7 @@ public class GameLogicThread extends Thread{
|
||||
//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;
|
||||
final int port = 18240;
|
||||
|
||||
try {
|
||||
client = new Socket(host, port);
|
||||
@@ -94,8 +104,7 @@ public class GameLogicThread extends Thread{
|
||||
switch (serveurCmd)
|
||||
{
|
||||
case COMMAND.GET_DECK:
|
||||
//TODO get deck from player
|
||||
clientOut.writeObject("deckDemo");
|
||||
clientOut.writeObject(deckName);
|
||||
//TODO assing this deck
|
||||
String deckstr = (String)clientIn.readObject();
|
||||
deck = new NetworkDeck(deckstr,gameActivity.getBaseContext());
|
||||
@@ -194,6 +203,10 @@ public class GameLogicThread extends Thread{
|
||||
return board;
|
||||
}
|
||||
|
||||
/**
|
||||
* cette fonction a pour rôle de kill le thread
|
||||
* vu que Thread.destroy() est déprecier c'est la seul methode possible;
|
||||
*/
|
||||
public void terminate() {
|
||||
ready=false;
|
||||
try {
|
||||
|
||||
@@ -33,7 +33,11 @@ public class GameActivity extends Activity {
|
||||
Display display = getWindowManager().getDefaultDisplay();
|
||||
FpsTime.init(display);
|
||||
|
||||
renderer = new Renderer(getBaseContext(),this);
|
||||
String deck = getIntent().getStringExtra("DECK");
|
||||
|
||||
renderer = new Renderer(getBaseContext(),deck,this);
|
||||
|
||||
|
||||
|
||||
setContentView(renderer);
|
||||
}
|
||||
|
||||
@@ -1,32 +1,44 @@
|
||||
package com.iutlaval.myapplication;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private Context context;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.context=this;
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
final Button playButton = (Button) findViewById(R.id.playButton);
|
||||
playButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
//Toast.makeText(getApplicationContext(), "click sur button", Toast.LENGTH_LONG).show();
|
||||
Intent gameActivity = new Intent(MainActivity.this, GameActivity.class);
|
||||
gameActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
|
||||
startActivity(gameActivity);
|
||||
pickDeck();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String pickDeck() {
|
||||
DialogFragment d = new DeckPickDialogue(this);
|
||||
d.show(getSupportFragmentManager(),"s");
|
||||
|
||||
|
||||
return "demodeck";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,12 @@ public class Renderer extends SurfaceView implements SurfaceHolder.Callback {
|
||||
private boolean needToUpdate;
|
||||
|
||||
private List<Drawable> toDraw;
|
||||
private String deckName;
|
||||
|
||||
public Renderer(Context context, GameActivity gameActivity) {
|
||||
public Renderer(Context context, String deck, GameActivity gameActivity) {
|
||||
super(context);
|
||||
this.gameActivity=gameActivity;
|
||||
this.deckName=deck;
|
||||
|
||||
holder = getHolder();
|
||||
holder.addCallback(this);
|
||||
@@ -153,7 +155,7 @@ public class Renderer extends SurfaceView implements SurfaceHolder.Callback {
|
||||
}
|
||||
|
||||
Log.i("RENDERER","STARTING ENGINE");
|
||||
engine = new GameLogicThread(gameActivity,renderer);
|
||||
engine = new GameLogicThread(gameActivity,deckName,renderer);
|
||||
engine.start();
|
||||
while (!engine.isReady());
|
||||
Log.i("RENDERER","ENGINE STARTED");
|
||||
|
||||
Reference in New Issue
Block a user