我必须创建一副牌来制作扑克牌。我在屏幕上打印时创建的卡片看起来像这样:
----------
|K |
| |
| |
| |
| |
| |
| |
| |
| K|
----------
我的卡输出定义如下:
void deck::cardKing(){
cout << "----------" << endl;
cout << "|K " << setw(7) << "|" << endl;
cout << "|" << setw(9) << "|" << endl;
cout << "|" << setw(9) << "|" << endl;
cout << "|" << setw(9) << "|" << endl;
cout << "|" << setw(9) << "|" << endl;
cout << "|" << setw(9) << "|" << endl;
cout << "|" << setw(9) << "|" << endl;
cout << "|" << setw(9) << "|" << endl;
cout << "|" << setw(9) << "K|" << endl;
cout << "----------" << endl;
}
我的问题是,截至目前,当我打印出整个套牌时,它们就像一条线(垂直)一样:
----------
|3 |
| |
| |
| |
| |
| |
| |
| |
| 3|
----------
----------
|10 |
| |
| |
| |
| |
| |
| |
| |
| 10|
----------
----------
|K |
| |
| |
| |
| |
| |
| |
| |
| K|
----------
当我需要像这样显示它们时:
--------- ---------
|K | |2 |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| K| | 2|
--------- ---------
让卡片水平显示而不是垂直显示的最佳方法是什么?我可以使用卡片的图片而不是仅仅在屏幕上打印出来吗?
答案 0 :(得分:1)
解决这个问题的一种方法是收集每行的内容
'0'
对于每张卡,不要写入屏幕,而是更新卡片线
function presskey(mykey)
keys={'KEY_FIRST ','KEY_LAST ','KEY_PRESSED ','KEY_RELEASED ','KEY_TYPED ','VK_0 ','VK_1 ','VK_2 ','VK_3 ','VK_4 ','VK_5 ','VK_6 ','VK_7 ','VK_8 ','VK_9 ','VK_A ','VK_ACCEPT ','VK_ADD ','VK_AGAIN ','VK_ALL_CANDIDATES ','VK_ALPHANUMERIC ','VK_ALT ','VK_ALT_GRAPH ','VK_AMPERSAND ','VK_ASTERISK ','VK_AT ','VK_B ','VK_BACK_QUOTE ','VK_BACK_SLASH ','VK_BACK_SPACE ','VK_BRACELEFT ','VK_BRACERIGHT ','VK_C ','VK_CANCEL ','VK_CAPS_LOCK ','VK_CIRCUMFLEX ','VK_CLEAR ','VK_CLOSE_BRACKET ','VK_CODE_INPUT ','VK_COLON ','VK_COMMA ','VK_COMPOSE ','VK_CONTROL ','VK_CONVERT ','VK_COPY ','VK_CUT ','VK_D ','VK_DEAD_ABOVEDOT ','VK_DEAD_ABOVERING ','VK_DEAD_ACUTE ','VK_DEAD_BREVE ','VK_DEAD_CARON ','VK_DEAD_CEDILLA ','VK_DEAD_CIRCUMFLEX ','VK_DEAD_DIAERESIS ','VK_DEAD_DOUBLEACUTE ','VK_DEAD_GRAVE ','VK_DEAD_IOTA ','VK_DEAD_MACRON ','VK_DEAD_OGONEK ','VK_DEAD_SEMIVOICED_SOUND ','VK_DEAD_TILDE ','VK_DEAD_VOICED_SOUND ','VK_DECIMAL ','VK_DELETE ','VK_DIVIDE ','VK_DOLLAR ','VK_DOWN ','VK_E ','VK_END ','VK_ENTER ','VK_EQUALS ','VK_ESCAPE ','VK_EURO_SIGN ','VK_EXCLAMATION_MARK ','VK_F ','VK_F1 ','VK_F10 ','VK_F11 ','VK_F12 ','VK_F13 ','VK_F14 ','VK_F15 ','VK_F16 ','VK_F17 ','VK_F18 ','VK_F19 ','VK_F2 ','VK_F20 ','VK_F21 ','VK_F22 ','VK_F23 ','VK_F24 ','VK_F3 ','VK_F4 ','VK_F5 ','VK_F6 ','VK_F7 ','VK_F8 ','VK_F9 ','VK_FINAL ','VK_FIND ','VK_FULL_WIDTH ','VK_G ','VK_GREATER ','VK_H ','VK_HALF_WIDTH ','VK_HELP ','VK_HIRAGANA ','VK_HOME ','VK_I ','VK_INSERT ','VK_INVERTED_EXCLAMATION_MARK ','VK_J ','VK_JAPANESE_HIRAGANA ','VK_JAPANESE_KATAKANA ','VK_JAPANESE_ROMAN ','VK_K ','VK_KANA ','VK_KANJI ','VK_KATAKANA ','VK_KP_DOWN ','VK_KP_LEFT ','VK_KP_RIGHT ','VK_KP_UP ','VK_L ','VK_LEFT ','VK_LEFT_PARENTHESIS ','VK_LESS ','VK_M ','VK_META ','VK_MODECHANGE ','VK_MULTIPLY ','VK_N ','VK_NONCONVERT ','VK_NUM_LOCK ','VK_NUMBER_SIGN ','VK_NUMPAD0 ','VK_NUMPAD1 ','VK_NUMPAD2 ','VK_NUMPAD3 ','VK_NUMPAD4 ','VK_NUMPAD5 ','VK_NUMPAD6 ','VK_NUMPAD7 ','VK_NUMPAD8 ','VK_NUMPAD9 ','VK_O ','VK_OPEN_BRACKET ','VK_P ','VK_PAGE_DOWN ','VK_PAGE_UP ','VK_PASTE ','VK_PAUSE ','VK_PERIOD ','VK_PLUS ','VK_PREVIOUS_CANDIDATE ','VK_PRINTSCREEN ','VK_PROPS ','VK_Q ','VK_QUOTE ','VK_QUOTEDBL ','VK_R ','VK_RIGHT ','VK_RIGHT_PARENTHESIS ','VK_ROMAN_CHARACTERS ','VK_S ','VK_SCROLL_LOCK ','VK_SEMICOLON ','VK_SEPARATER ','VK_SHIFT ','VK_SLASH ','VK_SPACE ','VK_STOP ','VK_SUBTRACT ','VK_T ','VK_TAB ','VK_U ','VK_UNDEFINED ','VK_UNDERSCORE ','VK_UNDO ','VK_UP ','VK_V ','VK_W ','VK_X ','VK_Y ','VK_Z'};
a=(find(~cellfun('isempty',strfind(keys,mykey))));
if ~isempty(a)
mykey=keys{a(1)};
robot = java.awt.Robot;
eval(['robot.keyPress (java.awt.event.KeyEvent.' mykey ')']);
eval(['robot.keyRelease (java.awt.event.KeyEvent.' mykey ')']);
end
end
然后当你需要打印时
enum { eEdge, eTop, eMid, eBot, eMax };
std::ostringstream cardline[eMax];
然后,当你想要一个新的卡片线
void Deck::CardKing()
{
cardline[eEdge] << "--------- ";
cardline[eTop] << "|K | ";
cardline[eMid] << "| | ";
cardline[eBot] << "| K| ";
}