-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslotgame.java
More file actions
77 lines (77 loc) · 2.38 KB
/
slotgame.java
File metadata and controls
77 lines (77 loc) · 2.38 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
import java.util.Scanner;
import java.util.Random;
class slotgame
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int balance = 100;
int bet,c;
String ch="yes";
String[] row;
System.out.println("*********************************");
System.out.println("Welcome to the slot machine game");
System.out.println("Symbols are: 🎶,❤,🎃,🚑,🍔");
System.out.println("********************************");
while(balance>0)
{
System.out.println("Current balance is:- "+balance);
System.out.println("Enter bet amount");
bet=sc.nextInt();
if(bet>balance)
{
System.out.println("insufficient funds");
continue;
}
else if(bet<0)
{
System.out.println("bet cannot be negative");
continue;
}
else
{
balance -= bet;
System.out.println("remaining balance is:- "+balance);
}
System.out.println("spinning....");
row = spinrow();
if(row[0]==row[1]&&row[1]==row[2])
{
System.out.println("Win!!");
c=2*bet;
balance=balance+c;
System.out.println("Balance "+balance);
}
else
{
System.out.println("Sorry you lost");
}
System.out.println("Do you want to continue yes or no");
ch=sc.next();
if(ch.equals("yes"))
{
continue;
}
else
{
System.out.println("closing amount is "+balance);
break;
}
}
sc.close();
}
static String[] spinrow()
{
String[] symbols = {"🎶","❤","🎃","🚑","🍔"};
String[] row = new String[3];
Random rd= new Random();
for(int i=0;i<3;i++)
{
row[i]=symbols[rd.nextInt(symbols.length)];
}
System.out.println("*****************");
System.out.println(row[0]+" | "+row[1]+" | "+row[2]);
System.out.println("*****************");
return row;
}
}