-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWord.java
144 lines (106 loc) · 2.67 KB
/
Word.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package com.kct.fifthsem.cseb.assignment.hangman;
public class Word {
private String wordString = null;
private int length = 0;
private char[] wordInCharArray = null;
private char[] listofLettersFound = null;
private int numberofLettersFoundinWord = 0;
private char[] displayWordForGame = null;
public Word(final String word)
{
if(word!=null && word.length()>0)
{
this.wordString = word;
this.length = word.length();
this.wordInCharArray = word.toCharArray();
this.initilizeDisplayWordFormart();
}
}
private void initilizeDisplayWordFormart() {
displayWordForGame = new char[length];
for(int index=0;index<length;index++)
{
displayWordForGame[index] = '_';
}
}
public String wordInGameFormat()
{
return new String(this.displayWordForGame);
}
public void updateDisplayWordFormat(final int[] indexcestoUpatde,char letter)
{
if(indexcestoUpatde!=null)
{
int numberofTimesLetterOcurred = 0;
for(int index=0;index<indexcestoUpatde.length;index++)
{
if(indexcestoUpatde[index]==1)
{
this.displayWordForGame[index] = letter;
numberofTimesLetterOcurred++;
}
}
this.updateNumberofLettersFoundinWord(numberofTimesLetterOcurred);
}
}
public int wordLength()
{
return length;
}
public int[] arrayofLetterIndexcesinWord(char letter)
{
int[] letterIndexces = null;
for(int index=0;index<wordInCharArray.length;index++)
{
if(letter == wordInCharArray[index])
{
if(letterIndexces == null)
{
letterIndexces = new int[this.length];
}
letterIndexces[index] = 1;
}
}
return letterIndexces;
}
public char[] getListofLettersFound()
{
return this.listofLettersFound;
}
public void addLetterTotheFoundLettersList(final char letterFound)
{
if(this.listofLettersFound == null)
{
this.listofLettersFound = new char[length];
}
for(int index=0;index<listofLettersFound.length;index++)
{
if(listofLettersFound[index]=='\u0000')
{
listofLettersFound[index] = letterFound;
break;
}
}
}
public int getNumberofLettersFoundinWord()
{
return this.numberofLettersFoundinWord;
}
private void updateNumberofLettersFoundinWord (final int count)
{
this.numberofLettersFoundinWord += count;
}
@Override
public boolean equals(Object obj) {
if(obj!=null && obj instanceof Word)
{
Word word = (Word) obj;
if(word.wordString.equals(this.wordString)
&& word == this)
{
return true;
}
}
return false;
}
}