PDA

View Full Version : Aiuto! Creare un generatore casuale [HTML]


Spiderbite
17-05-2013, 09:15
Salve a tutti! Intanto spero di aver scritto nella sezione giusta.
Come da titolo vorrei realizzare un generatore casuale, nello specifico un generatore di kit per Battlefield 3, nelle mie intenzioni vorrebbe somigliare a questo:
http://www.derekfordesign.com/bf3random_quick.html
tuttavia qui sono presenti degli errori nell'associazione tra la categoria dell'arma e quella degli accessori.
Come posso creare un generatore casuale che tenga conto di limitazioni imposte sugli accessori di ogni singola arma sia nel tipo sia nell'ordine?
Me la cavo con l'html ma se non si può fare così posso imparare qualcos'altro.
Sono consapevole che il mio problema non è spiegato molto chiaramente in particolare se nessuno gioca al titolo in questione e me ne scuso ma spero che qualcuno abbia la pazienza per almeno provare ad aiutarmi. Grazie a tutti in anticipo

kwb
17-05-2013, 11:06
Salve a tutti! Intanto spero di aver scritto nella sezione giusta.
Come da titolo vorrei realizzare un generatore casuale, nello specifico un generatore di kit per Battlefield 3, nelle mie intenzioni vorrebbe somigliare a questo:
http://www.derekfordesign.com/bf3random_quick.html
tuttavia qui sono presenti degli errori nell'associazione tra la categoria dell'arma e quella degli accessori.
Come posso creare un generatore casuale che tenga conto di limitazioni imposte sugli accessori di ogni singola arma sia nel tipo sia nell'ordine?
Me la cavo con l'html ma se non si può fare così posso imparare qualcos'altro.
Sono consapevole che il mio problema non è spiegato molto chiaramente in particolare se nessuno gioca al titolo in questione e me ne scuso ma spero che qualcuno abbia la pazienza per almeno provare ad aiutarmi. Grazie a tutti in anticipo
In HTML non si può fare.
L'html non è tecnicamente un linguaggio di programmazione.
Ti serve o un linguaggio server-side ( php, python ) oppure un linguaggio client-side ( scripting ): Javascript.

Per ciò che riguarda l'implementazione io penso siano necessari un po' di array in cui inserisci per ognuno una serie di oggetti possibili. Da ogni array estrarrai a caso ( o secondo certe regole ) uno di questi oggetti e poi li stampi sulla pagina.

Sta a te però capire quali devono essere i vincoli che legano un oggetto di un array A ad uno di un array B e viceversa.

The_ouroboros
17-05-2013, 11:11
modificati il codice che usano in quella pagina, no?



/* Qucik and Dirty */
var class_gen = Math.floor(Math.random()*4);
var allkitcheck = Math.floor(Math.random()*3);
var pistol_gen = Math.floor(Math.random()*15);
var spec_gen = Math.floor(Math.random()*7);
var scope_attatch = Math.floor(Math.random()*13);
var second_attatch = Math.floor(Math.random()*7);
var third_attatch = Math.floor(Math.random()*10);

/* ASSAULT CLASS */
if(class_gen === 0) {
document.write("<p>Your class is Assault</p>");

if(allkitcheck === 0) {
var weapon_gen = Math.floor(Math.random()*11);
if(weapon_gen === 0) {document.write("<p>Your weapon is the M416");}
if(weapon_gen === 1) {document.write("<p>Your weapon is the AEK-971");}
if(weapon_gen === 2) {document.write("<p>Your weapon is the AK-74M");}
if(weapon_gen === 3) {document.write("<p>Your weapon is the M16A3");}
if(weapon_gen === 4) {document.write("<p>Your weapon is the F2000");}
if(weapon_gen === 5) {document.write("<p>Your weapon is the AN-94");}
if(weapon_gen === 6) {document.write("<p>Your weapon is the G3A3");}
if(weapon_gen === 7) {document.write("<p>Your weapon is the KH2002");}
if(weapon_gen === 8) {document.write("<p>Your weapon is the FAMAS");}
if(weapon_gen === 9) {document.write("<p>Your weapon is the L85A2");}
if(weapon_gen === 10) {document.write("<p>Your weapon is the M16A4");}
}

if(scope_attatch === 1){scope_attatch = 5;}
if(scope_attatch === 4){scope_attatch = 0;}
if(scope_attatch === 12){scope_attatch = 2;}
if(second_attatch === 3||4) {second_attatch = 0;}
if(second_attatch === 5||6) {second_attatch = 1;}

if(third_attatch === 6) {third_attatch = 5;}
if(third_attatch === 7) {third_attatch = 3;}
if(third_attatch === 8) {third_attatch = 1;}
if(third_attatch === 9) {third_attatch = 0;}
if(third_attatch === 1) {third_attatch = 10;}

}
/* ENGINEER CLASS */
if(class_gen === 1) {
document.write("<p>Your class is Engineer</p>");

if(allkitcheck === 0) {
var weapon_gen = Math.floor(Math.random()*9);
if(weapon_gen === 0) {document.write("<p>Your weapon is the M4A1");}
if(weapon_gen === 1) {document.write("<p>Your weapon is the AKS-74U");}
if(weapon_gen === 2) {document.write("<p>Your weapon is the SG553");}
if(weapon_gen === 3) {document.write("<p>Your weapon is the M4");}
if(weapon_gen === 4) {document.write("<p>Your weapon is the A-91");}
if(weapon_gen === 5) {document.write("<p>Your weapon is the G36C");}
if(weapon_gen === 6) {document.write("<p>Your weapon is the SCAR-H");}
if(weapon_gen === 7) {document.write("<p>Your weapon is the G53");}
if(weapon_gen === 8) {document.write("<p>Your weapon is the QBZ-958");}
}

if(scope_attatch === 1){scope_attatch = 6;}
if(scope_attatch === 4){scope_attatch = 2;}
if(scope_attatch === 12){scope_attatch = 3;}
if(second_attatch === 1) {second_attatch = 0;}
if(second_attatch === 3||4) {second_attatch = 0;}
if(second_attatch === 5||6) {second_attatch = 0;}

if(third_attatch === 6) {third_attatch = 5;}
if(third_attatch === 7) {third_attatch = 3;}
if(third_attatch === 8) {third_attatch = 1;}
if(third_attatch === 9) {third_attatch = 10;}
if(third_attatch === 1) {third_attatch = 0;}

}
/* SUPPORT CLASS */
if(class_gen === 2) {
document.write("<p>Your class is Support</p>");

if(allkitcheck === 0) {
var weapon_gen = Math.floor(Math.random()*9);
if(weapon_gen === 0) {document.write("<p>Your weapon is the M27 IAR");}
if(weapon_gen === 1) {document.write("<p>Your weapon is the RPK-74M");}
if(weapon_gen === 2) {document.write("<p>Your weapon is the M249");}
if(weapon_gen === 3) {document.write("<p>Your weapon is the Type 88");}
if(weapon_gen === 4) {document.write("<p>Your weapon is the PKP Pecheneg");}
if(weapon_gen === 5) {document.write("<p>Your weapon is the M240B");}
if(weapon_gen === 6) {document.write("<p>Your weapon is the M60E4");}
if(weapon_gen === 7) {document.write("<p>Your weapon is the QBB-95");}
if(weapon_gen === 8) {document.write("<p>Your weapon is the MG36");}
}

if(scope_attatch === 1){scope_attatch = 7;}
if(scope_attatch === 4){scope_attatch = 3;}
if(scope_attatch === 12){scope_attatch = 5;}

if(second_attatch === 3||4) {second_attatch = 0;}
if(second_attatch === 5||6) {second_attatch = 1;}

if(third_attatch === 6) {third_attatch = 5;}
if(third_attatch === 7) {third_attatch = 3;}
if(third_attatch === 8) {third_attatch = 1;}
if(third_attatch === 9) {third_attatch = 0;}
if(third_attatch === 2) {third_attatch = 1;}
if(third_attatch === 3) {third_attatch = 1;}
if(third_attatch === 10) {third_attatch = 3;}

}
/* RECON CLASS */
if(class_gen === 3) {
document.write("<p>Your class is Recon</p>");

if(allkitcheck === 0) {
var weapon_gen = Math.floor(Math.random()*9);
if(weapon_gen === 0) {document.write("<p>Your weapon is the SVD");}
if(weapon_gen === 1) {document.write("<p>Your weapon is the MK11");}
if(weapon_gen === 2) {document.write("<p>Your weapon is the M39 EMR");}
if(weapon_gen === 3) {document.write("<p>Your weapon is the SV98");}
if(weapon_gen === 4) {document.write("<p>Your weapon is the M98B");}
if(weapon_gen === 5) {document.write("<p>Your weapon is the M40A5");}
if(weapon_gen === 6) {document.write("<p>Your weapon is the SKS");}
if(weapon_gen === 7) {document.write("<p>Your weapon is the QBU-88");}
if(weapon_gen === 8) {document.write("<p>Your weapon is the L96");}
}

if(second_attatch === 3||4) {second_attatch = 0;}
if(second_attatch === 5||6) {second_attatch = 1;}

if(third_attatch === 6) {third_attatch = 5;}
if(third_attatch === 7) {third_attatch = 3;}
if(third_attatch === 8) {third_attatch = 1;}
if(third_attatch === 9) {third_attatch = 0;}
if(third_attatch === 1) {third_attatch = 3;}
if(third_attatch === 10) {third_attatch = 2;}

}

/* ALL KIT WEAPONS */
if(allkitcheck === 1) {
var weapon_gen = Math.floor(Math.random()*7);

if(scope_attatch === 12){scope_attatch = 13;}
if(third_attatch === 6) {third_attatch = 5;}
if(third_attatch === 7) {third_attatch = 3;}
if(third_attatch === 8) {third_attatch = 1;}
if(third_attatch === 9) {third_attatch = 0;}
if(third_attatch === 10) {third_attatch = 2;}

if(weapon_gen === 0) {document.write("<p>Your weapon is the PP-2000");}
if(weapon_gen === 1) {document.write("<p>Your weapon is the UMP-45");}
if(weapon_gen === 2) {document.write("<p>Your weapon is the MP7");}
if(weapon_gen === 3) {
document.write("<p>Your weapon is the AS VAL");
if(third_attatch === 1) {
third_attatch = 0;
}
if(scope_attatch = 13){
scope_attatch = 12;
}
}
if(weapon_gen === 4) {document.write("<p>Your weapon is the PDW-R");}
if(weapon_gen === 5) {
document.write("<p>Your weapon is the P90");
if(third_attatch === 1) {
third_attatch = 0;
}
}
if(weapon_gen === 6) {
document.write("<p>Your weapon is the PP-19");
if(third_attatch === 1) {
third_attatch = 0;
}
}

if(scope_attatch = 13){scope_attatch = 2;}
if(second_attatch === 1) {second_attatch = 0;}
if(second_attatch == 3||4) {second_attatch = 0;}
if(second_attatch == 5||6) {second_attatch = 0;}

}
if(allkitcheck === 2) {
var weapon_gen = Math.floor(Math.random()*6);
if(weapon_gen === 0) {document.write("<p>Your weapon is the 870MCS");}
if(weapon_gen === 1) {document.write("<p>Your weapon is the SAIGA 12K");}
if(weapon_gen === 2) {document.write("<p>Your weapon is the M1014");}
if(weapon_gen === 3) {document.write("<p>Your weapon is the DAO-12");}
if(weapon_gen === 4) {document.write("<p>Your weapon is the USAS-12");}
if(weapon_gen === 5) {document.write("<p>Your weapon is the MK3A1");}

if(second_attatch === 0) {second_attatch = 3;}
if(second_attatch === 1) {second_attatch = 5;}

if(third_attatch === 0||1) {third_attatch = 6;}
if(third_attatch === 2||3) {third_attatch = 8;}
if(third_attatch === 4||5) {third_attatch = 9;}
if(third_attatch === 10) {third_attatch = 7;}

}

if(scope_attatch === 0) {document.write(" with the ACOG 4X,");}
if(scope_attatch === 1) {document.write(" with the Ballistic Sight 12X,");}
if(scope_attatch === 2) {document.write(" with the Reflex RDS,");}
if(scope_attatch === 3) {document.write(" with the IRNV Infrared Sight,");}
if(scope_attatch === 4) {document.write(" with the PKS-07 7X,");}
if(scope_attatch === 5) {document.write(" with the M145 3.4X,");}
if(scope_attatch === 6) {document.write(" with the PSO-1 4X,");}
if(scope_attatch === 7) {document.write(" with the HOLO Holographic Sight,");}
if(scope_attatch === 8) {document.write(" with the PKA-S Holographic Sight,");}
if(scope_attatch === 9) {document.write(" with the Kobra RDS,");}
if(scope_attatch === 10) {document.write(" with the PK-A 3.4X,");}
if(scope_attatch === 11) {document.write(" with Iron Sights,");}
if(scope_attatch === 12) {document.write(" with the Rifle Scope,");}

if(second_attatch === 0) {document.write(" Foregrip,");}
if(second_attatch === 1) {document.write(" Bipod,");}
if(second_attatch === 2) {document.write(" Nothing in the second slot,");}
/* for shotguns */
if(second_attatch === 3) {document.write(" Extended Mag,");}
if(second_attatch === 4) {document.write(" Tactical Light,");}
if(second_attatch === 5) {document.write(" Laser Sight,");}
if(second_attatch === 6) {document.write(" Flash Suppresor,");}

if(third_attatch === 0) {document.write(" and Nothing in the third slot</p>");}
if(third_attatch === 1) {document.write(" and Extended Mag</p>");}
if(third_attatch === 2) {document.write(" and Tactical Light</p>");}
if(third_attatch === 3) {document.write(" and Laser Sight</p>");}
if(third_attatch === 4) {document.write(" and Flash Suppresor</p>");}
if(third_attatch === 5) {document.write(" and Silencer</p>");}
if(third_attatch === 10) {document.write(" and Heavy Barrel</p>");}
/* for shotguns */
if(third_attatch === 6) {document.write(" and 12G Frag</p>");}
if(third_attatch === 7) {document.write(" and 12G Slug</p>");}
if(third_attatch === 8) {document.write(" and 12G Buckshot</p>");}
if(third_attatch === 9) {document.write(" and 12G Flechette</p>");}

/* SIDEARM GEN */
if(pistol_gen === 0) {document.write("<p>Your sidearm is the MP412 REX</p>");}
if(pistol_gen === 1) {document.write("<p>Your sidearm is the 93R</p>");}
if(pistol_gen === 2) {document.write("<p>Your sidearm is the G17C</p>");}
if(pistol_gen === 3) {document.write("<p>Your sidearm is the M9 TACT.</p>");}
if(pistol_gen === 4) {document.write("<p>Your sidearm is the MP443 TACT.</p>");}
if(pistol_gen === 5) {document.write("<p>Your sidearm is the G17C SUPP.</p>");}
if(pistol_gen === 6) {document.write("<p>Your sidearm is the M9 SUPP.</p>");}
if(pistol_gen === 7) {document.write("<p>Your sidearm is the MP443 SUPP.</p>");}
if(pistol_gen === 8) {document.write("<p>Your sidearm is the G18</p>");}
if(pistol_gen === 9) {document.write("<p>Your sidearm is the .44 Magnum</p>");}
if(pistol_gen === 10) {document.write("<p>Your sidearm is the G18 SUPP.</p>");}
if(pistol_gen === 11) {document.write("<p>Your sidearm is the .44 SCOPED</p>");}
if(pistol_gen === 12) {document.write("<p>Your sidearm is the M1911</p>");}
if(pistol_gen === 13) {document.write("<p>Your sidearm is the M1911 TACT.</p>");}
if(pistol_gen === 14) {document.write("<p>Your sidearm is the M1911 SUPP.</p>");}

/* ASSAULT CLASS EQUIPMENT */
if(class_gen === 0) {
var equip_gen = Math.floor(Math.random()*5);

if(equip_gen === 0) {document.write("<p>Your third slot item is the Health Pack</p>");}
if(equip_gen === 1) {document.write("<p>Your third slot item is the M320</p>");}
if(equip_gen === 2) {document.write("<p>Your third slot item is the M320 Buck</p>");}
if(equip_gen === 3) {document.write("<p>Your third slot item is the M320 Smoke</p>");}
if(equip_gen === 4) {document.write("<p>Your third slot item is the M26 Mass</p>");}

}
/* ENGINEER CLASS EQUIPMENT */
if(class_gen === 1) {
var equip_gen = Math.floor(Math.random()*3);
var equiptwo_gen = Math.floor(Math.random()*3);

if(equip_gen === 0) {document.write("<p>Your third slot item is the SA-18 IGLA/FIM-92 STINGER</p>");}
if(equip_gen === 1) {document.write("<p>Your third slot item is the FGM-148 JAVELIN</p>");}
if(equip_gen === 2) {document.write("<p>Your third slot item is the RPG-7V2/SMAW</p>");}

if(equiptwo_gen === 0) {document.write("<p>Your fourth slot item is the EOD Bot</p>");}
if(equiptwo_gen === 1) {document.write("<p>Your fourth slot item is the Repair Tool</p>");}
if(equiptwo_gen === 2) {document.write("<p>Your fourth slot item is the M15 AT Mine</p>");}
}
/* SUPPORT CLASS EQUIPMENT */
if(class_gen === 2) {
var equip_gen = Math.floor(Math.random()*3);

if(equip_gen === 0) {document.write("<p>Your third slot item is the M18 Claymore</p>");}
if(equip_gen === 1) {document.write("<p>Your third slot item is the M224 Mortar</p>");}
if(equip_gen === 2) {document.write("<p>Your third slot item is C4 Explosives</p>");}

}
/* RECON CLASS EQUIPMENT */
if(class_gen === 3) {
var equip_gen = Math.floor(Math.random()*3);

if(equip_gen === 0) {document.write("<p>Your third slot item is the Soflam</p>");}
if(equip_gen === 1) {document.write("<p>Your third slot item is the T-UGS</p>");}
if(equip_gen === 2) {document.write("<p>Your third slot item is the MAV</p>");}

}

/* SPECIALIZATION GEN */
if(spec_gen === 0) {document.write("<p>Your specialization is Improved Sprint Speed (SPRNT)</p>");}
if(spec_gen === 1) {document.write("<p>Your specialization is Extra Ammo (AMMO)</p>");}
if(spec_gen === 2) {document.write("<p>Your specialization is Extra Explosives (EXPL)</p>");}
if(spec_gen === 3) {document.write("<p>Your specialization is Suppression Reduction (COVR)</p>");}
if(spec_gen === 4) {document.write("<p>Your specialization is Inmproved Suppressive Fire (SUPR)</p>");}
if(spec_gen === 5) {document.write("<p>Your specialization is Extra Grenades (FRAG)</p>");}
if(spec_gen === 6) {document.write("<p>Your specialization is Reduced Damage From Explosions (FLAK)</p>");}

clockover
17-05-2013, 11:26
tuttavia qui sono presenti degli errori nell'associazione tra la categoria dell'arma e quella degli accessori.

Io mi farei un bel diagrammino delle classi http://it.wikipedia.org/wiki/Class_diagram, dove ogni classe rappresenta: classe (Assalto, Geniere, Supporto, Recon), arma (Pecheneg, M98, UMP-45, ecc...), mirino (standard, 3.4x, 6, ecc..), impugnatura (bipode, innesto sottocanna, ecc...), canna (pesante, silenziatore, ecc...), arma secondaria, specializzazione, accessorio 1 e accessorio 2, ecc....
Dopo che hai fatto tutto ciò stabilisci i tuoi vincoli: l'assalto può utilizzare solo alcuni fucili, il mirino massimo dell'UMP è il 3.4x e non ha canna pesante, ecc... Questi vincoli insieme ti serviranno al momento della scelta random ad associare per bene tutti i kit.
Il lavoro non è difficile assolutamente, ma è abbastanza lunghetto, anche perchè BF3 ha una marea di roba tra armi e accessori, e questo si ripercuote sui vincoli che devi introdurre.
Utilizzerei php per fare tutta questa roba (questione di gusti)

Spiderbite
18-05-2013, 21:40
Penso che per prima cosa proverò a fare come mi ha consigliato ouroboros visto che sembrerebbe una soluzione abbastanza rapida da provare avendo la maggior parte del codice già pronta.
Se avesse ragione kwb e provare con l'html equivale a sbattere ripetutamente e con violenza la testa contro un muro di mattoni mi risolverò a imparare qualcosa di nuovo. Ora la domanda è mi coverrebbe java o php? Quale dei due è piú semplice?