Thread: Simon Game w/ C

  1. #1
    Registered User
    Join Date
    Nov 2017
    Posts
    3

    Simon Game w/ C

    Hey! I'm currently designing a program which allows the user to play Simon on a hardware module. I'm not so sure why my code doesn't work. Would anyone be willing to help me out? It says that there is an error regarding the colornum variable in the int press(void) function.

    Sorry if this thread seems stupid or anything; I'm an extremely amateur C programming student!

    Below is my program:
    Code:
    /*
    Simon Game
    */
    #define _CRT_SECURE_NO_WARNINGS
    #include <stdio.h>
    #include <stdlib.h>
    #include <Windows.h>
    #include <DAQlib.h>
    #include <time.h>
    #include <math.h>
    
    
    #define ON 1
    #define OFF 0
    
    
    #define Green 0
    #define Red 1
    #define Yellow 2
    #define Blue 3
    
    
    #define GreenLED 0
    #define RedLED 1
    #define YellowLED 2
    #define BlueLED 3
    
    
    #define GreenButton 0
    #define RedButton 1
    #define YellowButton 2
    #define BlueButton 3
    
    
    #define second 1000
    
    
    #define TRUE 1
    #define FALSE 0
    
    
    void game(void);
    void zzz(int index);
    int press(void);
    
    
    int main(void)
    {
        int setupNum;
        printf("Please enter 0 for the Hardware, 6 for the Simulator: ");
        scanf("%d", &setupNum);
        if (setupDAQ(setupNum) == TRUE)
        {
            /* Stopped for one second to allow everything to load and user to get ready*/
            Sleep(second);
            game();
        }
        else
        {
            printf("Error intializing DAQ...");
        }
        system("PAUSE");
        return 0;
    
    
    }
    
    
    void game(void)
    {
    
    
        while (continueSuperLoop() == TRUE)
        {
            int index;
            int count;
            index = 0;
            int NumNum = 5;
    
    
            /* Test that it does enter the Super Loop, and turns each light on, and then off after 1 second, one by one. */
            for (count = 0; count <= 3; count++)
            {
                digitalWrite(count, ON);
                Sleep(second);
                digitalWrite(count, OFF);
            }
    
    
            while (index < NumNum)
            {
                static int randArray[5];
                srand((unsigned)time(NULL));
                randArray[index] = rand() % 4;
    
    
    
    
                for (count = 0; count <= index; count++)
                {
                    digitalWrite(randArray[count], ON);
                    zzz(index);
                    digitalWrite(randArray[count], OFF);
                }
    
    
                for (count = 0; count <= index; count++)
                {
                    int pressed;
                    pressed = press();
    
    
                    if (press != randArray[count])
                    {
                        index = 0;
                    }
                    else
                    {
    
    
                    }
                }
                index++;
    
    
            }
    
    
    
    
        }
        return;
    }
    
    
    void zzz(int count)
    {
        int time, time_decrease_percentage, degree;
        time = second;
        time_decrease_percentage = 0.75;
        degree = count + 1;
    
    
        if (count = 0)
        {
            Sleep(time * pow(time_decrease_percentage, degree));
        }
        else if (count = 1)
        {
            Sleep(time * pow(time_decrease_percentage, degree));
        }
        else if (count = 2)
        {
            Sleep(time * pow(time_decrease_percentage, degree));
        }
        else
        {
            Sleep(time * pow(time_decrease_percentage, degree));
        }
        return;
    }
    
    
    
    
    int press(void)
    {
        int colornum;
    
    
        if (digitalRead(GreenButton) == ON)
        {
            colornum = Green;
        }
    
    
        if (digitalRead(RedButton) == ON)
        {
            colornum = Red;
        }
    
    
        if (digitalRead(YellowButton) == ON)
        {
            colornum = Yellow;
        }
    
    
        if (digitalRead(BlueButton) == ON)
        {
            colornum = Blue;
        }
    
    
        return colornum;
    }

  2. #2
    Registered User
    Join Date
    Jun 2017
    Posts
    88
    Might the DAQlib.h be a library specifically built for your online course at coursehero? If not, I am not sure what that is. I think it is important to know though because I believe it is needed for line 52, and if it is a coursehero specific library, your program will be difficult to debug for anyone who doesn't have the library.
    Last edited by jack jordan; 11-26-2017 at 01:01 AM.

  3. #3
    Registered User
    Join Date
    Nov 2017
    Posts
    3
    Thanks for noting that out! I'll attach the install files on!

  4. #4
    Registered User
    Join Date
    Nov 2017
    Posts
    3
    Hey! the install file is on this link (for the DAQlib.h)

    thanks!!
    Dropbox - DAQ_Student.zip

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Starting a simple game server for tile based game
    By cpu0 in forum Game Programming
    Replies: 1
    Last Post: 01-19-2017, 12:15 PM
  2. Simon Says - PIC16f84a
    By WashAutumnstar in forum C Programming
    Replies: 8
    Last Post: 12-16-2015, 08:23 AM
  3. Help need to understand simple simon game
    By devaraj in forum C Programming
    Replies: 2
    Last Post: 11-13-2011, 01:30 AM
  4. a game of Simon Says
    By skorman00 in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 04-22-2005, 07:32 PM
  5. They Cut Simon's Head Off In Lord Of The Flies
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 10-19-2003, 04:25 PM

Tags for this Thread