Package com.appspot.bambugame.server.data

Examples of com.appspot.bambugame.server.data.HangmanPlurkQuestion


        }
    }
   
    public void analyzeAliveQuestionIDResponses(long pPlurkQuestionID, Objectify pObjectify) throws PlurkException, JSONException
    {
        HangmanPlurkQuestion tPlurkQuestion = pObjectify.get( HangmanPlurkQuestion.class, pPlurkQuestionID );
       
        if (tPlurkQuestion.LAST_RESPONSE_OFFSET == null) tPlurkQuestion.LAST_RESPONSE_OFFSET = 0;
       
        JSONObject tPlurkResponse = PlurkService.getInstance().responseGet( String.valueOf( tPlurkQuestion.PLURK_ID ) );
        JSONArray tResponseArray = tPlurkResponse.getJSONArray( "responses" );
       
        System.out.println("Analyzing plurk ID " + tPlurkQuestion.PLURK_ID + ", plurk received " + tResponseArray.length() + " plurk responses. Full JSON response of the plurk is " + tPlurkResponse);
       
        Set<Character> tGuessedCharacterSet = new HashSet<Character>();
       
        Long tGuesserPlurkID = null;
        boolean tIsWinBecauseOfDirectGuess = false;
       
        Set<String> tGuesserWrongGuessStringSet = new HashSet<String>();
        Set<String> tGuesserLateGuessStringSet = new HashSet<String>();
       
        System.out.println("Plurk last response offset is : " + tPlurkQuestion.LAST_RESPONSE_OFFSET);
       
        for (int i = tPlurkQuestion.LAST_RESPONSE_OFFSET; i < tResponseArray.length(); i++)
        {
            JSONObject tResponseObject = tResponseArray.getJSONObject( i );
            String tResponseAnswer = tResponseObject.getString( "content_raw" ).trim().toLowerCase();
           
            System.out.println("Validating response #" + i + ", answer from @" + tPlurkResponse.getJSONObject( "friends" ).getJSONObject( String.valueOf( tResponseObject.getLong( "user_id" ) ) ).getString( "nick_name" ) + " : " + tResponseAnswer);
           
            if (tResponseAnswer.length() == 1)
            {
                Character tGuessedCharacter = tResponseAnswer.charAt( 0 );
               
                if (Character.isLetterOrDigit( tGuessedCharacter ) && !tPlurkQuestion.hasCharacterBeenGuessed( tGuessedCharacter ))
                {
                    tGuessedCharacterSet.add( tGuessedCharacter );
                    tPlurkQuestion.addGuessedCharacter( tGuessedCharacter );
                   
                    if (tPlurkQuestion.hasQuestionBeenGuessed() && tGuesserPlurkID == null)
                    {
                        tGuesserPlurkID = tResponseObject.getLong( "user_id" );
                    }
                    if (tPlurkQuestion.hasQuestionBeenHanged())
                    {
                        break;
                    }
                }
            }
            else if (tResponseAnswer.startsWith( "!guess " ))
            {
                String tPlurkerGuessString = tResponseAnswer.substring( "!guess".length() );
               
                if (tPlurkQuestion.isGuessStringCorrect(tPlurkerGuessString) && tGuesserPlurkID == null)
                {
                    tGuesserPlurkID = tResponseObject.getLong( "user_id" );
                    tIsWinBecauseOfDirectGuess = true;
                }
                else if (tPlurkQuestion.isGuessStringCorrect(tPlurkerGuessString) && tGuesserPlurkID != null)
                {
                    String tPlurkerNameString = tPlurkResponse.getJSONObject( "friends" ).getJSONObject( String.valueOf( tResponseObject.getLong( "user_id" ) ) ).getString( "nick_name" );
                    tGuesserLateGuessStringSet.add( tPlurkerNameString + "|" + tPlurkerGuessString );
                   
                    System.out.println("Adding [" + tPlurkerNameString + "|" + tPlurkerGuessString + "] to the late map " + tGuesserLateGuessStringSet.toString());
                }
                else
                {
                    String tPlurkerNameString = tPlurkResponse.getJSONObject( "friends" ).getJSONObject( String.valueOf( tResponseObject.getLong( "user_id" ) ) ).getString( "nick_name" );
                    tGuesserWrongGuessStringSet.add( tPlurkerNameString + "|" + tPlurkerGuessString );
                   
                    System.out.println("Adding [" + tPlurkerNameString + "|" + tPlurkerGuessString + "] to the map " + tGuesserWrongGuessStringSet.toString());
                }
            }
        }
       
        if (tGuesserPlurkID != null) // we have a winner here!
        {
            JSONObject tWinnerJSONObject = tPlurkResponse.getJSONObject( "friends" ).getJSONObject( String.valueOf( tGuesserPlurkID ) );
            int tAnswererAnswerCount = incrementAnswererAnswerCount( tGuesserPlurkID, tWinnerJSONObject.getString( "nick_name" ) );
           
            if (tIsWinBecauseOfDirectGuess)
            {
                postCongratulatoryMessage(tPlurkQuestion, tWinnerJSONObject, tIsWinBecauseOfDirectGuess, tAnswererAnswerCount);
            }
            else
            {
                postCharacterGuessesResponse(tPlurkQuestion, tGuessedCharacterSet);
               
                try { Thread.sleep( 100 ); } catch (Exception ex) {}
               
                postCongratulatoryMessage(tPlurkQuestion, tWinnerJSONObject, tIsWinBecauseOfDirectGuess, tAnswererAnswerCount);
            }
           
            try { Thread.sleep( 100 ); } catch (Exception ex) {}
           
            tPlurkQuestion.IS_SOLVED = Boolean.TRUE;
           
            // reset the monitored ID
            pObjectify.put( GlobalGameConfig.withKey( cLastMonitoredPlurkID ).withValue( null ) );
           
            if (tPlurkQuestion.SENTENCE.equalsIgnoreCase( "You have been trolled" ))
            {
                PlurkService.getInstance().responseAdd( String.valueOf (tPlurkQuestion.PLURK_ID), "(troll)", Qualifier.GIVES);
            }
        }
        else if (!tGuessedCharacterSet.isEmpty()) // no winner yet, post new guesses result if someone made a guess
        {
            postCharacterGuessesResponse(tPlurkQuestion, tGuessedCharacterSet);
        }
       
        if (!tGuesserWrongGuessStringSet.isEmpty())
        {
            for (String tWrongGuess : tGuesserWrongGuessStringSet)
            {
                String tPlurkerName = tWrongGuess.substring( 0, tWrongGuess.indexOf( "|" ) );
                String tPlurkerAnswer = tWrongGuess.substring( tWrongGuess.indexOf( "|" ) + 1 ).trim();
               
                PlurkService.getInstance().responseAdd( String.valueOf (tPlurkQuestion.PLURK_ID), "sorry @" + tPlurkerName + ", the answer is not `" + tPlurkerAnswer + "`", Qualifier.SAYS );
            }
        }
       
        if (!tGuesserLateGuessStringSet.isEmpty())
        {
            for (String tLateGuess : tGuesserLateGuessStringSet)
            {
                String tPlurkerName = tLateGuess.substring( 0, tLateGuess.indexOf( "|" ) );
                String tPlurkEmote = "(troll)";
               
                if (tPlurkerName.equalsIgnoreCase( "ruicilita" )) tPlurkEmote = "(cozy)";
               
                PlurkService.getInstance().responseAdd( String.valueOf (tPlurkQuestion.PLURK_ID), "the answer is correct @" + tPlurkerName + ", but you are too late. " + tPlurkEmote, Qualifier.SAYS );
            }
        }
       
        if (tPlurkQuestion.hasQuestionBeenHanged()) // if question has been hanged
        {
            PlurkService.getInstance().responseAdd( String.valueOf (tPlurkQuestion.PLURK_ID), "Whoops, you guys ran out of tries, this question is closed now. (yarr) Remember, there are only 10 incorrect guesses allowed per question.", Qualifier.SAYS );
           
            try { Thread.sleep( 100 ); } catch (Exception ex) {}
           
View Full Code Here


        if (tRandomQuestionID == null) return; // this means there are no questions in the datastore
       
        Objectify tObjectify = ObjectifyService.begin();
        HangmanQuestion tQuestion = tObjectify.get( HangmanQuestion.class, tRandomQuestionID );
       
        HangmanPlurkQuestion tPlurkQuestion = new HangmanPlurkQuestion( 0, tQuestion.SENTENCE, tQuestion.HINT, tQuestion.EXTRAS );
       
        JSONObject tAddResponse = PlurkService.getInstance().plurkAdd( getQuestionSentence( tPlurkQuestion ), Qualifier.ASKS );
        tPlurkQuestion.PLURK_ID = tAddResponse.getLong( "plurk_id" );
        tObjectify.put( tPlurkQuestion );
       
View Full Code Here

TOP

Related Classes of com.appspot.bambugame.server.data.HangmanPlurkQuestion

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.