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.