Results 1 to 3 of 3
  1. #1
    LuluMM is offline Member
    Join Date
    Mar 2012
    Posts
    9
    Rep Power
    0

    Default Using StringBuffer

    I have written code that prints out something like this:


    Java Code:
      111111111 2222222 3333333 44444444
      +---------+---------+---------+---------+
    1|            |            |            |            |
    1|            |            |            |            |
    1|            |            |            |            |
      +---------+---------+---------+---------+
    2|            |            |            |            |
    2|            |            |            |            |
    2|            |            |            |            |
      +---------+---------+---------+---------+
    3|            |            |            |            |
    3|            |            |            |            |
    3|            |            |            |            |
      +---------+---------+---------+---------+



    Now I need to store this in a StringBuffer, because this is a game, and I need to know the position of the player at all times. How should I go about this?
    Last edited by JosAH; 05-22-2012 at 10:08 PM. Reason: added [code] ... [/code] tags

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default Re: Using StringBuffer

    Use a two dimensional char array? i.e. char[][]

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Using StringBuffer

    Yeah, as Jos said, with a 2D array, you just need the xy coords of the character. If you really are doing it all in a string buffer, you would need to keep track of row offsets and then a column index. The 2D array would be much easier to work with.

Similar Threads

  1. StringBuffer
    By Dayanand in forum New To Java
    Replies: 9
    Last Post: 03-01-2011, 10:04 AM
  2. How to use a StringBuffer?
    By Hallowed in forum New To Java
    Replies: 5
    Last Post: 02-18-2011, 05:38 AM
  3. How to do this with StringBuffer???
    By mlibot in forum New To Java
    Replies: 2
    Last Post: 03-24-2010, 12:40 AM
  4. Replies: 3
    Last Post: 03-04-2009, 06:03 AM
  5. Replies: 1
    Last Post: 03-03-2009, 05:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •