战争卡牌游戏C++
War Card Game C++
我有一个任务,它创建纸牌游戏战争并使用rand_range作为卡号。如果数字 11、12、13 或 14 弹出,我应该将它们分别更改为 J、K、Q 和 A。我不知道如何将卡号的无符号缩写更改为常量字符或字符串。
#include<iostream>
#include<cstdlib>
#include<ctime>
#include<iomanip>
#include<stdlib.h>
#include<string>
using namespace std;
unsigned short rand_range(unsigned short min, unsigned short max)
{
return rand() % (max - min + 1) + min;
}
int main(void)
{srand((unsigned)time(0));
unsigned char suit1 = ' ', suit2 = ' ';
unsigned char verticalLine = ' ', horizontalDouble = ' ';
unsigned char doubleCornerr = ' ', doubleCornerl = ' ', doubleCornerlb = ' ';
unsigned char doubleCornerrb = ' ', topLine = ' ', verticalDouble = ' ', topCornerr = ' ';
unsigned char topCornerl = ' ', bottomCornerl = ' ', bottomCornerr = ' ', hyphen = ' ';
unsigned short cardNumber1 = rand_range(2,14);
unsigned short cardNumber2 = rand_range(2,14);
suit1 = rand_range(3,6);
suit2 = rand_range(3,6);
verticalLine = 179;
horizontalDouble = 205;
doubleCornerr = 187;
doubleCornerl = 201;
doubleCornerlb = 200;
doubleCornerrb = 188;
topLine = 196;
verticalDouble = 186;
topCornerr = 191;
topCornerl = 218;
bottomCornerl = 192;
bottomCornerr = 217;
//The next portion of code will ensure that the suits are different
if (suit1 == suit2)
suit1 += 1;
if (suit1 == 6)
suit1 = 3;
//The next portion will change the numbers 11,12,13,14
// J, K, Q, A, respectively.
string royalcard;
switch (cardNumber1 & cardNumber2) {
case 11:
royalcard = "J";
break;
case 12:
royalcard = "Q";
break;
case 13:
royalcard = "K";
break;
case 14:
royalcard = "A";
break;
default:
break;
}
使用 if 或 选择...案例找出答案。希望这就是你要找的。
// x holds the random number you have generated
string royalcard;
switch (x) {
case 11:
royalcard = "Jack";
break;
case 12:
royalcard = "Queen";
break;
case 13:
royalcard = "King"
break;
case 14:
royalcard = "Ace"
break;
default:
break;
}
相关文章:
- 在C++游戏中与库存系统作斗争
- 换位表导致测试失败(但在游戏中运行良好)
- Craps游戏问题,忽略if语句
- 矢量下标超出SFML游戏中的范围
- 我是 c++ 的新手.学习基本知识后,我想做井字游戏.对于印刷板,我在下面写代码,但它显示错误
- 我在贪吃蛇游戏中收到了错误代码 -1073741571
- 我应该在简单的策略游戏中为各个派系使用类吗 - C++
- 游戏体验和升级
- 我的代码运行良好,但在游戏循环中中断
- 如何使用 SFML 在贪吃蛇游戏中定义游戏结束?
- 我可以使用任何好的逻辑来阻止计算机将 O 放在井字游戏中的现有 X 上
- 将鼠标和键盘输入发送到 unity3d 游戏 (Rust)
- 在猜谜游戏 c++ 中不计算尝试次数
- 在C++不适用于猜数字游戏的情况下再次播放选项
- 在为我的基于文本的 RPG 游戏制作库存时遇到困难
- 在定义字符数组(井字游戏)的 for 循环中应用输入限制
- Frank Luna 在他的书"使用 DirectX12 进行 3D 游戏编程"的介绍中盒子示例的问题
- 如何在Linux上正确发布C++软件(游戏)
- 提高基于组件的游戏引擎的效率
- 文本冒险游戏 - 如何区分一种项目类型与另一种项目类型以及如何构建项目类/子类