Hi my name is Jakob and I'm new to programming. My project now is to make a game called Mastermind in Java Eclipse. Here is an explanation of what Mastermind is: http://sv.wikipedia.org/wiki/Mastermind
My game is going to be text-/number-based and it's just going to be able to run in the console, nothing advanced like an applet etc.
Would you professional programmers like to help me with this game? Please! :)
Here is how far I've come, not much, but it's a start :P
public class JakobMastermind {
public static void main(String[] args) {
// INTRODUCTION
System.out.println("Hi and welcome to the game Mastermind!! :)\nMade by Jakob Petersson\n\n");
// ANSWER/SECRET
// (4 arrays for a combination of 4 numbers that will guess a number between 1 and 6)
int[] secret=new int[4];
for(int i=0;i<4;i++){
secret[i]=(int)(Math.random()*6+1);
}
// (Type out the answer)
System.out.println("The secret: "+secret[0]+secret[1]+secret[2]+secret[3]);
// GUESSES
int[] guess=new int[4];
for(int i=0;i<4;i++){
do{
guess[i]=Kbd.readInt("Guess number "+(i+1)+": ");
}while(!(guess[i]>=1 && guess[i]<=6));
}
System.out.println("Your guess was: "+guess[0]+guess[1]+guess[2]+guess[3]+"\n");
// CONTROL
// WHITE
int white=0;
if(guess[0]==secret[1] || guess[0]==secret[2] || guess[0]==secret[3]){
white=white+1;
}
if(guess[1]==secret[0] || guess[1]==secret[2] || guess[1]==secret[3]){
white=white+1;
}
if(guess[2]==secret[0] || guess[2]==secret[1] || guess[2]==secret[3]){
white=white+1;
}
if(guess[3]==secret[0] || guess[3]==secret[1] || guess[3]==secret[2]){
white=white+1;
}
// BLACK
int black=0;
if(guess[0]==secret[0]){
black=black+1;
}
if(guess[1]==secret[1]){
black=black+1;
}
if(guess[2]==secret[2]){
black=black+1;
}
if(guess[3]==secret[3]){
black=black+1;
}
// CONTROL - ANSWER
white=white-black;
if(white>1 && black>=1){
System.out.print("You have "+white+" white pins");
}else if(white==1 && black>=1){
System.out.print("You have "+white+" white pin");
}else if(white>1 && black==0){
System.out.println("You have "+white+" white pins.");
}else if(white==1 && black==0){
System.out.println("You have "+white+" white pin.");
}
if(black>1 && white>=1){
System.out.println(" and "+black+" black pins.");
}else if(black==1 && white>=1){
System.out.println(" and "+black+" black pin.");
}else if(black==1 && white<1){
System.out.println("You have "+black+" black pin.");
}else if(black>1 && white<1){
System.out.println("You have "+black+" black pins.");
}
// WIN
if(secret[0]==guess[0] && secret[1]==guess[1] && secret[2]==guess[2] && secret[3]==guess[3]){
System.out.println("\nCongratulations, you've won!! :D");
}
}
}