⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adventuretextui.java

📁 The project Adventure is a simple text-based adventure game. The game, as given, involves the hero t
💻 JAVA
字号:
package ope.adventure.ui;


import java.util.Scanner;

import ope.adventure.Area;
import ope.adventure.Adventure;
import ope.adventure.Player;


/**
 * This class contains a fully text-based user interface for the 
 * Adventure game project. The UI reads its input from the console
 * using a <CODE>Scanner</CODE> object.
 * 
 * @see ope.adventure.ui.AdventureGUI
 * @see java.util.Scanner
 */
public class AdventureTextUI {

  private Adventure adventure;				// fixed value: a session only has one adventure and ends when that one finishes
  private Player player;							// fixed value
  private Scanner keyboard; 					// fixed value: used to read keyboard input

  
  /**
   * Sets up a new user interface and starts a new adventure
   * from the beginning.
   */
  public AdventureTextUI() {
    this.adventure = new Adventure();
    this.player = this.adventure.getPlayer();
    this.keyboard = new Scanner(System.in);
  }

  
  /**
   * Runs the user interface. First, a welcome message
   * is displayed. Then the user is repeatedly asked to 
   * play a turn until the adventure is over. Finally,
   * a goodbye message is printed.
   */
  public void run() {
    System.out.println(this.adventure.getWelcome());
    while (!this.adventure.isOver()) {
      this.printAreaInfo();
      this.playTurn();
    } 
    System.out.println("\n" + this.adventure.getGoodbye());
  }


  /**
   * Prints a description of the player's current location.
   */
  private void printAreaInfo() {
    Area area = this.player.getLocation();
    System.out.println("\n\n" + area.getName());
    System.out.println(area.getName().replaceAll(".", "-"));
    System.out.println(area.getFullDescription() + "\n");
  }

  
  /**
   * Lets the user play a turn: asks for a command,
   * executes it, and prints out the consequences.
   */
  private void playTurn() {
    System.out.println();
    System.out.print("Command: ");
    String command = this.keyboard.nextLine();
    String turnReport = this.adventure.playTurn(command);
    System.out.println(turnReport);
  }
  

  /**
   * Creates a user interface and starts it.
   */
  public static void main(String[] arguments) {
    AdventureTextUI ui = new AdventureTextUI();
    ui.run();
  }
  
  
  
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -