repl.it
@imigames/

black jack

Java

No description

fork
loading
Files
  • Main.java
Main.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import java.util.Random;
import java.util.Scanner;



class Main {
  static String player_print;
  static String computer_print;
  static int player;
  static int player_deal;
  static int computer;
  static int computer_deal;
  static int player2;
  static int player3;
  static int computer2;
  static int computer3;
  static int player_deal2;
  static int player_deal3;
  static int computer_deal2;
  static int computer_deal3;
  static int player4;
  static int computer4;
  static int player_deal4;
  static int computer_deal4;
  static int player5;
  static int computer5;
  static int player_deal5;
  static int computer_deal5;
  static int playerxx;
  static int computerxx;
  static int hand = 0;
  public static void main(String[] args) {
    Random r = new Random();
 Scanner input = new Scanner(System.in);
 System.out.println("Hello, Let's play Blackjack");
 while(true){
System.out.println("Press 1 to deal");
    int deal =input.nextInt();
    
if (deal == 1){
  hand = hand +1;
    if (hand==1){
    player = 1 + r.nextInt(14);
    player_deal=player;
    computer= 1 + r.nextInt(14);
    computer_deal=computer;
    System.out.println("Player1   vs    Computer1");
    System.out.println(""+player_deal +"       vs     "+computer_deal);
    }
    else if (hand ==2 && player_deal<21){
     player2 = 1 + r.nextInt(14);
     computer2 = 1 + r.nextInt(14);
     player_deal2 = player + player2;
     player_deal = player_deal2;
     computer_deal2 = computer + computer2;
     computer_deal=computer_deal2;
    System.out.println("Player2   vs    Computer2");
    System.out.println("   "+player_deal2 +"       vs     "+computer_deal2);
    }
    else if (hand ==3 && player_deal<21){
     player3 = 1 + r.nextInt(14);
     computer3 = 1 + r.nextInt(14);
     player_deal3 = player_deal2 + player3;
     player_deal = player_deal3;
     computer_deal3 = computer_deal2 + computer3;
     computer_deal=computer_deal3;
    System.out.println("Player3   vs    Computer3");
    System.out.println("   "+player_deal3 +"       vs     "+computer_deal3);
    }
    else if (hand ==4 && player_deal<21){
     player4 = 1 + r.nextInt(14);
     computer4 = 1 + r.nextInt(14);
     player_deal4 = player_deal3 + player4;
     player_deal = player_deal4;
     computer_deal4 = computer_deal3 + computer4;
     computer_deal=computer_deal4;
    System.out.println("Player4   vs    Computer4");
    System.out.println("   "+player_deal4 +"       vs     "+computer_deal4);
    }
    else if (hand ==5 && player_deal<21){
     player5 = 1 + r.nextInt(14);
     computer5 = 1 + r.nextInt(14);
     player_deal5 = player_deal4 + player5;
     player_deal = player_deal5;
     computer_deal5 = computer_deal4 + computer5;
     computer_deal=computer_deal5;
    System.out.println("Player5   vs    Computer5");
    System.out.println("   "+player_deal5 +"       vs     "+computer_deal5);
    }
    else if (player_deal >21){
      System.out.println("You lose");
      break;
    }
    else if (player_deal<=21 && computer_deal>21){
      System.out.println("You won");
      break;
    }
}
else if(deal == 2){
  while (true){
    if (computer_deal< player_deal && computer_deal<21 && player_deal<21 ){
    playerxx = player_deal;
     computerxx = 1 + r.nextInt(14);
     player_deal = player_deal;
     
     computer_deal = computer_deal + computerxx;
     
    System.out.println("Player   vs    Computer");
    System.out.println("   "+player_deal +"       vs     "+computer_deal);
    if (player_deal>computer_deal && player_deal<=21){
      System.out.println("You won");
    }
  
}}}





/*
    // Player chose
    if (player ==1){
       player_print = "Ace";
    }
    else if(player == 2){
       player_print = "Two";
    }
    else if(player == 3){
       player_print = "Three";
    }
    else if(player == 4){
       player_print = "Four";
    }
    else if(player == 5){
       player_print = "Five";
    }
    else if(player == 6){
       player_print = "Six";
    }
    else if(player == 7){
       player_print = "Seven";
    }
    else if(player == 8){
       player_print = "Eight";
    }
    else if(player == 9){
       player_print = "Nine";
    }
    else if(player == 10){
       player_print = "Ten";
    }
    else if(player == 11){
       player_print = "Ace";
    }
    else if(player == 12){
       player_print = "Jack";
    }
    else if(player == 13){
       player_print = "Queen";
    }
    else if(player == 14){
       player_print = "King";
    }
    //Computer Chose
    if (computer ==1){
       computer_print = "Ace";
    }
    else if(computer == 2){
       computer_print = "Two";
    }
    else if(computer == 3){
       computer_print = "Three";
    }
    else if(computer == 4){
       computer_print = "Four";
    }
    else if(computer == 5){
       computer_print = "Five";
    }
    else if(computer == 6){
       computer_print = "Six";
    }
    else if(computer == 7){
       computer_print = "Seven";
    }
    else if(computer == 8){
       computer_print = "Eight";
    }
    else if(computer == 9){
       computer_print = "Nine";
    }
    else if(computer == 10){
       computer_print = "Ten";
    }
    else if(computer == 11){
       computer_print = "Ace";
    }
    else if(computer == 12){
       computer_print = "Jack";
    }
    else if(computer == 13){
       computer_print = "Queen";
    }
    else if(computer == 14){
       computer_print = "King";
    }

    System.out.println("You draw a "+  player_print +" and have "+player +" points");
    System.out.println("Computer draw a "+ computer_print+" and have "+ computer +" points");
    */
  
  }
  }
}