Thread: newbie needs help

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    15

    newbie needs help

    Hello there.

    Im trying to learn C++ and have done some smaller things but wanted to make a little test game and need some help if possible. i wanted to load from a file a gamearea that is 3x3 square with the numbers 1-8 in 8 of the 9 avaliable squares but i have no clue how to do this yet, anyone that can help or give an example ?

  2. #2
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    This would be easier if more information was given. What kind of game? What library (opengl, allegro, so on..)? what for/purpose? etc...

    Example that might get you started (i made this in the reply window so it might be wrong).

    Code:
    int grid[3][3]; //3x3 grid
    int count = 1;
    
    for(int i = 0; i < 3; i++){
         for(int n = 0; n < 3; n++){
              if(i == 2 && n == 2) break; //stops from loading in 9th grid
              grid[i][n] = count; //assign 1-8
              count++;
         }
    }

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    15
    Hey there

    WHat i wanted to try to make is a game in 3*3 squares with 1 number in each square except the last one as i said in the other post. the blank one you are supposed to be able to move around and when you move the blank one where annother number is they switch places, and you win when you have the numbers lined up in order 1 to 8 etc.

    But what i had a problem with then starting this is getting a grid to load from file X why i want it to load from a file at start is becuase it going to make the numberd square be at random places at every start and keep track of what what numbers landed at wich places.

    i the way of looks i was thinking of someting like this

    http://www.imagefrog.net/out.php/i2874_4.jpg

  4. #4
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    Why would you have to load it from a file, unless you wanted to have pre-set grids for different difficulties. But loading from a file would not be random by nature. There is the rand() function (which sometimes doesn't appear too random from my experience). I would probably start by having the user being able to move in different directions, and set the values of the squares depending on the move.

    Pseudocode that should get you started
    Code:
    give user option to move in a direction
    if user tries to move outside grid don't allow it
    else set current square to the square you are moving to
    set moved to square to 0 or w/e you want
    edit: there are a lot of ways to approach the same problem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getting to grips with allegro and ms vc++ (newbie)
    By jimjamjahaa in forum C++ Programming
    Replies: 4
    Last Post: 11-18-2005, 07:49 PM
  2. Newbie in problem with looping
    By nrain in forum C Programming
    Replies: 6
    Last Post: 11-05-2005, 12:53 PM
  3. Newbie Programmer
    By Extropian in forum C++ Programming
    Replies: 3
    Last Post: 05-18-2004, 01:17 PM
  4. C++ newbie / linux not so newbie question
    By goldmonkey in forum C++ Programming
    Replies: 7
    Last Post: 12-13-2003, 12:27 PM
  5. Newbie Game Develpoers Unite!
    By Telenosis in forum Game Programming
    Replies: 10
    Last Post: 06-22-2002, 02:02 PM