0
이 줄에 "identifyer expected"라는 오류 메시지가 계속 나타납니다. hk.guess (charToGuess); 수정하려면 무엇을해야합니까?식별자가 exepected
나는 간단한 행맨 게임을 만들고있어 많은 어려움을 겪고있다. 나는 프로그래밍에있어서 아주 새로운데, 나는이 프로젝트에 대해 너무 많은 생각을하기 시작했다.
import java.util.Random;
import java.util.Scanner;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Hangman {
public static void main(String[] args) {
HangmanSession hangmanSession = new HangmanSession();
hangmanSession.play();
}
private HiddenKeyword hiddenKeyword;
private int triesNumber = 7;
hiddenKeyword hk = new HiddenKeyword();
hk.guess(charToGuess);
private void printState() {
System.out.print("Hidden word : ");
hiddenKeyword.print();
System.out.print("Tries left: " + triesNumber + "\n<guess letter:>");
}
public void play() {
boolean bool = true;
while(true) {
bool = true;
printState();
System.out.println("Try again, you've already used that letter " + char.class);
bool = false;
}
if(bool) {
if(hiddenKeyword.guess(char.class)) {
System.out.println("YAY! you have found letter! " + ch);
}
else {
triesNumber--;
}
if(triesNumber < 1)
gameOver();
if(hiddenKeyword.found())
congratulations();
}
} //end of bool
public void congratulations() {
System.out.println("Congratulations " + player + ", you win!");
System.exit(0);
}
public void gameOver() {
System.out.println("Sorry " + player + ", you lost, but you can try again!");
System.exit(0);
}
private String fValue;
private StringBuffer pValue;
private int lfoundNumber = 0;
public String words() {
Random r = new Random();
int random = r.nextInt(20)+1;
}
public boolean found() {
System.out.println("Letters found:" + lfoundNumber + "/" + fValue.length());
return (lfoundNumber == fValue.length());
}
public boolean guess(char c) {
int index = fValue.indexOf(c);
if(index == -1)
return false;
else {
lfoundNumber = lfoundNumber + findOccurances(c);
return true;
}
}
private int findOccurances(char c) {
int idx = fValue.indexOf(c);
pValue.setCharAt(idx, fValue.charAt(idx));
int counter = 1;
while(idx != -1) {
int idxx = fValue.indexOf(c, idx + 1);
idx = idxx;
if(idx != -1) {
counter++;
pValue.setCharAt(idx, fValue.charAt(idx));
}
}
return counter;
}
public void print() {
System.out.println(pValue);
}
private char[] lbox = new char[24];
private int counter = 0;
public boolean contains(char c) {
for(int i = 0; i < counter; i++) {
if(lbox[i] == c)
return true;
}
lbox[counter] = c;
counter++;
return false;
}
public void print() {
System.out.print("\nLetterBox:");
for(int i = 0; i < counter; i++) {
System.out.print(lbox[i]);
}
System.out.println("");
}
public static void main(String[] args) {
int words = 20;String wordsString;
switch(random) {
case 1:
return "star";
case 2:
return "hooray";
case 3:
return "dog";
case 4:
return "improvise";
case 5:
return "teacher";
case 6:
return "college";
case 7:
return "seahawks";
case 8:
return "read";
case 9:
return "computer";
case 10:
return "program";
case 11:
return "holiday";
case 12:
return "film";
case 13:
return "music";
case 14:
return "learn";
case 15:
return "library";
case 16:
return "waterfall";
case 17:
return "book";
case 18:
return "semester";
case 19:
return "first";
case 20:
return "vacation";
default:
return"";
}
}
}
}