问题描述
我正在开发一个 C++ 纸牌游戏,但我遇到了一个问题,我在不同的过程中有变量,但它们似乎没有在每种方法中保留它们的值。
在处理程序方面,我完全是初学者,因此对于看起来如此简单的问题,我深表歉意。
这是我的代码供参考:
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
/* run this program using the console pauser or add your own getch,system("pause") or input loop */
class player {
public:
string name = "";
int credit = 0;
int bet = 0;
};
class cards {
public:
string suit;
int number = 0;
};
void Initialise() {
//initialise Vars
string suits[4] = { "Coins","Flasks","Sabers","Staves" };
int values[15] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 };
}
void DefineCards(cards Card[60]) {
//Define Card Values
for (int c = 0; c < 60; c++) {
if (c >= 0 && c <= 14) {
Card[c].suit = "Coins";
Card[c].number = c;
}
else if (c >= 15 && c <= 29) {
Card[c].suit = "Flasks";
Card[c].number = c - 14;
}
else if (c >= 30 && c <= 44) {
Card[c].suit = "Sabers";
Card[c].number = c - 29;
}
else if (c >= 45 && c <= 60) {
Card[c].suit = "Staves";
Card[c].number = c - 44;
}
}
}
void CreatePlayer(player CurrentPlayer) {
bool correct = false;
string choice;
do {
cout << "Please input your name: " << endl;
cin >> CurrentPlayer.name;
cout << "Your name is " << CurrentPlayer.name << "? (Y/N)" << endl;
cin >> choice;
if (choice == "y" || choice == "Y") {
correct = true;
}
else {
correct = false;
}
} while (correct == false);
CurrentPlayer.credit = 1000;
}
//Game Procedeures
void Betting(player CurrentPlayer){
int pot = 0;
int bet = 0;
bool correct = false;
do {
cout << "Current Bet: " << CurrentPlayer.bet << " Total Pot: " << pot << " Credit: " << CurrentPlayer.credit << "\n\n";
cout << "Please enter a bet to begin: " << endl;
cin >> bet;
if (bet <= CurrentPlayer.credit) {
correct = true;
}
else if (bet > CurrentPlayer.credit) {
cout << "You don't have enough credits.";
}
else if (bet < 1) {
cout << "That's an impossible value,Please try again.";
}
} while (correct == false);
pot = pot + bet;
}
int main(int argc,char** argv) {
cards Card[60];
player CurrentPlayer;
//Initialisation procedeures
Initialise();
DefineCards(Card);
CreatePlayer(CurrentPlayer);
//Game
Betting(CurrentPlayer);
//display Cards
return 0;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)