Dibawah ini adalah condingnya:
import java.util.Scanner;
public class ScissorRockPaperGame {
public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner s = new Scanner(System.in);
// User memilih item yang akan dimainkan dengan memasukkan angka sesuai petunjuk
System.out.print("Enter 0 (Scissor), 1 (Rock), 2 (Paper). Your Choice: ");
int choice = s.nextInt();
// Computer juga memilih item yang dimainkan dengan menghasilkan angka acak 0 - 2
long com = System.currentTimeMillis() % 3;
// Menangkap semua kemungkinan yang ada dengan percabangan IF
if (choice == 0 && com == 0)
System.out.println("Computer is Scissor. You are Scissor too. It is DRAW!");
else if (choice == 1 && com == 1)
System.out.println("Computer is Rock. You are Rock too. It is DRAW!");
else if (choice == 2 && com == 2)
System.out.println("Computer is Paper. You are Paper too. It is DRAW!");
else if (choice == 0 && com == 1)
System.out.println("Computer is Rock. You are Scissor. You LOST!");
else if (choice == 0 && com == 2)
System.out.println("Computer is Paper. You are Scissor. You WON!");
else if (choice == 1 && com == 0)
System.out.println("Computer is Scissor. You are Rock. You WON!.");
else if (choice == 1 && com == 2)
System.out.println("Computer is Paper. You are Rock. You LOST!.");
}
}
Berikut coding lengkapnya untunk permainan Kertas-Gunting-Batu.
Download here
0 Response to "Permainan kertas, gunting, batu dengan Pemrograman Java"
Post a Comment