Re: How do I fix this issue?
How do you fix what? Unless you tell us what your problems are we have no idea how to help.
Re: How do I fix this issue?
Step one, Download eclipse or another good ide
Step two look for errors and figure out why they are they, if your unsure specificly ask on certain code lines
Re: How do I fix this issue?
true, okay so the program has to ask you to enter a word. At the same time it randomly generates a letter. Say you enter "word" and the letter it generates is "r"...If there is 4 or less randomly gen'd letters in the word you enter it only takes away 5 points, but if you enter a word that has no secret letters in it, it takes away 10 points....my problem is, is that I cant figure out how to make it do that. If I enter the secret letter once it says "you win", but if I enter the letter multiple times it doesn't work. (what I have to do is on the PDF attached)
Re: How do I fix this issue?
Re: How do I fix this issue?
I haven't read your code as it is unformatted and hard to read. In future place [ code ] before and [ /code ] after your code (without the spaces).
You need to loop over the word entered by the user and compare each char with the secret letter. If it matches increment a count. After that if count is greater than zero subtract 5 points else subtract 10 points. By the way your massive if statement generating the secret letter can be replaced with a single line. Here's a hint:
Code:
System.out.println((char)(0 + 'a'));
System.out.println((char)(25 + 'a'));
Re: How do I fix this issue?
Thank you sooo much!! it works now. And its my first time programming so I'll keep that in mind. Thanks again!
Re: How do I fix this issue?
do you mean like this:
Code:
// Guess the Secret Letter Game
// Designed By: Ben Smith
// November 10th 2011
// Version: 1.0
import hsa. * ;
public class BenSmithGuessTheSecretLetterGame{
public static void main(String[] args){
Console con = new Console(40,60);
// Variables
String strMenuSelect;
String strGuess;
String strRand;
String strLetter;
int intCounter;
int intCounter2;
int intPoints;
int intRand;
int intLength;
int intLose;
int intMaxAlpha;
// Menu and User menu selection
con.println("Welcome to Guess the Secret Letter Game!!");
con.println(" *************");
con.println(" *****************");
con.println(" ****** ******");
con.println(" ***** ******");
con.println(" **** *****");
con.println(" *****");
con.println(" *******");
con.println(" *******");
con.println(" ********");
con.println(" *****");
con.println(" *****");
con.println(" *****");
con.println(" *****");
con.println(" *****");
con.println("");
con.println(" ***");
con.println(" *****");
con.println(" ***");
// Defaulting Variables
intCounter = 0;
intCounter2= 0;
intPoints = 50;
intRand = 0;
intLose = 0;
intMaxAlpha = 26;
strMenuSelect = "";
strGuess = "";
strRand = "";
strLetter = "";
// Menu Seleciton
con.println("Menu");
con.println("==============");
con.println("(P)lay Game");
con.println("(I)nstructions");
con.println("(Q)uit");
con.println("Enter you selection here");
strMenuSelect = con.readLine();
// Generating the number and assigning a lettetr to a number
intRand = (int)(Math.random()*26+1);
if(intRand == 1){
strRand = ("a");
}else if(intRand == 2){
strRand = ("b");
}else if(intRand == 3){
strRand = ("c");
}else if(intRand == 4){
strRand = ("d");
}else if(intRand == 5){
strRand = ("e");
}else if(intRand == 6){
strRand = ("f");
}else if(intRand == 7){
strRand = ("g");
}else if(intRand == 8){
strRand = ("h");
}else if(intRand == 9){
strRand = ("i");
}else if(intRand == 10){
strRand = ("j");
}else if(intRand == 11){
strRand = ("k");
}else if(intRand == 12){
strRand = ("l");
}else if(intRand == 13){
strRand = ("m");
}else if(intRand == 14){
strRand = ("n");
}else if(intRand == 15){
strRand = ("o");
}else if(intRand == 16){
strRand = ("p");
}else if(intRand == 17){
strRand = ("q");
}else if(intRand == 18){
strRand = ("r");
}else if(intRand == 19){
strRand = ("s");
}else if(intRand == 20){
strRand = ("t");
}else if(intRand == 21){
strRand = ("u");
}else if(intRand == 22){
strRand = ("v");
}else if(intRand == 23){
strRand = ("w");
}else if(intRand == 24){
strRand = ("x");
}else if(intRand == 25){
strRand = ("y");
}else if(intRand == 26){
strRand = ("z");
}
con.println(strRand); // Prints the randomly gen'd letter on the main console
// Play Game Code
if(strMenuSelect.equalsIgnoreCase("P")){
Console con2 = new Console();
con2.println("You selected Play Game");
con2.println("==============");
con2.println("You currently have 50 points");
for(intCounter = 0; intCounter <= intLose; intCounter--){
con2.println("Enter a word with the secret letter in it");
strGuess = con2.readLine();
for(intCounter2 = 0; intCounter2 < strGuess.length(); intCounter2++){
if(strRand.equals (strGuess)){
strLetter = strGuess.substring(intCounter2, intCounter2+1);
while(strGuess.equalsIgnoreCase(strRand)){ // Verifys that the guess equals the gen'd letter
if(strLetter.equalsIgnoreCase(strRand)){ // If the guess equals the gen'd letter then it runs the game code
intPoints = 0;
con2.println("YOU WIN!!!");
break;
}
}
}else if(!strLetter.equalsIgnoreCase(strRand)){
con2.println("WRONG DEDUCTING 5 POINTS!");
intPoints = intPoints-5;
}
if(strGuess.equalsIgnoreCase(strRand)){
intLength = strLetter.length();
}
if(intPoints < 0){
con2.println("YOU LOSE!!");
}
}
}
}
// Instructions
if(strMenuSelect.equalsIgnoreCase("I")){
Console con3 = new Console();
con3.println("You selected Instructions");
con3.println("How to play");
con3.println("====================");
con3.println("You start with 50 points. A secret");
con3.println("letter will be generated and you have");
con3.println("to enter a word with that letter in it.");
con3.println("If the word you enter does not have");
con3.println("the secret letter then you will lose 10 ");
con3.println("points. If the word you enter has the ");
con3.println("letter once or up to 4 times then you ");
con3.println("lose 5 points. If the word you enter ");
con3.println("has the letter 5 times or more you win! ");
con3.println("If your points are 0 or less then you lose.");
}
// Quit
if(strMenuSelect.equalsIgnoreCase("Q")){
con.println("=============");
con.println("Thank you for playing Guess the Secret Letter!!");
con.println("Created By: Ben Smith");
}
}
}
Re: How do I fix this issue?
That managed to wrap code tags around it but it is still hard to read due to lack of indentation.