-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.java
131 lines (106 loc) · 3.29 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
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
//Vincent Lim
//Player.java
//Player object made for each player.
//Houses:
// Socket, PrintWriter/Reader, Cards
import java.net.*;
import java.io.*;
import java.util.*;
public class Player{
private Socket socket;
private PrintWriter writer;
private BufferedReader reader;
private Card [] cards;
private PokerHand bestHand;
private int money;
private String name;
private boolean folded;
private int amountBet; //amount bet in the current betting round
private boolean hasBet;
public Player(Socket socket, int money){
this.socket = socket;
try {
this.writer = new PrintWriter(this.socket.getOutputStream(), true);
this.reader = new BufferedReader(new InputStreamReader(this.socket.getInputStream()));
} catch (IOException e){
e.printStackTrace();
System.out.println("I/O Error when creating input and output stream writers");
} catch (NullPointerException e){ //DELETE THIS LATER
} //DELETE THIS LATER
try{
this.name = reader.readLine();
writer.println("Hi "+ name + ", Welcome to Poker!");
} catch (IOException e){
e.printStackTrace();
//System.err.println("IO Error when during readline. Connection is probably closed or reset");
} catch (NullPointerException e){ //DELETE THIS LATER
} //DELETE THIS LATER
this.money = money;
}
//DELETE THIS LATER
public void setName(String s){
name = s;
}
public int getMoney(){
return this.money;
}
public void setMoney(int money){
this.money = money;
}
public void betMoney(int x){
if(x>=money){ //player goes all in
x=money;
amountBet+=money;
money=0;
}
money-=x;
amountBet+=x;
}
public void setAmountBet(int x){
amountBet = x;
}
public int getAmountBet(){
return this.amountBet;
}
public boolean getFolded(){
return folded;
}
public void setFolded(boolean x){
this.folded = x;
}
public Socket getSocket(){
return this.socket;
}
public PrintWriter getWriter(){
return this.writer;
}
public BufferedReader getReader(){
return this.reader;
}
public boolean getHasBet(){
return hasBet;
}
public void setHasBet(boolean b){
hasBet = b;
}
public void setBestHand(ArrayList<Card> communityCards){ //Community cards are the cards in the center that everyone shares
ArrayList<Card> temp = new ArrayList<>(communityCards);
for(int i=0; i<cards.length; i++) temp.add(cards[i]);
//System.out.println("Combined cards: "+temp.toString());
//now the ArrayList "temp" has both this player's cards and the community cards
bestHand = HandEvaluator.returnHighestHand(temp);
System.out.println(name + " has a hand ranking of " + bestHand.getRanking());
}
public PokerHand getBestHand(){
return bestHand;
}
public String getName(){
return this.name;
}
public Card[] getCards(){
return this.cards;
}
public void setCards(Card [] cards){
this.cards = cards;
}
}