Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define SIZE 10
- char matrix[SIZE][SIZE] = {
- {'$','@','*','%','&','#','@','#','#','@'},
- {'%','$','@','%','#','%','@','*','&','*'},
- {'#','*','&','*','#','@','@','&','%','@'},
- {'%','@','*','$','%','&','#','*','@','&'},
- {'$','*','&','&','&','@','#','%','*','*'},
- {'#','#','@','#','&','%','*','$','#','#'},
- {'&','$','$','#','@','#','@','$','%','*'},
- {'@','$','$','*','&','$','#','*','#','*'},
- {'%','$','*','@','&','@','&','#','#','#'},
- {'#','@','%','*','#','&','#','$','%','#'}
- };
- char arr[] = {'@','#','$','%','&','*'};
- int i,j,k,m,n;
- int mxa=10,mya=10,mxb=10,myb=10,play=1;
- char chx;
- int main(int argc, char *argv[]) {
- srand(time(NULL));
- reCreateMatrix();
- system("PAUSE");
- return 0;
- }
- // to make the game feel more animated
- waitForIt() { int n; for(n=0;n<30000000;n++); }
- // to make the game feel more animated
- waitForIt2(int times) { int n; for(n=0;n<30000000*times;n++); }
- reCreateMatrix() {
- char r;
- for (i=0; i<SIZE-1; i++) {
- for (j=0;j<SIZE;j++) {
- r = rand_lim(5); // 0 to 5
- matrix[i][j] = arr[r];
- }
- }
- waitForIt();
- doIt();
- }
- doIt() {
- system("cls");
- if(mxa<10||mya<10||mxb<10||myb<10) {
- chx = matrix[mxa][mya];
- matrix[mxa][mya] = matrix[mxb][myb];
- matrix[mxb][myb] = chx;
- }
- int x = 0;
- while(x<SIZE) {
- // Remove vertical matches
- removeVerticals();
- // Remove horizontal matches
- removeHorizontals();
- // Move down
- moveDown(1);
- printf("Ran : %d",x);
- x++;
- }
- //system("cls"); printScreen();
- /*
- printf("Move from:\n");
- printf("Enter X:\n");
- scanf("%d",&mxa);
- printf("Enter Y:\n");
- scanf("%d",&mya);
- printf("Move to:\n");
- printf("Enter X:\n");
- scanf("%d",&mxb);
- printf("Enter Y:\n");
- scanf("%d",&myb);
- play=0;
- if(mxa>9||mya>9||mxb>9||myb>9) {
- printf("Enter a number less than 10 for each value.\n");
- printf("Redirecting....\n");
- waitForIt();
- waitForIt();
- doIt();
- play = 1;
- } else {
- doIt();
- play = 1;
- }*/
- }
- // to print the screen
- printScreen() {
- printf(" | ");
- for (i=0; i<SIZE; i++) {
- printf("%d ",i);
- }
- printf("\n----");
- for (i=0; i<SIZE; i++) {
- printf("--");
- }
- printf("\n");
- for (i=0; i<SIZE; i++) {
- printf("%d | ",i);
- for (j=0;j<SIZE;j++) {
- printf("%c ",matrix[i][j]);
- }
- printf("\n");
- }
- }
- // remove Verticals
- removeVerticals() {
- for (i=0; i<SIZE-2; i++) { //checking only till the third last row
- for (j=0;j<SIZE;j++) {
- if (matrix[i][j] == matrix[i+1][j] && matrix[i+1][j] == matrix[i+2][j]) {
- matrix[i][j] = ' ';
- matrix[i+1][j] = ' ';
- matrix[i+2][j] = ' ';
- }
- }
- }
- }
- // remove Horizontals
- removeHorizontals() {
- for (i=0; i<SIZE; i++) {
- for (j=0;j<SIZE-2;j++) {
- if (matrix[i][j] == matrix[i][j+1] && matrix[i][j+1] == matrix[i][j+2]) {
- matrix[i][j] = ' ';
- matrix[i][j+1] = ' ';
- matrix[i][j+2] = ' ';
- }
- }
- }
- }
- // to move the digits down
- moveDown(int printx) {
- int moved = 0,r;
- for (m=0; m<SIZE; m++) {
- moved = 0;
- for (i=0; i<SIZE-1; i++) {
- for (j=0;j<SIZE;j++) {
- if (matrix[i+1][j] == ' ') {
- matrix[i+1][j] = matrix[i][j];
- matrix[i][j] = ' ';
- moved = 1;
- }
- }
- }
- i=0;
- for (j=0;j<SIZE;j++) {
- r = rand_lim(5); // 0 to 5
- if (matrix[i][j] == ' ') {
- matrix[i][j] = arr[r];
- }
- }
- if(printx==1 && moved==1) {
- system("cls"); printScreen();
- // Remove vertical matches
- removeVerticals();
- // Remove horizontal matches
- removeHorizontals();
- waitForIt();
- moved = 0;
- }
- }
- }
- int rand_lim(int limit) {
- /* return a random number between 0 and limit inclusive.
- */
- int divisor = RAND_MAX/(limit+1);
- int retval;
- do {
- retval = rand() / divisor;
- } while (retval > limit);
- return retval;
- }
Advertisement
Add Comment
Please, Sign In to add comment