Two Questions (They never end... -,-)

This is a discussion on Two Questions (They never end... -,-) within the C++ Programming forums, part of the General Programming Boards category; (WinXP, Borland C++ Free Command Line Compiler) Ok, I'm trying to initialize my game based off a 2d array. (25x80). ...

  1. #1
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379

    Two Questions (They never end... -,-)

    (WinXP, Borland C++ Free Command Line Compiler)

    Ok, I'm trying to initialize my game based off a 2d array. (25x80). I would rather not have to initialize every peice like
    Code:
    Map[0][0] = 0;
    Map[0][1] = 0;
    ...
    Map[18][3] = 1;
    I realize I will have to type in each array value by hand, but its there any way to initialize the array like:

    Code:
    int main() {
     int Map[25][80] = { 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0, ect}
    When I try to compile that, my compiler goes nuts, so I guess I'm either doing some wrong, or that type of initializing an array is impossible?

    And my second question;

    So far, I have been using getch() to detect for arrow keys. However, as I start using more advance code, getch() isint really working. What I'm trying to do is detect for multiple arrows/keys. So when I hold down the up and down arrow, it doesnt detect only the one I presses first. Not sure, but I dont think getch() is capable of this.

    Well thank you again for your help!
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,806
    You can initialize a 2-D array. As an example:
    Code:
    int array[3][4] = { {0,1,2,3}, {4,5,6,7}, {8,9,10,11} };
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    Ouch... This is gunna be hard -,-... Now I just need to make a program that tell me every time I hit a character every 120 times... -,-.
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  4. #4
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    So far, I have been using getch() to detect for arrow keys. However, as I start using more advance code, getch() isint really working. What I'm trying to do is detect for multiple arrows/keys. So when I hold down the up and down arrow, it doesnt detect only the one I presses first. Not sure, but I dont think getch() is capable of this.
    Maybe you should use a nonstandard function...For instance GetAsyncKeyState in windows.h

  5. #5
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    Ah, thank you both!
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    113
    If you have to initialise it to zero ie.one number only use a nested for loop instead

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    If you have to initialise it to zero ie.one number only use a nested for loop instead
    Or better yet, memset().
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198
    ooh ooh ooh! i can't believe nobody has said this yet... for the initialization, you can just declare the map like this:
    Code:
    Map[25][80] = {0};
    everything is initialized to 0. but that only works if you want everything to be 0. it won't exactly work the same with any other number.
    Last edited by linucksrox; 01-16-2006 at 02:10 PM.
    "What are all you parallelograms doing here?" - Peter Griffin (to Joe and his wheelchair buddies)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Modify to make Doubly Linked List
    By Dampecram in forum C Programming
    Replies: 10
    Last Post: 11-03-2008, 07:25 PM
  3. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 05:14 AM
  4. Burning fire effect
    By Alexthunder in forum C Programming
    Replies: 9
    Last Post: 11-09-2005, 12:18 PM
  5. singly linked to doubly linked
    By jsbeckton in forum C Programming
    Replies: 10
    Last Post: 11-06-2005, 07:47 PM

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