-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplayer.java
More file actions
119 lines (84 loc) · 2.41 KB
/
Copy pathplayer.java
File metadata and controls
119 lines (84 loc) · 2.41 KB
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
import java.util.*;
//donc hna tbda la classe player
public class player{
private card card;
private String name;
private List<card> hand;
private Scanner scan = new Scanner(System.in);
private deck deck;
//constructeur
public player(String name){
this.name = name;
this.hand = new ArrayList<>();
}
//constructeur with deck
public player(String name, deck d){
this.name = name;
this.hand = new ArrayList<>();
this.deck = d;
}
//now the methods
public void draw(int n){
for(int i = 0; i < n; i++) {
card c = deck.drawplus(1);
hand.add(c);
}
}
// show cards and plat turn method
public card showcards(deck deck){
card paintcard; //for the drawable card
System.out.println("\n " + name + " hand :");
for(int i = 0 ; i < hand.size() ; i++){
System.out.println((i+1) + ":");
paintcard = hand.get(i);
paintcard.logo();
}
while (true) {
System.out.println(" \n choose a card to play, or press 0 to draw");//writing under the painted cards
int index = scan.nextInt();
if(index == 0){
draw(1);
return null;
} else {
index--;// for machine array for that it starts from 0,im making it user friendly
//the draw method()
if(index < 0 || index >= hand.size()){
System.out.println(" invalid index");
continue;
} else {
card c = hand.get(index);
if(!c.allowplay(deck.getTopDiscard())){
System.out.println(" you cant play this card");
continue;
} else {
deck.addtodiscard(c);
hand.remove(index);
if (c instanceof nonregular){
System.out.println( "\n "+getName()+((nonregular)c).gettype());}
else {
System.out.println( "\n "+getName()+((regular)c).getnumber());
}
if (hand.size() == 1){
System.out.println(name + " says: UNO!");
}
return c;
}
}
}
}
//and from here nroho to the main() and gameManagement
//not sure if all classes are here so ill be working au fur et a mesure
}// end showcards
public List<card> getHand() {
return hand;
}
public boolean hasEmptyHand() {
return hand.isEmpty();
}
public int getHandSize() {
return hand.size();
}
public String getName() {
return name;
}
}