Ideal Corner

Объявление

Мы переехали на http://idealphotoshop.spybb.ru/

Информация о пользователе

Привет, Гость! Войдите или зарегистрируйтесь.


Вы здесь » Ideal Corner » .Скрипты. » Кубики (Дайсы).


Кубики (Дайсы).

Сообщений 1 страница 2 из 2

1

Скрипт позволит "кидать кубики" прямо на форуме.
Полезно для ролевых форумов.

Ставить в HTML в форме ответа

Вариант 1.

Код:
<input type="button" onclick="dice()" value="Кинуть кубики" />
<script type="text/javascript">
function dice()
{
	var FoundErrors = '';
	var diceRes=""
	var CountCube = prompt("Количество кубиков", "3");
	var SideCube = prompt("Сколько граней у кубика?", "6");
	if(CountCube>9){
	alert("Нельзя бросать столько кубиков"); 
	return false;}
	if(SideCube>9){
	alert("Не бывает таких кубиков"); 
	return false;}
	if (!CountCube)
	{return false;}
	if (!SideCube)
	{return false;}
	for(i=0; i<CountCube;i++){
	var dice = (Math.round(Math.random()*SideCube))
	if(dice==0) dice=1;
	diceRes += dice*1936+"-"
	}
	smile('[dice='+diceRes+CountCube+SideCube+']')
}
</script>
<script>
function addDice(str,from,internal){
var pos=0,pos2=0,newpos=0
if((pos=str.indexOf("[dice=",from))==-1) return str;
if((pos2=str.indexOf("]"),pos+6)==-1) return str;
newpos=str.indexOf("]",pos+6)
if(newpos<pos2 && newpos!=-1) str=addDice(str,pos+6,true)
if((pos2=str.indexOf("]",pos+6))==-1) return str;
str=str.substring(0,pos)+makeDice(str.substring(pos+6,pos2))+str.substring(pos2+1,str.length)
if( str.indexOf("[dice=")!=-1 && internal==false) str=addDice(str,0,false)
return str}

function makeDice(dice){
diceMass = dice.split("-")
diceC = dice.substring(dice.length-2, dice.length-1)
diceS = dice.substring(dice.length-1, dice.length)
var diceR=0, diceRu="";
for(i=0;i<diceMass.length-1;i++){diceR+=diceMass[i]/1936;}
for(i=0;i<diceMass.length-1;i++){if(diceMass[i]==diceMass[diceMass.length-2]){diceRu+=diceMass[i]/1936;}else{diceRu+=parseInt(diceMass[i]/1936)+"+";}}
txt="<div class=\"quote-box\"><blockquote><p><b>Количество кубиков</b>: "+diceC+"<br /><b>Граней в кубике</b>: "+diceS+"<br /><br /><b>Результаты броска</b>: ("+diceRu+")="+diceR+"</p></blockquote></div>"
return txt}

if(document.URL.indexOf("viewtopic.php")!=-1){
elm=document.getElementById("pun-main").getElementsByTagName("div")
for(x in elm) if(elm[x].className=="post-content"){
var post=elm[x]
post.innerHTML=addDice(post.innerHTML,0,false)}}
</script>

Вариант 2.

Код:
<input type="button" onclick="dice()" value="Кинуть кубики" />
<script type="text/javascript">
function dice()
{
	var FoundErrors = '';
	var diceRes=""
	var CountCube = prompt("Количество кубиков", "3");
	var SideCube = prompt("Сколько граней у кубика?", "6");
	if(CountCube>9){
	alert("Нельзя бросать столько кубиков"); 
	return false;}
	if(SideCube>9){
	alert("Не бывает таких кубиков"); 
	return false;}
	if (!CountCube)
	{return false;}
	if (!SideCube)
	{return false;}
	for(i=0; i<CountCube;i++){
	var dice = (Math.round(Math.random()*SideCube))
	if(dice==0) dice=1;
	diceRes += dice*1936+"-"
	}
	smile('[dice='+diceRes+CountCube+SideCube+']')
}
</script>
<script>
function addDice(str,from,internal){
var pos=0,pos2=0,newpos=0
if((pos=str.indexOf("[dice=",from))==-1) return str;
if((pos2=str.indexOf("]"),pos+6)==-1) return str;
newpos=str.indexOf("]",pos+6)
if(newpos<pos2 && newpos!=-1) str=addDice(str,pos+6,true)
if((pos2=str.indexOf("]",pos+6))==-1) return str;
str=str.substring(0,pos)+makeDice(str.substring(pos+6,pos2))+str.substring(pos2+1,str.length)
if( str.indexOf("[dice=")!=-1 && internal==false) str=addDice(str,0,false)
return str}

function makeDice(dice){
diceMass = dice.split("-")
diceC = dice.substring(dice.length-2, dice.length-1)
diceS = dice.substring(dice.length-1, dice.length)
var diceR=0, diceRu="";
for(i=0;i<diceMass.length-1;i++){diceR+=diceMass[i]/1936;}
for(i=0;i<diceMass.length-1;i++){if(diceMass[i]==diceMass[diceMass.length-2]){diceRu+=diceMass[i]/1936;}else{diceRu+=parseInt(diceMass[i]/1936)+"+";}}
txt="<div class=\"quote-box\"><blockquote><p><b>Исходный бросок</b>: "+diceC+"d"+diceS+"<br /><br /><b>Результаты броска</b>: ("+diceRu+")="+diceR+"</p></blockquote></div>"
return txt}

if(document.URL.indexOf("viewtopic.php")!=-1){
elm=document.getElementById("pun-main").getElementsByTagName("div")
for(x in elm) if(elm[x].className=="post-content"){
var post=elm[x]
post.innerHTML=addDice(post.innerHTML,0,false)}}
</script>

Описание, скриншоты и поддержка - ... скоро будет))...

Добавлено:

Добавил ограничение в количестве граней и кубиков. 10 максимум

0

2

Сам процесс выглядит так:
http://i012.radikal.ru/0904/6d/0ee3ad20c9e2.bmp
http://s42.radikal.ru/i097/0904/3a/92ee2a6f92c0.bmp
Пользователь вводит сколько надо бросить кубиков и сколько в нем граней.
Далее получает уникальный код, который может произвольно перемещать в сообщении
http://s49.radikal.ru/i124/0904/29/9d6a82b83dc2.bmp
После отправки в сообщении будет такая картина
http://s57.radikal.ru/i157/0904/fa/218d3d3b9d7e.bmp

0


Вы здесь » Ideal Corner » .Скрипты. » Кубики (Дайсы).