Help with Lightpaths program

This is a discussion on Help with Lightpaths program within the C Programming forums, part of the General Programming Boards category; I'm trying to create a C program that emulates the Itunes app store game light paths. Basically what it does ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    9

    Help with Lightpaths program

    I'm trying to create a C program that emulates the Itunes app store game light paths.

    Basically what it does is it creates a grid with numbers on the sides (top, bottom, left, right). All those numbers emit lights. Those number emitting light has to bounce off a mirror at an angle to hit another light perpendicular to it, depending on the angle. The goal of the game is to get all the numbers to shine light with their corresponding numbers using mirrors at angle / , 45 degrees, or how I've labeled it the program 1. Or using angle \ or 2.

    A picture of the game.
    http://img.wareseeker.com/software/i..._115200562.jpg

    What I have so far is this. I'm having trouble generating numbers on the sides that correspond to the randomly generated mirrors on the top. Any ideas?

    Code:
    #include <stdio.h>
    #include <ctype.h>
    #include <time.h>
    main()
    {
    int a[7][7], y, D, x, i, j, temp, count;
    x=time(NULL);
    srand(x);
    for(i=0;i<8;i++)
       {
        for(j=0;j<8;j++)
       {
            a[i][j]=0;
            }
            }
    
    count=0;
    while(count<7)
    {
            i=(rand()%6)+1;
            j=(rand()%6)+1;
            a[i][j]=(rand()%2)+1;
            count++;
    }
    
       for(j=1;j<7;j++)
       {
            a[0][j]=(rand()%12)+1;
       }
    
    while(i=0)
    {
    D=1;
    for(j=1;j<9;j++)
     {
    a[i][j]=y;
    while((i<9)&&(j<9))
    {
    switch(a[i][j])
    {
    case 0:
    if(a[i][j]==0)
    break;
    
    case 1:
    if(a[i][j]==13);
    D=(D*2)%3;
    break;
    
    case 2:
    if(a[i][j]==14);
    D=(D*-2)%3;
    break;
    
    if(D==1)
    i++;
    if(D==-1)
    i--;
    if(D==2)
    j++;
    if(D==-2)
    j--;
    }
    }
    }
    if((i==8)||(i==0)||(j==0)||(j==8))
    y=a[i][j];
    }
    
    
    
    
    for(i=0;i<8;i++)
    {
    printf("\n\n");
            {
            for(j=0;j<8;j++)
            printf("%d    ", a[i][j]);
            }
    }
    printf("\n\n");
       }

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Skeeter View Post
    Any ideas?
    Yeah:

    1) Go straight to "Learn how to indent properly". Do not pass Go. Do not get out of jail otherwise.

    The number of people in the world who do not bother to indent but write real programs = 0. There is a reason. I look at this, and I see a SIGNIFICANT added hassle in reading the code. So, you can not bother to indent = I cannot bother to deal with the hassle either.

    Once you start indenting your code properly and writing more, you will recognize the value of it and this will make sense, as opposed to perhaps seeming like a grumpy anal dis, or something.
    Last edited by MK27; 12-02-2009 at 04:45 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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