-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.java
61 lines (45 loc) · 1.3 KB
/
Game.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
import javax.swing.*;
public class Game {
public static int totalPlayers=2;
public static int humanPlayers=1;
public static int computerPlayers=1;
private static Card discardPile;
private Player currentPlayer;
private Player p1;
private Player p2;
private String name;
public static void setDiscardPile(Card playedCard)
{discardPile=playedCard;}
public void setCurPlayer(Player p)
{currentPlayer= p;}
public String getName(){return name;}
public Player getPlayer1(){return p1;}
public Player getPlayer2(){return p2;}
public Card getDiscardPile(){return discardPile;}
public Player getCurPlayer(){return currentPlayer;}
public void setPlayer(){
name=JOptionPane.showInputDialog("Please enter your name:");
}
public void createPlayers(int tp, int hp, String n1){
p1 = new Human(n1);
p2 = new Computer("Computer");
}
public boolean isValid(Card a, Card b){
if((a.getSuit().equals(b.getSuit())))return true;
else if((a.getValue()==b.getValue())||a.getValue()==8)return true;
else{
System.out.println("Invalid Card, Please try again.");
return false;
}
}
public void nextPlayer(){
if(currentPlayer.name==name){
p1=currentPlayer;
currentPlayer=p2;
}
else{
p2=currentPlayer;
currentPlayer=p1;
}
}
}