Bots Home
|
Create an App
Trixbot Hangman
Author:
acalex2
Description
Source Code
Launch Bot
Current Users
Created by:
Acalex2
// wtf cb.settings_choices = [ {name: 'word', type: 'str', minLength: 1, maxLength: 12}, {name: 'tip_amount', type: 'int', minValue: 1} ]; function setCharAt(str,index,chr) { if(index > str.length-1) return str; return str.substring(0,index) + chr + str.substring(index+1); } var trixBot = { puzzle : "", gameString : "", init : function () { this.puzzle += cb.settings.word; this.puzzle = this.puzzle.toLowerCase(); stringHandler.setup(); cb.chatNotice("Hangman is setup!"); cb.chatNotice("Current Puzzle Has: " +this.puzzle.length+" letters."); cb.chatNotice(this.gameString); } }; var tipped = { onTip : function(tip) { var tipAmt = parseInt(tip['amount']); if(tipAmt == cb.settings.tip_amount){ cb.chatNotice("Letter guessed: " + tip['message']); hangman.guessed(tip); } } } var hangman = { availableLetters : [{label: 'a'}, {label: 'b'}, {label: 'c'},{label: 'd'}, {label: 'e'}, {label: 'f'}, {label: 'g'}, {label: 'h'}, {label: 'i'},{label: 'j'}, {label: 'k'}, {label: 'l'}, {label: 'm'}, {label: 'n'}, {label: 'o'},{label: 'p'}, {label: 'q'}, {label: 'r'}, {label: 's'}, {label: 't'}, {label: 'u'},{label: 'v'}, {label: 'w'}, {label: 'x'}, {label: 'y'}, {label: 'z'} ], guessed : function(tip) { s = tip['message']; if(s.charCodeAt(0) - 97 >= 0 && s.charCodeAt(0) - 97 <= 26){ this.availableLetters.splice(s.charCodeAt(0) - 97,1,{label: '-'}); stringHandler.reveal(s); } } } var stringHandler = { setup : function(){ for(i = 0; i<trixBot.puzzle.length;i++){ trixBot.gameString += "-"; } }, reveal : function(chr){ a = 0; if(trixBot.puzzle.includes(chr)){ while(a < trixBot.puzzle.length){ if(trixBot.puzzle[a] == chr){ cb.chatNotice("Letter found!"); trixBot.gameString = setCharAt(trixBot.gameString,a,chr); } a++; } cb.chatNotice("Update:"); cb.chatNotice(trixBot.gameString); this.check(); } else{ cb.chatNotice("Sorry! Guess was incorrect."); } }, check : function () { if(trixBot.gameString == trixBot.puzzle){ cb.chatNotice("***** Puzzle Has Been Solved!!! *****"); } } } cb.onStart(user => { cb.chatNotice(user['user'] + ' started a game of Hangman!!'); }); cb.tipOptions(function(user) { return {options: hangman['availableLetters'], label:"Hangman Guess: "+cb.settings['tip_amount']+" tokens"}; }); cb.onTip(function (tip) { tipped.onTip(tip); }); trixBot.init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.