import java.util.Scanner; /* * RomanNumeralGame.java * * This file contains a sample game for * playing with Roman Number objects. * * CS112 * * Christine Papadakis-Kanaris * */ public class RomanNumeralGame { public static String gameName = "RomanNumeralGame"; /* * This is the main control method. * * Just filling it with the basics so you can see * how to beging play. * */ public static void main( String[] args ) { Scanner scan = new Scanner( System.in ); System.out.println( "Welcome to the most fantastic " + gameName ); System.out.print( "Who am I playing with today? " ); String fname = scan.next(); String lname = scan.next(); Name player = new Name( fname, lname ); System.out.print( "Welcome " + player + ", what is your game name? " ); // Careful here when using nextLine() after next() (or nextInt(), etc). // the next() method reads up to the newLine character, // but LEAVES the newling character on the input stream. // Therefore the next read command will begin with the \n. If using next() // there is no problem, because this method ignores leading spaces and // newlines, however, the nextLine() method will read until it comes to a newline // character, and if this is the first character on the input stream, the method // will effectively stop at that first \n encountered and return. // // One solution is to issue a nextLine() statement to read through it. // // scan.nextLine(); // read through \n - you can comment out this line to see what would happen fname = scan.nextLine(); // read the next input line player.setGameName(fname); System.out.println( "Thank you " + player + "!"); player.setDisplayName(player.getGameName()); System.out.println( "From now on you are known as " + player + "!" ); // Now go play the game boolean stopPlay = false; do { playGame(player.getGameName()); System.out.println( "Would you like to play again (yes/no)? " ); String answer = scan.next(); if (!answer.equals("yes")) stopPlay = true; } while( !stopPlay ); player.setDisplayName(player.getFirstName()); System.out.println( "Thanks for playing " + player + "!" ); } /* * playGame( Player ): void * * This is the game to be played... can have many possible implementaions. * */ public static void playGame( String gameName ) { System.out.println( "ok " + gameName + ", let's begin!" ); } } // class