-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGuessGame.java
61 lines (56 loc) · 2.03 KB
/
GuessGame.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.company;
import java.util.Arrays;
import java.util.Scanner;
//To do: add comments
//Character.isLetter(string.charAt(index))
public class CleanCode {
private boolean StringToChars(String param) {
Scanner sc = new Scanner(System.in);
boolean found = false;
char[] missingLetters = new char[param.length()];
int d = Integer.MAX_VALUE;
char[] buffer = param.toCharArray();
char[] chars = new char[buffer.length];
d = chars.length;
System.out.println("Can you guess the movie ? " + " \n" + "hint: " +
param.length() + " letters");
String c = sc.nextLine();
char[] Cbuffer = c.toCharArray();
char[] Cchars = new char[param.length()];
for (int x=0;x<Cchars.length;x++) {
Cchars[x] = Cbuffer[x];
}
System.out.println("each char: ");
for (int i=0;i<chars.length;i++) {
chars[i] = buffer[i];
if(chars[i] == Cchars[i]) {
d--;
System.out.print(Cchars[i] + " ");
} else if (chars[i] != Cchars[i]){
System.out.print(" _ ");
missingLetters[i] = chars[i];
found = false;
// System.out.println("> " + missingLetters[i] + " <");
}
found = (d == 0);
if (found){System.out.println("100% found WOW!");}
}
System.out.print("missing letters: " /*Arrays.toString(missingLetters)*/);
for(char x:missingLetters){
if (!Character.isLetter(x)){
System.out.print("_");
}else{
System.out.print(x + " ");
}
}
System.out.println("\nremained " + d + " letters unfound");
// System.out.println(Arrays.toString(chars));
return found;
}
public static void main(String[] args) {
CleanCode cleanCode = new CleanCode();
String movieName = "Hidalgo";
cleanCode.StringToChars(movieName);
String x = movieName = "h";
}
}