fin affichage victoire/defaite

This commit is contained in:
Haïssous Kayyissa 2023-04-09 20:20:28 +02:00
parent df84ff5644
commit e2b69773c7
3 changed files with 53 additions and 17 deletions

View File

@ -144,14 +144,15 @@ public class GameActivity extends Activity implements SaisieActivity {
for (int i=0;i<4;i++){ for (int i=0;i<4;i++){
this.saisie.addSelection(this.combiGagnante[i]); this.saisie.addSelection(this.combiGagnante[i]);
} }
EndView lastview=new EndView(this, this.grille, this.combiGagnante); EndView lastview=new EndView(this, this.grille, this.combiGagnante, this.rootView);
this.view=lastview; this.view=lastview;
this.rootView.removeAllViews(); this.rootView.removeAllViews();
this.view.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); this.view.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
this.view.setBackgroundColor(this.getResources().getColor(R.color.grey));
this.rootView.addView(this.view); this.rootView.addView(this.view);
TextView textView = new TextView(this); TextView textView = new TextView(this);
textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
textView.setGravity(Gravity.CENTER); textView.setGravity(Gravity.CENTER);
if (gagne){ if (gagne){
textView.setText("Victoire de l'attaquant en "+this.grille.getSizeSubs()+" coups"); textView.setText("Victoire de l'attaquant en "+this.grille.getSizeSubs()+" coups");
@ -159,7 +160,7 @@ public class GameActivity extends Activity implements SaisieActivity {
textView.setText("Victoire du défenseur"); textView.setText("Victoire du défenseur");
} }
this.rootView.addView(textView); this.rootView.addView(textView);
System.out.println(textView.getText()); System.out.println(textView.getX() + " : " + textView.getY());
this.rootView.invalidate(); this.rootView.invalidate();
} }

View File

@ -9,6 +9,7 @@ import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.view.View; import android.view.View;
import android.widget.LinearLayout;
import com.example.mastermind.GameActivity; import com.example.mastermind.GameActivity;
import com.example.mastermind.R; import com.example.mastermind.R;
@ -25,17 +26,18 @@ public class EndView extends View {
private Grille grille; private Grille grille;
private Paint circle; private Paint circle;
private int nbcoups; private int nbcoups;
public EndView(Context context, Grille grille, Integer[] combiWin) { private LinearLayout rootView;
public EndView(Context context, Grille grille, Integer[] combiWin, LinearLayout rootView) {
super(context); super(context);
this.combiWin=combiWin; this.combiWin=combiWin;
this.grille=grille; this.grille=grille;
this.circle = new Paint(); this.circle = new Paint();
this.rootView = rootView;
} }
@Override @Override
protected void onDraw(Canvas canvas){ protected void onDraw(Canvas canvas){
super.onDraw(canvas); super.onDraw(canvas);
this.setBackgroundColor(this.getResources().getColor(R.color.grey));
//affichage des anciennes soumissions //affichage des anciennes soumissions
//copie des soumissions //copie des soumissions
LinkedList<Integer> grille = new LinkedList<Integer>(); LinkedList<Integer> grille = new LinkedList<Integer>();
@ -43,7 +45,7 @@ public class EndView extends View {
for (int y = 0; y < 10; y++) { for (int y = 0; y < 10; y++) {
for (int x = 0; x < 4; x++) { for (int x = 0; x < 4; x++) {
this.circle.setColor(grille.pop()); this.circle.setColor(grille.pop());
canvas.drawCircle((x * this.getWidth() / 8 + (this.getWidth() * 21 / 68)), (y * this.getHeight() / 14 + this.getHeight() / 21), this.getWidth() / 17, this.circle); canvas.drawCircle((x * this.getWidth() / 8 + (this.getWidth() * 21 / 68)), (y * this.rootView.getHeight() / 14 + this.rootView.getHeight() / 21), this.getWidth() / 17, this.circle);
} }
} }
LinkedList<Integer> notation = new LinkedList<Integer>(); LinkedList<Integer> notation = new LinkedList<Integer>();
@ -51,18 +53,52 @@ public class EndView extends View {
for(int y=0; y<10; y++) { for(int y=0; y<10; y++) {
for(int x=0; x<2; x++) { // colonne gauche for(int x=0; x<2; x++) { // colonne gauche
this.circle.setColor(notation.pop()); this.circle.setColor(notation.pop());
canvas.drawCircle((x*this.getWidth()/11+(this.getWidth()/11)),(y*this.getHeight()/14+getHeight()/21), this.getWidth()/26, this.circle); canvas.drawCircle((x*this.getWidth()/11+(this.getWidth()/11)),(y*this.rootView.getHeight()/14+this.rootView.getHeight()/21), this.getWidth()/26, this.circle);
} }
for(int x=0; x<2; x++) { // colonne droite for(int x=0; x<2; x++) { // colonne droite
this.circle.setColor(notation.pop()); this.circle.setColor(notation.pop());
canvas.drawCircle((x*this.getWidth()/11+(this.getWidth()*4/5)),(y*this.getHeight()/14+getHeight()/21), this.getWidth()/26, this.circle); canvas.drawCircle((x*this.getWidth()/11+(this.getWidth()*4/5)),(y*this.rootView.getHeight()/14+this.rootView.getHeight()/21), this.getWidth()/26, this.circle);
} }
} }
// affichage de la zone de saisie // affichage de la zone de saisie
//copie de la zone de saisie //copie de la zone de saisie
for (int i=0;i<4;i++){ for (int i=0;i<4;i++){
this.circle.setColor(this.combiWin[i]); this.circle.setColor(this.combiWin[i]);
canvas.drawCircle((i*this.getWidth()/5+this.getWidth()/5),this.getHeight()-this.getHeight()*2/9, this.getWidth()/14, this.circle); canvas.drawCircle((i*this.getWidth()/5+this.getWidth()/5),this.rootView.getHeight()*7/9, this.getWidth()/14, this.circle);
} }
} }
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int desiredWidth = this.getWidth();
int desiredHeight = this.rootView.getHeight()*7/9+this.getWidth()/5+this.rootView.getWidth()/7;
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
int width;
int height;
if (widthMode == MeasureSpec.EXACTLY) {
width = widthSize;
} else if (widthMode == MeasureSpec.AT_MOST) {
width = Math.min(desiredWidth, widthSize);
} else {
width = desiredWidth;
}
if (heightMode == MeasureSpec.EXACTLY) {
height = heightSize;
} else if (heightMode == MeasureSpec.AT_MOST) {
height = Math.min(desiredHeight, heightSize);
} else {
height = desiredHeight;
}
setMeasuredDimension(width, height);
System.out.println("Voulu : "+width+" par "+height);
}
} }

View File

@ -43,22 +43,21 @@ public class Bot {
for(int i=0; i<4;i++) { for(int i=0; i<4;i++) {
if (copyCombi[i]==soumission[i]) { if (copyCombi[i]==soumission[i]) {
note.add(this.pionsNotation[1]); note.add(this.pionsNotation[1]);
System.out.println(copyCombi[i]+" good "+i);
copyCombi[i]=null; copyCombi[i]=null;
soumission[i]=null; soumission[i]=null;
System.out.println(copyCombi[i]+" good "+i);
} }
} }
//blancs //blancs
for(int i=0; i<4;i++) { for(int i=0; i<4;i++) {
if(copyCombi[i]!=null){ if(soumission[i]!=null){
for (int y=0;y<4;y++){ for (int y=0;y<4;y++){
if (soumission[y]==copyCombi[i]) { if (soumission[i]==copyCombi[y]) {
note.add(this.pionsNotation[0]); note.add(this.pionsNotation[0]);
System.out.println(copyCombi[i] + " almost "+i+" "+y); copyCombi[y] = null;
copyCombi[i] = null; soumission[i] = null;
System.out.println(copyCombi[i] + " almost "+i+" "+y); System.out.println(i+" "+y);
break;
} }
} }
} }