-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGUI.java
92 lines (74 loc) · 3.57 KB
/
GUI.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
//THIS IS A PROJECT DONE BY UZAY MACAR THAT IS DUE TO 08.01.2016 12:00.
//THIS PROJECT IS A FLUENT BLACKJACK GAME THAT HAS A MENU AND A GAMING COMPONENT.
//UZAY MACAR CODED BOTH THE INSIDE GAME MECHANICS (CARD, DECK, AND GAME CLASSES)
//AND OUTSIDE COMPONENTS (THE LAYOUT, BUTTONS, MENU, ETC.)
package blackjack;
import javax.swing.JFrame;
public class GUI {
public static JFrame gameFrame = new JFrame(); //This is the frame in which the real blackjack game will be played.
public static Game_GUI newGame = new Game_GUI(gameFrame); //we initialize a 'Game_GUI' in order to control, start, and calculate the blackjack game.
public Thread gameCheckThread;
public void runGUI(Card[] card_deck,Card []player1hand, Card []player2hand,Card []player3hand,Card []dealerhand){
gameCheckThread = new Thread(new Runnable() {
public Card player1[]=new Card[2];
public Card player2[]=new Card[2];
public Card player3[]=new Card[2];
public Card dealer[]=new Card[2];
public Card deck[]=new Card[52];
public Runnable init(Card[]card_deck, Card []player1hand, Card []player2hand,Card []player3hand,Card []dealerhand) {
try{
for(int i=0;i<2;i++)// knowing that at the begining each player will have 2 cards by default
{
this.player1[i]=new Card(player1hand[i]);
this.player2[i]=new Card(player2hand[i]);
this.player3[i]=new Card(player3hand[i]);
this.dealer[i] = new Card(dealerhand[i]);
}
}
catch(Exception e)
{
System.out.println("A Null Exception happened.. Make sure that you pass a 2 sized Cards Deck array");
}
try{
for(int i=0;i<52;i++)// knowing that at the begining each player will have 2 cards by default
{
if(card_deck[i] != null)
this.deck[i]=new Card(card_deck[i]);
}
}
catch(Exception e)
{
System.out.println("A Null Exception happened.. Make sure that you pass a 52 sized Cards Deck array");
}
return this;
}
@Override
public void run() {
gameFrame.getContentPane().removeAll(); //we remove everything from the frame.
newGame = new Game_GUI(gameFrame); //we initialize a new game on the same frame.
newGame.formGame(this.deck,this.player1, this.player2,this.player3, this.dealer); //we set the atmosphere of the game(which is everything except the cards.)
}
}.init(card_deck,player1hand,player2hand,player3hand, dealerhand));
gameCheckThread.start();
gameRefreshThread.start();
};
public void updatePlayerHand(Card c, int player_no){
Card[] Deck=new Card[4];
newGame.updatePlayerHand(c, player_no, Deck);
}
public void updateDealerHand(Card c,Card[] Deck, boolean k){
if(k == true){
newGame.updateDealerHand(c,Deck, k);
}
else{
newGame.updateDealerHand(c,Deck, k);
}
}
public static Thread gameRefreshThread = new Thread () { //this first thread (each thread must have a run method) serves to continuously [since we put true inside the while loop, it will continue forever.] refresh the component.
public void run () {
while(true){
newGame.atmosphereComponent.refresh(newGame.faceDown);
}
}
};
}