微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ncruses mvinch(y,x),奇怪的输出

如何解决ncruses mvinch(y,x),奇怪的输出

我会尽可能清楚地解释我所经历的事情。这是一段代码。最终目标是确定游戏地图中的下一个角色是什么,以及如果对象继续朝那个方向前进(也就是遇到非空白坐标),是否会发生“碰撞” .根据文档 mvinch(y,x) 应该返回一个在平面上给定坐标中的字符。我不明白的是为什么输出似乎不一致。如果我在打印屏幕中有一个空白区域(printBoard() 内的区域,ASCII 输出值为 288。此外,如果为边框打印 ASCII 字符,它也仅在水平方向上显示为 288。任何东西printBoard() 的区域之外是空白的 ASCII 值,这正是我所期望的。有没有办法让它更可预测?我是否错误地使用了 mvinch(x,y)?

#include <ncurses.h>
#include<map>
#include<string>
#include<iostream>

void printBoard();

int main()
{
        char direction = 'w'; //Make this an input.
        initscr();
        scrollok(stdscr,TRUE);
        nodelay(stdscr,TRUE);
        cbreak();
        noecho();
        curs_set(0);
        start_color();
        int boardX;
        int boardY;
        boardX = 10; //replace 10 and 5 with in put to the function for a current position of the object. 
        boardY = 5;

        printBoard();
        while(true)
        {
                if(direction == 'w')
                {
                        boardY++;
                }
                else if(direction == 's')
                {
                        boardY--;
                }
                else if(direction == 'd')
                {
                        boardX++;
                }
                else if(direction == 'a')
                {
                        boardX--;
                }
                int check = mvinch(boardY,boardX);
                int check1 = mvinch(20,20); //<--- values inside board have weird outputs
                int check2 = mvinch(25,50); //<--- values at boarders are not consistant. 
                int check3 = mvinch(60,60);//<-values outside the board have expected outputs.
                int check4 = mvinch(0,0);
                if(check != 288) //<<---- Trial and error found 288 to be whitespace in ncurses????
                {
                        bool collision = true;
                }
        }
}
void printBoard()
{
        int width = 50;
        int height = 25;

//print topline.
        for(int i=0; i<width; i++)
        {
                printw("X");
       }
        printw("\n");
        for(int i=0; i<height-1; i++)
                for(int j =0; j<width; j++)
                {
                        if(j == 0) //Then print a boarder.
                        {
                                printw("X");
                        }
                        else if(j == width -1)
                        {
                                printw("X\n");
                        }
                        else //print whitespace.
                        {
                                printw(" ");
                        }
                }


        for(int i=0; i<width; i++)
        {
                printw("X");

        }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。