I'm making a pacman video game and I would like to display the game board using the printw command from the ncurses library (Linux). I am not able to do this as the printw function only accepts a const char input and my map is a string type.
I've been trying to make the map a 2d array type char array but have been unsuccessful. I've also tried to convert string type to char but no luck.
Code:
#include <iostream>
#include <stdio.h>
#include <string>
#include "pacman.h"
#include <ncurses.h>
using namespace std;
string map[31] = {
"┌────────────┐┌────────────┐",
"│⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅││⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅│",
"│⋅┌──┐⋅┌───┐⋅││⋅┌───┐⋅┌──┐⋅│",
"│∙│ │⋅│ │⋅││⋅│ │⋅│ │∙│",
"│⋅└──┘⋅└───┘⋅└┘⋅└───┘⋅└──┘⋅│",
"│⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅│",
"│⋅┌──┐⋅┌┐⋅┌──────┐⋅┌┐⋅┌──┐⋅│",
"│⋅└──┘⋅││ └──┐┌──┘⋅││⋅└──┘⋅│",
"│⋅⋅⋅⋅⋅⋅││⋅⋅⋅⋅││⋅⋅⋅⋅││⋅⋅⋅⋅⋅⋅│",
"└────┐⋅│└──┐ ││ ┌──┘│⋅┌────┘",
" │⋅│┌──┘ └┘ └──┐│⋅│ ",
" │⋅││ ││⋅│ ",
" │⋅││ ┌──────┐ ││⋅│ ",
"─────┘⋅└┘ │ │ └┘⋅└─────",
" ⋅ │ │ ⋅ ",
"─────┐⋅┌┐ │ │ ┌┐⋅┌─────",
" │⋅││ └──────┘ ││⋅│ ",
" │⋅││ ││⋅│ ",
" │⋅││ ┌──────┐ ││⋅│ ",
"┌────┘⋅└┘ └──┐┌──┘ └┘⋅└────┐",
"│⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅││⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅│",
"│⋅┌──┐⋅┌───┐⋅││⋅┌───┐⋅┌──┐⋅│",
"│⋅└─┐│⋅└───┘⋅└┘⋅└───┘⋅│┌─┘⋅│",
"│∙⋅⋅││⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅││⋅⋅∙│",
"└─┐⋅││⋅┌┐⋅┌──────┐⋅┌┐⋅││⋅┌─┘",
"┌─┘⋅└┘⋅││⋅└──┐┌──┘⋅││⋅└┘⋅└─┐",
"│⋅⋅⋅⋅⋅⋅││⋅⋅⋅⋅││⋅⋅⋅⋅││⋅⋅⋅⋅⋅⋅│",
"│⋅┌────┘└──┐⋅││⋅┌──┘└────┐⋅│",
"│⋅└────────┘⋅└┘⋅└────────┘⋅│",
"│⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅│",
"└──────────────────────────┘"
};
int main()
{
// ncurses libary functions
initscr();
// Draw Map
for (unsigned int i = 0; i < (sizeof(map) / sizeof(map[0])); i++)
{
mvprintw(i, 25, map[i]); // unable to do this because map is not a const char
}
refresh();
getch();
endwin();
return 0;
}
If anyone has any suggestions could they please post the code so I get get a better idea as I am new to C++.