So i am working on a school project and the project is to make a simplified yahtzee program with two of the yahtzee point systems, ex small ladder or three of a kind and so far i have made small ladder (1,2,3,4,5) and big ladder (2,3,4,5,6) to work but i have 2 questions. 1. How can i make a point system for three of a kind? 2. A part of the project is to make a category if you dont get one of the implied point systems, ex if you get (1,1,4,5,6) then the user is gonna get the option to choose which number he wants to pick for maximum points. I know i cant explain this very well since im swedish and my english isnt the best. But here is my code:
import javax.swing.*;
import java.util.*;
public class Projekt1 {
public static void main(String[] args) {
char fortsatta = 'j';
boolean ja;
do{
JOptionPane.showMessageDialog(null, "V?lkommen till Johans Yatzy");
int starta = JOptionPane.showConfirmDialog(null, "Vill du starta spelet?", "Spela igen",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if(starta == JOptionPane.YES_OPTION ){
JOptionPane.showMessageDialog(null, "Du har nu startat spelet");
int[] tar = new int[5];
for(int i=0; i<5; i++){
tar[i] = (int)(Math.random()*6+1);
}
String output = "";
java.util.Arrays.sort(tar);
for (int i = 0; i < tar.length; i++) {
output = output + tar[i] + " ";
}
JOptionPane.showMessageDialog(null, "Du har nu kastat dina t?rningar och kasten blev f?ljande: " + output);
if (tar[0] == 1 && tar[1] == 2 && tar[2]==3 && tar[3] == 4 && tar[4] == 5) {
JOptionPane.showMessageDialog(null, "Grattis, du fick liten stege som ?r v?rt 15 po?ng");
}
else if (tar[0] == 2 && tar[1] == 3 && tar[2]==4 && tar[3] ==5 && tar[4] ==6) {
JOptionPane.showMessageDialog(null, "Grattis, du fick stor stege som ?r v?rt 20 po?ng");
}
else{
JOptionPane.showMessageDialog(null, "T?rningskastet resulterade i varken liten stege eller stor stege");
}
}
else if(starta == JOptionPane.NO_OPTION){
JOptionPane.showMessageDialog(null, "Programmet kommer nu att st?ngas ner");
System.exit(0);
}
String startaom;
startaom = JOptionPane.showInputDialog("Vill du spela igen? Skriv J f?r att spela igen");
fortsatta = startaom.charAt(0);
}while(fortsatta == 'j');
}
}
See Question&Answers more detail:os