Apps Home
|
Create an App
Word Master
Author:
xunil79
Description
Source Code
Launch App
Current Users
Created by:
Xunil79
function format_username(e){return e===null?"--":e.substring(0,12)}function getSecret(){return cb.settings.secret_word.trim().toLowerCase()}function getBestGuess(){return best_guess_word===null?"--":best_guess_word}function getGameInfoForPanel(){var e="Guess the secret "+getSecret().length+" letter word for only "+cb.settings.cost_per_guess+" Tokens per try";if(cb.settings.reward&&cb.settings.reward.trim().length>0){e+=", in order to win "+cb.settings.reward}return e}function formatGuess(e){return"| "+e.word+" | "+e.letters+" | "+e.positions+" |"}function getWelcomeMessage(){var e=MSG_GAME_HEADER;e+=getGameInfoForPanel()+"\n";e+="Type /gameinfo for getting instructions.";return e}function getWinMessage(e){var t=MSG_GAME_HEADER;t+="We have a new winner!\n";t+=e.from+" has guessed the correct word: "+e.word;if(cb.settings.reward&&cb.settings.reward.trim().length>0){t+=" and wins "+cb.settings.reward}return t}function getGuessMessage(e){var t=MSG_GAME_HEADER;t+=e.from+" has guessed the word "+e.word+". "+e.letters+" correct letters, "+e.positions+" in the right position.";return t}function calculateCorrectLetters(e){var t=getSecret().split("");for(var n=0;n<t.length;n++){if(t[n]===e.word.charAt(n)){e.positions+=1}if(e.word.indexOf(t[n])!==-1){e.letters+=1}}return e}function checkGuess(e){chat_message=null;e=calculateCorrectLetters(e);chat_message=getGuessMessage(e);temp_score=e.positions*100+e.letters;if(temp_score>best_guess_score){best_guess_score=temp_score;best_guess_user=e.from;best_guess_word=e.word}max_score=getSecret().length*100+getSecret().length;if(max_score===temp_score){game_state_won=true;chat_message=getWinMessage(e)}if(chat_message){cb.chatNotice(chat_message)}cb.log(formatGuess(e))}function validateGuess(e){secret_length=getSecret().length;if(e.word.length===getSecret().length){return true}else{cb.chatNotice("Dear "+e.from+", "+e.word+" is not a "+getSecret().length+" letter word. But thank you for your tip. "+cb.room_slug+" appreciate your tip!");return false}}function handleGuess(e){cb.log("**** Entering handleGuess ...");guess={word:e["message"].split(" ")[0].toLowerCase(),from:e["from_user"],letters:0,positions:0};if(validateGuess(guess)){guess_count+=1;checkGuess(guess)}cb.log("**** Leaving handleGuess ...")}function drawGamePanel(){return{template:"3_rows_12_22_31",row1_label:LABEL_GUESS_TIPS,row1_value:guess_count+" / "+total_tipped,row2_label:"Best guess:",row2_value:getBestGuess().toUpperCase()+" by "+format_username(best_guess_user),row3_value:getGameInfoForPanel()}}function drawWinPanel(){return{template:"3_rows_12_21_31",row1_label:LABEL_GUESS_TIPS,row1_value:guess_count+" / "+total_tipped,row2_value:"Game finished!",row3_value:format_username(best_guess_user)+" guessed the right word: "+getBestGuess().toUpperCase()}}function advertise(){cb.chatNotice(getWelcomeMessage());cb.setTimeout(advertise,cb.settings.advertise_in_chat*6e4)}function init(){cb.changeRoomSubject(cb.settings.room_description);cb.setTimeout(advertise,cb.settings.advertise_in_chat*6e4)}const MSG_GAME_HEADER="--== Word Master ==--\n";const LABEL_GUESS_TIPS="Guesses / Tips";var best_guess_user=null;var best_guess_word=null;var best_guess_score=0;var guess_count=0;var total_tipped=0;var game_state_won=false;cb.settings_choices=[{name:"cost_per_guess",type:"int",minValue:1,defaultValue:25,label:"Cost for guessing a word:"},{name:"reward",type:"str",minLength:1,maxLength:255,required:false,label:"Reward for guessing the right word:"},{name:"secret_word",type:"str",minLength:5,maxLength:15,label:"The secret word:"},{name:"room_description",type:"str",minLength:1,maxLength:255,label:"Room Description:"},{name:"advertise_in_chat",type:"int",minValue:1,maxValue:999,defaultValue:5,label:"How often to advertise the game: (minuntes)"}];cb.onTip(function(e){total_tipped+=e["amount"];if(e["amount"]===cb.settings.cost_per_guess&&game_state_won===false){handleGuess(e)}cb.drawPanel()});cb.onMessage(function(e){if(e["m"]=="/gameinfo"){var e=MSG_GAME_HEADER;e+="You can read "+cb.room_slug+"'s mind? Send a tip of "+cb.settings.cost_per_guess+" tokens with your guess in the tip notes.\n";e+="I will tell you the number of letters that are in both your guessed word and "+cb.room_slug+"'s secret word. To make it a little bit easier, ";e+="I will even tell you, how many letters are in the correct position.";if(cb.settings.reward&&cb.settings.reward.trim().length>0){e+="\nIf you are a good mindreader, you are able to win "+cb.settings.reward}cb.chatNotice(e,e["user"])}});cb.onDrawPanel(function(e){return game_state_won===true?drawWinPanel():drawGamePanel()});init()
© Copyright Chaturbate 2011- 2026. All Rights Reserved.