2

Is there a way or function available which would stop me from going over the characters. The maze looks like the following below. I actually dont use printf, but mvprint. I just used printf as an example below.

printf("xxxxxx x");
printf("xxxxxx x");
printf("xxxxxx x");
printf("x      x");
printf("x xxxxxx");
printf("x xxxxxx");

I tried the this code below but it doesn't seem to work. The cursor still goes over the x characters. In the third line of the code you can see I've said that if there is a character 'f' there which is created by the bunch of printf statements seen above, the cursor shouldn't move. This doesn't seem to work.

if(m == 's')
{
    if((oldy+1,x)=='x') // This is the part of the code where i say that if the next spot is an 'x' dont move.
    {
        mvprint(win, 10,0,"Sorry, you cant move there.");   
        refresh(win);
    }
    else
    {
        move((y= oldy+1),x);
        refresh();
        oldy = y;
    }
}
user3753834
  • 277
  • 2
  • 5
  • 11
  • `if(oldy+1,x)=='x')` Isn't this line missing a `(`? – Andrew_CS Jul 09 '14 at 12:47
  • Yea, I fixed it, it was just a typing error on the site. It had no affect when the code though. – user3753834 Jul 09 '14 at 12:53
  • That's why I put it as a comment and not an answer ;) – Andrew_CS Jul 09 '14 at 12:54
  • Ty :). And.. How is this question flagged as a duplicate? Its asking totally different things. – user3753834 Jul 09 '14 at 12:58
  • 1
    "if you use **printf** or any other non-curses method of putting text on the screen (including a system call to another program that uses curses) you will not be able to read the content of the screen." - Appears you may need to switch from `printf`. – Andrew_CS Jul 09 '14 at 13:01
  • I'm not sure why it's a duplicate either. – Andrew_CS Jul 09 '14 at 13:02
  • Does this mean no one else can see my questio now since its marked a sa duplicate? What should I do? – user3753834 Jul 09 '14 at 13:05
  • 1
    I'm guessing that `(oldy+1,x)` is the problem, since there's no function. You're just testing `x`, due to the comma operator, and `x` is very unlikely to be 120 ('x'). I forget the _what character is at this location_ function, though. – John C Jul 25 '14 at 20:33

1 Answers1

1

After a little bit of research, I think you want your inner condition to be:

if(mvinch(oldy+1,x) == 'x')

The mvinch(y,x) function moves and returns the character at that location.

Also, as other people mentioned, mixing standard I/O and Curses is unreliable at best. When I tried something like this on my machine to test, my program told me that the entire screen was made up of spaces.

John C
  • 1,931
  • 1
  • 22
  • 34