We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, so here's the speech : A friend and I are working on a Simon memory game in processing. We are beginners (some would say "complete noobs"), for this project we have to use the basic processing library and we also have to use tables. The comments in our code are in french (sorry). Our idea is a Simon memory game in which you first have a pre-loaded sequence that plays when you hit the start button and if the colors you click (when it's your turn to play) are corect then the game move to a random sequence color and so on until you fail, and if you fail you have to restart the game. As I said we are complete noobs and we got to this point (of course this is mostly ideas and mainly nothing that works or you can launch), we would love some help it would already be awesome for us if we could launch the first sequence (even without player interaction) : You can download the file here --> Download
//Color Sync , jeu de mémoire
//declarations
//tableaux pour carrés, positions et couleurs
PShape[] carres = new PShape[4];
int x[] = {250, 500, 250, 500};
int y[] = {250, 250, 500, 500};
//couleur d'affichage prédéfini (fond de base)
color couleursfond[] = new color[4];
//couleurs pour les séries - plus intenses
color couleurs[] = new color[4];
//tableau pour sequence de couleur pré-enregistrée
int sequence[] = new color[4];
//initialisation - sous-programmes natifs
void setup () {
//affichage de départ
size(1000, 1000, P2D);
background(255, 255, 255);
//affichage titre
String titre = "COLOR SYNC.";
fill(50);
textAlign(CENTER);
textSize(70);
text(titre, 0, 20, 1000, 100);
//affichage description
String description = "Inspiré du célèbre jeu pour enfant le 'Simon', Color Sync vous propose de tester votre capacité de mémorisation. ";
fill(50);
textSize(12);
text(description, 0, 160, 1000, 30);
//couleurs des quatre carrés à l'origine, sans animation.
couleursfond[0]=color(255, 100, 100);
couleursfond[1]=color(100, 255, 100);
couleursfond[2]=color(100, 100, 255);
couleursfond[3]=color(255, 255, 100);
//Bouton pour démarrer
fill(255);
stroke(0);
rect(430, 760, 145, 60, 5);
String lancer = "Lancer!";
fill(0);
textSize(30);
text(lancer, 500, 800);
//Caractéristiques de la séquence pré-définie
sequence[0]=0;
sequence[1]=2;
sequence[2]=1;
sequence[3]=3;
//définition couleurs et tailles
for(int i= 0; i<4; i=i+1) {
noStroke();
fill(couleursfond[i]);
carres[i]=createShape(RECT, 0, 0, 240, 240);
}
//définition positions
for(int i= 0; i<4; i=i+1) {
shape(carres[i], x[i], y[i]);
}
//réduit la nombre d'image par seconde du draw (ici une image par seconde)
frameRate(1);
}
//entrée de la variable permettant de faire la série de couleurs pré-définies 'i'
int i=0;
void draw(){
/* //le joueur interagit avec le bouton pour démarrer la partie (interaction) et affiche la séquence de couleur pré-enregistrée pour le premier niveau
while (!(mousePressed && mouseX> 430 && mouseX <575 && mouseY> 760 && mouseY <820)) {
}
*/
//couleurs plus intense pour les série à afficher au joueur
couleurs[0]=color(255, 0 , 0);
couleurs[1]=color(0, 255, 0);
couleurs[2]=color(0, 0, 255);
couleurs[3]=color(255, 255, 0);
fill(couleurs[i]);
//nous aide pour les tests à voir le fonctionnement de la série de couleurs prédéfinie
background(0);
int numerocouleur = sequence[i];
shape(carres[numerocouleur], x[numerocouleur], y[numerocouleur]);
if(i<3){
i=i+1;
}
/*
//après la séquence préenregistrée le jeu devient plus difficile et une couleur s'ajoute. Les couleurs sont choisies aléatoirement par la machine
if(sequence[i]= sequence joueur ){
sequence[i]= random;
//augmentation de la difficulté en ajoutant une couleur en plus dans chaque séquence
while(sequence[]= sequence faite par le joueur ) {
sequence[i]=sequence[i]+1;
}
}
else {
sequencePreenregistree();
}
*/
}
/* idée -
if() {
programme d'affichage automatique (appuyer sur ent pour activer l'animation)
} else {
programme du jeu
}
Answers
I see there is already a sequence playing when I start it.
So your problem is how to implement the start button to make it start in the first place?
It is to implement the start button and to play the first sequence, because we faced a problem while we tried to do this, we wan't to have an interface in the beginning that shows the colored squares but when we clicked start as we try to play the sequence that we created in the draw part, the background turns black and we only see the sequence playing without the basic interface.
my core idea here is that the program has states.
so the program knows whether to display a start screen, display a sequence or receive a sequence
the state has names which are constants
in draw() we evaluate the state with
switch
in
mousepressed()
as well;-)
the next step in state EnterSequence is then that you display the 4 rects and monitor the mouse inputs (in func mousePressed()).
count your i up again from 0 to 3 and check every time if the mouse was pressed in the right rect (using if mouseX>.... etc. )
;-)
the idea of state is like the idea of having a boolean variable
playerIsPlaying = true
orshowSequenceNow = true
or so....Using one var
state
instead is much smarter...because mostly, only one of the boolean var would be true and all others would be false...
;-)
Thank you so much , you helped us a lot !
great!