JAvaクイズデジタルゲーム

2328 ワード

Javaを学んだばかりで、簡単な数字を当てる小さなゲームpackage MathGameを書きます.
import java.util.Random; import java.util.Scanner;
public class game {
private  int count; //    
private int range; //         

public void play(int count, int range) {
    this.count = count;
    this.range = range;

    Random random = new Random();
    int ans = random.nextInt(range);
    int guessNum=0;
    for (int i = 0; i < count; i++) {
        System.out.print("       :");
        guessNum = new Scanner(System.in).nextInt();
        if(guessNum > ans) {
            System.out.println("   ,   !");
            System.out.println("   " + (count-i-1) + "   ");
        }else if(guessNum < ans){
            System.out.println("   ,   !");
            System.out.println("   " + (count-i-1) + "   ");
        }else{
            System.out.println("      !");
            break;
        }

    }
    System.out.println("    ");
}

public void play() {

    System.out.println("         ");
    range = new Scanner(System.in).nextInt();
    System.out.println("       ");
    count = new Scanner(System.in).nextInt();
    Random random = new Random();
    int ans = random.nextInt(range);
    int guessNum=0;
    for (int i = 0; i < count; i++) {
        System.out.print("       :");
        guessNum = new Scanner(System.in).nextInt();
        if(guessNum > ans) {
            System.out.println("   ,   !");
            System.out.println("   " + (count-i-1) + "   ");
        }else if(guessNum < ans){
            System.out.println("   ,   !");
            System.out.println("   " + (count-i-1) + "   ");
        }else{
            System.out.println("      !");
            break;
        }

    }
    System.out.println("    ");
}

public int getCount() {
    return count;
}

public void setCount(int count) {
    this.count = count;
}

public int getRange() {
    return range;
}

public void setRange(int range) {
    this.range = range;
}

}
///////////////////////////////////////////////////////////////////package MathGame;
public class testgame { public static void main(String[] args) { game gg = new game(); gg.play(); } }