Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider d118943c rédigé par Guillaume DOEUVRE's avatar Guillaume DOEUVRE :yawning_face:
Parcourir les fichiers

Merge branch 'fix_#59_refactor_modul-b' into 'main'

fix_smell_Stack.java fix_smell_SquareBegin.java fix_smell_Square.java fix_smell_Question.java

Closes #59

See merge request !5
parents d9be3047 9b4baa6c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!5fix_smell_Stack.java fix_smell_SquareBegin.java fix_smell_Square.java fix_smell_Question.java
...@@ -2,6 +2,7 @@ package fr.unantes.sce.trivial.model; ...@@ -2,6 +2,7 @@ package fr.unantes.sce.trivial.model;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Map.Entry; import java.util.Map.Entry;
...@@ -58,22 +59,23 @@ public class Question implements Serializable { ...@@ -58,22 +59,23 @@ public class Question implements Serializable {
i++; i++;
} }
} }
switch (i) {
case 1: if (i == 1) {
return true; return true;
default: } else {
return false; return false;
} }
} }
public boolean equals(Object o) { public boolean equals(Object o) {
if (o instanceof Question) { if (o instanceof Question q) {
Question q = (Question) o;
return this.statement.equals(q.statement); return this.statement.equals(q.statement);
} }
return false; return false;
} }
public String getAuthor() { public String getAuthor() {
return author; return author;
} }
...@@ -98,22 +100,23 @@ public class Question implements Serializable { ...@@ -98,22 +100,23 @@ public class Question implements Serializable {
this.category = category; this.category = category;
} }
public void setChoices(HashMap<String, Boolean> choices) { public void setChoices(Map<String, Boolean> choices) {
this.choices = choices; this.choices = new HashMap<>(choices);
} }
public HashMap<String, Boolean> getChoices() {
HashMap<String, Boolean> map = new HashMap<>(4);
Set<Entry<String, Boolean>> entries = choices.entrySet(); public Map<String, Boolean> getChoices() {
Map<String, Boolean> map = new HashMap<>(4);
for (Entry<String, Boolean> e : entries) { for (Entry<String, Boolean> entry : choices.entrySet()) {
map.put(e.getKey(), e.getValue()); map.put(entry.getKey(), entry.getValue());
} }
return map; return map;
} }
public String toString() { public String toString() {
final String SEPARATOR = "\",\n"; final String SEPARATOR = "\",\n";
StringBuilder tmp = new StringBuilder(); StringBuilder tmp = new StringBuilder();
......
...@@ -10,11 +10,11 @@ import java.util.List; ...@@ -10,11 +10,11 @@ import java.util.List;
*/ */
public abstract class Square public abstract class Square
{ {
private List<Piece>joueursSurLaCase; private final List<Piece>joueursSurLaCase;
private int id; private final int id;
private static int nbCase=0; private static int nbCase=0;
public Square() protected Square()
{ {
joueursSurLaCase=new ArrayList<>(); joueursSurLaCase=new ArrayList<>();
id=nbCase; id=nbCase;
...@@ -23,7 +23,7 @@ public abstract class Square ...@@ -23,7 +23,7 @@ public abstract class Square
/** /**
* add a piece on this square * add a piece on this square
* @param Piece p * @param p p
*/ */
public void addPiece(Piece p){ public void addPiece(Piece p){
if(!joueursSurLaCase.contains(p)){ if(!joueursSurLaCase.contains(p)){
...@@ -33,12 +33,10 @@ public abstract class Square ...@@ -33,12 +33,10 @@ public abstract class Square
/** /**
* remove a piece on this square * remove a piece on this square
* @param Piece p * @param p p
*/ */
public void removePiece(Piece p){ public void removePiece(Piece p){
if(joueursSurLaCase.contains(p)){
joueursSurLaCase.remove(p);
}
} }
public int getIdCase() { public int getIdCase() {
...@@ -57,7 +55,7 @@ public abstract class Square ...@@ -57,7 +55,7 @@ public abstract class Square
/** /**
* This method check if the player is on this square * This method check if the player is on this square
* @param pie * @param pie p
* @return boolean * @return boolean
*/ */
public boolean getThisPiece(Piece pie){ public boolean getThisPiece(Piece pie){
......
package fr.unantes.sce.trivial.model; package fr.unantes.sce.trivial.model;
import java.util.Random; import java.util.Random;
/**
* This class is an extend of the abstract class Square
* It allows to create the beginning square
* @author Thomas
*
*/
public class SquareBegin extends Square { public class SquareBegin extends Square {
private Category cat; private Category cat;
private Random random;
public SquareBegin(){
public SquareBegin() {
super(); super();
random = new Random();
} }
public Category getCategorie(){ public Category getCategorie() {
Random ran = new Random(); int valCat = random.nextInt(6) + 1;
int valCat= ran.nextInt(6)+1; for (Category c : Category.values()) {
for(Category c: Category.values()){ if (c.getId() == valCat) {
if(c.getId()==valCat){ cat = c;
cat=c;
} }
} }
return cat; return cat;
......
...@@ -7,6 +7,8 @@ import java.util.Iterator; ...@@ -7,6 +7,8 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import fr.unantes.sce.trivial.utility.Serialisation; import fr.unantes.sce.trivial.utility.Serialisation;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
public class Stack extends Observable implements Serializable public class Stack extends Observable implements Serializable
...@@ -83,14 +85,18 @@ public class Stack extends Observable implements Serializable ...@@ -83,14 +85,18 @@ public class Stack extends Observable implements Serializable
{ {
List<Question> list = new ArrayList<>(); List<Question> list = new ArrayList<>();
int i = 1; int i = 1;
for(Question q : listQuestion) for(Question q : listQuestion)
{ {
list.add(new Question(q.getAuthor(),q.getStatement(),q.getCategory())); list.add(new Question(q.getAuthor(),q.getStatement(),q.getCategory()));
list.get(list.indexOf(q)).setChoices(q.getChoices()); list.get(list.indexOf(q)).setChoices(q.getChoices());
logger.info(i + q.getStatement());
if (logger.isLoggable(Level.INFO)) {
logger.info(String.format("%d. %s", i, q.getStatement()));
}
i++; i++;
} }
...@@ -190,13 +196,9 @@ public class Stack extends Observable implements Serializable ...@@ -190,13 +196,9 @@ public class Stack extends Observable implements Serializable
public Question getRandomQuestionByCat(Category cat){ public Question getRandomQuestionByCat(Category cat){
for(Question q: listQuestion){ for(Question q: listQuestion){
if(q!= null)
{ if (q != null && q.getCategory().equals(cat)) {
if(q.getCategory().equals(cat)) return q;
{
return q;
}
} }
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter