Exemplo n.º 1
0
  public static void main(String[] args) {
    /*
    *문제
    카드 두장을 비교해서 카드 번호가 더 큰 수가 이기는 게임프로그램을 작성하시오.
    일단, 프로토타입(시제품) 프로그램으로
    개발자가 임의의 숫자를 입력하면

    [출력]
    [홍길동 : 7] vs [김유신 : 3]
    홍길동 승리

    * */

    Scanner scanner = new Scanner(System.in);

    System.out.println("이름 입력 : ");
    CardBean hong = new CardBean(scanner.next());
    System.out.println("이름 입력 : ");
    CardBean kim = new CardBean(scanner.next());

    // 인터넷 망을 타고 데이터값이 게임회사 들어옴

    CardGame cardGame = new CardGame(hong, kim);

    // 사용자가 결과화면을 보는 중....
    System.out.println(cardGame.toString());
  }
Exemplo n.º 2
0
  public static void main(String[] args) {
    /*
    [오더]
    카드 두장을 비교해서 카드 번호가
    더 큰 수가 이기는 게임 프로그램을 작성하시오.
    일단, 프로토타입(시제품) 프로그램으로
    개발자가 임의의 숫자를 입력하면
    [출력]
    [홍길동 : 7] vs [김유신 : 3]
    홍길동 승리
    * */
    Scanner scanner = new Scanner(System.in);
    System.out.println("이름을 입력");
    CardBean3 hong = new CardBean3(scanner.next());
    // 숫자를 랜덤으로 들어오게하기 위해 scanner지움
    System.out.println("이름2:");
    CardBean3 kim = new CardBean3(scanner.next());
    CardGame game = new CardGame(hong, kim);

    System.out.println(game.toString());

    // 객체를 생성함

    // System.out.println(hong.getName()+":"+hong.getCard1());
    // System.out.println(kim.getName()+":"+kim.getCard1());
  }
Exemplo n.º 3
0
 /**
  * Main method, entry point of the program.
  *
  * @param args
  */
 public static void main(String[] args) {
   CardGame cardGame = new CardGame();
   cardGame.setVisible(true);
 }
  public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    // VARIABLES
    int number, option, playerNumber, a = 0;
    String name;
    boolean cik = true;
    CardGame game;
    ScoreCard scores;

    while (cik) {
      // Print menu for user to start game or quit
      System.out.println("1) Start Game");
      System.out.println("2) Quit");

      System.out.print("Enter Number: ");
      number = scan.nextInt();

      // Start game
      if (number == 1) {
        // Get how many users will play
        System.out.print("Enter the number of player: ");
        playerNumber = scan.nextInt();

        // Create Player array to keep players
        Player[] players = new Player[playerNumber];

        // Get users' names and add them to array
        for (int i = 0; i < playerNumber; i++) {
          System.out.print("Enter player's names: ");
          name = scan.next();
          players[i] = new Player(name);
        }

        game = new CardGame(players);

        // Print menu while enough cards exist for all players
        while (a < (52 / playerNumber)) {
          // Print menu to play a round or show score or quit
          System.out.println("1) Play a round");
          System.out.println("2) Scores");
          System.out.println("3) Quit");

          System.out.print("Enter Number: ");
          option = scan.nextInt();

          // Play a round
          if (option == 1) {
            for (int i = 0; i < playerNumber; i++) {
              game.playTurn(players[game.getTurnOfPlayerNo()], new Card(1));
            }
            a++;
          }

          // Show all players' scores
          else if (option == 2) {
            for (int i = 0; i < playerNumber; i++) {
              System.out.println(game.getScore(i));
            }
          }

          // Quit game
          else if (option == 3) {
            a = (52 / playerNumber) + 1;
          }
        }
      }
      // Quit game
      if (number == 2) {
        cik = false;
      }
    }
  }