Memory
De DigiWiki.
Le moteur du jeu (root)
// Memory v1.1 by Bestmomo // Nombre de paires de couleurs integer NombrePaires; // Liste des etats des plots list Visible = []; // Liste melange des plots list Melange; // Liste des couleurs list Couleurs = []; // Premier plot touche integer Premier; // Second plot touche integer Second; // Constante de communication integer GO = 10; // Constante pour les plots integer NON_TOUCHE = -1; initialisations() { // Initialisation du nombre de paires NombrePaires = 8; // Initialisation des touches Premier = NON_TOUCHE; Second = NON_TOUCHE; // Nombre total de plots integer NombrePlots = NombrePaires * 2; // Index du dbut des plots integer Debut = llGetNumberOfPrims() - NombrePlots + 1; // Creation et remplissage de la liste des plots integer x; list Plots = []; for(x = Debut; x < NombrePlots + Debut; x++) { Plots += x; // Plots noirs au depart llSetLinkColor(x, <0,0,0>, ALL_SIDES); } // Creation d'une liste melange des plots Melange = llListRandomize(Plots, 1); // Creation de la liste des couleurs des plots par paires for(x = 0; x < NombrePaires; x++) { vector col = <llFrand(1),llFrand(1),llFrand(1)>; Couleurs += col; Couleurs += col; } // Remplissage de 0 de la liste Visible for(x = 0; x < NombrePlots; x++) Visible += [0]; // Avis de depart llSay(PUBLIC_CHANNEL, "Jeu en cours"); } // Renvoie l'index du Plot integer IndexPlot(list sender_number) { return llListFindList(Melange, sender_number); } // Renvoie la valeur de visibilite TRUE (1) ou FALSE (0) integer TestVisible(list sender_number) { integer Index = IndexPlot(sender_number); return llList2Integer(Visible, Index); } // Affecte la visibilite au Plot SetVisible(integer plot) { integer Index = IndexPlot([plot]); Visible = llListReplaceList(Visible, [1], Index, Index); } // Met en couleur le plot ColorePlot(integer sender_number) { llSetLinkColor(sender_number, llList2Vector(Couleurs, IndexPlot([sender_number])), ALL_SIDES); } // Test de paire integer TestePaire(integer a, integer b) { if(llList2Vector(Couleurs, IndexPlot([a])) == llList2Vector(Couleurs, IndexPlot([b]))) return TRUE; return FALSE; } // Test de fin integer TestFin() { if(llListFindList(Visible, [0]) == -1) return TRUE; return FALSE; } default { // Attente action du bouton link_message(integer sender_number, integer number, string message, key id) { // Depart du jeu if(number == GO) { initialisations(); state PremierPlot; } return; } } state PremierPlot { // Reception d'un message des plots link_message(integer sender_number, integer number, string message, key id) { // Nouveau depart du jeu ? if(number == GO) { initialisations(); return; } // Plot deja visible ? if(TestVisible([sender_number])) return; else { // Affectation premier plot Premier = sender_number; // Colorisation du plot ColorePlot(sender_number); // Passage au choix du second plot state SecondPlot; } } } state SecondPlot { // Reception d'un message des plots link_message(integer sender_number, integer number, string message, key id) { // Nouveau depart du jeu ? if(number == GO) { initialisations(); state PremierPlot; } // Deja un second plot touche ? if(Second != NON_TOUCHE) return; // Deuxieme plot choisi Second = sender_number; if(TestVisible([Second]) || Second == Premier) return; else { // Colorisation du plot ColorePlot(Second); // Test paire trouvee if(TestePaire(Premier, Second)) { // Affecte visible pour les deux plots SetVisible(Premier); SetVisible(Second); // Reinitialisation Premier = NON_TOUCHE; Second = NON_TOUCHE; // Test de fin du jeu if(TestFin()) llResetScript(); // Retour au choix du premier plot state PremierPlot; } else // Timer 2 secondes llSetTimerEvent(2); } } // Temporisation timer() { // Remise a noir de la couleur des deux plots llSetLinkColor(Premier, <0,0,0>, ALL_SIDES); llSetLinkColor(Second, <0,0,0>, ALL_SIDES); // Reinitialisation des touches Premier = NON_TOUCHE; Second = NON_TOUCHE; // Reset du timer llSetTimerEvent(.0); // Retour au choix du premier plot state PremierPlot; } }
Les pieces
// Slot v0.1 integer TOUCHE = 1; default { touch_start(integer total_number) { llMessageLinked(LINK_ROOT, TOUCHE, "", NULL_KEY); } }
Le bouton on/off
// Power v0.1 integer GO = 10; default { touch_start(integer total_number) { llMessageLinked(LINK_ROOT, GO, "", NULL_KEY); } }