001    package core;
002    
003    /**
004     * An enum with a user readable message about what why someone won. Also used to
005     * output the reason to the schema.
006     */
007    public enum GameOver
008    {
009            CHECKMATE, PIECES_LOST, TIME_EXPIRED, NONE;
010    
011            /**
012             * @returns a string representation of the enum (useful for the xml schema)
013             */
014            public String toString()
015            {
016                    switch (this)
017                    {
018                    case CHECKMATE:
019                            return "checkmate";
020                    case PIECES_LOST:
021                            return "piecesLost";
022                    case TIME_EXPIRED:
023                            return "timeExpired";
024                    default:
025                            return "none";
026                    }
027            }
028    
029            /**
030             * @returns a human readable string representation of the enum (useful for
031             *          messages to the user)
032             */
033            public String humanReadableString()
034            {
035                    switch (this)
036                    {
037                    case CHECKMATE:
038                            return "by checkmating the opponent.";
039                    case PIECES_LOST:
040                            return "by losing all of his/her/its pieces.";
041                    case TIME_EXPIRED:
042                            return "by running the opponent out of time.";
043                    default:
044                            throw new RuntimeException(
045                                            "No human readable game over message if the game isn't over.");
046                    }
047            }
048    }