Reputation: 173
I'm currently working on a small Arduino project, and I'm kinda stuck. Here's my code so far:
#include "_init.h"
void setup() {
ds_init();
Serial.begin(9600);
randomSeed(analogRead(LIGHT_SENSOR_PIN));
int rol1[] = {1, 2, 3, 4, 5};
int rol2[] = {3, 5, 1, 2, 4};
int rol3[] = {5, 1, 4, 3, 2};
int rol1Mid = random(0, 5);
int rol1Bov = rol1Mid + 1;
int rol1Ond = rol1Mid - 1;
if (rol1Bov == 5){
rol1Bov = 0;
}
if (rol1Ond == -1){
rol1Ond = 4;
}
int rol2Mid = random(0, 5);
int rol2Bov = rol2Mid + 1;
int rol2Ond = rol2Mid - 1;
if (rol2Bov == 5){
rol2Bov = 0;
}
if (rol2Ond == -1){
rol2Ond = 4;
}
int rol3Mid = random(0, 5);
int rol3Bov = rol3Mid + 1;
int rol3Ond = rol3Mid - 1;
if (rol3Bov == 5){
rol3Bov = 0;
}
if (rol3Ond == -1){
rol3Ond = 4;
}
Serial.println(rol1[rol1Bov]);
Serial.println(rol1[rol1Mid]);
Serial.println(rol1[rol1Ond]);
Serial.println("----");
Serial.println(rol2[rol2Bov]);
Serial.println(rol2[rol2Mid]);
Serial.println(rol2[rol2Ond]);
Serial.println("----");
Serial.println(rol3[rol3Bov]);
Serial.println(rol3[rol3Mid]);
Serial.println(rol3[rol3Ond]);
if(rol1[rol1Mid] && rol2[rol2Mid] == rol3[rol3Mid]){
Serial.println("Yaay!");
} else {
Serial.println("Jammer, probeer het nogmaals.");
}
/*
if(rol1[positieBov] && rol2[positieBov] == rol3[positieBov]){
Serial.println("Yaay!");
} else {
Serial.println("Jammer, probeer het nogmaals.");
}
if(rol1[positieOnd] && rol2[positieOnd] == rol3[positieOnd]){
Serial.println("Yaay!");
} else {
Serial.println("Jammer, probeer het nogmaals.");
}
*/
}
void loop() {
// put your main code here, to run repeatedly:
}
Basically, I'm trying to create a slot machine. There's probably tons of things wrong with my code, but for the time being, I'm stuck on the if statement that checks if the user won or not.
I know I shouldnt be coding in the setup() part of Arduino, but as soon as this all works, I'm going to put it in a function in the loop(), where I will use my dangershield's buttons to operate the three roll's separately.
Upvotes: 0
Views: 182
Reputation: 173
Okay, managed to fix it... I feel silly now
if(rol1[rol1Mid] == rol2[rol2Mid] && rol2[rol2Mid] == rol3[rol3Mid])
Upvotes: 1