import java.util.Random;
import java.util.Scanner;
public class Main {
public static void main
(String[] args
) {
Scanner scan
= new Scanner
(System.
in); int yourHandNo = 3; // とりあえず3
int yourHandMem = 3;
int cpuHandNo = 3;
boolean isGameLoop = false;
int loopNo = 1; // 繰り返し回数
int logicPattern = 1; // cpuの思考パターン
int winCount = 0;
int drawCount = 0;
int loseCount = 0;
do {
System.
out.
println("これから(また)じゃんけんをします。グー・チョキ・パーのいずれかを入力して下さい。"); yourHandStr = scan.nextLine();
if (yourHandStr.equals("グー")) {
yourHandNo = 0;
} else if (yourHandStr.equals("チョキ")) {
yourHandNo = 1;
} else if (yourHandStr.equals("パー")) {
yourHandNo = 2;
} else {
System.
out.
println("文字列を正しく入力して下さい。終了します。"); }
if (loopNo == 1) {
cpuHandNo = rand.nextInt(3);
} else {
logicPattern = rand.nextInt(4) + 1;
switch (logicPattern) {
case 1:
cpuHandNo = rand.nextInt(3); // 考えなし
break;
case 2: // 相手より強い手出したがり
if (yourHandMem == 0) {
cpuHandNo = 2;
} else if (yourHandMem == 1) {
cpuHandNo = 0;
} else {
cpuHandNo = 1;
}
break;
case 3: // あえて相手より弱い手出したがり
if (yourHandMem == 0) {
cpuHandNo = 1;
} else if (yourHandMem == 1) {
cpuHandNo = 2;
} else {
cpuHandNo = 0;
}
break;
case 4: // 相手と同じ手出したがり
if (yourHandMem == 0) {
cpuHandNo = 0;
} else if (yourHandMem == 1) {
cpuHandNo = 1;
} else {
cpuHandNo = 2;
}
break;
}
}
if (yourHandNo == 0) {
yourHandMem = 0;
} else if (yourHandNo == 1) {
yourHandMem = 1;
} else {
yourHandMem = 2;
}
if (yourHandNo == cpuHandNo) {
drawCount++;
} else if (cpuHandNo - yourHandNo == 1 || yourHandNo - cpuHandNo == 2) {
System.
out.
println("あなたの勝ちです。"); winCount++;
} else {
System.
out.
println("CPUの勝ちです。"); loseCount++;
}
switch (cpuHandNo) {
case 0:
System.
out.
println("CPUの手はグーでした。"); break;
case 1:
System.
out.
println("CPUの手はチョキでした。"); break;
case 2:
System.
out.
println("CPUの手はパーでした。"); break;
}
// System.out.println("logicPatterは" + logicPattern);
System.
out.
println("あなたは" + winCount
+ "勝" + loseCount
+ "敗" + drawCount
+ "引き分け" +"です。"); System.
out.
println("ジャンケンを続けますか?続ける/やめるを入力して下さい。"); gameLoopStr = scan.nextLine();
if (gameLoopStr.equals("続ける")) {
isGameLoop = true;
} else if (gameLoopStr.equals("やめる")) {
isGameLoop = false;
} else {
System.
out.
println("文字列を正しく入力して下さい。終了します。"); }
loopNo++;
} while(isGameLoop == true);
}
}