MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / HangMan

Class HangMan

Programs/Games/HangMan.java:6–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4import java.util.Scanner;
5
6public class HangMan {
7 private String[] wordCollection = {"banana", "apple", "mango", "pinapple", "grapefruit", "kiwi", "custardapple", "dragonfruit", "coconut", "strawberry", "blueberry", "melon", "tangerine", "apricot", "peach", "orange", "cherry", "grape", "watermelon", "pear"};
8 private String compPick = null;
9 private int guesses;
10 private int warning = 4;
11 private String alphabets = "abcdefghijklmnopqrstuvwxyz";
12
13 private char[] guessedWord = null;
14 private int[] indices;
15
16 public char inputChar(){
17 System.out.print("Enter Your Guess: ");
18 Scanner num = new Scanner(System.in);
19 return num.next().charAt(0);
20 }
21
22 public void pickWord(){
23 int rng = wordCollection.length;
24 Random num = new Random();
25 int i = num.nextInt(rng);
26 this.compPick = wordCollection[i];
27 }
28
29 public void setGuessedWord(){
30 int length = this.compPick.length();
31 this.guessedWord = new char[length];
32 for(int i = 0; i < length; i++){
33 this.guessedWord[i] = '_';
34 }
35 }
36
37 public void setGuess(String word){
38 this.guesses = (int) (word.length()*1.5);
39 }
40
41 public Boolean isInPick(char letter) {
42 return this.compPick.indexOf(letter) != -1;
43 }
44
45 public void setIndices(char letter){
46 int length = this.compPick.length();
47 int ind = 0;
48 char[] comPickArray = this.compPick.toCharArray();
49 this.indices = new int[length];
50 for(int i = 0; i < length; i++){
51 if(letter == comPickArray[i]){
52 this.indices[ind] = i;
53 ind++;
54 }
55 }
56 }
57
58 public void updateGuessed(char letter, int[] loc) {
59 int length = this.guessedWord.length;
60 int ind = 0;
61 for(int i = 0; i < length; i++){
62 if(i == loc[ind]){
63 ind++;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected