コード:
#include <iostream> //入出力関連ヘッダ
#include <string> //文字列関連ヘッダ
#include <Windows.h> //windowsAPI使用ヘッダ
int main()
{
const int Npage = 2; // 50音表ページ
const int Nx = 13; //50音表列
const int Ny = 5; //50音表行
const std::string Chars[Npage][Ny][Nx] = {
{
"あ", "か", "さ", "た", "な", "は", "ま", "や", "ゃ", "ら", "わ","ぁ", " ",
"い", "き", "し", "ち", "に", "ひ", "み", " ", " ", "り", "を","ぃ", " ",
"う", "く", "す", "つ", "ぬ", "ふ", "む", "ゆ", "ゅ", "る", "ん","ぅ", " ",
"え", "け", "せ", "て", "ね", "へ", "め", " ", " ", "れ", "゛","ぇ", " ",
"お", "こ", "そ", "と", "の", "ほ", "も", "よ", "ょ", "ろ", "゜","ぉ", " "
},{
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
"(", ")", "'", "@", "/", " ", ".", ",", "-", "!", "?", "<", ">"
}
};
int PosPage = 0;
int PosX = 0;
int PosY = 0;
std::string CurrStr;
bool bRedraw = true; //審議判定
while (1)
{
if (bRedraw)
{
bRedraw = false;
system("cls");
for (int y = 0; y<Ny; y++)
{
for (int x = 0; x<Nx; x++)
{
if (x == PosX && y == PosY)
{
std::cout << '[' << Chars[PosPage][y][x] << ']';
}
else
{
std::cout << ' ' << Chars[PosPage][y][x] << ' ';
}
}
std::cout << std::endl;
}
std::cout << std::endl << CurrStr;
}
//key
if (GetAsyncKeyState(VK_ESCAPE))break;
if (GetAsyncKeyState(VK_UP))
{
PosY = (PosY>0 ? PosY - 1 : Ny - 1); bRedraw = true;
}
else if (GetAsyncKeyState(VK_DOWN))
{
PosY = (PosY<Ny - 1 ? PosY + 1 : 0); bRedraw = true;
}
else if (GetAsyncKeyState(VK_LEFT))
{
PosX = (PosX>0 ? PosX - 1 : Nx - 1); bRedraw = true;
}
else if (GetAsyncKeyState(VK_RIGHT))
{
PosX = (PosX<Nx - 1 ? PosX + 1 : 0); bRedraw = true;
}
else if (GetAsyncKeyState(VK_RETURN))
{
CurrStr.push_back('\n'); bRedraw = true;
}
else if (GetAsyncKeyState(VK_BACK))
{
if (CurrStr.size() >= 2) // そのままだとstd::out_of_rangeがthrowされたので追加
CurrStr = CurrStr.erase(CurrStr.size()-2); bRedraw = true;
}
else if (GetAsyncKeyState(VK_SPACE))
{
CurrStr += Chars[PosPage][PosY][PosX]; PosPage = (PosPage + 1) % Npage; bRedraw = true;
}
Sleep(50);
}
//
return 0;
}