// Draft of the game of life #include <iostream> using namespace std; const int WIDE = 10; const int HEIGHT = 10; char world[WIDE] [HEIGHT]; int a = 0; int xSeed[256]; //Initiating the variable that will get the user input for the X coordinate of the Seed int ySeed[256]; //Same as the xSeed, except for the y coordinate int Seeds; //Initiating the variable that will tell me how high I will have to list upwards in the array int neighbors; //Used in the function birth to count how many neighbors a cell has char var2[4]; //Variable used to enter another seed, only will be used once. //Creating function that will print the gameboard onto the screen. int gameboard(){ // Making the gameboard. Helped to learn about line continuation :P cout << "\n__| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10" << \ "\n1 | " << world[1] [1] << " " << world[2] [1] << " " << world[3] [1] << " " << world[4] [1] << " " << world[5] [1] << " " << world[6] [1] << " " << world[7] [1] << " " << world[8] [1] << " " << world[9] [1] << " " << world[10] [1] << \ "\n2 | " << world[1] [2] << " " << world[2] [2] << " " << world[3] [2] << " " << world[4] [2] << " " << world[5] [2] << " " << world[6] [2] << " " << world[7] [2] << " " << world[8] [2] << " " << world[9] [2] << " " << world[10] [2] << \ "\n3 | " << world[1] [3] << " " << world[2] [3] << " " << world[3] [3] << " " << world[4] [3] << " " << world[5] [3] << " " << world[6] [3] << " " << world[7] [3] << " " << world[8] [3] << " " << world[9] [3] << " " << world[10] [3] << \ "\n4 | " << world[1] [4] << " " << world[2] [4] << " " << world[3] [4] << " " << world[4] [4] << " " << world[5] [4] << " " << world[6] [4] << " " << world[7] [4] << " " << world[8] [4] << " " << world[9] [4] << " " << world[10] [4] << \ "\n5 | " << world[1] [5] << " " << world[2] [5] << " " << world[3] [5] << " " << world[4] [5] << " " << world[5] [5] << " " << world[6] [5] << " " << world[7] [5] << " " << world[8] [5] << " " << world[9] [5] << " " << world[10] [5] << \ "\n6 | " << world[1] [6] << " " << world[2] [6] << " " << world[3] [6] << " " << world[4] [6] << " " << world[5] [6] << " " << world[6] [6] << " " << world[7] [6] << " " << world[8] [6] << " " << world[9] [6] << " " << world[10] [6] << \ "\n7 | " << world[1] [7] << " " << world[2] [7] << " " << world[3] [7] << " " << world[4] [7] << " " << world[5] [7] << " " << world[6] [7] << " " << world[7] [7] << " " << world[8] [7] << " " << world[9] [7] << " " << world[10] [7] << \ "\n8 | " << world[1] [8] << " " << world[2] [8] << " " << world[3] [8] << " " << world[4] [8] << " " << world[5] [8] << " " << world[6] [8] << " " << world[7] [8] << " " << world[8] [8] << " " << world[9] [8] << " " << world[10] [8] << \ "\n9 | " << world[1] [9] << " " << world[2] [9] << " " << world[3] [9] << " " << world[4] [9] << " " << world[5] [9] << " " << world[6] [9] << " " << world[7] [9] << " " << world[8] [9] << " " << world[9] [9] << " " << world[10] [9] << \ "\n10| " << world[1] [10] << " " << world[2] [10] << " " << world[3] [10] << " " << world[4] [20] << " " << world[5] [10] << " " << world[6] [10] << " " << world[7] [10] << " " << world[8] [10] << " " << world[9] [10] << " " << world[10] [10]; return 0; // Returning a vaulue to the function to signify that the function ran without a hitch } //Creating a function that places the cells on the board int cells(){ for(int a=0; a != 11; a++){ world[a] [1] = '-'; // This changes every cell on the x axis on the 1 y coordinate to '-' } for(int b=0; b != 11; b++){ int inc = 0; inc++; world[inc] [b] = '-'; // InC increases the X coordinate, while B stays on the same Y coordinate, changing the whole line to a dash inc++; world[inc] [b] = '-'; // Same as before comment inc++; world[inc] [b] = '-'; inc++; world[inc] [b] = '-'; inc++; world[inc] [b] = '-'; inc++; world[inc] [b] = '-'; inc++; world[inc] [b] = '-'; inc++; world[inc] [b] = '-'; inc++; world[inc] [b] = '-'; inc++; world[inc] [b] = '-'; } return 0; //Returning a value to the function to signify that the function ran without a problem } //Creating function that allows the user to create seed cells. int seeds(){ cout << "\n\nHow many seed cells would you wish to have? "; cin >> Seeds; cout << "\n\nPlease enter the X and Y coordinates for the seed."; cout << "\nX: "; cin >> xSeed[1]; cout << "\nY: "; cin >> ySeed[1]; int SeedY = 1; int q=1; while(SeedY != Seeds){ SeedY++; q++; if(q <= Seeds){ cout << "\n\nPlease enter the X and Y coordinates for the seed."; cout << "\nX: "; cin >> xSeed[q]; cout << "\nY: "; cin >> ySeed[q]; } } int q2 = q; //Alright, variable q is the number of seeds there are in the arrays in the variables xSeed and ySeed, this just assigns that number to a new variable. q = 0; while(q2 != 0){ //Finnally found a way to change all the seed cells to alive on the gameboard, and let the user chose how many he wants! world[xSeed[q2]] [ySeed[q2]] = '+'; q2--; } return 0; } // Function that creates the neighbors of the seed cells :P int birth(){ for (int m = 0; m < 11; m++){ //This will start at 1, making the Y coordinate 1, and will increase each time for (int n = 0; n < 11; n++){ //When the first for loop executes, this one will execute, making the X coordinate 1, and will increase once each thru unctil it is 10. if(world[m] [n] == '-'){ //This checks if a cell (ex. 1,1) is dead, if so it checks if surrounding cells are alive if(world[m++] [n] == '+'){ //Check if 2,1 is alive, if so move on neighbors++; } if(world[m] [n++] == '+'){ //Check if 1,2 is alive if so, make 2,2 alive. neighbors++; } if(world[m--] [n] == '+'){ neighbors++; } else if(world[m] [n--] == '+'){ neighbors++; } else if(world [m++] [n++] == '+'){ neighbors++; } else if(world [m--] [n--] == '+'){ neighbors++; } else if(world [m++] [n--] == '+'){ neighbors++; } else if(world [n--] [m++] == '+'){ neighbors++; } else{ cout << ""; } } if(neighbors == 3){ world[m] [n] = '+'; } } } } int main(){ cells(); //Assigning values to world[] [] gameboard(); //Prints gameboard to screen seeds();//Allows user to be prompted for seed coordinates gameboard(); birth(); gameboard(); cin.sync(); cin.get(); return 0; }