Compare commits
6 Commits
viewIsJava
...
miseEnPlac
Author | SHA1 | Date | |
---|---|---|---|
5e84efc0b4 | |||
405c41e2d3 | |||
ef0b698a77 | |||
dfc3a84cd3 | |||
75ac209aef | |||
e34c000f65 |
60
app/src/main/java/com/example/mastermind/game/Bot.java
Normal file
60
app/src/main/java/com/example/mastermind/game/Bot.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package com.example.mastermind.game;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
/* TODO: Modifs pour GameView :
|
||||
- création d'un Bot si le mode de jeu est solo
|
||||
- création d'une méthode redraw(){invalidate()}
|
||||
- variable qui :
|
||||
+ interdit le switch de state
|
||||
+ demande de verif si victoire au Bot lors des soumissions
|
||||
+ soumet à grille sa notation
|
||||
*/
|
||||
public class Bot {
|
||||
private Integer[] collectionWin;
|
||||
private Integer pionVide;
|
||||
private Integer[] pionsNotation;
|
||||
|
||||
public Bot(Collection<Integer> pionsAutorisés, Integer[] pionsNotation, Integer pionVide){
|
||||
this.collectionWin = new Integer[4];
|
||||
this.pionVide=pionVide;
|
||||
this.pionsNotation=pionsNotation;
|
||||
generationCombiWin(pionsAutorisés);
|
||||
}
|
||||
|
||||
protected void generationCombiWin(Collection<Integer> pions){
|
||||
Random rand = new Random();
|
||||
int nbPions = pions.size();
|
||||
Integer[] tabPions=(Integer[]) pions.toArray();
|
||||
for (int i=0;i<4;i++){
|
||||
this.collectionWin[i]=tabPions[rand.nextInt(nbPions)];
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<Integer> notation(Integer[] soumission){
|
||||
Collection<Integer> note=new LinkedList<Integer>();
|
||||
for(int i=0; i<4;i++) {
|
||||
if (this.collectionWin[i] == soumission[i]) {
|
||||
note.add(this.pionsNotation[1]);
|
||||
}
|
||||
}
|
||||
//On crée une copie de la combinaison gagnante pour la modifier et éviter la fausse répétition de pions blancs
|
||||
Integer[] copyCombi = this.collectionWin;
|
||||
for(int i=0; i<4;i++) {
|
||||
for (int y=0; y<4;y++) {
|
||||
if (i!=y){
|
||||
if (this.collectionWin[y] == soumission[i]){
|
||||
note.add(this.pionsNotation[0]);
|
||||
this.collectionWin[y]=null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return note;
|
||||
}
|
||||
}
|
@@ -45,7 +45,7 @@ public class GameView extends View {
|
||||
for (int x=0;x<4;x++) {
|
||||
this.circle.setColor(grille.pop());
|
||||
//TODO: coordonnées propres
|
||||
canvas.drawCircle(( x*this.getWidth()/8+(this.getWidth()*21/68)),(y*this.getWidth()/8+this.getWidth()/10), this.getWidth()/17, this.circle);
|
||||
canvas.drawCircle(( x*this.getWidth()/8+(this.getWidth()*21/68)),(y*this.getHeight()/14+this.getHeight()/21), this.getWidth()/17, this.circle);
|
||||
}
|
||||
}
|
||||
// affichage de la zone de saisie
|
||||
@@ -55,7 +55,7 @@ public class GameView extends View {
|
||||
for (int i=0;i<this.saisie.getSelection().size();i++){
|
||||
this.circle.setColor(saisie.pop());
|
||||
//TODO: coordonnées propres (encore)
|
||||
canvas.drawCircle((i*this.getWidth()/5+this.getWidth()/5),this.getWidth()*58/40, this.getWidth()/12, this.circle);
|
||||
canvas.drawCircle((i*this.getWidth()/5+this.getWidth()/5),this.getHeight()-this.getHeight()*2/9, this.getWidth()/14, this.circle);
|
||||
}
|
||||
|
||||
// affichage des couleurs choisissables
|
||||
@@ -66,13 +66,16 @@ public class GameView extends View {
|
||||
for (int i=0;i<this.saisie.getChoix().size();i++){
|
||||
this.circle.setColor(couleurs.pop());
|
||||
//TODO: coordonnées propres (encore)
|
||||
canvas.drawCircle((i*this.getWidth()*2/13+this.getWidth()/8),this.getWidth()*689/420, this.getWidth()/15, this.circle);
|
||||
canvas.drawCircle((i*this.getWidth()*2/13+this.getWidth()/8),this.getHeight()-this.getHeight()/7, this.getWidth()/16, this.circle);
|
||||
}
|
||||
//TODO: ajout des colonnes de notation
|
||||
//TODO: ajout des boutons
|
||||
//Test de bouton valider
|
||||
this.circle.setColor(this.getResources().getColor(R.color.green));
|
||||
canvas.drawCircle((this.getWidth()/2),this.getHeight()-this.getWidth()/9, this.getWidth()/10, this.circle);
|
||||
canvas.drawCircle((this.getWidth()/2),this.getHeight()-this.getHeight()/16, this.getWidth()/13, this.circle);
|
||||
// bouton retour
|
||||
/* this.circle.setColor(this.getResources().getColor(R.color.blue));
|
||||
canvas.drawCircle((this.getWidth()/2), this.getHeight()-this.getHeight()/16, this.getWidth()/13, this.circle);*/
|
||||
}
|
||||
|
||||
//Change l'état de soumission à notation après qu'une combinaision ai été soumise puis inversement
|
||||
|
@@ -17,7 +17,7 @@ public class TouchListener implements View.OnTouchListener{
|
||||
if (action==MotionEvent.ACTION_UP)
|
||||
{
|
||||
//Surveille quel bouton de couleur est choisi
|
||||
if (v.getWidth()*689/420-v.getWidth()/15<y && y<v.getWidth()*689/420+v.getWidth()/15){
|
||||
if (v.getHeight()-v.getHeight()/7-v.getWidth()/16<y && y<v.getHeight()-v.getHeight()/7+v.getWidth()/16){
|
||||
if(v.getWidth()/8-v.getWidth()/15<x && x<v.getWidth()/8+v.getWidth()/15){
|
||||
this.view.addChoix(0);
|
||||
} else if(v.getWidth()*2/13+v.getWidth()/8-v.getWidth()/15<x && x<v.getWidth()*2/13+v.getWidth()/8+v.getWidth()/15){
|
||||
|
@@ -4,7 +4,6 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#333"
|
||||
android:padding="10dp"
|
||||
tools:context=".MainActivity"
|
||||
>
|
||||
|
||||
|
Reference in New Issue
Block a user