import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
public class PigGames {
public static void main
(String[] args
) {
Scanner sc
= new Scanner
(System.
in);
List<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(3);
list.add(4);
list.add(5);
list.add(6);
int turns = 0;
int score = 0;
int die = 0;
while (score<20){
turns++;
System.
out.
println("TURN " + turns
);
int turn_score = 0;
while (true) {
System.
out.
print("Roll or Hold? (r/h): ");
char val = sc.nextLine().charAt(0);
switch (val) {
case 'r':
die = list.get(random.nextInt(6));
System.
out.
println("Die: " + die
);
if(die != 1){
turn_score += die; // turn_score=turn_score+die //curent die turn
score += die; //overall turn
}else {
score -= turn_score;
turn_score = 0;
}
if (score>20){
break;
}
break;
case 'h':
System.
out.
println("Score for turn: " + turn_score
);
System.
out.
println("Total score: " + score
);
break;
default:
System.
out.
println("Invalid character");
}
if (val == 'h' || die == 1 || score > 20){
break;
}
}
}
System.
out.
println("Total score: " + score
);
System.
out.
println("You finished in "+turns
+" turns!");
System.
out.
println("Game Over!");
}
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}