Bots Home
|
Create an App
s
Author:
lugubal
Description
Source Code
Launch Bot
Current Users
Created by:
Lugubal
//Battleship by slavabo [cbslavabo[at]gmail.com] //Modified with prizes by rowan596 //Modified again as a bot by indshadow // var rls = 'v20130809'; //ReLeaSe version of game var tct = 0; //TipCounT: total tips received var act; //ACTivity (timestamp) var spc = String.fromCharCode(160); //SPaCe: non collapsible character // var bsz = 9; //BoardSiZe: cannot exceed 9 due to regex, brd[], ltr[] and fromLetter() var shp; //SHiPs: array of unhit ship coordinates; shp[0][0] is remaining (unhit) length of ship; shp[0][1+] is coordinates var brd; //BoaRD: status array of all board coordinates var ltr = ["A","B","C","D","E","F","G","H","I"]; //LeTteRs: used for numeric to alphabetic conversions // cb.settings_choices = [ {name:'cst', type:'int', minValue:0, maxValue:999, default:10, label: 'Missile Cost (0-999)'}, {name: 'hashtags', type: 'str', label: 'Hashtags', defaultValue:'#sexy #strip #pussy #cumshow #dildo #boobs #wet #sex'}, {name: 'prize_1', type: 'str', label: '1st sink prize'}, {name: 'prize_2', type: 'str', label: '2nd sink prize'}, {name: 'prize_3', type: 'str', label: '3rd sink prize'}, {name: 'prize_4', type: 'str', label: '4th sink prize'}, {name: 'grand_prize', type: 'str', label: 'Grand prize (all boats sunken)', defaultValue:'cum show'}, ]; cb.onEnter(function(user) { if (user['has_tokens']&&shp.length) cb.chatNotice('*** A Raiders of the Battleship game is in progress. tip '+cb.settings.cst+' tokens to fire a missile. Type /prizes to see the prizes and /board to see the current board.',user['user'],'','','bold'); }); cb.tipOptions(function(user) { var opt = []; for (var to1=1;to1<=bsz;to1++) for (var to2=1;to2<=bsz;to2++) if (brd[to1-1][to2-1]=='_') opt.push({label:ltr[to1-1]+to2}); return {options:opt, label:'*** SELECT YOUR COORDINATES FROM BELOW ***'}; }); cb.onTip(function (tip) { if (tip['amount']>=cb.settings.cst&&tip['message'].match(/^[A-I]{1}[1-9]{1}$/gi)) { //regex a1-i9 ret = takeInput(tip['message']); cb.chatNotice('*** '+ret.message,'','','','bold'); showBoard(); if (ret.prize!=null) { cb.sendNotice(tip['from_user']+' '+ret.prize, '', '#99FF99', '', 'bold'); } } tct += tip['amount']; cb.drawPanel(); }); cb.onDrawPanel(function(user) { return { 'template': '3_rows_of_labels', 'row1_label': 'Total Tips:', 'row1_value': tct, 'row2_label': 'Ship Sizes:', 'row2_value': '5, 4, 3, 3, 2', 'row3_label': 'Missile Cost:', 'row3_value': (cb.settings.cst==1)?cb.settings.cst+' token':cb.settings.cst+' tokens' }; }); cb.onMessage(function (msg) { if (/(?:camshacks|danacamsessions|girls4party|nude4strip).*c[o0]m/ig.test(msg['m'])) msg['X-Spam'] = true; //block spam else if (msg['m']=='/board') { msg['X-Spam'] = true; showBoard(msg['user']); } else if (msg['m']=='/newgame'&&msg['user']==cb.room_slug&&!shp.length) { msg['X-Spam'] = true; cb.chatNotice('*** Broadcaster has begun a new round of Battleship!','','','','bold'); initGame(); } else if (msg['m']=='/prizes') { msg['X-Spam'] = true; showPrizes(msg['user']); } else if (msg['m']=='/help'||msg['m']=='/rules') { msg['X-Spam'] = true; cb.chatNotice('*** Legend: _ indicates an unhit location, X is a hit, 0 is a miss | Type /prizes to see what you can win.',msg['user']); } else if (msg['m']=='/about') { msg['X-Spam'] = true; cb.chatNotice('*** BATTLESHIP '+rls+' by slavabo (botted by indshadow).','','','bold'); } return msg; }); // function createShip(ssz) { if (ssz>bsz-1) ssz = bsz-1; reroll: do { var tmp = [ssz]; do { var p1b=p1e=Math.floor((Math.random()*bsz)); var p2b=p2e=Math.floor((Math.random()*bsz)); } while (brd[p1b][p2b]=='X'); tmp.push(ltr[p1b]+(p2b+1)); switch (Math.floor((Math.random()*2))) { case 0: //vertical for (var aaa=0;aaa<ssz-1;aaa++) { if ((p1b==0)||((Math.floor((Math.random()*2))&&p1e+1<bsz)&&(brd[p1e+1][p2e]!='X'))) { if (brd[p1e+1][p2b]=='X') continue reroll; p1e++; tmp.push(ltr[p1e]+(p2e+1)); } else { if (brd[p1b-1][p2b]=='X') continue reroll; p1b--; tmp.push(ltr[p1b]+(p2b+1)); } brd[p1b][p2b]='X'; brd[p1e][p2e]='X'; } break reroll; case 1: //horizontal for (var aaa=0;aaa<ssz-1;aaa++) { if ((p2b==0)||((Math.floor((Math.random()*2))&&p2e+1<bsz)&&(brd[p2e+1][p2e]!='X'))) { if (brd[p1b][p2e+1]=='X') continue reroll; p2e++; tmp.push(ltr[p1e]+(p2e+1)); } else { if (brd[p1b][p2b-1]=='X') continue reroll p2b--; tmp.push(ltr[p1b]+(p2b+1)); } brd[p1b][p2b]='X'; brd[p1e][p2e]='X'; } break reroll; } } while (!0); shp.push(tmp); } function showBoard(user) { var sbm = spc+spc; for (var aaa=0;aaa<bsz;aaa++) { for (var bbb=0;bbb<bsz;bbb++) { sbm += brd[aaa][bbb]+spc+spc+spc; } sbm += '| '+ltr[aaa]+'\n'+spc+spc; } for (aaa=1;aaa<=bsz;aaa++) sbm += aaa+spc+spc+spc; sbm += '('+shp.length+' ship'; if (shp.length>1) sbm+= "s"; sbm += ' remaining)\n*** Legend: X = hit, o = miss | Type /help for more info'; if (user) cb.chatNotice(sbm,user); else cb.chatNotice(sbm); } function showPrizes(username) { var notices = '**** Possible Prizes ****\n'; notices += '1st sink - ' + cb.settings.prize_1 + '\n'; notices += '2nd sink - ' + cb.settings.prize_2 + '\n'; notices += '3rd sink - ' + cb.settings.prize_3 + '\n'; notices += '4th sink - ' + cb.settings.prize_4 + '\n'; notices += 'Win game (all 5 sunken) - ' + cb.settings.grand_prize; cb.sendNotice(notices, username, '#D1F0FF', '', 'bold'); } function takeInput(loc) { loc=loc.toUpperCase(); var prizemsg = null; act = new Date().getTime(); if (brd[fromLetter(loc.charAt(0))][loc.charAt(1)-1]!="_") return loc+" has already been guessed. Tip forfeited."; else if (shp.join().indexOf(loc)==-1) { //no ship at location tim = 'Sorry, '+loc+' is a miss. Better luck next time!'; brd[fromLetter(loc.charAt(0))][loc.charAt(1)-1]='o'; } else { baseloop: for (var aaa=0;aaa<shp.length;aaa++) { for (var bbb=1;bbb<shp[aaa].length;bbb++) { if (shp[aaa][bbb]===loc) { shp[aaa][0]--; if (!shp[aaa][0]) { //ship sunk var ssz = shp[aaa].length-1; shp.splice(aaa,1); if (!shp.length) { //no more ships cb.changeRoomSubject("Raiders of the Battleship - Game Over. Thanks For Tipping!"+ cb.settings.hashtags); tim = loc+" is a hit and sink! There are no remaining ships on the board."; prizemsg = 'won the grand prize! '+cb.settings.grand_prize+'!'; cb.chatNotice('*** Type /newgame to begin a new game of Battleship.',cb.room_slug,'','','bold'); } else { if (shp.length == 4) { prize = cb.settings.prize_1; } else if (shp.length == 3) { prize = cb.settings.prize_2; } else if (shp.length == 2) { prize = cb.settings.prize_3; } else if (shp.length == 1) { prize = cb.settings.prize_4; } prizemsg = 'won a prize! ' + prize; tim = loc+" is a hit and has sunk a 1x"+ssz+" sized "+shipName(ssz)+"!"; } } else tim = loc+" is a hit! Keep firing, the ship is still afloat."; break baseloop; } } } brd[fromLetter(loc.charAt(0))][loc.charAt(1)-1]='X'; } return { message: tim, prize: prizemsg } } function fromLetter(ltr) { switch (ltr) { case "A": return 0; case "B": return 1; case "C": return 2; case "D": return 3; case "E": return 4; case "F": return 5; case "G": return 6; case "H": return 7; case "I": return 8; } } function shipName(ssz) { switch (ssz) { case 2: return 'Destroyer'; case 3: return 'Cruiser'; case 4: return 'Battleship'; case 5: return 'Carrier'; default: return 'Unknown Ship'; } } function initGame() { cb.changeRoomSubject("Raiders of the Battleship - tip "+cb.settings.cst+" tokens to fire a missile. " + cb.settings.hashtags); shp = []; brd = [[],[],[],[],[],[],[],[],[]]; //Populate ship coordinates; largest to smallest createShip(5); createShip(4); createShip(3); createShip(3); createShip(2); //Zero out status board; must occur after createShip() for (var aaa=0;aaa<bsz;aaa++) for (var bbb=0;bbb<bsz;bbb++) { brd[aaa][bbb] = "_"; //"fill" character } showBoard(); act = new Date().getTime(); counter(); } function counter() { if (!shp.length) return false; if (new Date().getTime()-act>=60000) { cb.chatNotice('Try your chance at sinking a ship- tip *'+cb.settings.cst+'tkn* to fire a missile! Type /prizes to see the prizes and /board to see the board','','','','bold'); if (!(Math.floor((new Date().getTime()-act)/1000)%300)) showBoard(); cb.setTimeout(counter,60000); } else cb.setTimeout(counter,60000-(new Date().getTime()-act)); } // initGame();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.