UNO小游戏2

2024-09-01 23:44
文章标签 小游戏 uno

本文主要是介绍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的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1128382

相关文章

贪吃蛇的小游戏--用C语言实现

贪吃蛇的小游戏–用C语言实现 游戏背景 贪吃蛇是久负盛名的游戏,它也和俄罗斯⽅块,扫雷等游戏位列经典游戏的⾏列。 实现基本的功能: • 贪吃蛇地图绘制 • 蛇吃⻝物的功能 (上、下、左、右⽅向键控制蛇的动作) • 蛇撞墙死亡 • 蛇撞⾃⾝死亡 • 计算得分 • 蛇⾝加速、减速 • 暂停游戏 技术要点 C语⾔函数、枚举、结构体、动态内存管理、预处理指令、链表、Win32

MFC对话框贪吃蛇小游戏

花了近一个月的时间,学习了一下VC++深入详解,做了个贪吃蛇小游戏,虽然有很多的瑕疵,但还是想分享一下战果。 说一下思路: ①我们要绘制图形,我们可以用CClientDC(客户区设备上下文,与特定的窗口关联)声明一个dc对象作图。 当然这里我们要画蛇的身体和食物,设置一个食物类和蛇身体结构体 ②我们如何让图形动起来?SetTimer创建一个计时器,KillTimer()用来销毁计时器

GameFi生存法则:从巨头争霸到小游戏革命,掀起区块链游戏的全新风暴

随着区块链技术的飞速发展,GameFi(游戏与去中心化金融的结合)正成为加密世界的一个重要领域。然而,随着时间的推移,这一领域也经历了显著的演变,从最初的3A大作到如今流行的Telegram小游戏,这种变化不仅反映了市场需求的转变,也揭示了GameFi如何在生存与繁荣之间找到平衡。 一、GameFi 的演变:从 3A 大作到 Telegram 小游戏 不同类型 GameFi 项目的优劣 Ga

Unity实战案例 2D小游戏HappyGlass(模拟水珠)

本案例素材和教程都来自Siki学院,十分感谢教程中的老师 本文仅作学习笔记分享交流,不作任何商业用途 预制体   在这个小案例中,水可以做成圆形但是带碰撞体,碰撞体比图形小一圈,顺便加上Trail renderer组件   材质 将碰撞材质的friction为0,bonciness可以按照需要修改 脚本  生成水珠的脚本并不难, 只是需要创建大量实例化对象的时候,加一个携程

Arduino UNO 编程 第一期——下载及使用

字幕君已上线...... 副字幕君已上线...... 计数君已上线...... 彩色字幕君 ( 花了重金请来的 ) 已上线...... Doge智能系统已上线...... Doge:嗨嗨我又来了! 观众们......已上线!!!!! OK LET`S GO! Arduino是一组开发板,其中Arduino UNO就是其中之一。给Arduino编写代码,就需要Arduino语

C++战列舰小游戏Lv. 1.2版本(半成品)

这是一组初始数据: a[1].gas=1000;     a[1].attack=0;     a[1].att_1=0;     a[1].att_2=0;     a[1].att_3=0;     a[1].att_4=0;     a[1].fire=0;     a[1].gas_good=0.9;     a[1].guard=0;     a[1].HP=15000;     a[

C++实现简易俄罗斯方块小游戏

实现一个简易的俄罗斯方块(Tetris)游戏涉及多个方面,包括图形显示、游戏逻辑、用户输入等。下面是一个简化版本的俄罗斯方块游戏的实现步骤和代码示例。这个实现会使用 C++ 和一个简单的图形库——如 SFML(Simple and Fast Multimedia Library),这是一个非常适合游戏开发的跨平台图形库。 1. 环境准备 -安装 SFML: 你可以从 SFML 官网 下载适合你

Nuxt 项目实战 - 15:自定义unocss规则,让编写样式更高效

与UI设计师约定颜色命名规则 配置color变量 color.scss $colors: ((#ffffff,#f8f8f8,#ebebeb,#dbdbdb,#cccccc,#999999,#666666,#333333,#000000),(#daf6ef, #b4ecde, #08c193, #228f73, #43d7b2),(#f62f3b, #edc9c9, #f0e2e2, #

Unity实战案例 2D小游戏HappyGlass(画笔摇晃效果)

本案例素材和教程都来自Siki学院,十分感谢教程中的老师 本文仅作学习笔记分享交流,不作任何商业用途 using System.Collections;using System.Collections.Generic;using UnityEngine;public class Pencil : MonoBehaviour{//摆动速度public float pencilSpeed

第一次使用Egret开发微信小游戏经验总结(包括排行榜排序,每周一数据清零,超越好友等处理)

转自:https://blog.csdn.net/xw1110280055/article/details/82469825 最近项目组立项了个小游戏,用Egret(白鹭)开发,本来游戏核心功能2天就完成了,后来准备接入微信好友排行榜的时候,用到了子域,加入分享给好友的时候,图片合成后分享给微信好友有时候不能显示出图片内容。现整理一下,避免大家踩坑。 好友排行榜微信只让我们在开放数据域(后文都简