Need Help with C Programming ASAP

This is a discussion on Need Help with C Programming ASAP within the C Programming forums, part of the General Programming Boards category; I have a C programming Final Project due in a couple days. I need help on getting a few things ...

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    2

    Exclamation Need Help with C Programming ASAP

    I have a C programming Final Project due in a couple days. I need help on getting a few things done properly. I have some things started but I don't really know where to go from here. First things first, the project is to create a program that will emulate the iPhone game called LightPaths. I have attached the instructions file below. Ok so for what I have done already:

    The part of the program I have done so far is part of the puzzle generator. I have two ways of going about it. The first way I was going about it was by creating an array that uses randomly generated number to create the array which the game will use. The code for that is:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    main()
    {
        int game[8][8]={0};										//declare variables for game
        int a[24];
        int start[12];
        int end[12];
        int j, i, x, in, out, temp;
        char play;
        x = time(NULL);
        srand(x); 												//seed the random value to the time
       
        printf("\n");
        printf("\t\t     LightPaths!\n");
        printf("\t\tThe puzzle of mirrors\n\n");
        printf("\t\t Want to play? y/n: ");
        scanf("%c", &play);
        printf("\n\n");
    
        if(play=='y')
        {
       
            game[0][0]= 0;										//sets all 4 corner cells to 0
            game[0][7]= 0;
            game[7][0]= 0;
            game[7][7]= 0;
           
            for(j=1; j<7; j++)
            {													//insert a random value for the top row, first column, last row, and last column
                game[0][j] = (rand()%12) +1;
                game[j][0] = (rand()%12) +1;
                game[7][j] = (rand()%12) +1;
                game[j][7] = (rand()%12) +1;
            }
           
            for(j=1, i=0; j<7; j++, i++)
            {													//begins to form a new array out of all the random values 0-6
                a[i] = game[0][j];
            }
           
            for(j=1, i=6; j<7; j++, i++)
            {													//continue to form the new array out of all the random values 7-12
                a[i] = game[j][0];
            }
           
            for(j=1, i=12; j<7; j++, i++)
            {													//continue to form the new array out of all the random values 13-18
                a[i] = game[7][j];
            }
           
            for(j=1, i=18; j<7; j++, i++)
            {													//continue to form the new array out of all the random values 18-23
                a[i] = game[j][7];
            }
    
            for(i=0; i<24; i++)
            { 													//print the values of the new array
                printf("%d ", a[i]);
            }
            printf("\n\n\n"); 										//sort the new array to determine repeated values
            for(out=0; out<24; out++)
            {
                for(in=out+1; in<24; in++)
                {
                    if(a[out]>a[in])
                    {
                        temp = a[in];
                        a[in] = a[out];
                        a[out] = temp;
                    }
                }
            }
           
            for(i=0; i<24; i++)
            {													//print the sorted array
                printf("%d ", a[i]);
            }
           
            for(i=0; i<8; i++)
            {													//print the game 2D array
                printf("\n\n");
                     for(j=0; j<8; j++)
                     {
                      printf("     %2d", game[i][j]);
                }
            }
            printf("\n\n");
        }
        else
            printf("\t\t   Until next time!\n\n");
           
        return 0;
       
    }
    If anyone can help me figure out how to make it so the array only has the numbers 1-12 repeated twice. That was the 24 boundary squares have a start and end to the 12 "beams of light". Thanks for the help in advance.
    Attached Images Attached Images
    Last edited by yabs; 12-07-2009 at 09:30 PM.

  2. #2
    Registered User
    Join Date
    Dec 2009
    Posts
    2

    Link to game

    Here is a link to the game

    Lightpaths 1.1
    Last edited by yabs; 12-07-2009 at 09:31 PM.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Initialize your array to zeroes.
    Code:
    for( x = 0; x < 12; x++ )
    {
        while( array[y = rand() % 24] );
        array[y] = x;
        while( array[y = rand() % 24] );
        array[y] = x;
    }
    There's a lazy way to do it, assuming you want to put 1 through 12 in an array twice. It's not the most efficient way to do it, but then, I'm not the one turning it in for homework either.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help ASAP ,
    By Haytham in forum C Programming
    Replies: 3
    Last Post: 05-14-2007, 10:21 AM
  2. Need Help ASAP....
    By Maxwell in forum C++ Programming
    Replies: 16
    Last Post: 09-14-2005, 06:56 PM
  3. Strange characters in output Need Help ASAP
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 12-14-2003, 05:35 PM
  4. Count_nums (need help ASAP!)
    By legacye in forum C Programming
    Replies: 6
    Last Post: 11-22-2003, 05:32 PM
  5. Help Needed Asap With Searching An Array!
    By HelpMe++ in forum C++ Programming
    Replies: 5
    Last Post: 05-23-2003, 04:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21