soumission ok et remplissage grille
This commit is contained in:
parent
1e0f8e845a
commit
c313f2846e
@ -24,10 +24,9 @@ public class GameView extends View {
|
||||
super(context);
|
||||
this.saisie=saisie;
|
||||
this.grille=grille;
|
||||
//this.setOnTouchListener(new TouchListener());
|
||||
this.setOnTouchListener(new TouchListener(this));
|
||||
//on initialise les collections de pions
|
||||
initpions();
|
||||
initSizes();
|
||||
//state indique si le joueur soumet une combinaison ou false si elle est noté
|
||||
this.state=true;
|
||||
this.circle = new Paint();
|
||||
@ -50,12 +49,10 @@ public class GameView extends View {
|
||||
// affichage de la zone de saisie
|
||||
LinkedList<Integer> saisie = new LinkedList<Integer>();
|
||||
saisie.addAll(this.saisie.getSelection());
|
||||
System.out.println(saisie.size());
|
||||
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);
|
||||
System.out.println("rond saisie");
|
||||
}
|
||||
|
||||
// affichage des couleurs choisissables
|
||||
@ -66,18 +63,31 @@ public class GameView extends View {
|
||||
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);
|
||||
System.out.println("rond saisie");
|
||||
}
|
||||
//Test pour 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);
|
||||
}
|
||||
|
||||
public void changeState() {
|
||||
if (this.saisie.getSizeSelection() == 4) {
|
||||
/*this.state = !this.state;
|
||||
if (this.state) {
|
||||
this.saisie.setChoix(this.pionsAttaquant);
|
||||
} else if (!this.state) {
|
||||
this.saisie.setChoix(this.pionsDefenseur);
|
||||
}*/
|
||||
this.grille.addSoumission(this.saisie.getSelection());
|
||||
this.saisie.initSelection(this.getResources().getColor(R.color.pionVide));
|
||||
this.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
protected void initSizes(){
|
||||
|
||||
//Soumet une nouvelle couleur pour la séléction à soumettre
|
||||
public void addChoix(int choix){
|
||||
this.saisie.addSelection(choix);
|
||||
this.invalidate();
|
||||
}
|
||||
|
||||
protected void redraw(){
|
||||
invalidate();
|
||||
}
|
||||
|
||||
//initialise les collections de pions
|
||||
public void initpions(){
|
||||
//on initialise les pions
|
||||
@ -99,14 +109,8 @@ public class GameView extends View {
|
||||
this.pionsAttaquant.add(this.getResources().getColor(R.color.white));
|
||||
|
||||
// on inisialise la saisie
|
||||
if (this.state) {
|
||||
saisie.setChoix(this.pionsAttaquant);
|
||||
} else if(!this.state){
|
||||
saisie.setChoix(this.pionsAttaquant);
|
||||
} else {
|
||||
System.out.println("KC");
|
||||
}
|
||||
saisie.setSelection(this.pionsPasPlaces);
|
||||
saisie.setChoix(this.pionsAttaquant);
|
||||
saisie.initSelection(this.getResources().getColor(R.color.pionVide));
|
||||
|
||||
// on rempli la grille de cases grises
|
||||
grille.initGrille(this.pionsPasPlaces);
|
||||
|
@ -10,16 +10,22 @@ import java.util.LinkedList;
|
||||
représente la grille de jeu à savoir la liste des soumissions ainsi que leur notation
|
||||
*/
|
||||
public class Grille {
|
||||
private int sizeSubs;
|
||||
private LinkedList<Integer> soumissions;
|
||||
private LinkedList<Integer> notations;
|
||||
|
||||
public Grille(){
|
||||
this.soumissions=new LinkedList<Integer>();
|
||||
this.notations=new LinkedList<Integer>();
|
||||
this.sizeSubs=0;
|
||||
}
|
||||
|
||||
public void addSoumission(Collection<Integer> newSub){
|
||||
this.soumissions.addAll((this.soumissions.size()-4),newSub);
|
||||
public void addSoumission(LinkedList<Integer> newSub){
|
||||
for (int i=4;i>0;i--){
|
||||
System.out.println("i="+i+", new sub="+newSub);
|
||||
this.soumissions.set(this.soumissions.size()-this.sizeSubs*4-i,newSub.pop());
|
||||
}
|
||||
this.sizeSubs+=1;
|
||||
}
|
||||
|
||||
public void initGrille(Collection<Integer> SubToCopy){
|
||||
|
@ -13,6 +13,7 @@ import java.util.LinkedList;
|
||||
*/
|
||||
public class Saisie {
|
||||
|
||||
private int sizeSelection;
|
||||
private LinkedList<Integer> choix;
|
||||
private LinkedList<Integer> selection;
|
||||
public Saisie(){
|
||||
@ -22,11 +23,24 @@ public class Saisie {
|
||||
|
||||
// getters et setters
|
||||
|
||||
public void setSelection(Collection<Integer> chosenColors){
|
||||
this.selection.addAll(chosenColors);
|
||||
public void initSelection(Integer chosenColors){
|
||||
this.selection.removeAll(this.selection);
|
||||
for (int i=0;i<4;i++){
|
||||
this.selection.add(chosenColors);
|
||||
}
|
||||
this.sizeSelection=0;
|
||||
|
||||
}
|
||||
public void setSelection(Integer chosenColors, int index){
|
||||
this.selection.set(index, chosenColors);
|
||||
public void addSelection(Integer chosenColors){
|
||||
if (this.sizeSelection<4){
|
||||
this.selection.set(this.sizeSelection,this.choix.get(chosenColors));
|
||||
this.sizeSelection+=1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int getSizeSelection(){
|
||||
return this.sizeSelection;
|
||||
}
|
||||
|
||||
public Collection<Integer> getChoix(){
|
||||
@ -34,10 +48,11 @@ public class Saisie {
|
||||
}
|
||||
|
||||
public void setChoix(Collection<Integer> colorsSelected){
|
||||
this.choix.removeAll(this.choix);
|
||||
this.choix.addAll(colorsSelected);
|
||||
}
|
||||
|
||||
public Collection<Integer> getSelection(){
|
||||
public LinkedList<Integer> getSelection(){
|
||||
return this.selection;
|
||||
}
|
||||
|
||||
|
@ -4,9 +4,10 @@ import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
public class TouchListener implements View.OnTouchListener{
|
||||
|
||||
public TouchListener(){}
|
||||
|
||||
private GameView view;
|
||||
public TouchListener(GameView view) {
|
||||
this.view=view;
|
||||
}
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
int action = event.getActionMasked();
|
||||
@ -15,7 +16,23 @@ public class TouchListener implements View.OnTouchListener{
|
||||
|
||||
if (action==MotionEvent.ACTION_UP)
|
||||
{
|
||||
|
||||
if (v.getWidth()*689/420-v.getWidth()/15<y && y<v.getWidth()*689/420+v.getWidth()/15){
|
||||
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){
|
||||
this.view.addChoix(1);
|
||||
} else if(2*v.getWidth()*2/13+v.getWidth()/8-v.getWidth()/15<x && x<2*v.getWidth()*2/13+v.getWidth()/8+v.getWidth()/15) {
|
||||
this.view.addChoix(2);
|
||||
} else if(3*v.getWidth()*2/13+v.getWidth()/8-v.getWidth()/15<x && x<3*v.getWidth()*2/13+v.getWidth()/8+v.getWidth()/15){
|
||||
this.view.addChoix(3);
|
||||
} else if(4*v.getWidth()*2/13+v.getWidth()/8-v.getWidth()/15<x && x<4*v.getWidth()*2/13+v.getWidth()/8+v.getWidth()/15) {
|
||||
this.view.addChoix(4);
|
||||
} else if(5*v.getWidth()*2/13+v.getWidth()/8-v.getWidth()/15<x && x<5*v.getWidth()*2/13+v.getWidth()/8+v.getWidth()/15){
|
||||
this.view.addChoix(5);
|
||||
}
|
||||
} else if (v.getHeight()-v.getWidth()/9-v.getWidth()/10<y && y<v.getHeight()-v.getWidth()/9+v.getWidth()/10){
|
||||
this.view.changeState();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user