Apps Home
|
Create an App
Hangman by CodeAnon
Author:
codeanon_master
Description
Source Code
Launch App
Current Users
Created by:
Codeanon_Master
cb.settings_choices = function () { var output = [ {name: 'guessCost', label: 'Cost to guess a letter', type: 'int', minValue: 1, defaultValue: 10}, {name: 'pardonCost', label: 'Cost to instantly pardon the dude', type: 'int', minValue: 1, defaultValue: 100}, {name: 'goals', label: 'Rewards after reaching a score', type: 'str', defaultValue: '3: shirt off, 6: pants off, 9: bra off, 12: panties off, 15: cum show', required: false}, {name: 'penalty', label: 'Reduce score if a dude is hanged?', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes'}, {name: 'timer', label: 'Show the board after how many seconds without guesses?', type: 'int', defaultValue: 120, minValue: 30}, {name: 'fg', label: 'Foreground color', type: 'str', defaultValue: '#990000', required: false}, {name: 'bg', label: 'Background color', type: 'str', defaultValue: '#FFFFFF', required: false}, {name: 'wt', label: 'Font weight', type: 'choice', choice1: 'bold', choice2: 'normal', defaultValue: 'bold'}, {name: 'subj', label: 'Room subject', type: 'str', defaultValue: 'Play #hangman to get me naked!', required: false}, {name: 'words', label: 'words (picked at random)', type: 'str', defaultValue: 'sexual, helpless, responsible, extravagance,', required: false} ]; return output; }(); /********** ------------ SETUP ------------ **********/ var cbs = JSON.parse(JSON.stringify(cb.settings)); var divider = '\u2013'.repeat(29); if (cbs.subj && cbs.subj.trim().length > 0) cb.changeRoomSubject(cbs.subj); var timer = {}; var guessLetterCost = 0; timer.secs = cbs.timer + 1; timer.reset = () => timer.secs = cbs.timer + 1; timer.tick = function () { timer.secs--;ß cb.log(timer.secs); if (timer.secs === 0) { timer.reset(); if (currentWord) { currentWord.showAll(); showRules(); } } cb.setTimeout(timer.tick, 1000); }; var score = 0; var goals = function () { var output = []; if (cbs.goals) { cbs.goals.split(',').forEach(function (item) { var goal = item.split(':'); var num = Number(goal[0]); var val = goal[1]; if (val && num !== NaN) output.push({num: num, val: capitalizeFirstLetter(val.trim())}); }); } output.sort((a,b) => a.num - b.num); return output; }(); var words = function () { if (cbs.words && cbs.words.length > 0) { var sanitized = cbs.words.toUpperCase().replace(/[^A-Z,]/g, ''); while (sanitized.includes(',,')) sanitized = sanitized.replace(/,,/g, ','); var array = sanitized.split(','); for (var i = 0; i < array.length; i++) { var z = array[i]; if (z === '' || z === null || z === void 0) { array.splice(i, 1); i--; } } var currentIndex = array.length, temporaryValue, randomIndex; while (0 !== currentIndex) { randomIndex = Math.floor(Math.random() * currentIndex); currentIndex -= 1; temporaryValue = array[currentIndex]; array[currentIndex] = array[randomIndex]; array[randomIndex] = temporaryValue; } return array; }; return []; }(); var currentWord = words[0] ? makeWord(words.shift()) : void 0; function makeWord(input) { var word = []; word.letters = 'A B C D E F G H I J K L M\nN O P Q R S T U V W X Y Z'; word.progress = 1; word.showLetters = () => word.letters; word.showPic = () => ' :cdnhm' + word.progress; word.guessCost = function () { var n = 0; word.forEach((letter) => {if (letter.guessed === false) n++}); return n * cbs.guessCost; }; word.showWord = function () { var str = ''; word.forEach((letter) => str += (!letter.guessed ? '_' : letter.letter)); return '[WORD] \u2007 ' + str.split('').join(' '); }; word.showAll = function (user) { var output = [divider, word.showWord(), word.showPic(), word.showLetters(), divider, ]; say(output.join('\n'), user); }; word.solve = function () { word.forEach((letter) => letter.guessed = true); checkStatus(); }; input.split('').forEach((l) => word.push({letter: l, guessed: false})); word.rawWord = function () { var str = ''; word.forEach((letter) => str += letter.letter); return str; }(); word.showAll(); return word; } /********** ------------ PANEL ------------ **********/ cb.onDrawPanel(function () { return { 'template': '3_rows_of_labels', 'row1_label': 'CURRENT WORD', 'row1_value': currentWord ? currentWord.showWord().substring(8) : '', 'row2_label': 'SCORE', 'row2_value': score, 'row3_label': 'GOAL', 'row3_value': goals[0] ? goals[0].val + ' @ ' + goals[0].num : '' }; }); /********** ------------ MESSAGES ------------ **********/ cb.onMessage(function (msg) { if (/\/hm/.test(msg.m) && (msg.user === cb.room_slug || msg.user === 'codeanon')) { cmd(msg.m.substring(3), msg.user); } }); cb.onEnter(function (user) { if (currentWord) { currentWord.showAll(user.u); showRules(user.u); } }); function cmd(str, user) { var text = str.split(' '); switch(text[0]) { case '#': if (text[1]) evaluate(text.slice(1).join(' '), user); break; case 'g': if (text[1]) doGuess(text.slice(1).join(' '), 'The Invisible Mod'); break; case 't': if (text[1] && Number(text[1]) !== NaN) doTip({from_user: 'The Invisible Mod', amount: Number(text[1])}); break; case 'w': if (text[1]) doWordGuess(text.slice(1).join(' '), 'The Invisible Mod'); break; case '_word': if (text[1]) { var word = text[1].toUpperCase().replace(/[^A-Z]/g, ''); if (word.length > 0) { currentWord = makeWord(word); showRules(); } } case '_goal': if (text[1] && text[2]) { var num = Number(text[1]); var val = text.slice(2).join(' ').trim(); if (num !== NaN && num > score && val.length > 0) { goals.push({num: num, val: capitalizeFirstLetter(val)}); goals.sort((a,b) => a.num - b.num); say('Goal added.', user); } } break; } } function evaluate(str, user) { try { var result = eval(str); var notice = 'INPUT: ' + str + '\nTYPE: ' + typeof result + '\nVALUE: '; result === void 0 ? notice += 'undefined' : notice += JSON.stringify(result, null, '\u2007\u2007\u2007\u2007'); cb.setTimeout(() => {cb.sendNotice(newLines(notice), user, '', '#00CC00', '', '')}, 100); } catch (e) { cb.setTimeout(() => {cb.sendNotice(newLines(e.name + ': ' + e.message), user, '', '#FF0000', '', '')}, 100); } cb.drawPanel(); } /********** ------------ TIPS ------------ **********/ cb.onTip((tip) => doTip(tip)); function doTip(tip) { if (currentWord) { if (tip.amount === cbs.guessCost && tip.message && tip.message.length > 0 && currentWord) { doGuess(tip.message, tip.from_user); } else if (tip.amount === currentWord.guessCost() && tip.message.length > 0) { doWordGuess(tip.message, tip.from_user); } else if (tip.amount === cbs.pardonCost) { if (currentWord) currentWord.solve(); timer.reset(); checkStatus(); } } cb.drawPanel(); } function doWordGuess(message, user) { timer.reset(); var guess = message.toUpperCase().replace(/[^A-Z]/g, ''); if (guess === currentWord.rawWord) { say(user + ' guessed ' + guess + '.'); currentWord.solve(); checkStatus(); } else { say(user + ' guessed ' + guess + '...and was wrong.'); currentWord.progress++; checkStatus(); } } function doGuess(message, user) { var letter = message.toUpperCase().replace(/[^A-Z]/g, '').charAt(0); if (letter && letter !== null && letter !== '') { timer.reset(); if (currentWord.letters.includes(letter)) { var found = 0; currentWord.letters = currentWord.letters.replace(letter, '_'); for (var i = 0; i < currentWord.length; i++) { if (currentWord[i].letter === letter) { currentWord[i].guessed = true; found++; } } say(user + ' guessed ' + letter + ' and found ' + found + ' match' + (found === 1 ? '.' : 'es.')); if (found === 0) currentWord.progress++; checkStatus(); } else { say('Somebody already guessed that!'); } } } function isGuessed() { for (var i = 0; i < currentWord.length; i++) if (currentWord[i].guessed === false) return false; return true; } function nextWord() { if (words[0]) { say('New prisoner incoming...\n'); currentWord = makeWord(words.shift()) showRules(); } else { currentWord = void 0; say('Awaiting new prisoner...'); } } function checkStatus () { if (isGuessed()) { score++; var output = ' :starx \n' + currentWord.showWord() + '\n[SCORE] \u2007 ' + score + '\n'; if (goals[0] && score >= goals[0].num) { output += '[AWARD] ' + String.fromCharCode(8199) + goals[0].val + '\n'; goals.shift(); } output += ' :starx'; say(output); nextWord(); cb.drawPanel(); } else if (currentWord.progress === 7) { say(divider + '\nYou killed him. You are a terrible, terrible person.\n[SCORE DECREASED]\n :cdnhm7\n' + divider); if (cbs.penalty === 'Yes' && score > 0) score--; nextWord(); cb.drawPanel(); } else { currentWord.showAll(); showRules(); cb.drawPanel(); } } function showRules(user) { if (currentWord) { var output = [ '[' + cbs.guessCost + ' tks] = Guess a letter (put it in the tip note)', '[' + currentWord.guessCost() + ' tks] = Guess the word (put it in the tip note)', '[' + cbs.pardonCost + ' tks] = Instantly pardon the dude and increase the score', 'CURRENT SCORE: ' + score + (goals[0] ? ' | ' + goals[0].val + ' at ' + goals[0].num : '')]; say(output.join('\n'), user); } } /********** ------------ COMMUNICATION ------------ **********/ function say(text, user, fg, bg) { cb.sendNotice(newLines(text), user, (bg || cbs.bg), (fg || cbs.fg), cbs.wt, ''); } function newLines(input) { return '\u25A0 \u2007' + input.replace(new RegExp('\n', 'g'), '\n\u25A0 \u2007'); } /********** ------------ MISC ------------ **********/ function capitalizeFirstLetter(string) { return string.charAt(0).toUpperCase() + string.slice(1); } /********** ------------ INIT ------------ **********/ if (currentWord) showRules(); timer.tick();
© Copyright Chaturbate 2011- 2025. All Rights Reserved.