/*  Author:  Jose Hernandez  1415865  

     Subject:       COP 3804   M-Th 5:00

     Instructor:  Norman Pestaina  ECS 364

     Assigment:  1 Formating dates    DUE Sunday 07/06;

     Oath: I certify that this work is my own and that

           none of it is the work of any other person.

*/

 

import javax.swing.JOptionPane;

public class PlayGame

{

    public static void main(String[] args)

    {

            GamePlayer game;

           

            String gameName = JOptionPane.showInputDialog("Which game do you wish to play?");

            if (gameName.equalsIgnoreCase("hangman"))

            {

                   

                    game = new HangMan();

            }

            else

                    throw new RuntimeException(gameName + ": No such game available");

                   

            System.out.println( game );

           

            while ( !game.isOver() )

            {

                    if ( game.isPlayersTurn() )

                    {

                            String move;

                           

                            do

                            {

                                    move = game.getPlayerMove();

                            } while ( !game.isValidMove(move) );

                           

                            game.playerMoves(move);

                    }

                    else

                            game.computerMoves();

                           

                    System.out.println( game );

            }

           

            JOptionPane.showMessageDialog(null,

                                    (game.playerWins() ?

                                         "Congratulations! You won" : "Sorry. You lost") );

    }

}