From d503223261e8014c18e2d3e0df4e0971e2552f14 Mon Sep 17 00:00:00 2001 From: KILNETA <47145154+KILNETA@users.noreply.github.com> Date: Sun, 6 Jun 2021 23:29:42 +0800 Subject: [PATCH] Complete game flow v2.0 Complete game flow v2.0 --- Main.cpp | 15 +- MultiplayerGame.cpp | 556 +++++++++++++++++++++++++++++++++++--------- Player.cpp | 17 ++ Player.h | 6 + Title.cpp | 88 ++++++- 5 files changed, 563 insertions(+), 119 deletions(-) diff --git a/Main.cpp b/Main.cpp index 096b77a..21d3c07 100644 --- a/Main.cpp +++ b/Main.cpp @@ -3,7 +3,9 @@ #include extern void Title(); //片頭 (Title.cpp) -extern void MultiplayerGame(); //片頭 (Title.cpp) +extern int MainScreen();//主畫面 (Title.cpp) +extern void Enactment();//設定 +extern void MultiplayerGame(); //多人遊戲 (MultiplayerGame.cpp) #include #include @@ -14,5 +16,14 @@ using namespace std; int main() { - MultiplayerGame(); + while (1) + { + switch (MainScreen()) + { + case 1:break;//單 人 遊 戲 + case 2:MultiplayerGame(); break;//多 人 遊 戲 + case 3:break;//設 置 + case 4: return 0; break;//離 開 遊 戲 + } + } } diff --git a/MultiplayerGame.cpp b/MultiplayerGame.cpp index e1ba770..dd79de5 100644 --- a/MultiplayerGame.cpp +++ b/MultiplayerGame.cpp @@ -1,24 +1,40 @@ #include #include #include -#include #include #include - +#include #include "Card.h" #include "Player.h" using namespace std; /*Function索引*/ -void MultiplayerGame();//遊戲函式 -int PlayerNumber();//問幾個玩家 -void ShufflePoker();//洗牌 -void inputPublicCard();//發公牌 -void lostCard();//蓋牌 -void inputPlayerCard();//發手牌 -void ShowPublicCard(vector publicCard);//印出公牌 +//移動 輸入處 +#include +#include +#pragma comment(lib,"winmm.lib") + +void gotoxyGame(double x, double y) +{ // the type is double, so objects can move less than 1 unit + HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); + COORD dwPos; + dwPos.X = x; // start from 0 + dwPos.Y = y; // start from 0 + SetConsoleCursorPosition(hCon, dwPos); +} +void MultiplayerGame();//遊戲函式 +int PlayerNumber();//問幾個玩家 +void inputPlayerNullData();//創造空值玩家資料 V +void ShufflePoker();//洗牌 V +void GameInterface();//印遊戲介面 +void inputPublicCard();//發公牌 V +void lostCard();//蓋牌 V +void inputPlayerCard();//發手牌 V +void ShowPublicCard();//印出公牌 +void ShowPlayerOperating(int playerNumber);//印出所有玩家上一次的操作記錄 void ShowPlayerCard(int playerNumber);//印出手牌 +void HidePlayerCard();//手牌隱藏 void MaxWinCards(int playerNumber);//印最佳牌型 void ShowMaxWinCards(int playerNumber);//最佳牌型 展示 void ShowWinner();//最贏 @@ -29,14 +45,16 @@ void RecordingMaxWinNumber(int *compareNum, int cardNumber);//記錄勝算編號 /*Function索引*/ /*公用參數*/ -vector publicCard; -vector player; -const int NUMBER_OF_CARDS = 52; -Card poker[52]; -const int player_number = PlayerNumber(); -static int cardNumber = 0; -int AllBet = 0; -int Around = 0; +int x = 0, y = 0; +vector publicCard; //可擴充的公牌 +vector player;//可擴充的player +const int NUMBER_OF_CARDS = 52; //poker牌有52張 +Card poker[NUMBER_OF_CARDS]; //52張Class poker牌 +int player_number = PlayerNumber(); //玩家數 +static int cardNumber = 0; //當前已用卡號至 +int AllBet = 0; //彩池 +int LastBet = 0; //上一注金額 +int Around = 0; //回合數 /*公用參數*/ //////////////////////////// Functions //////////////////////////////////// @@ -47,8 +65,15 @@ int PlayerNumber() int player = 0; cout << "有幾個人: " << endl; cin >> player; + system("cls"); return player; } +//創造空值玩家資料 +void inputPlayerNullData() +{ + Player playertest; + for (int i = 0; i < player_number; i++) { player.push_back(playertest); } +} //洗牌 void ShufflePoker() { @@ -74,35 +99,184 @@ void ShufflePoker() poker[i].setNumber(deck[i] % 13); //輸入數字 } } +//印遊戲介面 +void GameInterface() +{ + gotoxyGame(x, y + 1); + cout << " __________ __________ __________ __________ __________ " << endl; + cout << " 公牌 | || || || || |" << endl; + cout << " | || || || || |" << endl; + cout << " | || || || || |" << endl; + cout << " | || || || || |" << endl; + cout << " | || || || || |" << endl; + cout << " | || || || || |" << endl; + cout << " |__________||__________||__________||__________||__________|" << endl << endl; + for (int y1 = 0; y1 < 25; y1++) + { + gotoxyGame(x + 68, y + y1); cout << "|"; + } + gotoxyGame(x + 37, y + 12); cout << " ______________________________"; + for (int y1 = 13; y1 < 25; y1++) + { + gotoxyGame(x + 37, y + y1); cout << "|"; + } + gotoxyGame(x, y + 12); + cout << " __________ __________" << endl; + cout << " 手牌 | || |" << endl; + cout << " | || |" << endl; + cout << " | || |" << endl; + cout << " | || |" << endl; + cout << " | || |" << endl; + cout << " | || |" << endl; + cout << " |__________||__________|" << endl << endl; +} //印出公牌 -void ShowPublicCard(vector publicCard) +void ShowPublicCard() { - string suits[] = { "愛心","方塊","梅花","黑桃" }; - string ranks[] = { "A","2","3","4","5","6","7","8","9","10","J","Q","K" }; - - cout << "--------------------------PublicCard"<< endl; + string species[] = { "紅心","方塊","梅花","黑桃" }; + string ranks[] = { "A"," 2","3","4","5","6","7","8","9","10","J","Q","K" }; for (int i = 0; i < publicCard.size(); i++) { - cout << suits[publicCard[i].getSpecies()] << " " <> addBet; + if (addBet > (LastBet*2)) + { + LastBet = addBet; + gotoxyGame(x + 50, y + 15); + Sleep(1000); + return addBet; + } + else + { + gotoxyGame(x + 53, y + 19); cout << "加注失敗 !"; + Sleep(1000); + gotoxyGame(x + 53, y + 19); cout << " "; + } + } +} +//玩家操作 +void PlayerOperating(int playerNumber) +{ + gotoxyGame(x + 40, y + 15); cout << "R 加 注  "; + gotoxyGame(x + 40, y + 17); cout << "C 跟 注  "; + gotoxyGame(x + 40, y + 19); cout << "S 過 牌  "; + gotoxyGame(x + 40, y + 21); cout << "F 蓋 牌  "; + gotoxyGame(x + 53, y + 17); cout << LastBet<<" $"; + gotoxyGame(x + 79, y + 24); + while(1){ + if (player[playerNumber].getLastOperation()==0){return;}//此玩家已棄牌 + switch (_getch()) + { + case 114://加 注 + gotoxyGame(x + 38, y + 15); cout << ">"; + //進加注介面(未寫) + for (int i = 0; i < player_number; i++) + { + if (player[i].getEnd() == true ) + { + player[i].setEnd(false); + } + } + player[playerNumber].setEnd(true); + player[playerNumber].setLastOperation(1); + Sleep(2000); gotoxyGame(x + 38, y + 15); cout << " "; + return; + break; + case 99://跟 注 + gotoxyGame(x + 38, y + 17); cout << ">"; + AllBet += LastBet; + player[playerNumber].setLastOperation(2); + Sleep(2000); gotoxyGame(x + 38, y + 17); cout << " "; + return; + break; + case 115://過 牌 + gotoxyGame(x + 38, y + 19); cout << ">"; + player[playerNumber].setLastOperation(3); + Sleep(2000); gotoxyGame(x + 38, y + 19); cout << " "; + return; + break; + case 102://蓋 牌 + gotoxyGame(x + 38, y + 21); cout << ">"; + player[playerNumber].setLastOperation(0); + Sleep(2000); gotoxyGame(x + 38, y + 21); cout << " "; + return; + break; + } + } +} +//大小盲注 +void PlayerBlind(int playerNumber) +{ + static int Blind = 1;//盲注 + switch (Blind) + { + case 1: + gotoxyGame(x + 40, y + 15); cout << "B 小 盲 注"; + gotoxyGame(x + 79, y + 24); + break; + case 2: + gotoxyGame(x + 40, y + 15); cout << "B 大 盲 注"; + gotoxyGame(x + 58, y + 15); cout << LastBet * 2 << " $"; + gotoxyGame(x + 79, y + 24); + break; + } + while (1) { + if (player[playerNumber].getLastOperation() == 0) { return; }//此玩家已棄牌 + switch (_getch()) + { + case 98://小 盲 注 + if (Blind == 1) + { + gotoxyGame(x + 38, y + 15); cout << ">"; + //進加注介面(未寫) + player[playerNumber].setLastOperation(4); + Sleep(2000); gotoxyGame(x + 38, y + 15); cout << " "; + Blind++; + } + else//大 盲 注 + { + gotoxyGame(x + 38, y + 15); cout << ">"; + player[playerNumber].setLastOperation(5); + AllBet += LastBet * 2; + Sleep(2000); gotoxyGame(x + 38, y + 15); cout << " "; + Blind++; + } + return; + break; + } + } +} +//驗證 +void Verification() +{ + srand(time(0)); //取時間 + int verificationNumber = (rand()%36)+1; + if(verificationNumber>=1 && verificationNumber <= 10) + { + verificationNumber += 47; + } + else { + if (verificationNumber >= 11 && verificationNumber <= 36) + { + verificationNumber += 86; + } + } + gotoxyGame(x + 10, y + 16); cout << "驗證:"; + gotoxyGame(x + 24, y + 16); cout << char(verificationNumber); + gotoxyGame(x + 79, y + 24); + while (1) + { + if (_getch()== verificationNumber) + { + gotoxyGame(x + 10, y + 16); cout << " "; + gotoxyGame(x + 24, y + 16); cout << " "; + return; + } + } +} +// +bool CheckAddBet() +{ + for (int i = 0; i < player_number; i++) + { + if (player[i].getEnd() == true) + { + return true; + } + } + return false; +} +// +void Revert_CheckAddBet_and_PlayerOperating() +{ + for (int i = 0; i < player_number; i++) + { + player[i].setEnd(false); + player[i].setLastOperation(-1); + } +} //遊戲函式 void MultiplayerGame() @@ -341,96 +680,91 @@ void MultiplayerGame() int Place_a_bet = 0; int winPlayer = 0; int Maxwin = 0; + /*初始遊戲*/ ShufflePoker(); //洗牌function - - Player playertest; - for (int i = 0; i < player_number; i++) + inputPlayerNullData(); //初始玩家Data + GameInterface(); // 初始遊戲介面 + /*初始遊戲*/ + ShowPlayerOperatinglist(); + gotoxyGame(x + 79, y + 24); + //盲注time start + gotoxyGame(x + 71, y); cout << "盲 注"; + for (int i = 0; i < 2; i++) { - player.push_back(playertest); + ShowPlayerOperating(i); + PlayerBlind(i); + HidePlayerCard(); } - - cout << "目前彩池" << AllBet << " Player " << 1 << endl; - cout << "小盲注下多少: "; - cin >> Place_a_bet; - AllBet += Place_a_bet; - cout << endl << endl << "按任意鍵下一位" << endl; - _getch(); - - system("cls"); - cout << "目前彩池" << AllBet << " Player " << 2 << endl; - cout << "強制下大盲注: "<< Place_a_bet*2; - AllBet += (Place_a_bet*2); - cout << endl << endl << "按任意鍵下一位" << endl; - _getch(); - - inputPlayerCard(); - //印自己+下注 - for (int j = 2; j < player_number; j++) + inputPlayerCard();//發手牌 + //盲注time over + /*第一回合 start*/ + Around++; gotoxyGame(x + 71, y); cout << "第 " << Around << " 局"; + //發手牌後由第3位玩家開始下注 (只有兩位玩家會跳過此步) + for (int i = 2; i < player_number; i++) { - system("cls"); - cout << "目前彩池" << AllBet <<" Player "<< j+1 << endl; - ShowPlayerCard(j); - cout << "下注多少: "; - cin >> Place_a_bet; - AllBet += Place_a_bet; - cout << endl << endl << "按任意鍵下一位" << endl; - _getch(); + ShowPlayerOperating(i); + Verification(); + ShowPlayerCard(i); + PlayerOperating(i); + HidePlayerCard(); } - for (int j = 0; j < 2; j++) + for (int i = 0; i < 2; i++) { - system("cls"); - cout << "目前彩池" << AllBet << " Player " << j+1 << endl; - ShowPlayerCard(j); - cout << "下注多少: "; - cin >> Place_a_bet; - AllBet += Place_a_bet; - cout << endl << endl << "按任意鍵下一位"<> Place_a_bet; - AllBet += Place_a_bet; - cout << endl << endl << "按任意鍵下一位" << endl; - _getch(); - } - Around++; - lostCard(); inputPublicCard(); ;//棄一牌 發公牌+1 - for (int j = 0; j < player_number; j++) - { - system("cls"); - cout << "目前彩池" << AllBet << " Player " << j + 1 << endl; - ShowPublicCard(publicCard); - ShowPlayerCard(j); - cout << "下注多少: "; - cin >> Place_a_bet; - AllBet += Place_a_bet; - cout << endl << endl << "按任意鍵下一位" << endl; - _getch(); - } - Around++; - lostCard(); inputPublicCard(); ;//棄一牌 發公牌+1 - for (int j = 0; j < player_number; j++) + /*第一回合 end*/ + /*第二~四回合 start*/ + for(int tep=0;tep<3;) { - system("cls"); - cout << "目前彩池" << AllBet << " Player " << j + 1 << endl; - ShowPublicCard(publicCard); - ShowPlayerCard(j); - cout << "下注多少: "; - cin >> Place_a_bet; - AllBet += Place_a_bet; - cout << endl << endl << "按任意鍵下一位" << endl; - _getch(); - } - Around++; + Revert_CheckAddBet_and_PlayerOperating(); + ShowPlayerOperatinglist(); + bool around_cards=true; + if (tep == 0) + { + lostCard(); inputPublicCard(); inputPublicCard(); inputPublicCard();//棄一牌 發公牌*3 + ShowPublicCard();//開公牌 + } + else + { + lostCard(); inputPublicCard();//棄一牌 發公牌 + ShowPublicCard();//開公牌 + } + Around++; gotoxyGame(x + 71, y); cout << "第 " << Around << " 局"; + while (around_cards) + { + for (int i = 0; i < player_number; i++) + { + if (player[i].getEnd() == true) + { + player[i].setEnd(false); + around_cards = false; + break; + } + else + { + ShowPlayerOperating(i); + Verification(); + ShowPlayerCard(i); + PlayerOperating(i); + HidePlayerCard(); + } + } + if (!CheckAddBet()) + { + around_cards = false; + } + } + tep++; + } + /*第二~四回合 end*/ + system("cls"); gotoxyGame(x, y); + /*比輸贏*/ for (int j = 0; j < player_number; j++) { Public_Player_combination(j); @@ -439,5 +773,7 @@ void MultiplayerGame() { ShowPlayerCard(j); } - ShowWinner(); + ShowWinner();_getch(); + system("cls"); gotoxyGame(x, y); + /*比輸贏*/ } \ No newline at end of file diff --git a/Player.cpp b/Player.cpp index 2f33f6b..7f262df 100644 --- a/Player.cpp +++ b/Player.cpp @@ -65,6 +65,15 @@ void Player::setMaxWin(int maxWinMode , int maxWin[], Card maxWinCards[]) ArrangeCards(); } } +void Player::setLastOperation(int operation) +{ + LastOperation = operation; +} +void Player::setEnd(bool end) +{ + End = end; +} + int Player::getCardNumber(int num) { @@ -94,4 +103,12 @@ int Player::getMaxWinMode() int Player::getMaxWinNumber(int num) { return MaxWin[num]; +} +int Player::getLastOperation() +{ + return LastOperation; +} +bool Player::getEnd() +{ + return End; } \ No newline at end of file diff --git a/Player.h b/Player.h index 5f7632b..a369811 100644 --- a/Player.h +++ b/Player.h @@ -10,6 +10,8 @@ class Player int MaxWin[5] = {}; int MaxWinMod=0; Card MaxWinCards[5] = {}; + int LastOperation = -1; + bool End = false; bool CalculationMaxWinNumber(int[]); void ArrangeCards(); @@ -19,6 +21,8 @@ class Player void setCard(int,Card); void setMaxWin(int, int[], Card[]); + void setLastOperation(int); + void setEnd(bool); int getCardNumber(int); int getCardSpecies(int); @@ -27,6 +31,8 @@ class Player Card getCard(int); int getMaxWinMode(); int getMaxWinNumber(int); + int getLastOperation(); + bool getEnd(); }; diff --git a/Title.cpp b/Title.cpp index 3a885b0..0a5f22b 100644 --- a/Title.cpp +++ b/Title.cpp @@ -1,9 +1,7 @@ -#ifndef Title_CPP -#define Title_CPP - -#include +#include #include #include +#include #include #pragma comment(lib,"winmm.lib") @@ -20,6 +18,84 @@ void gotoxy(double x, double y) SetConsoleCursorPosition(hCon, dwPos); } +//主畫面 +int MainScreen() +{ + int x = 0, y = 0; + gotoxy(x + 45, y + 5); cout << " __________ ▁"; + gotoxy(x + 45, y + 6); cout << "|| |/ \\"; + gotoxy(x + 45, y + 7); cout << "|| Texas | 20 $|\\"; + gotoxy(x + 45, y + 8); cout << "|| hold |\\ ▁ / $|"; + gotoxy(x + 45, y + 9); cout << "|| 'em |  |▁ /"; + gotoxy(x + 45, y + 10); cout << "|| | |"; + gotoxy(x + 45, y + 11); cout << "|| Game ▍ |"; + gotoxy(x + 45, y + 12); cout << "||__________▉ |"; + gotoxy(x + 45, y + 13); cout << " | ▉▉ |"; + gotoxy(x + 45, y + 14); cout << " | ▉ A|"; + gotoxy(x + 45, y + 15); cout << " |_________ |"; + gotoxy(x + 40, y + 19); cout << "Texas hold'em Game"; + gotoxy(x + 12, y + 15); cout << "單 人 遊 戲"; + gotoxy(x + 12, y + 17); cout << "多 人 遊 戲"; + gotoxy(x + 12, y + 19); cout << "設 定"; + gotoxy(x + 12, y + 21); cout << "離 開 遊 戲"; + + bool the_break=true; + int select = 1; + + while (the_break) + { + gotoxy(x + 10, y + 15); cout << " "; + gotoxy(x + 10, y + 17); cout << " "; + gotoxy(x + 10, y + 19); cout << " "; + gotoxy(x + 10, y + 21); cout << " "; + + gotoxy(x + 10, y + 13+(select*2)); cout << ">"; + gotoxy(x + 79, y + 24); + switch (_getch()) + { + case 72: + if (select > 1) { select--; }//up + break; + case 80: + if (select < 4) { select++; }//up + //down + break; + case 13: + the_break = false; //enter + break; + } + } + system("cls"); + return select; +} + +//設定 +void Enactment() +{ + int x = 0, y = 0; + + bool the_break = true; + int select = 1; + + while (1) + { + + switch (_getch()) + { + case 72: + if (select > 1) { select--; }//up + break; + case 80: + if (select < 5) { select++; }//up + //down + break; + case 13: + the_break = false; //enter + break; + } + } +} + //片頭 //漸逝 void Title_lost(int x, int y) { @@ -573,6 +649,4 @@ void Title() gotoxy(x - 30, y + 14); cout << "║╚╩═║╚╝║╚╝║╚╝║║╚═╝║╚╝║╚═╣╔╗╗╔╗"; gotoxy(x - 30, y + 15); cout << "╚═══╩══╩══╩══╝╚═══╩══╩══╩╝╚╝╚╝"; Sleep(3100); Title_lost(x, y); } -} - -#endif \ No newline at end of file +} \ No newline at end of file