-
Notifications
You must be signed in to change notification settings - Fork 1
/
Player.java
98 lines (72 loc) · 1.72 KB
/
Player.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
package com.kct.fifthsem.cseb.assignment.hangman;
public class Player {
private String playerName = null;
private int numberofLifes;
private int numberofWordsIdentified;
private Word[] wordsIdentifiedByPlayer = null;
public Player(String playerName)
{
this.playerName = playerName;
this.numberofLifes = 4;
this.numberofWordsIdentified = 0;
}
public String getPlayerName()
{
return this.playerName;
}
public int getNumberofLifes()
{
return this.numberofLifes;
}
public void addLifetoUser(final int numberofLifestoAdd)
{
this.numberofLifes+=numberofLifestoAdd;
}
public void reduceLifeofUserByOne()
{
this.numberofLifes--;
}
private void upadteUserWordIdentifiedCount()
{
this.numberofWordsIdentified++;
}
public int getNumberofWordsIdentified()
{
return this.numberofWordsIdentified;
}
public Word[] getListofWordsIdentifiedByPlayer()
{
return this.wordsIdentifiedByPlayer;
}
public void updateWordIndentifiedByPlayerInList(final Word word)
{
if(this.wordsIdentifiedByPlayer == null)
{
this.wordsIdentifiedByPlayer = new Word[20];
}
for(int index=0;index<this.wordsIdentifiedByPlayer.length;
index++)
{
if(wordsIdentifiedByPlayer[index]==null)
{
wordsIdentifiedByPlayer[index] = word;
break;
}
}
this.upadteUserWordIdentifiedCount();
}
public boolean isPlayerIdentifiedThisWord(final Word word)
{
if(this.wordsIdentifiedByPlayer!=null)
{
for(Word wordinList : this.wordsIdentifiedByPlayer)
{
if(wordinList!=null && wordinList.equals(word))
{
return true;
}
}
}
return false;
}
}