Valutazione 4.87/ 5 (100.00%) 5838 voti

Condividi:        

[javascript]Accoppiamenti di stringhe casuali

Problemi di HTML? Di PHP, ASP, .NET, JSP, Perl, SQL, JavaScript, Visual Basic..?
Vuoi realizzare programmi in C, C++, Java, Ruby o Smalltalk, e non sai da che parte cominciare?
Entra qui e troverai le risposte!

Moderatori: Triumph Of Steel, archimede

[javascript]Accoppiamenti di stringhe casuali

Postdi chosenhack » 19/12/14 01:44

Ciao a tutti e complimenti per il forum vi seguo sempre e finalmente mi sono inscritto per chiedervi un aiuto...

premetto che sono un Genio nell'uso di excell quindi "perdonatemi" se vi sembro un po ritardato.. arriviamo al dunque:

Avrei bisogno di creare una sorta di funzione che mi permetta di generare accoppiamenti casuali tra due gruppi:
VADO NELLO SPECIFICO:

Codice: Seleziona tutto
LISTA PRIMARI:

1)Pounding: Inflicts an additional 8.5% damage to any type of monsters.   Decrease damage by 2.2% from enraged monsters.
2)Bitter: Critical attacks against any type of monsters do +1.52 times damage when attacking from the rear. Cannot stack with other Destroyer Rage crystals.   Regenerates 28 MP when attacked by a player.
3)Forceful: Critical attacks will increase your Power by 21 for 10 seconds when attacking opponents from the rear. Cannot stack with other Forceful crystals.   Resist critical hits 2.5% more when below 50% HP
4)Savage: Critical attacks do an additional +1.32 times damage when attacking from the rear. Cannot stack with other Savage crystals.   Increase maximum HP by 1359.
5)Slaying: Chance to inflict an additional +1.74 critical damage to monsters when below 50% HP. Cannot stack with other crystals with the same effect.   Decrease damage by 2.5% when below 50% HP
6)Furious: Chance to inflict an additional 10.5% damage to enemies when below 50% HP.   Provides HP regeneration of 91 per 5 seconds.
7)Focused: Your attacks do an additional +1.88 times critical damage against enraged monsters. Cannot stack with other Focused crystals.   
8)Virulent: Inflict critical hit on a knocked down target, they'll receive 1373 damage every second up to 5 seconds. Cannot stack with other Virulent crystals.   
9)Brutal: Inflicts 10.2% more damage on a knocked-down opponent.   
10)Cruel: Increases your crit damage by +0.48 for 7 seconds against knocked-down opponents. Cannot stack with other Cruel crystals.   
11)Threatening: Increases monster aggro by 16%.   
12)Carving: Increases crit rate by 3.3%. Cannot stack with other Carving crystals.   
13)Salivating: Immediately regenerates 89 MP when attacking a player. Cannot stack with other Salivating crystals.   
14)Brilliant: Provides MP regeneration of 43 per 5sec.   
15)Infused: Regenerates up to 285 MP total when knocked down. Cannot stack with other Infused crystals.   
16)Swift: Increases movement speed by 18 while in combat. Cannot stack with other Swift crystals.   
17)Cunning: Increases maximum MP by 278.   
18)Glistening: Critical hits recovers of 85 MP every second up to 3 seconds when attacking from the rear. Cannot stack with other Glistening crystals.


Codice: Seleziona tutto
LISTA SECONDARI:

1)Decrease damage by 2.2% from enraged monsters.
2)Regenerates 28 MP when attacked by a player.
3)Resist critical hits 2.5% more when below 50% HP
4)Increase maximum HP by 1359.
5)Decrease damage by 2.5% when below 50% HP
6)Provides HP regeneration of 91 per 5 seconds.


ecco io dovrei "generare" casualmente accoppiamenti tra il 1° e il 2° gruppo che per esempio dia come risultato:

-Threatening: Increases monster aggro by 16%.-Decrease damage by 2.5% when below 50% HP

il risultato sarebbe un generatore di bonus che mi servirebbe da utilizzare in un MMORPG ;)

*la cilieggina sulla torta sarebbe piu se sia possibile tipo in java da poter usare anche direttamente dal web.. ma qualsiasi sorta di aiuto che potete darmi va piu che bene....

GRAZIE in anticipo :D
Chosenhack
Gamer & Blogger per Looking4Gaming.it
Avatar utente
chosenhack
Newbie
 
Post: 4
Iscritto il: 19/12/14 01:29

Sponsor
 

Postdi Anthony47 » 19/12/14 15:00

Non sarebbe difficile farlo con macro excel, o anche solo con formule.
Credo pero' che ci siano linguaggi piu' idonei per l' utilizzo su pagine web; sposto quindi da Applicativi Office a Programmazione, dove troverai piu' facilmente una risposta.

Ciao
Anthony
Win7 + Office 2010 Ita; Win 7 + Office 2013 Ita
Xp + Office 2003 Ita
E voi cosa usate? (per istruzioni vedere viewtopic.php?f=26&t=97449)
Avatar utente
Anthony47
Moderatore
 
Post: 13899
Iscritto il: 21/03/06 16:03
Località: Ivrea

Postdi Dylan666 » 19/12/14 19:22

mi sa che hai scritto Java ma intendevi javascript
La cosa è facilemente cercando su google "display random text javascript" oppure "display random text php" se il tuo sito web è in quel linguaggio.
Solitamente gli esempi risportati servono a mostrare una "massima del giorno" o cose simili ma facilmente si applicano al tuo scopo semplicemente mettendo due volte lo stesso script, un per l'elemento uno e primario per l'elemento secondario.
A dire il vero sono talmente pochhi gli elementi che le combinazioni possibili sono solo (18x6=) 108 e si potrebbero anche prevedere tutte (anche se così la manutenzione dello script diventa esponenzialmente più lunga se aggiungerai altri elementi)

Esempio:
http://www.webdevelopersnotes.com/tips/ ... ipt_1.php3

Codice: Seleziona tutto
<script language="JavaScript">
<!--
var r_text = new Array ();
r_text[0] = "Pounding: Inflicts an additional 8.5% damage to any type of monsters.   Decrease damage by 2.2% from enraged monsters.";
r_text[1] = "Bitter: Critical attacks against any type of monsters do +1.52 times damage when attacking from the rear. Cannot stack with other Destroyer Rage crystals. Regenerates 28 MP when attacked by a player.";
r_text[2] = "Forceful: Critical attacks will increase your Power by 21 for 10 seconds when attacking opponents from the rear. Cannot stack with other Forceful crystals.   Resist critical hits 2.5% more when below 50% HP.";
r_text[3] = "Savage: Critical attacks do an additional +1.32 times damage when attacking from the rear. Cannot stack with other Savage crystals.   Increase maximum HP by 1359.";
r_text[4] = "Slaying: Chance to inflict an additional +1.74 critical damage to monsters when below 50% HP. Cannot stack with other crystals with the same effect.   Decrease damage by 2.5% when below 50% HP.";
r_text[5] = "Furious: Chance to inflict an additional 10.5% damage to enemies when below 50% HP.   Provides HP regeneration of 91 per 5 seconds.";
r_text[6] = "Focused: Your attacks do an additional +1.88 times critical damage against enraged monsters. Cannot stack with other Focused crystals.";
r_text[7] = "Virulent: Inflict critical hit on a knocked down target, they'll receive 1373 damage every second up to 5 seconds. Cannot stack with other Virulent crystals.";
r_text[8] = "Brutal: Inflicts 10.2% more damage on a knocked-down opponent.";
r_text[9] = "Cruel: Increases your crit damage by +0.48 for 7 seconds against knocked-down opponents. Cannot stack with other Cruel crystals."; 
r_text[10] = "Threatening: Increases monster aggro by 16%.";
r_text[11] = "Carving: Increases crit rate by 3.3%. Cannot stack with other Carving crystals.";
r_text[12] = "Salivating: Immediately regenerates 89 MP when attacking a player. Cannot stack with other Salivating crystals."; 
r_text[13] = "Brilliant: Provides MP regeneration of 43 per 5sec.";
r_text[14] = "Infused: Regenerates up to 285 MP total when knocked down. Cannot stack with other Infused crystals.";   
r_text[15] = "Swift: Increases movement speed by 18 while in combat. Cannot stack with other Swift crystals.";
r_text[16] = "Cunning: Increases maximum MP by 278.";
r_text[17] = "Glistening: Critical hits recovers of 85 MP every second up to 3 seconds when attacking from the rear. Cannot stack with other Glistening crystals.";
var i = Math.floor(7*Math.random())

var r_text2 = new Array ();
r_text2[0] = "Decrease damage by 2.2% from enraged monsters.";
r_text2[1] = "Regenerates 28 MP when attacked by a player.";
r_text2[2] = "Resist critical hits 2.5% more when below 50% HP";
r_text2[3] = "Increase maximum HP by 1359.";
r_text2[4] = "Decrease damage by 2.5% when below 50% HP";
r_text2[5] = "Provides HP regeneration of 91 per 5 seconds.";
var i2 = Math.floor(7*Math.random())

document.write('<font style="color: #f00; font-weight: bold;">' + r_text[i] + '</font> <font style="color: #00f; font-weight: bold;">' + r_text[i2] + '</font>');

//-->
</script>
Avatar utente
Dylan666
Moderatore
 
Post: 38040
Iscritto il: 18/11/03 16:46

Postdi chosenhack » 19/12/14 20:50

grazie dylan666 per la velocità.. allora ho fatto una prova copiando il tuo codice e testarlo... l'idea è quella ma ho notato che accoppia anche le voci dello stesso gruppo... mi escono anche accoppiamenti uguali... a me serve che prende casualmente uno del PRIMO gruppo e che lo unisce con uno del SECONDO gruppo.
penso sia un errore del codice perche come dici tu giustamente le coppie possibili sono "108"
Chosenhack
Gamer & Blogger per Looking4Gaming.it
Avatar utente
chosenhack
Newbie
 
Post: 4
Iscritto il: 19/12/14 01:29

Postdi chosenhack » 19/12/14 21:09

ho sistemato un pò il codice da lato delle scritte dei bonus forse qualche copia incolla uscito male l'ho riscritto ma non so perche non fa ancora quello che deve fare

Codice: Seleziona tutto
<script language="JavaScript">
<!--
var r_text = new Array ();
r_text[0] = "Inflicts an additional 8.5% damage to any type of monsters.";
r_text[1] = "Critical attacks against any type of monsters do +1.52 times damage when attacking from the rear.";
r_text[2] = "Critical attacks will increase your Power by 21 for 10 seconds when attacking opponents from the rear.";
r_text[3] = "Critical attacks do an additional +1.32 times damage when attacking from the rear.";
r_text[4] = "Chance to inflict an additional +1.74 critical damage to monsters when below 50% HP.";
r_text[5] = "Chance to inflict an additional 10.5% damage to enemies when below 50% HP.";
r_text[6] = "Your attacks do an additional +1.88 times critical damage against enraged monsters.";
r_text[7] = "Inflict critical hit on a knocked down target, they'll receive 1373 damage every second up to 5 seconds.";
r_text[8] = "Inflicts 10.2% more damage on a knocked-down opponent.";
r_text[9] = "Increases your crit damage by +0.48 for 7 seconds against knocked-down opponents."; 
r_text[10] = "Increases monster aggro by 16%.";
r_text[11] = "Increases crit rate by 3.3%.";
r_text[12] = "Immediately regenerates 89 MP when attacking a player."; 
r_text[13] = "Provides MP regeneration of 43 per 5sec.";
r_text[14] = "Regenerates up to 285 MP total when knocked down.";   
r_text[15] = "Increases movement speed by 18 while in combat.";
r_text[16] = "Increases maximum MP by 278.";
r_text[17] = "Critical hits recovers of 85 MP every second up to 3 seconds when attacking from the rear.";
var i = Math.floor(7*Math.random())

var r_text2 = new Array ();
r_text2[0] = "Decrease damage by 2.2% from enraged monsters.";
r_text2[1] = "Regenerates 28 MP when attacked by a player.";
r_text2[2] = "Resist critical hits 2.5% more when below 50% HP";
r_text2[3] = "Increase maximum HP by 1359.";
r_text2[4] = "Decrease damage by 2.5% when below 50% HP";
r_text2[5] = "Provides HP regeneration of 91 per 5 seconds.";
var i2 = Math.floor(7*Math.random())

document.write('<font style="color: #f00; font-weight: bold;">' + r_text[i] + '</font> <font style="color: #00f; font-weight: bold;">' + r_text[i2] + '</font>');

//-->
</script>
Chosenhack
Gamer & Blogger per Looking4Gaming.it
Avatar utente
chosenhack
Newbie
 
Post: 4
Iscritto il: 19/12/14 01:29

Postdi Dylan666 » 19/12/14 21:58

Prova ora

Codice: Seleziona tutto
    <script language="JavaScript">
    <!--
    var gruppo_primario = new Array ();
    gruppo_primario[0] = "Inflicts an additional 8.5% damage to any type of monsters.";
    gruppo_primario[1] = "Critical attacks against any type of monsters do +1.52 times damage when attacking from the rear.";
    gruppo_primario[2] = "Critical attacks will increase your Power by 21 for 10 seconds when attacking opponents from the rear.";
    gruppo_primario[3] = "Critical attacks do an additional +1.32 times damage when attacking from the rear.";
    gruppo_primario[4] = "Chance to inflict an additional +1.74 critical damage to monsters when below 50% HP.";
    gruppo_primario[5] = "Chance to inflict an additional 10.5% damage to enemies when below 50% HP.";
    gruppo_primario[6] = "Your attacks do an additional +1.88 times critical damage against enraged monsters.";
    gruppo_primario[7] = "Inflict critical hit on a knocked down target, they'll receive 1373 damage every second up to 5 seconds.";
    gruppo_primario[8] = "Inflicts 10.2% more damage on a knocked-down opponent.";
    gruppo_primario[9] = "Increases your crit damage by +0.48 for 7 seconds against knocked-down opponents.";
    gruppo_primario[10] = "Increases monster aggro by 16%.";
    gruppo_primario[11] = "Increases crit rate by 3.3%.";
    gruppo_primario[12] = "Immediately regenerates 89 MP when attacking a player.";
    gruppo_primario[13] = "Provides MP regeneration of 43 per 5sec.";
    gruppo_primario[14] = "Regenerates up to 285 MP total when knocked down.";   
    gruppo_primario[15] = "Increases movement speed by 18 while in combat.";
    gruppo_primario[16] = "Increases maximum MP by 278.";
    gruppo_primario[17] = "Critical hits recovers of 85 MP every second up to 3 seconds when attacking from the rear.";
    var Caso1 = Math.floor(7*Math.random())

    var gruppo_secondario = new Array ();
    gruppo_secondario[0] = "Decrease damage by 2.2% from enraged monsters.";
    gruppo_secondario[1] = "Regenerates 28 MP when attacked by a player.";
    gruppo_secondario[2] = "Resist critical hits 2.5% more when below 50% HP";
    gruppo_secondario[3] = "Increase maximum HP by 1359.";
    gruppo_secondario[4] = "Decrease damage by 2.5% when below 50% HP";
    gruppo_secondario[5] = "Provides HP regeneration of 91 per 5 seconds.";
    var Caso2 = Math.floor(7*Math.random())

    document.write('<font style="color: #f00; font-weight: bold;">' + gruppo_primario[Caso1] + '</font> <font style="color: #00f; font-weight: bold;">' + gruppo_secondario[Caso2] + '</font>');

    //-->
    </script>
Avatar utente
Dylan666
Moderatore
 
Post: 38040
Iscritto il: 18/11/03 16:46

Postdi Dylan666 » 19/12/14 22:15

Ops avevo dimenticato una cosa

Codice: Seleziona tutto
    <script language="JavaScript">
    <!--
    var gruppo_primario = new Array ();
    gruppo_primario[0] = "Inflicts an additional 8.5% damage to any type of monsters.";
    gruppo_primario[1] = "Critical attacks against any type of monsters do +1.52 times damage when attacking from the rear.";
    gruppo_primario[2] = "Critical attacks will increase your Power by 21 for 10 seconds when attacking opponents from the rear.";
    gruppo_primario[3] = "Critical attacks do an additional +1.32 times damage when attacking from the rear.";
    gruppo_primario[4] = "Chance to inflict an additional +1.74 critical damage to monsters when below 50% HP.";
    gruppo_primario[5] = "Chance to inflict an additional 10.5% damage to enemies when below 50% HP.";
    gruppo_primario[6] = "Your attacks do an additional +1.88 times critical damage against enraged monsters.";
    gruppo_primario[7] = "Inflict critical hit on a knocked down target, they'll receive 1373 damage every second up to 5 seconds.";
    gruppo_primario[8] = "Inflicts 10.2% more damage on a knocked-down opponent.";
    gruppo_primario[9] = "Increases your crit damage by +0.48 for 7 seconds against knocked-down opponents.";
    gruppo_primario[10] = "Increases monster aggro by 16%.";
    gruppo_primario[11] = "Increases crit rate by 3.3%.";
    gruppo_primario[12] = "Immediately regenerates 89 MP when attacking a player.";
    gruppo_primario[13] = "Provides MP regeneration of 43 per 5sec.";
    gruppo_primario[14] = "Regenerates up to 285 MP total when knocked down.";   
    gruppo_primario[15] = "Increases movement speed by 18 while in combat.";
    gruppo_primario[16] = "Increases maximum MP by 278.";
    gruppo_primario[17] = "Critical hits recovers of 85 MP every second up to 3 seconds when attacking from the rear.";
    var Caso1 = Math.floor(18*Math.random())

    var gruppo_secondario = new Array ();
    gruppo_secondario[0] = "Decrease damage by 2.2% from enraged monsters.";
    gruppo_secondario[1] = "Regenerates 28 MP when attacked by a player.";
    gruppo_secondario[2] = "Resist critical hits 2.5% more when below 50% HP";
    gruppo_secondario[3] = "Increase maximum HP by 1359.";
    gruppo_secondario[4] = "Decrease damage by 2.5% when below 50% HP";
    gruppo_secondario[5] = "Provides HP regeneration of 91 per 5 seconds.";
    var Caso2 = Math.floor(6*Math.random())

    document.write('<font style="color: #f00; font-weight: bold;">' + gruppo_primario[Caso1] + '</font> <font style="color: #00f; font-weight: bold;">' + gruppo_secondario[Caso2] + '</font>');

    //-->
    </script>
Avatar utente
Dylan666
Moderatore
 
Post: 38040
Iscritto il: 18/11/03 16:46

Postdi chosenhack » 20/12/14 00:51

FUNZIONAAAAAAAA :) :) :)

Mitico!!! mitico.... mi hai reso troppo felice... troppo!!!

l'ultima info anche se potrei cercarla solo ma vorrei sentire un tuo parere...
cosa mi consigli per creare una parte "grafica"? cioè un pulsante e sbizzarrirmi per personalizarla
Chosenhack
Gamer & Blogger per Looking4Gaming.it
Avatar utente
chosenhack
Newbie
 
Post: 4
Iscritto il: 19/12/14 01:29

Postdi Dylan666 » 20/12/14 11:17

Ti serve solo un bottone (o un link) di refresh
http://www.web-source.net/javascript_re ... VJVMfBBAIE
Avatar utente
Dylan666
Moderatore
 
Post: 38040
Iscritto il: 18/11/03 16:46


Torna a Programmazione


Topic correlati a "[javascript]Accoppiamenti di stringhe casuali":

Javascript
Autore: Stecco
Forum: Discussioni
Risposte: 2
Tabella in JavaScript
Autore: Ciozun
Forum: Programmazione
Risposte: 0

Chi c’è in linea

Visitano il forum: Nessuno e 6 ospiti