-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dice game.txt
75 lines (71 loc) · 1.61 KB
/
Dice game.txt
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
//Dice game
import java.util.Scanner;
import java.util.Random;
class Dice
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
Random rd = new Random();
System.out.println("welcome to dice game");
System.out.println("enter the first plyr name");
String fname=sc.next();
System.out.println("enter the second plyr name");
String sname=sc.next();
int ftotal=0;
int stotal=0;
while(true){
while(true)
{
System.out.println(fname+"press f to flip the dice");
char c1=sc.next().charAt(0);
if (c1=='F'|| c1=='f')
{
int score = rd.nextInt(6)+1;
System.out.println(fname+"you scored "+score);
if (ftotal+score<=100)
ftotal=ftotal+score;
if (ftotal==100)
{
System.out.println(fname+"won the game");
return;
}
else
{
System.out.println(fname+"total score is "+ftotal);
}
break;
}
else{
System.out.println("you not pressed f/F");
}
}
while(true)
{
System.out.println(fname+"press s to flip the dice");
char c1=sc.next().charAt(0);
if (c1=='S'|| c1=='s')
{
int score = rd.nextInt(6)+1;
System.out.println(sname+"you scored "+score);
if (stotal+score<=100)
stotal=stotal+score;
if (stotal==100)
{
System.out.println(sname+"won the game");
return;
}
else
{
System.out.println(sname+"total score is "+stotal);
}
break;
}
else
{
System.out.println("you not pressed s/S");
}
}
}
}
}