slider game

This is a discussion on slider game within the C Programming forums, part of the General Programming Boards category; i have to create a slider game i have made the part where you create non-repeating numbers each time you ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    7

    Post slider game

    i have to create a slider game i have made the part where you create non-repeating numbers each time you run the game:


    Code:
    #include <stdio.h>
    #include<time.h>
    
    int check(int num, int array[4][4]) {
    int i, j;
    
        for (i = 0; i < 4; i++) {
            for (j = 0; j < 4; j++) {
                if (array[i][j] == num) {
                    return 1;
                }
            }
        }
        
        return 2;
    }
    
    
    int main (){
        int x,y,arr[4][4];
        int w;
        int ok=0;
        srand(time(NULL));
    
        for (x=0;x<4;x++)
        {
            for(y=0;y<4;y++)
            {
                if (x ==3 && y ==3) {
                
                    printf("| \t");
                }
                else {
                    ok =1;
                    while (ok!=2) {
                        w = rand()%15+1;
                        ok = check(w, arr);
                    }
                    arr[x][y] = w;
                    printf("|   %i\t",arr[x][y]);
                }
        
            }
            printf("|\n");
        }
    i have to now assigne keys to move the numbers about
    can sum help me in doing this.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I remember a scifi show by that name, but not a game. What is the object of the game?

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    7
    you have to arrange the numbers in ascending order by moving the numbers around.

    i basically want to achieve this:
    How to do a sliding puzzle - YouTube

    i want to know how to assign keys to move the numbers up,down,left right.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Adak View Post
    I remember a scifi show by that name, but not a game. What is the object of the game?
    Fifteen puzzle - Wikipedia, the free encyclopedia

    Not really suited to console mode... but I guess an interesting challenge anyway.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I liked using getche() from conio.h, to get the keys, and had a menu like this:

    Code:
      do {
        gotoxy(54,12);
        printf("                       ");
        gotoxy(5,12);
        printf("Moves are: up, down, left, or right (q to quit) [u/d/l/r/q]: ");
        //scanf(" %c", &ch);
        ch = getche();
    //    r = getchar();
        switch (ch) {
          case 'u': up(); break;
          case 'd': down(); break;
          case 'l': left(); break;
          case 'r': right(); break;
          case 'q': return;
          default: 
            gotoxy(5,12);
            printf("That's not a move, please try again                             ");
            sleep(1);
        }
        printGrid();
      }while(!isDone());
    Other alternatives are to use getchar() or even scanf() (but remember to add the getchar() after them to remove the trailing newline from the keyboard buffer).

    Do you have conio.h on your compiler's header files?

    I recall playing with one while we drove across crountry as a kid. The odd thing about this puzzle is that it has a "left" and "right" arrangement to it. The "right" way, you can solve it. If it's set up with the "left" type of configuration, it can not be solved, though you try your hardest. It will always be one tile out of place. Google on that (but they don't call it left and right configuration, they have high-faluting names for it, of course).

    Rather famously, some guy made zillions of these sliding puzzles, and they were pre-set so you couldn't solve them! Had everybody scratching their heads for a long while. It was a fad, back in the 50's.
    Last edited by Adak; 11-19-2011 at 03:25 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Slider Puzzle (Unfinished)
    By Oldman47 in forum Game Programming
    Replies: 2
    Last Post: 04-19-2008, 12:00 PM
  2. Double Sticked Slider
    By AtomRiot in forum Windows Programming
    Replies: 0
    Last Post: 11-27-2004, 03:18 PM
  3. List box slider moving downwards
    By cfriend in forum Windows Programming
    Replies: 2
    Last Post: 09-16-2004, 11:31 PM
  4. How do you make a 'Slider' control?
    By Okiesmokie in forum Windows Programming
    Replies: 4
    Last Post: 04-26-2002, 04:49 PM
  5. MFC Slider control
    By Dual-Catfish in forum Windows Programming
    Replies: 0
    Last Post: 03-21-2002, 12:10 PM

Tags for this Thread


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