- 3
Help with domino java project
Don't onow how to start
21 Réponses
+ 1
I'm sorry, but in my last comment I've made a mistake: In the constructor of class Deck, the creation of the 28 dominoes can be done with 2 for cycles:
int z = 0;
for (int i = 0; i <= 6; i++) {
for(int j = i; j <= 6; j++) {
this.dominoes[z] = new Domino(i, j);
z++;
}
}
Then if it's the Formula 2, you need to change the if conditions.
You can create a HashMap to the values:
In the class Deck:
private final HashMap<Integer,Integer[]> numberNext = new HashMap<>();
In the Deck constructor:
numberNext.put(0,new Integer[]{6,1});
numberNext.put(1,new Integer[]{0,2});
numberNext.put(2,new Integer[]{1,3});
numberNext.put(3,new Integer[]{2,4});
numberNext.put(4,new Integer[]{3,5});
numberNext.put(5,new Integer[]{4,6});
numberNext.put(6,new Integer[]{5,0});
The first element is the before and the last element the after. With this you can define the getDominoesAvailableToPlay(Player player) as:
public ArrayList<Domino> getDominoesAvailableToPlay(Player player){
int right = this.dominoesOnTable.get(this.dominoesOnTable.size()-1).getBottomSide();
int left = this.dominoesOnTable.get(0).getTopSide();
ArrayList<Domino> dominoesAvailableToPlay = new ArrayList<>();
for(Domino domino : player.getHand()){
int right_plus = numberNext.get(domino.getBottomSide())[1];
int right_minus = numberNext.get(domino.getBottomSide())[0];
int left_plus = numberNext.get(domino.getTopSide())[1];
int left_minus = numberNext.get(domino.getTopSide())[0];
if(right_minus == right || right_plus == left || left_minus == right || left_plus == left){
dominoesAvailableToPlay.add(domino);
}
}
return dominoesAvailableToPlay;
}
+ 1
You can represent a piece as a Tuple, for that you can create a class Piece with left and rigth as attributes.
You can represent the Table as a Deque:
https://docs.oracle.com/javase/7/docs/api/java/util/Deque.html
Using the Deque you can define that the first is left and last is rigth. So a piece (p) will fit on the left if (p.left == first.left or p.rigth == first.left) and will fit on the right if (p.left == last.rigth or p.rigth == last.rigth)
I hope I helped.
+ 1
I saw your code but I have a question, how do you exactly play domino? I think my version is different.
If you have the piece [5/6] shouldn't you be able to put
either:
[?,5][5,6]
or:
[5,6][6,?]
?
+ 1
I made some corrections in the code and there is some things I've notice:
1. @Override has a capital O
2. Don't use import java.util.*, import only what you need. You have a really nice example here: https://stackoverflow.com/questions/147454/why-is-using-a-wild-card-with-a-java-import-statement-bad
3. Try to have the code in english because it's easier to other programmers analise and catch bugs.
4. The identation is really important since it makes easier to read and see if there is curly brackets missing. Here's my version (I only organized and fixed some syntax): https://code.sololearn.com/crPW4Hr7RZtY
For the table, as I said earlier, you can use a Deque. A Deque is the mix of a queue and a stack, you can either addFirst and addLast, this is going to make our life easier since the Domino's game you have two sides.
If you have any question about the implementation of the Deque I strongly sugest you see the documentation and some examples of how does it work:
https://docs.oracle.com/javase/7/docs/api/java/util/Deque.html
https://www.softwaretestinghelp.com/deque-in-java/
I also suggest you add a method on the class Joueur to add Dominoes to the ArrayList
+ 1
Can you explain me better how the score works? I tried to see on your code but it's very confusing, can you give me an example or explain me with words?
I did my version of your game the only thing I don't have is the score system since I don't know how does it work... You can see the code here:
https://code.sololearn.com/crPW4Hr7RZtY
Sorry, I didn't have time to comment, but I tried to use your type of writting and the names you used.
0
Didnt quite understand
0
I'm sorry I didn't see this was from a project. What's the project name, course and theme?
0
No if you have [5/6] you play
[5/6][0/ 2]
or
[4/4][5/6]
0
It is like this
[0/1][2/3][4/5][6/6][0/3]
0
So i complet it but didn't know how to add this condition can anyone help ??
0
Don't represent the players as an ArrayList, instead use a Circular Linked List:
https://www.baeldung.com/java-circular-linked-list
https://www.youtube.com/watch?v=0ODSrJcMT54
In the method findPlayerWithDoubleSix from the class Deck, you already have a method on the class Player that can see if the player has the Double Six.
for(Player player : this.players) {
if (player.findIndexOfDoubleSix() == -1) continue;
return player
}
In the method getDominoesAvailableToPlay(Player player) from the class Deck or either is wrong or you changed the rules. You said the domino [2/4] can match with [5,0] but can’t match with [4,6], but in your code you are saying that if you have a domino [x/y] it’ll match if the sides have either x or y. So, my question is, what’s the formula?
1. [x/y] will match if one of the sides have either x or y
2. [x/y] will match if (the left side has y+1 or x+1) or (the right side has x-1 or y-1)
3. Neither of them
I think you should print the table state everytime it’s changed and when the player needs to choose a domino, because rigth now when you’re choosing a domino the table isn’t updated and you can’t really remember how the table was.
0
Formula 2 is what i want
0
How do you calculate each player's score?
0
I forgot that in domino the score must be
Score (count) %5 ==0
0
There seems that i didn't put it in the account
0
Tomás Ribeiro can i speak to you
I have already sent you messges
0
Where did you send messages?
0
Tomás Ribeiro in sololearn
0
I'm having problems activating my account so I can't see your messages, do you have discord?