前提・実現したいこと
https://mrradiology.hatenablog.jp/entry/20160709/1468022084
上記のサイトのSaikoro.javaを参考にコードを書いたのですが、
エンターを一度押しただけで、Round1とRound2の二つの結果が表示されます。
初心者のためもともとそういうコードなのか、わたしが何が間違えているのか分かりません。
希望としてはエンター、Round1、エンター、Round2...のように一つずつ表示させたいです。
発生している問題・エラーメッセージ
エンターを一度押しただけで、Round1とRound2の二つの結果が表示されます。
一度のエンターで二つずつRoundが表示されてしまいます。
該当のソースコード
以下が私の書いたものになります。(Java)
public class Saikoro{ public static int score = 100; public static int bet = 5; public static int round = 1; public static String[] diceStrings = { "| * |", "| : |", "|...|", "|: :|", "|:.:|", "|:::|"}; public static void throwDices() { int me1 = (int)(Math.random()*6.0); int me2 = (int)(Math.random()*6.0); showDices(me1, me2); checkPoints(me1, me2); } public static void showDices(int a, int b){ System.out.println(""); System.out.println(diceStrings[a] + " " + diceStrings[b]); System.out.println(""); } public static void checkPoints(int a, int b){ int c = a + b + 2; if(c % 2 ==0){ if(a == b){ score += bet * 2; System.out.println("You win" + bet*2 + "$"); } else{ score += bet; System.out.println("You win" + bet + "$"); } } else{ if(c == 7){ score -= bet * 2; System.out.println("You lose" + bet*2 + "$"); } else{ score -= bet; System.out.println("You lose" + bet + "$"); } } System.out.println("You have" + score + "$"); } public static void keyInput(){ try{ int c = System.in.read(); } catch(Exception e){} } public static void main(String[] args){ while(score > 0){ System.out.println(""); System.out.println("Hit Enter"); keyInput(); System.out.println(""); System.out.println("Round" + round); throwDices(); round++; } System.out.println("You have no money, gameover"); } }
試したこと
コードを見比べてみましたが、サイトのものと同じに思えます。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答2件
あなたの回答
tips
プレビュー