some basic things

This is a discussion on some basic things within the C++ Programming forums, part of the General Programming Boards category; i just wanted to make a program that can move a '-' according to directional key input.. but i dont ...

  1. #1
    Registered User n3cr0_l0rd's Avatar
    Join Date
    Feb 2009
    Posts
    62

    some basic things

    i just wanted to make a program that can move a '-' according to directional key input.. but i dont know how to take input of the direction keys...
    Code:
    key = getch ();
    if (key == ????).....
    eh, is there any alternative to getch () ?

    and how do i change the current cursor position... i remeber using gotoxy(int , int) while i was doing C in borland 5.02 but it doesn't work now with codeblocks...
    I had crush on her, before that crush could CRUSH me, i CRUSHED that crush !!! Fun time over, Lets find a way to not to blow off the whole leg !

    __________________________________________________ __________________________________________________ _______________

    In C++ it's harder to shoot yourself in the foot, but when you do, you blow off your whole leg.
    - Bjarne Stroustrup

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    You need to use a library like ncurses.

  3. #3
    Registered User n3cr0_l0rd's Avatar
    Join Date
    Feb 2009
    Posts
    62
    i had expected it to be an easy job... isnt there any other way?
    I had crush on her, before that crush could CRUSH me, i CRUSHED that crush !!! Fun time over, Lets find a way to not to blow off the whole leg !

    __________________________________________________ __________________________________________________ _______________

    In C++ it's harder to shoot yourself in the foot, but when you do, you blow off your whole leg.
    - Bjarne Stroustrup

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    There are probably other ways, but I doubt any of them will be easier. You are looking for non-standard behavior. In other words, the C++ language does not provide the functionality you are looking for, so you need to use a third party library, or call OS specific functions (which is pretty much what the library would do for you).

  5. #5
    Registered User Sharke's Avatar
    Join Date
    Jun 2008
    Location
    NYC
    Posts
    303
    If you're using Windows, look in the Win32 forum for the useful links post, one of the links is a great tutorial which goes into setting cursor positions, reading keyboard input, changing colors etc. I'd post the link but I'm on my freaking Blackberry.

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    If you're using Windows, and you're using Microsoft's compiler or gcc (e.g. Dev-C++ or Code::Blocks), you can do it (albeit unportably). Cprogramming.com FAQ > How can I get input without having the user hit [Enter]?

    With Dev-C++, for example, you can use getche() (which unfortunately echos the character too), or Windows code to emulate getch().

    Then you have to figure out what the key sequences are for the arrow keys.

    You might be interested in this simple text editor I wrote a long time ago. The PLATFORM_WINDOWS code is the code you need for Dev-C++.

    [edit] I stripped the source code because it's pretty long. See attached file instead. [/edit]

    [edit=2] P.S. Traditionally the player is represented with a '@', if it's a rogue-like. [/edit]
    Attached Files Attached Files
    Last edited by dwks; 06-19-2009 at 11:40 AM.
    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.

  7. #7
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Here's the first page I found with a google search of "getch arrow keys"
    How do you check if arrow keys are pressed? - C
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  8. #8
    Registered User n3cr0_l0rd's Avatar
    Join Date
    Feb 2009
    Posts
    62
    huh... after a short 2 days vacation i finally figured it out.. i will use getch() to input keys (for now wsad, will go for arrow keys shortly) and create a function gotoxy using windows.h faq lvl 2 : how to ...
    Thx
    I had crush on her, before that crush could CRUSH me, i CRUSHED that crush !!! Fun time over, Lets find a way to not to blow off the whole leg !

    __________________________________________________ __________________________________________________ _______________

    In C++ it's harder to shoot yourself in the foot, but when you do, you blow off your whole leg.
    - Bjarne Stroustrup

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. noob with basic q's
    By SimplyComplex in forum C++ Programming
    Replies: 8
    Last Post: 11-19-2006, 12:17 PM
  2. Basic things I need to know
    By maxorator in forum C++ Programming
    Replies: 53
    Last Post: 10-15-2006, 04:39 PM
  3. what are your thoughts on visual basic?
    By orion- in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-22-2005, 04:28 AM
  4. visual basic vs C or C++
    By FOOTOO in forum Windows Programming
    Replies: 5
    Last Post: 02-06-2005, 07:41 PM
  5. Basic Window Creation, Dev C++ 4.9.9.0 Linking Error
    By Tronic in forum Windows Programming
    Replies: 2
    Last Post: 11-27-2004, 05:03 PM

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