Thread: Help with Arrays

  1. #1
    Registered User
    Join Date
    Apr 2016
    Posts
    48

    Help with Arrays

    So, I am a newbie in programming in C. Not even sure if i should post this in C or Game section because it seems like I am lacking basic skills.
    The problem is I have to give in this school project. It the project i have to make a game where my character walks in the 2D array(map) and has to retrieve a certain object to win it.

    My doubts right now are :
    -How do I insert this "Character" in the array ( i think i now how to make him move in there ).
    -How to insert hazards in the array ( traps that would kill the character if he goes on them ).

  2. #2
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Quote Originally Posted by MrPecanha View Post

    -How do I insert this "Character" in the array ( i think i now how to make him move in there ).
    -How to insert hazards in the array ( traps that would kill the character if he goes on them ).
    I think you question is fit for this sub-forum.

    Assuming you have a 2D array of characters, the parts of the map which don't contain hazards could be represented by say a '0', the character itself represented by say 'c' and finally the hazards represented by an 'r'.

    You should then do all the checks from within the array, change the position of the character in the array based on the user input and finally, if you like, to map the array contents onto a real window.

    That said, you would get better and more helpful responses here if you posted the code you have already written and say what you have tried.

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Quote Originally Posted by MrPecanha View Post
    -How do I insert this "Character" in the array ( i think i now how to make him move in there ).
    You just assign the character to the desired array position.

    For example, using a single-dimension array:

    Code:
    char array[8];
    You would assign the character 'x' to the fifth element like so:

    Code:
    array[4] = 'x';
    Quote Originally Posted by MrPecanha View Post
    -How to insert hazards in the array ( traps that would kill the character if he goes on them ).
    In a similar fashion to the previous answer.

    I suggest you create a function that prints the array in a neat format. Thus, you can easily view the results of assignments and modifications as you develop your code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-11-2013, 10:57 PM
  2. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  3. Passing pointers to arrays of char arrays
    By bobthebullet990 in forum C Programming
    Replies: 5
    Last Post: 03-31-2006, 05:31 AM
  4. Replies: 2
    Last Post: 02-23-2004, 06:34 AM
  5. separating line of arrays into array of arrays
    By robocop in forum C++ Programming
    Replies: 3
    Last Post: 10-20-2001, 12:43 AM