本文主要是介绍UNO小游戏2,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
前言
hello,大家好我是文宇。最近也是抽出时间更一期了。
bug还是很多(恼),所以就当个乐子看看,反正后面还会有的,先把这玩意儿发了再说。
正文
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
bool can = 1;
int colorsz1[25];
int cardsz1[25];
int colorsz2[25];
int cardsz2[25];
int onecard;
int onecolor;
int cardaa;
int coloraa;
int sj;
int j;
int sr;
string player1;
string player2;
void rule() {cout << " 规则:\n";cout << " 1.输入牌的位置出牌 \n";cout << " 2.只可以出与当前桌面颜色或数字相同的卡牌 \n";cout << " 3.10号卡可以使你的下家增加2张牌 \n";cout << " 4.11号卡可以使你的下家无法出牌一回 \n";cout << " 5.12号卡可以转换当前颜色 \n";cout << " 6.13号卡可以转换当前颜色,并让下家增加4张牌 \n";cout << " 7.其余1~9号卡没有特殊效果 \n";cout << " 8.谁的牌先打完谁就赢了 \n";cout << " 9.明牌打 \n";cout << " 10.手牌上限为25张 \n";cout << " 11.当你的手牌为25张时你就输了 \n";cout << " 12.开局有6张牌 \n";cout << " 13.牌显示为0为空位 \n";return;
}
void statr() {cout << " --------欢迎来到uno游戏---------\n";rule();cout << " 请输入玩家1的名字:";cin >> player1;cout << "\n 请输入玩家2的名字:";cin >> player2;system("cls");cout << "游戏开始\n";cout << "洗牌ing\n";return;
}
void carda() {srand(time(0)*time(0));sj = rand() % 13 + 1;cardaa = sj;sj = rand() % 4 + 1;coloraa = sj;return;
}
void cards1() {for (int i = 0; i <= 6; i++) {srand(time(0)*time(0));sj = rand() % 13 + 1;cardsz1[i] = sj;sj = rand() % 4 + 1;if (sj == 1) {colorsz1[i] = 1;}if (sj == 2) {colorsz1[i] = 2;}if (sj == 3) {colorsz1[i] = 3;}if (sj == 4) {colorsz1[i] = 4;}_sleep(1000);}return;
}
void cards2() {for (int i = 0; i <= 6; i++) {srand(time(0)*time(0));sj = rand() % 13 + 1;cardsz2[i] = sj;sj = rand() % 4 + 1;if (sj == 1) {colorsz2[i] = 1;}if (sj == 2) {colorsz2[i] = 2;}if (sj == 3) {colorsz2[i] = 3;}if (sj == 4) {colorsz2[i] = 4;}_sleep(1000);}return;
}
bool allZero1() {int total = 0;for (int i = 0; i < 25; i++) {if (cardsz1[i] == 0) {total++;}}if (total == 25) {return true;}return false;
}
bool allZero2() {int total = 0;for (int i = 0; i < 25; i++) {if (cardsz2[i] == 0) {total++;}}if (total == 25) {return true;}return false;
}
void onecards() {srand(time(0)*time(0));sj = rand() % 13 + 1;onecard = sj;sj = rand() % 4 + 1;onecolor = sj;return;
}
void card10_1() {srand(time(0)*time(0));sj = rand() % 13 + 1;for (int i = 0; i <= 25; i++) {if (cardsz2[i] == 0) {cardsz2[i] = sj;break;}}sj = rand() % 4 + 1;for (int i = 0; i <= 25; i++) {if (colorsz2[i] == 0) {colorsz2[i] = sj;break;}}}
void card10_2() {srand(time(0)*time(0));sj = rand() % 13 + 1;for (int i = 0; i <= 25; i++) {if (cardsz1[i] == 0) {cardsz1[i] = sj;break;}}sj = rand() % 4 + 1;for (int i = 0; i <= 25; i++) {if (colorsz1[i] == 0) {colorsz1[i] = sj;break;}}srand(time(0)*time(0));sj = rand() % 13 + 1;for (int i = 0; i <= 25; i++) {if (cardsz1[i] == 0) {cardsz1[i] = sj;break;}}sj = rand() % 4 + 1;for (int i = 0; i <= 25; i++) {if (colorsz1[i] == 0) {colorsz1[i] = sj;break;}}return;
}
void card12() {cout << "转换为红输入1\n";cout << "转换为绿输入2\n";cout << "转换为蓝输入3\n";cout << "转换为黄输入4\n";cin >> sr;if (sr == 1) onecolor = 1;if (sr == 2) onecolor = 2;if (sr == 3) onecolor = 3;if (sr == 4) onecolor = 4;return;}
void card13_1() {cout << "转换为红输入1\n";cout << "转换为绿输入2\n";cout << "转换为蓝输入3\n";cout << "转换为黄输入4\n";cin >> sr;if (sr == 1) onecolor = 1;if (sr == 2) onecolor = 2;if (sr == 3) onecolor = 3;if (sr == 4) onecolor = 4;srand(time(0)*time(0));sj = rand() % 13 + 1;for (int i = 0; i <= 25; i++) {if (cardsz2[i] == 0) {cardsz2[i] = sj;break;}}sj = rand() % 4 + 1;for (int i = 0; i <= 25; i++) {if (colorsz2[i] == 0) {colorsz2[i] = sj;break;}}srand(time(0)*time(0));sj = rand() % 13 + 1;for (int i = 0; i <= 25; i++) {if (cardsz2[i] == 0) {cardsz2[i] = sj;break;}}sj = rand() % 4 + 1;for (int i = 0; i <= 25; i++) {if (colorsz2[i] == 0) {colorsz2[i] = sj;break;}}return;
}
void card13_2() {cout << "转换为红输入1\n";cout << "转换为绿输入2\n";cout << "转换为蓝输入3\n";cout << "转换为黄输入4\n";cin >> sr;if (sr == 1) onecolor = 1;if (sr == 2) onecolor = 2;if (sr == 3) onecolor = 3;if (sr == 4) onecolor = 4;srand(time(0)*time(0));sj = rand() % 13 + 1;for (int i = 0; i <= 25; i++) {if (cardsz1[i] == 0) {cardsz1[i] = sj;break;}}sj = rand() % 4 + 1;for (int i = 0; i <= 25; i++) {if (colorsz1[i] == 0) {colorsz1[i] = sj;break;}}srand(time(0)*time(0));sj = rand() % 13 + 1;for (int i = 0; i <= 25; i++) {if (cardsz1[i] == 0) {cardsz1[i] = sj;break;}}sj = rand() % 4 + 1;for (int i = 0; i <= 25; i++) {if (colorsz1[i] == 0) {colorsz1[i] = sj;break;}}return;
}
void display() {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);cout << "\n\n玩家1的手牌是:";for (int i = 1; i <= 25; i++) {if (colorsz1[i] == 1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED); //redif (colorsz1[i] == 2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN); //greenif (colorsz1[i] == 3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE); //blueif (colorsz1[i] == 4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN); //yellowcout << cardsz1[i] << ' ';}cout << "\n\n";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);cout << "玩家2的手牌是:";for (int i = 1; i <= 25; i++) {if (colorsz2[i] == 1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED); //redif (colorsz2[i] == 2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN); //greenif (colorsz2[i] == 3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE); //blueif (colorsz2[i] == 4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN); //yellowcout << cardsz2[i] << ' ';}cout << "\n\n";return;
}
int main() {statr();cards1();cards2();onecards();cardsz1[25] = 0;while (1) {
chu1:display();SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);cout << "\n当前桌面上的牌为:";if (onecolor == 1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED); //redif (onecolor == 2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN); //greenif (onecolor == 3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE); //blueif (onecolor == 4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN); //yellowcout << onecard << "\n";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);if (allZero1()) {cout << player1 << "胜出!\n";return 0;} else if (allZero2()) {cout << player2 << "胜出!\n";return 0;}for (int i = 0; i <= 25; i++) {if (cardsz1[i] == onecard || cardsz1[i] == 13 || cardsz1[i] == 12) can = 0;if (colorsz1[i] == onecolor) can = 0;}if (can) {cout << "\n你没有可以出的,你获得一张:";if (coloraa == 1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED); //redif (coloraa == 2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN); //greenif (coloraa == 3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE); //blueif (coloraa == 4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN); //yellowcout << cardaa;} else {cout << player1 << "的回合,选择你的出卡:";cin >> sr;if ((cardsz1[sr] == onecard || colorsz1[sr] == onecolor || cardsz1[sr] == 12 || cardsz1[sr] == 13) && cardsz1[sr] != 0) {onecard = cardsz1[sr];onecolor = colorsz1[sr];cardsz1[sr] = 0;colorsz1[sr] = 0;if (cardsz1[sr] == 10) card10_1();if (cardsz1[sr] == 11) goto chu1;if (cardsz1[sr] == 12) card12();if (cardsz1[sr] == 13) card13_1();} else {cout << "\n不可以出这张\n";goto chu1;}}can = 1;
chu2:display();SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);cout << "\n当前桌面上的牌为:";if (onecolor == 1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED); //redif (onecolor == 2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN); //greenif (onecolor == 3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE); //blueif (onecolor == 4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN); //yellowcout << onecard << "\n";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);for (int i = 0; i <= 25; i++) {if (cardsz2[i] == onecard || cardsz2[i] == 13 || cardsz2[i] == 12) can = 0;if (colorsz2[i] == onecolor) can = 0;}if (can) {cout << "\n你没有可以出的,你获得一张:";if (coloraa == 1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED); //redif (coloraa == 2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN); //greenif (coloraa == 3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE); //blueif (coloraa == 4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN); //yellowcout << cardaa;can = 1;} else {cout << player2 << "的回合,选择你的出卡:";cin >> sr;if ((cardsz2[sr] == onecard || colorsz2[sr] == onecolor || cardsz2[sr] == 12 || cardsz2[sr] == 13) && cardsz2[sr] != 0) {onecard = cardsz2[sr];onecolor = colorsz2[sr];cardsz2[sr] = 0;colorsz2[sr] = 0;if (cardsz2[sr] == 10) card10_2();if (cardsz2[sr] == 11) goto chu2;if (cardsz2[sr] == 12) card12();if (cardsz2[sr] == 13) card13_2();} else {cout << "\n不可以出这张\n";goto chu2;}}can = 1;}return 0;
}
之前规则的制表符因为一些bug就删了,没办法
这篇关于UNO小游戏2的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!