游戏
井字棋
C++#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
#define red "\e[31m"
#define green "\e[32m"
#define blue "\e[34m"
#define yellow "\e[33m"
#define black "\e[0m"
#define sky "\e[36m"
#define purple "\e[35m"
#define normal "\e[0m"
#define cls aaa();
struct node {
char c = '&';
int cnt = -1;
};
node a[5][5] = {'&', -1};
void old_ai();
struct xy {
int x, y;
};
xy checkdie() {
for (int i = 1; i <= 3; i++) {
bool flag = 0;
int cnt = 0;
int x, y;
for (int j = 1; j <= 3; j++) {
if (a[i][j].c != '#') {
flag = 1;
x = i, y = j;
} else cnt++;
}
if (flag && a[x][y].cnt == 4)return {x, y};
}
for (int i = 1; i <= 3; i++) {
bool flag = 0;
int cnt = 0;
int x, y;
for (int j = 1; j <= 3; j++) {
if (a[j][i].c != '#') {
flag = 1;
x = i, y = j;
} else cnt++;
}
if (flag && a[x][y].cnt == 5)return {x, y};
}
if (a[1][1].c == '#' && a[2][2].c == '#' && a[3][3].c != '#' && a[3][3].cnt == 4)return {3, 3};
if (a[1][1].c == '#' && a[2][2].c != '#' && a[3][3].c == '#' && a[2][2].cnt == 4)return {2, 2};
if (a[1][1].c != '#' && a[2][2].c == '#' && a[3][3].c == '#' && a[1][1].cnt == 4)return {1, 1};
if (a[1][3].c != '#' && a[2][2].c == '#' && a[3][1].c == '#' && a[1][3].cnt == 4)return {1, 3};
if (a[1][3].c == '#' && a[2][2].c != '#' && a[3][1].c == '#' && a[2][2].cnt == 4)return {2, 2};
if (a[1][3].c == '#' && a[2][2].c == '#' && a[3][1].c != '#' && a[3][1].cnt == 4)return {3, 1};
return {0, 0};
}
string loading[13] = {
{
" \n \n \n \n "
},
{
" ### \n #\n #\n \n "
},
{
" ## \n #\n #\n #\n "
},
{
" # \n #\n #\n #\n # "
},
{
" \n #\n #\n #\n ## "
},
{
" \n \n #\n #\n ### "
},
{
" \n \n \n# #\n ### "
},
{
" \n \n# \n# \n ### "
},
{
" \n# \n# \n# \n ## "
},
{
" # \n# \n# \n# \n # "
},
{
" ## \n# \n# \n# \n "
},
{
" ### \n# \n# \n \n "
},
{
" ### \n# #\n \n \n "
},
};
void aaa() {
COORD topLeft = {0, 0};
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(console, topLeft);
for (int i = 1; i <= 20; i++) {
for (int f = 1; f <= 40; f++)
cout << " ";
cout << "\n";
}
SetConsoleCursorPosition(console, topLeft);
}
void load() {
system("cls");
for (int v = 1; v <= 10; v++) {
for (int i = 1; i <= 12; i++) {
cout << loading[i];
cout << "加载中...\n";
Sleep(10);
system("cls");
}
}
}
void printinfo(bool flag) {
if (flag)
MessageBox(NULL, "*代表你的棋子\n#代表人机的棋子\n.表示空白棋盘\n黄色的棋子在下一步时就会消失\n", "Tips", MB_OK | MB_ICONINFORMATION);
if (!flag)
MessageBox(NULL, "*代表红方的棋子\n#代表蓝方的棋子\n.表示空白棋盘\n黄色的棋子在下一步时就会消失\n", "Tips", MB_OK | MB_ICONINFORMATION);
}
void pause(double second) {
Sleep(second * 500);
}
void print(string test, string color = "normal") {
if (color == "red")cout << red;
else if (color == "red")cout << red;
else if (color == "blue")cout << blue;
else if (color == "purple")cout << purple;
else if (color == "yellow")cout << yellow;
else if (color == "sky")cout << sky;
else if (color == "black")cout << black;
for (int i = 0; i < test.length(); i++)
cout << test[i];
cout << normal;
}
void write() {
cout << "╔═══╦═══╦═══╗\n";
for (int i = 1; i <= 3; i++) {
cout << "║";
for (int j = 1; j <= 3; j++) {
if (a[i][j].cnt == 4)cout << yellow << " " << a[i][j].c << normal;
else if (a[i][j].c == '#')
cout << blue << " " << a[i][j].c << normal;
else if (a[i][j].c == '*')
cout << red << " " << a[i][j].c << normal;
else cout << " " << a[i][j].c;
cout << " ║";
}
cout << "\n";
if (i != 3)cout << "╠═══╬═══╬═══╣\n";
}
cout << "╚═══╩═══╩═══╝\n";
}
long long sj(int maxx) {
random_device rd;
mt19937 gen(rd());
uniform_int_distribution<> dis(1, maxx);
long long f = dis(gen);
return f;
}
int check() {
if (a[1][1].c == '*' && a[1][2].c == '*' && a[1][3].c == '*')return 1;
if (a[2][1].c == '*' && a[2][2].c == '*' && a[2][3].c == '*')return 1;
if (a[3][1].c == '*' && a[3][2].c == '*' && a[3][3].c == '*')return 1;
if (a[1][1].c == '*' && a[2][1].c == '*' && a[3][1].c == '*')return 1;
if (a[1][2].c == '*' && a[2][2].c == '*' && a[3][2].c == '*')return 1;
if (a[1][3].c == '*' && a[2][3].c == '*' && a[3][3].c == '*')return 1;
if (a[1][3].c == '*' && a[2][2].c == '*' && a[3][1].c == '*')return 1;
if (a[1][1].c == '*' && a[2][2].c == '*' && a[3][3].c == '*')return 1;
if (a[1][1].c == '#' && a[1][2].c == '#' && a[1][3].c == '#')return 2;
if (a[2][1].c == '#' && a[2][2].c == '#' && a[2][3].c == '#')return 2;
if (a[3][1].c == '#' && a[3][2].c == '#' && a[3][3].c == '#')return 2;
if (a[1][1].c == '#' && a[2][1].c == '#' && a[3][1].c == '#')return 2;
if (a[1][2].c == '#' && a[2][2].c == '#' && a[3][2].c == '#')return 2;
if (a[1][3].c == '#' && a[2][3].c == '#' && a[3][3].c == '#')return 2;
if (a[1][3].c == '#' && a[2][2].c == '#' && a[3][1].c == '#')return 2;
if (a[1][1].c == '#' && a[2][2].c == '#' && a[3][3].c == '#')return 2;
return 0;
}
void reddown() {
cout << "\n\n请红方下子(输入棋子的行和列):\n";
int x, y;
cin >> x >> y;
if (x < 1 || y > 3 || x > 3 || y < 1 || a[x][y].c != '.') {
cout << "坐标不合法!\n";
pause(0.5);
cls
write();
reddown();
return;
} else
a[x][y].c = '*';
}
void bluedown() {
cout << "\n\n请蓝方下子(输入棋子的行和列):\n";
int x, y;
cin >> x >> y;
if (x < 1 || y > 3 || x > 3 || y < 1 || a[x][y].c != '.') {
cout << "坐标不合法!\n";
pause(0.5);
cls
write();
bluedown();
return;
} else
a[x][y].c = '#';
}
void aidown(int x, int y) {
a[x][y].c = '#';
}
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
bool ok(int x, int y, char player) {
node temp = a[x][y];
a[x][y].c = player;
bool result = check() == (player == '*' ? 1 : 2);
a[x][y] = temp;
return result;
}
bool find_ai(char player, int& x, int& y) {
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
if (a[i][j].c == '.') {
if (ok(i, j, player)) {
x = i;
y = j;
return 1;
}
}
}
}
return 0;
}
void sjx() {
vector<pair<int, int >> ec;
for(int i = 1; i <= 3; i++)
for(int j = 1; j <= 3; j++)
if(a[i][j].c == '.')
ec.emplace_back(i, j);
if(!ec.empty()) {
int i = sj(ec.size()) - 1;
aidown(ec[i].first, ec[i].second);
}
}
int renji(bool xxx, int d = 0, int maxd = 3) {
int sc = check();
if(sc == 2) return 1;
if(sc == 1) return - 1;
bool flag = 1;
for(int i = 1; i <= 3; i++)
for(int j = 1; j <= 3; j++)
if(a[i][j].c == '.') {
flag = 0;
break;
}
if(flag || d >= maxd) return 0;
if (xxx) {
int maxn = -500;
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
if (a[i][j].c == '.') {
a[i][j].c = '#';
int sc = renji(0, d + 1, maxd);
a[i][j].c = '.';
maxn = max(sc, maxn);
}
}
}
return maxn;
} else {
int maxn = 500;
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
if (a[i][j].c == '.') {
a[i][j].c = '*';
int sc = renji(1, d + 1, maxd);
a[i][j].c = '.';
maxn = min(sc, maxn);
}
}
}
return maxn;
}
}
void ai() {
cout << "\n人机正在下子...\n";
pause(1);
int x, y;
if (find_ai('#', x, y)) {
aidown(x, y);
return;
}
if (find_ai('*', x, y)) {
aidown(x, y);
return;
}
int maxn = -500;
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
if (a[i][j].c == '.' || a[i][j].c != '#' && a[i][j].c != '.' && a[i][j].cnt == 4) {
a[i][j].c = '#';
int sc = renji(0);
a[i][j].c = '.';
if (sc > maxn) {
maxn = sc;
x = i;
y = j;
}
}
}
}
aidown(x, y);
}
void add() {
for (int i = 1; i <= 3; ++i) {
for (int j = 1; j <= 3; ++j) {
if (a[i][j].c != '.') {
if (++a[i][j].cnt == 6) {
a[i][j].cnt = 0;
a[i][j].c = '.';
}
}
}
}
}
void vs_ai() {
printinfo(1);
cout << "请选择难度:\n1:简单\n2:困难\n";
int flag;
cin >> flag;
for (int i = 1; i < 4; i++)
for (int j = 1; j < 4; j++) {
a[i][j].c = '.';
a[i][j].cnt = 0;
}
system("pause");
system("cls");
while (!check()) {
write();
reddown();
add();
cls
write();
pause(0.5);
if (flag == 1)old_ai();
else ai();
add();
cls
}
write();
pause(1);
cout << "\n";
cls
write();
if (check() != 1)system("color 8");
if (check() == 1) {
cls
for (int i = 1; i <= 10; i++) {
write();
cout << "\n";
cout << "你赢了!\n";
pause(0.5);
cls
pause(0.5);
}
} else cout << "你输了!\n";
pause(3);
system("color f");
cls
}
void pvp() {
for (int i = 1; i < 4; i++)
for (int j = 1; j < 4; j++) {
a[i][j].c = '.';
a[i][j].cnt = 0;
}
printinfo(0);
system("pause");
system("cls");
while (!check()) {
add();
write();
reddown();
if (check() == 1)break;
pause(0.5);
cls
add();
write();
bluedown();
if (check() == 2)break;
pause(0.5);
cls
}
pause(1);
cls
write();
if (check() == 1)cout << "红方赢了!\n";
else cout << "蓝方赢了!\n";
cls
for (int i = 1; i <= 8; i++) {
write();
if (check() == 1)cout << "红方赢了!\n";
else cout << "蓝方赢了!\n";
pause(0.5);
cls
pause(0.5);
}
cls
}
void translate(bool flag) {
cls
load();
cls
if (flag)vs_ai();
else pvp();
}
void old_ai() {
cout << "\n人机正在下子...\n";
pause(1);
int x, y;
if (find_ai('#', x, y)) {
aidown(x, y);
return;
}
if (find_ai('*', x, y)) {
aidown(x, y);
return;
}
sjx();
}
int main() {
while (1) {
cout << "人机对战:1\n双人:2\n";
int i;
cin >> i;
if (i == 1)translate(1);
else if (i == 2)translate(0);
else {
cout << "输入不合法!\n";
pause(0.5);
cls
continue;
}
}
return 0;
}
2048
C++#include<iostream>
#include<vector>
#include<ctime>
#include<cstdlib>
using namespace std;
class Game_2048
{
public:
Game_2048();
~Game_2048();
void introduction();
bool judgeOver(); //判断游戏是否结束
void reSize();
void printBoard(); //打印函数
void getRand(); //随机在棋盘上生成2,4;
void slide(); //滑动
private:
int m=4, n=4;
char op; //用户操作
vector< vector<int> > board; //棋盘
vector<int> row;
bool judgeInsert(int x,int y);
bool judgeSlide(); //判断是否能滑动
void copyBoard(vector< vector<int> > &newBoard,vector< vector<int> > &board);
void inputOp();
char getOp(); //返回操作符
bool judgeLeftSlide(bool mark=true);
void leftSlide(); //左滑动
bool judgeRightSlide(bool mark = true);
void rightSlide();
bool judgeUpSlide(bool mark = true);
void upSlide();
bool judgeDownSlide(bool mark = true);
void downSlide();
void reStart();
void enlarge(); //将值扩大二倍
};
int main()
{
Game_2048 NB;
NB.introduction();
NB.getRand();
NB.printBoard();
while (!NB.judgeOver())
{
NB.slide();
NB.getRand();
NB.printBoard();
}
cout << "游戏结束!!!\n";
system("pause");
return 0;
}
void Game_2048::introduction()
{
cout << "这是一个2048游戏,规则如下:\n";
cout << "上划:W;\n下滑:S;\n左划:A;\n右划:D;\n退出:Q;\n重新开始:R;\n请输入下次操作,\n";
}
void Game_2048::slide()
{
inputOp();
switch (getOp())
{
case 'a':
case 'A':
if (judgeLeftSlide())
do
leftSlide();
while (judgeLeftSlide(false));
else
{
cout << "无法左滑动,请重试!!!\n";
slide();
}
break;
case 'd':
case 'D':
if (judgeRightSlide())
do
rightSlide();
while (judgeRightSlide(false));
else
{
cout << "无法右滑动,请重试!!!\n";
slide();
}
break;
case 'w':
case 'W':
if(judgeUpSlide())
do
upSlide();
while (judgeUpSlide(false));
else
{
cout << "无法上滑动,请重试!!!\n";
slide();
}
break;
case 's':
case 'S':
if(judgeDownSlide())
do
downSlide();
while (judgeDownSlide(false));
else
{
cout << "无法下滑动,请重试!!!\n";
slide();
}
break;
case 'p':
case 'P':
enlarge();
break;
case 'q':
case 'Q':
exit(0);
break;
case 'r':
case 'R':
reStart();
break;
default:
cout << "输入错误,作为惩罚,随机生成一个数!\n";
break;
}
}
void Game_2048::reStart()
{
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++) {
board[i][j] = 0;
}
}
void Game_2048::enlarge()
{
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
{
board[i][j] *= 2;
}
}
char Game_2048::getOp()
{
return op;
}
void Game_2048::upSlide()
{
for (int j = 0; j < n; j++)
for (int i = m - 1; i > 0; i--) { //n-1!!
if (board[i][j] != 0 && board[i - 1][j] == 0) //移动
{
board[i - 1][j] = board[i][j];
board[i][j] = 0;
}
}
for (int j = 0; j < n; j++)
for (int i = m - 1; i > 0; i--) {
if (board[i][j] != 0 && board[i-1][j] == board[i][j]) //覆盖
{
board[i-1][j] += board[i][j];
board[i][j] = 0;
}
}
}
bool Game_2048::judgeUpSlide(bool mark)
{
if (mark)
{
for (int i = 0; i < m; i++)
for (int j = n - 1; j > 0; j--)
{
if (board[i][j] == 0)
return true;
}
}
for (int j = 0; j < n; j++)
for (int i = m - 1; i > 0; i--) { //n-1!!
if (board[i][j] != 0 && board[i - 1][j] == 0) //移动
return true;
if (board[i][j] != 0 && board[i - 1][j] == board[i][j]) //覆盖
return true;
}
return false;
}
bool Game_2048::judgeDownSlide(bool mark)
{
if (mark) {
for (int i = 0; i < m; i++)
for (int j = n - 1; j > 0; j--)
{
if (board[i][j] == 0)
return true;
}
}
for (int j = 0; j < n; j++)
for (int i = 0; i < m - 1; i++) { //n-1!!
if (board[i][j] != 0 && board[i + 1][j] == 0) //移动
return true;
if (board[i][j] != 0 && board[i + 1][j] == board[i][j]) //覆盖
return true;
}
return false;
}
void Game_2048::downSlide()
{
for (int j = 0; j < n; j++)
for (int i = 0; i < m - 1; i++) {
if (board[i][j] != 0 && board[i + 1][j] == 0) //移动
{
board[i + 1][j] = board[i][j];
board[i][j] = 0;
}
}
for (int j = 0; j < n; j++)
for (int i = 0; i < m - 1; i++) {
if (board[i][j] != 0 && board[i + 1][j] == board[i][j]) //覆盖
{
board[i + 1][j] += board[i][j];
board[i][j] = 0;
}
}
}
void Game_2048::rightSlide()
{
for (int i = 0; i < m; i++)
for (int j = 0; j < n - 1; j++) { //n-1!!
if (board[i][j] != 0 && board[i][j + 1] == 0) //移动
{
board[i][j + 1] = board[i][j];
board[i][j] = 0;
}
}
for (int i = 0; i < m; i++)
for (int j = 0; j < n - 1; j++) {
if (board[i][j] != 0 && board[i][j + 1] == board[i][j]) //覆盖
{
board[i][j + 1] += board[i][j];
board[i][j] = 0;
}
}
}
bool Game_2048::judgeRightSlide(bool mark )
{
if (mark) {
for (int i = 0; i < m; i++)
for (int j = n - 1; j > 0; j--)
{
if (board[i][j] == 0)
return true;
}
}
for (int i = 0; i < m; i++)
for (int j = 0; j < n - 1; j++) { //n-1!!
if (board[i][j] != 0 && board[i][j + 1] == board[i][j]) //覆盖
return true;
if (board[i][j] != 0 && board[i][j + 1] == 0)
return true;
}
return false;
}
void Game_2048::leftSlide()
{
for (int i = 0; i < m; i++)
for (int j = 1; j < n; j++) { //n-1!!
if (board[i][j] != 0 && board[i][j - 1] == 0) //移动
{
board[i][j - 1] = board[i][j];
board[i][j] = 0;
}
}
for (int i = 0; i < m; i++)
for (int j = 1; j < n; j++) {
if (board[i][j] != 0 && board[i][j - 1] == board[i][j]) //覆盖
{
board[i][j - 1] += board[i][j];
board[i][j] = 0;
}
}
}
bool Game_2048::judgeLeftSlide(bool mark)
{
if (mark) {
for (int i = 0; i < m; i++)
for (int j = n - 1; j > 0; j--)
{
if (board[i][j] == 0)
return true;
}
}
for (int i = 0; i < m; i++)
for (int j = n - 1; j > 0; j--) { //n-1!!
if (board[i][j] != 0 && board[i][j - 1] == 0) //移动
return true;
if (board[i][j] != 0 && board[i][j - 1] == board[i][j]) //覆盖
return true;
}
return false;
}
bool Game_2048::judgeOver()
{
if (op == 'q' || op == 'Q')
return true;
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++) {
if (board[i][j] == 2048)
{
printBoard();
cout << "有数字达到了2048,恭喜!!!\n";
return true;
}
}
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++) {
if (board[i][j] == 0)
return false;
}
if (judgeSlide())
return false;
else
{
cout << "无法再滑动\n";
return true;
}
}
bool Game_2048::judgeSlide()
{
vector< vector<int> > copyBoard; //棋盘
vector<int> copyRow;
for (int i = 0; i < n; i++) {
copyRow.push_back(0);
}
for (int i = 0; i < m; i++) {
copyBoard.push_back(copyRow);
}
copyBoard = board;
upSlide();
downSlide();
leftSlide();
rightSlide();
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
{
if (board[i][j] == 0) {
board = copyBoard;
return true;
}
}
return false;
}
void Game_2048::copyBoard(vector< vector<int> >& newBoard, vector< vector<int> >& board)
{
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
newBoard[i][j] = board[i][j];
}
bool Game_2048::judgeInsert(int x,int y)
{
if (board[x][y] == 0)
return true;
else
return false;
}
void Game_2048::getRand()
{
srand(time(0));
int x, y,val;
do
{
x = rand() % m;
y = rand() % n;
} while (!judgeInsert(x,y));
val = (rand() % 2 + 1)*2;
board[x][y] = val;
}
void Game_2048::inputOp()
{
cin >> op;
}
void Game_2048::reSize()
{
cout << "请输入棋盘大小m*n\n";
cin >> m >> n;
Game_2048();
}
Game_2048::~Game_2048()
{
}
Game_2048::Game_2048()
{
for (int i = 0; i < n; i++){
row.push_back(0);
}
for (int i = 0; i < m; i++){
board.push_back(row);
}
}
void Game_2048::printBoard()
{
cout << "\n--------------\n";
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
cout << board[i][j];
if (j < n-1)
{
cout << "—";
}
if (j == n-1 && i < m-1)
{
cout << endl;
int count = 0;
while (count++ < n-1)
{
cout << "| ";
}
cout << "|" << endl;
}
}
}
cout << "\n--------------\n" ;
}
五子棋
C++#include<iostream>
#include<time.h>
#include<stdlib.h>
using namespace std;
const int N = 15;//棋盘大小
const char ChessBoardFlag = ' ';
const char flag1 = 'O';
const char flag2 = 'X';
typedef struct Coordinate
{
int x;
int y;
}ChessCoordi;
class FiveChess
{
public:
FiveChess()
{
InitChessBoard();
}
void Play()
{
ChessCoordi Pos1;
ChessCoordi Pos2;
while (1){
int mode = ChoseMode();
while (1){
if (mode == 1){//玩家VS电脑
static size_t count = 1;
PalyerGo(Pos1, 1, flag1);
if (count++ >= 9 && GetWiner(Pos1, 1, flag1))
break;
ComputerGo(Pos2, flag2);
if (count++ >= 10 && GetWiner(Pos2, 0, flag2))
break;
}
else if (mode == 2){//玩家VS玩家
static size_t count = 1;
PalyerGo(Pos1, 1, flag1);
if (count++ >= 9 && GetWiner(Pos1,1, flag1))
break;
PalyerGo(Pos2,2 ,flag2);
if (count++ >= 10 && GetWiner(Pos2,2, flag2))
break;
}
}
cout << "再来一局 y or no" << endl;
char chose = 'y';
cin >> chose;
if (chose == 'n')
break;
}
}
void PrintChessBoard()
{
system("cls");
for (size_t i = 0; i < N + 1; ++i)
{
for (size_t j = 0; j < N + 1; ++j)
{
if (i == 0){
if (j != 0)
printf("%d ", j);
else if (j == 0)
printf(" ");
}
else if (j == 0){
if (i != 0)
printf("%2d", i);
}
else{
printf("%c |", ChessBoard[i][j]);
}
}
cout << endl;
cout << " ";
for (size_t i = 1; i < N + 1; ++i){
cout << "---+";
}
cout << endl;
}
}
void InitChessBoard()
{
for (size_t i = 0; i < N + 1; ++i){
for (size_t j = 0; j < N + 1; ++j){
ChessBoard[i][j] = ChessBoardFlag;
}
}
}
protected:
int ChoseMode()
{
system("cls");
InitChessBoard();
cout << "请选择 1.玩家VS电脑 2.玩家VS玩家 3.退出" << endl;
int chose = 0;
cin >> chose;
while (1){
if (chose == 1)
return chose;
else if (chose == 2)
return chose;
else if (chose == 3)
exit(1);
else
cout << "对不起 您的输入有误。。" << endl;
}
}
void PalyerGo(ChessCoordi& Pos, int player, char flag)
{
PrintChessBoard();
int x = 0;
int y = 0;
while (1){
cout << "请玩家" << player << "下一步棋" << endl;
cin >> Pos.x >> Pos.y;
if (JudgePos(Pos))
break;
else
cout << "玩家输入错误 ! 请重新输入" << endl;
}
ChessBoard[Pos.x][Pos.y] = flag;
}
void ComputerGo(ChessCoordi& Pos, char flag)
{
PrintChessBoard();
int x = 0;
int y = 0;
while (1){
x = rand() % N + 1;
srand((unsigned int)time(NULL));
y = rand() % N + 1;
srand((unsigned int)time(NULL));//这种方式下生成的x,y一定在棋盘上
if (ChessBoard[x][y] == ChessBoardFlag)
break;
}
Pos.x = x;
Pos.y = y;
ChessBoard[Pos.x][Pos.y] = flag;
}
int GetVictory(ChessCoordi Pos, char flag)//判断是否有赢家
{
int begin = 0;//在检查对角线时 作为行坐标的开始 结束
int end = 0;
//检查行是否连续5个子
int beginl = 0;//在检查对角线时 作为列坐标的开始 结束
int endl = 0;
(Pos.y - 4) > 0 ? begin = Pos.y - 4 : begin = 1;
(Pos.y + 4) < N ? end = Pos.y + 4 : end = N;
for (size_t i = Pos.x, j = begin; j + 4 <= end; ++j)
{
if (flag == ChessBoard[i][j] && flag == ChessBoard[i][j + 1] && \
flag == ChessBoard[i][j + 2] && flag == ChessBoard[i][j + 3] && \
flag == ChessBoard[i][j + 4])
return 1;
}
//检查列是否连续5个子
(Pos.x - 4) > 0 ? begin = Pos.x - 4 : begin = 1;
(Pos.x + 4) > N ? end = Pos.x + 4 : end = N;
for (size_t j = Pos.y, i = begin; i + 4 <= end; ++i)
{
if (flag == ChessBoard[i][j] && flag == ChessBoard[i + 1][j] && \
flag == ChessBoard[i + 2][j] && flag == ChessBoard[i + 3][j] && \
flag == ChessBoard[i + 4][j])
return 1;
}
int len = 0;
//检查主对角线是否满五个子
(Pos.x > Pos.y) ? len = Pos.y - 1 : len = Pos.x - 1;
if (len > 4)//找落子点到上 左两边的垂直距离较短的地方 如果其大于4 取4 不大于4 取其本身
len = 4;
begin = Pos.x - len;//向上 左移动适当距离找可能的五连子的起始位置
beginl = Pos.y - len;
(Pos.x > Pos.y) ? len = N - Pos.x : len = N - Pos.y;
if (len > 4)
len = 4;
end = Pos.x + len;//向下 右移动适当距离找可能的五连子的终止位置
endl = Pos.y + len;
for (size_t i = begin, j = beginl; i + 4 <= end && j + 4 <= endl; ++i, ++j)
{
if (flag == ChessBoard[i][j] && flag == ChessBoard[i + 1][j + 1] && \
flag == ChessBoard[i + 2][j + 2] && flag == ChessBoard[i + 3][j + 3] && \
flag == ChessBoard[i + 4][j + 4])
return 1;
}
//检查副对角线是否满五个子
(Pos.x - 1 > N - Pos.y) ? len = N - Pos.y : Pos.x - 1;
if (len > 4)//找落子点到右 下两边的垂直距离较短的地方 如果其大于4 取4 不大于4 取其本身
len = 4;
begin = Pos.x - len;//向上 右移动适当距离找可能的五连子的起始位置
beginl = Pos.y + len;
(N - Pos.x > Pos.y - 1) ? len = Pos.y - 1 : len = N - Pos.x;
end = Pos.x + len;//向下 左移动适当距离找可能的五连子的最终位置
endl = Pos.y - len;
for (size_t i = begin, j = beginl; i + 4 <= end && j - 4 >= endl; ++i, ++j)
{
if (flag == ChessBoard[i][j] && flag == ChessBoard[i + 1][j - 1] && \
flag == ChessBoard[i + 2][j - 2] && flag == ChessBoard[i + 3][j - 3] && \
flag == ChessBoard[i + 4][j - 4])
return 1;
}
//检查棋盘是否已满
for (size_t i = 1; i < N + 1; ++i){
for (size_t j = 1; j < N + 1; ++j){
if (ChessBoard[i][j] == ChessBoardFlag)
return 0;//表示棋盘没满
}
}
//和棋
return -1;
}
bool GetWiner(ChessCoordi& Pos, int player, char flag)//判断是谁赢了
{
int n = 0;
n = GetVictory(Pos, flag);
PrintChessBoard();
if (1 == n){
if (0 == player)
cout << "玩家1获胜" << endl;
else if (1 == player)
cout << "玩家1获胜" << endl;
else
cout << "电脑获胜"<<endl;
return true;
}
else if (-1 == n){
cout << "和棋" << endl;
return true;
}
else{
//还未分出胜负
return false;
}
}
bool JudgePos(const ChessCoordi& Pos)
{
if (Pos.x < N + 1 && Pos.x > 0 && Pos.y < N + 1 && Pos.x > 0\
&& ChessBoard[Pos.x][Pos.y] == ChessBoardFlag)
return true;
return false;
}
private:
char ChessBoard[N + 1][N + 1];
};
//#include"FiveChess.cpp"
int main()
{
//char a[] = "exit";
//for (size_t i = 0; i < sizeof(a) / sizeof(char);++i)
//printf(":%d", a[i]);
FiveChess a;
a.InitChessBoard();
a.PrintChessBoard();
a.Play();
system("pause");
return 0;
}
贪吃蛇
C++#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <conio.h>
#include <cmath>
#include <windows.h>
using namespace std;
/*** 光标定位 ***/
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord;
void locate(int x,int y)
{
coord.X=y;
coord.Y=x;
SetConsoleCursorPosition(hout,coord);
};
/*** 隐藏光标 ***/
void hide()
{
CONSOLE_CURSOR_INFO cursor_info={1,0};
SetConsoleCursorInfo(hout, &cursor_info);
}
/*** 生成随机数 ***/
double random(double start, double end)
{
return start+(end-start)*rand()/(RAND_MAX + 1.0);
}
/*** 定义地图的长宽,蛇的坐标,长度,方向,食物的位置 ***/
int m,n;
struct node
{
int x,y;
}snake[1000];
int snake_length,dir;
node food;
int direct[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
/*** 输出墙 ***/
void print_wall()
{
cout << " ";
for (int i=1;i<=n;i++)
cout << "-";
cout << endl;
for (int j=0;j<=m-1;j++)
{
cout << "|";
for (int i=1;i<=n;i++) cout << " ";
cout << "|" << endl;
}
cout << " ";
for (int i=1;i<=n;i++)
cout << "-";
}
/*** 首次输出蛇,其中snake[0]代表头 ***/
void print_snake()
{
locate(snake[0].x,snake[0].y);
cout << "@";
for (int i=1;i<=snake_length-1;i++)
{
locate(snake[i].x,snake[i].y);
cout << "*";
}
}
/*** 判断是否撞墙或者自撞 ***/
bool is_correct()
{
if (snake[0].x==0 || snake[0].y==0 || snake[0].x==m+1 || snake[0].y==n+1) return false;
for (int i=1;i<=snake_length-1;i++)
{
if (snake[0].x==snake[i].x && snake[0].y==snake[i].y) return false;
}
return true;
}
/*** 随机生成并输出食物位置 ***/
bool print_food()
{
srand((unsigned)time(0));
bool e;
while (1)
{
e=true;
int i=(int) random(0,m)+1,j=(int) random(0,n)+1;
food.x=i;food.y=j;
for (int k=0;k<=snake_length-1;k++)
{
if (snake[k].x==food.x && snake[k].y==food.y)
{
e=false;break;
}
}
if (e) break;
}
locate(food.x,food.y);
cout << "$";
return true;
}
/*** 蛇的前进 ***/
bool go_ahead()
{
node temp;
bool e=false;
temp=snake[snake_length-1];
for (int i=snake_length-1;i>=1;i--)
snake[i]=snake[i-1];
snake[0].x+=direct[dir][0];
snake[0].y+=direct[dir][1];
locate(snake[1].x,snake[1].y);
cout << "*";
/*** 吃到了食物 ***/
if (snake[0].x==food.x && snake[0].y==food.y)
{
snake_length++;
e=true;
snake[snake_length-1]=temp;
}
/*** 输出此时蛇状态 ***/
if (!e)
{
locate(temp.x,temp.y);
cout << " ";
}
else
print_food();
locate(snake[0].x,snake[0].y);
cout << "@";
/*** 如果自撞 ***/
if (!is_correct())
{
system("cls");
cout << "You lose!" << endl << "Length: " << snake_length << endl;
return false;
}
return true;
}
/*** 主函数 ***/
int main()
{
cout << "--------------------贪吃蛇---------------------" << endl;
cout << "请注意窗口大小,以免发生错位.建议将窗口调为最大." << endl;
cout << "先选择难度.请在1-10中输入1个数,1最简单,10则最难" << endl;
cout << "然后进入游戏画面,以方向键控制方向.祝你游戏愉快!" << endl;
cout << "-----------------------------------------------" << endl;
m=25;
n=40;
if (m<10 || n<10 || m>25 || n>40)
{
cout << "ERROR" << endl;
system("pause");
return 0;
}
int hard;
cin >> hard;
if (hard<=0 || hard>100)
{
cout << "ERROR" << endl;
system("pause");
return 0;
}
/*** 数据全部初始化,包括蛇长,位置,方向 ***/
snake_length=5;
clock_t a,b;
char ch;
double hard_len;
for (int i=0;i<=4;i++)
{
snake[i].x=1;
snake[i].y=5-i;
}
dir=3;
/*** 输出初始地图,蛇与食物 ***/
system("cls");
hide();
print_wall();
print_food();
print_snake();
locate(m+2,0);
cout << "Now length: ";
/*** 开始游戏 ***/
while (1)
{
/*** 难度随长度增加而提高 ***/
hard_len=(double)snake_length/(double) (m*n);
/*** 调节时间,单位是ms ***/
a=clock();
while (1)
{
b=clock();
if (b-a>=(int)(400-30*hard)*(1-sqrt(hard_len))) break;
}
/*** 接受键盘输入的上下左右,并以此改变方向 ***/
if (kbhit())
{
ch=getch();
if (ch==-32)
{
ch=getch();
switch(ch)
{
case 72:
if (dir==2 || dir==3)
dir=0;
break;
case 80:
if (dir==2 || dir==3)
dir=1;
break;
case 75:
if (dir==0 || dir==1)
dir=2;
break;
case 77:
if (dir==0 || dir==1)
dir=3;
break;
}
}
}
/*** 前进 ***/
if (!go_ahead()) break;
/*** 在最后输出此时长度 ***/
locate(m+2,12);
cout << snake_length;
}
system("pause");
return 0;
}
飞机大战
C++#include<iostream>
#include<windows.h>
#include<conio.h>
#include<time.h>
#include<string>
using namespace std;
/*=============== all the structures ===============*/
typedef struct Frame {
COORD position[2];
int flag;
} Frame;
/*=============== all the functions ===============*/
void SetPos(COORD a) { // set cursor
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(out, a);
}
void SetPos(int i, int j) { // set cursor
COORD pos = {i, j};
SetPos(pos);
}
void HideCursor() {
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
//把第y行,[x1, x2) 之间的坐标填充为 ch
void drawRow(int y, int x1, int x2, char ch) {
SetPos(x1, y);
for (int i = 0; i <= (x2 - x1); i++)
cout << ch;
}
//在a, b 纵坐标相同的前提下,把坐标 [a, b] 之间填充为 ch
void drawRow(COORD a, COORD b, char ch) {
if (a.Y == b.Y)
drawRow(a.Y, a.X, b.X, ch);
else {
SetPos(0, 25);
cout << "error code 01:无法填充行,因为两个坐标的纵坐标(x)不相等";
system("pause");
}
}
//把第x列,[y1, y2] 之间的坐标填充为 ch
void drawCol(int x, int y1, int y2, char ch) {
int y = y1;
while (y != y2 + 1) {
SetPos(x, y);
cout << ch;
y++;
}
}
//在a, b 横坐标相同的前提下,把坐标 [a, b] 之间填充为 ch
void drawCol(COORD a, COORD b, char ch) {
if (a.X == b.X)
drawCol(a.X, a.Y, b.Y, ch);
else {
SetPos(0, 25);
cout << "error code 02:无法填充列,因为两个坐标的横坐标(y)不相等";
system("pause");
}
}
//左上角坐标、右下角坐标、用row填充行、用col填充列
void drawFrame(COORD a, COORD b, char row, char col) {
drawRow(a.Y, a.X + 1, b.X - 1, row);
drawRow(b.Y, a.X + 1, b.X - 1, row);
drawCol(a.X, a.Y + 1, b.Y - 1, col);
drawCol(b.X, a.Y + 1, b.Y - 1, col);
}
void drawFrame(int x1, int y1, int x2, int y2, char row, char col) {
COORD a = {x1, y1};
COORD b = {x2, y2};
drawFrame(a, b, row, col);
}
void drawFrame(Frame frame, char row, char col) {
COORD a = frame.position[0];
COORD b = frame.position[1];
drawFrame(a, b, row, col);
}
void drawPlaying() {
drawFrame(0, 0, 48, 24, '=', '|');// draw map frame;
drawFrame(49, 0, 79, 4, '-', '|');// draw output frame
drawFrame(49, 4, 79, 9, '-', '|');// draw score frame
drawFrame(49, 9, 79, 20, '-', '|');// draw operate frame
drawFrame(49, 20, 79, 24, '-', '|');// draw other message frame
SetPos(52, 6);
cout << "得分:";
SetPos(52, 7);
cout << "称号:";
SetPos(52, 10);
cout << "操作方式:";
SetPos(52, 12);
cout << "a,s,d,w控制战机,k发射子弹。";
SetPos(52, 14);
cout << " p 暂停游戏。";
SetPos(52, 16);
cout << " e 退出游戏。";
}
//在[a, b)之间产生一个随机整数
int random(int a, int b) {
int c = (rand() % (a - b)) + a;
return c;
}
//在两个坐标包括的矩形框内随机产生一个坐标
COORD random(COORD a, COORD b) {
int x = random(a.X, b.X);
int y = random(a.Y, b.Y);
COORD c = {x, y};
return c;
}
bool judgeCoordInFrame(Frame frame, COORD spot) {
if (spot.X >= frame.position[0].X)
if (spot.X <= frame.position[1].X)
if (spot.Y >= frame.position[0].Y)
if (spot.Y <= frame.position[0].Y)
return true;
return false;
}
void printCoord(COORD a) {
cout << "( " << a.X << " , " << a.Y << " )";
}
void printFrameCoord(Frame a) {
printCoord(a.position[0]);
cout << " - ";
printCoord(a.position[1]);
}
int drawMenu() {
SetPos(30, 1);
cout << "P l a n e W a r";
drawRow(3, 0, 79, '-');
drawRow(5, 0, 79, '-');
SetPos(28, 4);
cout << "w 和 s 选择, k 确定";
SetPos(15, 11);
cout << "1. 简单的敌人";
SetPos(15, 13);
cout << "2. 冷酷的敌人";
drawRow(20, 0, 79, '-');
drawRow(22, 0, 79, '-');
SetPos(47, 11);
cout << "简单的敌人:";
SetPos(51, 13);
cout << "简单敌人有着较慢的移动速度。";
SetPos(24, 21);
cout << "制作:YCX";
int j = 11;
SetPos(12, j);
cout << ">>";
//drawFrame(45, 9, 79, 17, '=', '|');
while (1) {
if ( _kbhit() ) {
char x = _getch();
switch (x) {
case 'w' : {
if ( j == 13) {
SetPos(12, j);
cout << " ";
j = 11;
SetPos(12, j);
cout << ">>";
SetPos(51, 13);
cout << " ";
SetPos(47, 11);
cout << "简单的敌人:";
SetPos(51, 13);
cout << "简单敌人有着较慢的移动速度,容易对付。";
}
break;
}
case 's' : {
if ( j == 11 ) {
SetPos(12, j);
cout << " ";
j = 13;
SetPos(12, j);
cout << ">>";
SetPos(51, 13);
cout << " ";
SetPos(47, 11);
cout << "冷酷的敌人:";
SetPos(51, 13);
cout << "冷酷的敌人移动速度较快,难对付哟!!!";
}
break;
}
case 'k' : {
if (j == 8) return 1;
else return 2;
}
}
}
}
}
/*
DWORD WINAPI MusicFun(LPVOID lpParamte)
{
//DWORD OBJ;
sndPlaySound(TEXT("bgm.wav"), SND_FILENAME|SND_ASYNC);
return 0;
}
*/
/*================== the Game Class ==================*/
class Game {
public:
COORD position[10];
COORD bullet[10];
Frame enemy[8];
int score;
int rank;
int rankf;
string title;
int flag_rank;
Game ();
//初始化所有
void initPlane();
void initBullet();
void initEnemy();
//初始化其中一个
//void initThisBullet( COORD );
//void initThisEnemy( Frame );
void planeMove(char);
void bulletMove();
void enemyMove();
//填充所有
void drawPlane();
void drawPlaneToNull();
void drawBullet();
void drawBulletToNull();
void drawEnemy();
void drawEnemyToNull();
//填充其中一个
void drawThisBulletToNull( COORD );
void drawThisEnemyToNull( Frame );
void Pause();
void Playing();
void judgePlane();
void judgeEnemy();
void Shoot();
void GameOver();
void printScore();
};
Game::Game() {
initPlane();
initBullet();
initEnemy();
score = 0;
rank = 25;
rankf = 0;
flag_rank = 0;
}
void Game::initPlane() {
COORD centren = {39, 22};
position[0].X = position[5].X = position[7].X = position[9].X = centren.X;
position[1].X = centren.X - 2;
position[2].X = position[6].X = centren.X - 1;
position[3].X = position[8].X = centren.X + 1;
position[4].X = centren.X + 2;
for (int i = 0; i <= 4; i++)
position[i].Y = centren.Y;
for (int i = 6; i <= 8; i++)
position[i].Y = centren.Y + 1;
position[5].Y = centren.Y - 1;
position[9].Y = centren.Y - 2;
}
void Game::drawPlane() {
for (int i = 0; i < 9; i++) {
SetPos(position[i]);
if (i != 5)
cout << "O";
else if (i == 5)
cout << "|";
}
}
void Game::drawPlaneToNull() {
for (int i = 0; i < 9; i++) {
SetPos(position[i]);
cout << " ";
}
}
void Game::initBullet() {
for (int i = 0; i < 10; i++)
bullet[i].Y = 30;
}
void Game::drawBullet() {
for (int i = 0; i < 10; i++) {
if ( bullet[i].Y != 30) {
SetPos(bullet[i]);
cout << "★";
}
}
}
void Game::drawBulletToNull() {
for (int i = 0; i < 10; i++)
if ( bullet[i].Y != 30 ) {
COORD pos = {bullet[i].X, bullet[i].Y + 1};
SetPos(pos);
cout << " ";
}
}
void Game::initEnemy() {
COORD a = {1, 1};
COORD b = {45, 15};
for (int i = 0; i < 8; i++) {
enemy[i].position[0] = random(a, b);
enemy[i].position[1].X = enemy[i].position[0].X + 3;
enemy[i].position[1].Y = enemy[i].position[0].Y + 2;
}
}
void Game::drawEnemy() {
for (int i = 0; i < 8; i++)
drawFrame(enemy[i].position[0], enemy[i].position[1], '-', '|');
}
void Game::drawEnemyToNull() {
for (int i = 0; i < 8; i++) {
drawFrame(enemy[i].position[0], enemy[i].position[1], ' ', ' ');
}
}
void Game::Pause() {
SetPos(61, 2);
cout << " ";
SetPos(61, 2);
cout << "暂停中...";
char c = _getch();
while (c != 'p')
c = _getch();
SetPos(61, 2);
cout << " ";
}
void Game::planeMove(char x) {
if (x == 'a')
if (position[1].X != 1)
for (int i = 0; i <= 9; i++)
position[i].X -= 2;
if (x == 's')
if (position[7].Y != 23)
for (int i = 0; i <= 9; i++)
position[i].Y += 1;
if (x == 'd')
if (position[4].X != 47)
for (int i = 0; i <= 9; i++)
position[i].X += 2;
if (x == 'w')
if (position[5].Y != 3)
for (int i = 0; i <= 9; i++)
position[i].Y -= 1;
}
void Game::bulletMove() {
for (int i = 0; i < 10; i++) {
if ( bullet[i].Y != 30) {
bullet[i].Y -= 1;
if ( bullet[i].Y == 1 ) {
COORD pos = {bullet[i].X, bullet[i].Y + 1};
drawThisBulletToNull( pos );
bullet[i].Y = 30;
}
}
}
}
void Game::enemyMove() {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 2; j++)
enemy[i].position[j].Y++;
if (24 == enemy[i].position[1].Y) {
COORD a = {1, 1};
COORD b = {45, 3};
enemy[i].position[0] = random(a, b);
enemy[i].position[1].X = enemy[i].position[0].X + 3;
enemy[i].position[1].Y = enemy[i].position[0].Y + 2;
}
}
}
void Game::judgePlane() {
for (int i = 0; i < 8; i++)
for (int j = 0; j < 9; j++)
if (judgeCoordInFrame(enemy[i], position[j])) {
SetPos(62, 1);
cout << "坠毁";
drawFrame(enemy[i], '+', '+');
Sleep(1000);
GameOver();
break;
}
}
void Game::drawThisBulletToNull( COORD c) {
SetPos(c);
cout << " ";
}
void Game::drawThisEnemyToNull( Frame f ) {
drawFrame(f, ' ', ' ');
}
void Game::judgeEnemy() {
for (int i = 0; i < 8; i++)
for (int j = 0; j < 10; j++)
if ( judgeCoordInFrame(enemy[i], bullet[j]) ) {
score += 5;
drawThisEnemyToNull( enemy[i] );
COORD a = {1, 1};
COORD b = {45, 3};
enemy[i].position[0] = random(a, b);
enemy[i].position[1].X = enemy[i].position[0].X + 3;
enemy[i].position[1].Y = enemy[i].position[0].Y + 2;
drawThisBulletToNull( bullet[j] );
bullet[j].Y = 30;
}
}
void Game::Shoot() {
for (int i = 0; i < 10; i++)
if (bullet[i].Y == 30) {
bullet[i].X = position[5].X;
bullet[i].Y = position[5].Y - 1;
break;
}
}
void Game::printScore() {
if (score == 120 && flag_rank == 0) {
rank -= 3;
flag_rank = 1;
}
else if ( score == 360 && flag_rank == 1) {
rank -= 5;
flag_rank = 2;
} else if ( score == 480 && flag_rank == 2) {
rank -= 5;
flag_rank = 3;
}
int x = rank / 5;
SetPos(60, 6);
cout << score;
if ( rank != rankf ) {
SetPos(60, 7);
if ( x == 5)
title = "初级飞行员";
else if ( x == 4)
title = "中级飞行员";
else if ( x == 3)
title = "高级飞行员";
else if ( x == 2 )
title = "王牌飞行员";
cout << title;
}
rankf = rank;
}
void Game::Playing() {
//HANDLE MFUN;
//MFUN= CreateThread(NULL, 0, MusicFun, NULL, 0, NULL);
drawEnemy();
drawPlane();
int flag_bullet = 0;
int flag_enemy = 0;
while (1) {
Sleep(8);
if (_kbhit()) {
char x = _getch();
if ('a' == x || 's' == x || 'd' == x || 'w' == x) {
drawPlaneToNull();
planeMove(x);
drawPlane();
judgePlane();
} else if ('p' == x)
Pause();
else if ( 'k' == x)
Shoot();
else if ( 'e' == x) {
//CloseHandle(MFUN);
GameOver();
break;
}
}
/* 处理子弹 */
if ( 0 == flag_bullet ) {
bulletMove();
drawBulletToNull();
drawBullet();
judgeEnemy();
}
flag_bullet++;
if ( 5 == flag_bullet )
flag_bullet = 0;
/* 处理敌人 */
if ( 0 == flag_enemy ) {
drawEnemyToNull();
enemyMove();
drawEnemy();
judgePlane();
}
flag_enemy++;
if ( flag_enemy >= rank )
flag_enemy = 0;
/* 输出得分 */
printScore();
}
}
void Game::GameOver() {
system("cls");
COORD p1 = {28, 9};
COORD p2 = {53, 15};
drawFrame(p1, p2, '=', '|');
SetPos(36, 12);
string str = "Game Over!";
for (int i = 0; i < str.size(); i++) {
Sleep(80);
cout << str[i];
}
Sleep(1000);
system("cls");
drawFrame(p1, p2, '=', '|');
SetPos(31, 11);
cout << "击落敌机:" << score / 5 << " 架";
SetPos(31, 12);
cout << "得 分:" << score;
SetPos(31, 13);
cout << "获得称号:" << title;
SetPos(30, 16);
Sleep(1000);
cout << "继续? 是(y)| 否(n) 制作:YCX";
as:
char x = _getch();
if (x == 'n')
exit(0);
else if (x == 'y') {
system("cls");
Game game;
int a = drawMenu();
if (a == 2)
game.rank = 20;
system("cls");
drawPlaying();
game.Playing();
} else goto as;
}
/*================== the main function ==================*/
int main() {
//游戏准备
srand((int)time(0)); //随机种子
HideCursor(); //隐藏光标
Game game;
int a = drawMenu();
if (a == 2)
game.rank = 20;
system("cls");
drawPlaying();
game.Playing();
}
苍穹世界
C++#include<stdio.h>
#include<ctime>
#include<time.h> //suiji
#include<windows.h> //SLEEP函数
struct Player { //玩家结构体,并初始化player
char name[21];
int attack;
int defense;
int health;
long int max_health;
int level;
int exp;
int range_exp;
long int max_exp;
} player = {"勇者", 50, 40, 100, 100, 1, 0, 0, 100};
struct Enemy { //怪的结构体,并初始化各种怪
char name[20];
char wupin[12];
int attack;
int defense;
int health;
int money;
long int exp;
int wupin_sign;
int wupinpro;
int double_attack;
int miss;
} strongman = {"森林巨人", "黄金圣衣", 40, 50, 350, 200, 100, 1, 2, 1, 0},
witch = {"森林女巫", "银甲", 25, 15, 100, 50, 50, 2, 2, 1, 1},
xiyi = {"森林蜥蜴", "铁甲", 18, 10, 50, 30, 35, 3, 3, 2, 2},
big_strongman = {"森林巨人王", "巨人晶石", 40 * 5, 50 * 5, 200 * 5, 200 * 5, 100 * 5, 4, 4, 2, 0},
lion = {"草原雄狮", "绝世好剑", 60, 30, 280, 200, 100, 5, 2, 1, 0},
horse = {"草原野马", "碧血剑", 28, 12, 90, 50, 50, 6, 2, 1, 1},
bee = {"草原黄蜂", "长剑", 17, 11, 60, 30, 35, 7, 3, 2, 2},
shitu = {"使徒", "\0", 60 * 8, 30 * 8, 280 * 8, 200 * 8, 100 * 8, 9, 1, 1, 0},
guai = {"\0", "\0", 0, 0, 0, 0, 0, 0, 0, 0, 0};
struct Place {
int bar, hotel, forest1, forest2, forest3, grass1, grass2, grass3;
} place = {1, 2, 3, 4, 5, 6, 7, 8};
int max_exp = 0;
int choose_number = 0, s = 0, strongman_arm = 0, battle = 0, money = 500, place_sign = 9;
int cao = 3, jijiubao = 2, baiyao = 2, superbaiyao = 1, boom = 3, dubiao = 2, atom_boom = 1;
int fang = 0, fang1 = 10, fang1n = 0, fang2 = 20, fang2n = 0, fang3 = 40, fang3n = 0, fang4 = 100, fang4n = 0;
int gong = 0, gong1 = 8, gong1n = 0, gong2 = 15, gong2n = 0, gong3 = 25, gong3n = 0, gong4 = 60, gong4n = 0;
int jingyancao = 0, jingyanbao = 0, jingyanshi = 0;
char gongname[20] = "无", fangname[20] = "无";
char proof;
void AddWupin(int);
int AttackResult();
void BattleAct();
void ChooseWupin();
void DisplayState();
void OrdinaryAct();
int SuiJi();
int SuiJi100();
void WhetherLevelUp();
void SlowDisplay(char *);
int main() {
int i = 0, j = 0, k = 0;
char player_name[21];
Sleep(1000);
printf("--------------------------欢迎来到 [苍穹世界] 2.2 测试版-----------------------\n\n\n");
//如果想使用外挂,名字请输入:“圣战斗士 ”。
Sleep(1000);
printf("这里是苍穹世界! 雅莉萨斯国的罗茜公主被陌生人绑架了!\n\n\n 伟大的勇者啊~拿起你们的武器,营救公主!\n\n\n输入你的名字: (20个字符)\n\n\n");
scanf("%s", player_name);
strncpy(player.name, player_name, 20);
if (strcmp(player.name, "圣战斗士") == 0) {
printf("\n\n\n封印多年的圣剑血统啊!你终于觉醒了!\n\n\n圣战斗士,你成为了天选之人,请你救出公主吧!\n\n\n");
player.attack = 999;
player.defense = 999;
player.health = 9999;
player.max_health = 9999;
}
getchar();
OrdinaryAct();
return 0;
}
int SuiJi() {
srand((unsigned)time(NULL));
return rand() % 10;
}
int SuiJi100() {
srand((unsigned)time(NULL));
return rand() % 100;
}
void ChooseWupin() { //选择物品 并使用
printf("物品: 1,止血草%d个 2,急救包%d个 3,云南白药%d个 4,超级云南白药%d个 5,手雷%d个 6,毒标%d个 7,手抛式原子弹%d个 8,经验草%d个 9,经验包%d个 10,经验石%d个 11,巨人晶石%d个 0,返回\n\n\n", cao, jijiubao, baiyao, superbaiyao, boom, dubiao, atom_boom, jingyancao, jingyanbao, jingyanshi, strongman_arm);
switch (scanf("%d", &choose_number), choose_number) {
case 1:
if (cao > 0) {
printf("使用止血草,HP增加60\n\n\n");
cao--;
if (player.health + 60 > player.max_health)player.health = player.max_health;
else player.health += 60;
} else printf("没有止血草了\n\n\n");
break;
case 2:
if (jijiubao > 0) {
printf("使用急救包,HP增加80\n\n\n");
jijiubao--;
if (player.health + 80 > player.max_health)player.health = player.max_health;
else player.health += 80;
} else printf("没有急救包了\n\n\n");
break;
case 3:
if (baiyao > 0) {
printf("使用云南白药,HP增加120\nz\n\n");
baiyao--;
if (player.health + 120 > player.max_health)player.health = player.max_health;
else player.health += 120;
} else printf("没有云南白药了\n\n\n");
break;
case 4:
if (superbaiyao > 0) {
printf("使用超级云南白药,HP增加200\n\n\n");
superbaiyao--;
if (player.health + 200 > player.max_health)player.health = player.max_health;
else player.health += 200;
} else printf("没有超级云南白药了\n\n\n");
break;
case 5:
if (battle) { //在战斗中(battle=1),否则(battle=0)不能使用攻击性物品
if (boom > 0) {
printf("使用手雷,敌人HP减少100\n\n\n");
boom--;
guai.health -= 100;
AttackResult();
}
} else printf("非战斗状态,不能使用手雷!\n\n\n");
break;
case 6:
if (battle) { //在战斗中(battle=1),否则(battle=0)不能使用攻击性物品
if (dubiao > 0) {
printf("使用毒标,敌人HP减少200\n\n\n");
dubiao--;
guai.health -= 200;
AttackResult();
}
} else printf("非战斗状态,不能使用毒标!\n\n\n");
break;
case 7:
if (battle) { //在战斗中(battle=1),否则(battle=0)不能使用攻击性物品
if (atom_boom > 0) {
printf("使用手抛式原子弹,敌人HP减少666666666\n\n\n");
atom_boom--;
guai.health -= 666666666;
AttackResult();
}
} else printf("非战斗状态,不能使用手抛式原子弹!\n\n\n");
break;
case 8:
if (jingyancao > 0 && player.level < 1000) {
printf("使用经验草,等级增加10级\n\n\n");
jingyancao--;
player.level += 10;
printf("等级:%d\n", player.level);
} else if (jingyancao < 1) {
printf("没有经验草了\n\n\n");
} else printf("等级超过45级,修为太高,无法使用。\n\n\n");
break;
case 9:
if (jingyanbao > 0 && player.level < 1000) {
if (player.level > 44 && player.level < 1000) {
int sheng;
sheng = 45 - player.level;
player.level += sheng;
printf("使用经验包,等级增加%d级", sheng);
printf("等级:%d\n", player.level);
} else {
printf("使用经验包,等级增加2级\n\n\n");
jingyanbao--;
player.level += 2;
printf("等级:%d\n", player.level);
}
} else if (jingyanbao < 1) {
printf("没有经验包了");
} else printf("等级超过45级,修为太高,无法使用。\n\n\n");
break;
case 10:
if (jingyanshi > 0 && player.level < 1000) {
if (player.level > 42 && player.level < 1000) {
int sheng;
sheng = 45 - player.level;
player.level += sheng;
printf("使用经验石,等级增加%d级\n", sheng);
printf("等级:%d\n", player.level);
} else {
printf("使用经验石,等级增加10级\n");
jingyanshi--;
player.level += 10;
}
} else if (jingyanshi < 1) {
printf("没有经验石了\n\n\n");
} else printf("等级超过45级,修为太高,无法使用。\n\n\n");
break;
case 11:
if (strongman_arm > 0 && player.level < 10000) {
if (player.level > 29 && player.level < 10000) {
int sheng;
sheng = 45 - player.level;
player.level += sheng;
printf("使用巨人晶石,等级增加%d级", sheng);
printf("等级:%d\n", player.level);
} else {
printf("使用巨人晶石,等级增加16级\n\n\n");
strongman_arm--;
player.level += 16;
printf("等级:%d\n", player.level);
}
} else if (strongman_arm < 1) {
printf("没有巨人晶石了。\n\n\n");
} else printf("等级超过45级,修为太高,无法使用。\n\n\n");
break;
case 0:
break;
default:
printf("ChooseWupin error!\n\n\n");
}
}
int AttackResult() { //攻击结果:判断是否获胜 是否获得物品 和 是否升级
if (guai.health <= 0) {
battle = 0;
printf("战斗胜利!获得金币%d,经验%d\n\n\n", guai.money, guai.exp);
player.exp += guai.exp;
player.range_exp += guai.exp;
money += guai.money;
s = SuiJi();
if (s < guai.wupinpro) {
printf("从敌人尸骸中发现");
printf("%s\n\n\n", guai.wupin);
AddWupin(guai.wupin_sign);
}
WhetherLevelUp();
if (strcmp(guai.name, "使徒") == 0) {
printf("战斗胜利,救出公主!!!");
getchar();
getchar();
exit(0);
}
return 1; //攻击有结果了返回1,否则返回0,用于判断是否继续做战斗行为
} else {
int s = SuiJi();
if ((guai.attack + s - player.defense / 3) < 0) {
player.health -= 1;
printf("%s反击,你的HP减少了 1\n\n", guai.name);
} else {
player.health -= guai.attack + s - player.defense / 3;
printf("%s反击,你的HP减少了%d\n\n", guai.name, guai.attack + s - player.defense / 3);
}
if (player.health < 0) {
battle = 0;
printf("%s战死!金币掉落%d\n\n\n", player.name, player.level * 500);
money -= player.level * 500;
player.health = player.max_health / 5;
OrdinaryAct();//
return 1;
}
}
return 0;
}
void AddWupin(int wupin_sign) {
switch (wupin_sign) {
case 1:
fang4n++;
break;
case 2:
fang3n++;
break;
case 3:
fang2n++;
break;
case 4:
strongman_arm = 1;
break;
case 5:
gong4n++;
break;
case 6:
gong3n++;
break;
case 7:
gong2n++;
break;
default:
printf("AddWupin error\n\n\n");
}
}
void WhetherLevelUp() {
int i = 0, j = 0;
int l1 = player.range_exp / 100;
int l2 = player.range_exp / 300;
int l3 = player.range_exp / 600;
if (player.level <= 15 && l1 > 0) { //15级以下,经验足够 都满足则升级
if (l1 == 1) {
printf("%s", player.name);
printf(" 升级!\n\n\n攻击力+3, 防御力+2, HP上限+20\n\n\n");
player.exp = player.exp + guai.exp - (player.exp + guai.exp) % 100;
player.attack += 3;
player.defense += 2;
player.max_health += 20;
player.health = player.max_health;
player.level++;
player.range_exp = 0;
player.exp = player.max_exp;
player.max_exp += 100;
} else {
printf("好厉害!连升%d级!", l1);
printf("攻击力+%d, 防御力+%d, HP上限+%d\n\n\n", 3 * l1, 2 * l1, 20 * l1);
player.exp = (player.exp + guai.exp) || player.exp - ((player.exp + guai.exp) || player.exp) % 100;
player.attack += 3 * l1;
player.defense += 2 * l1;
player.max_health += 20 * l1;
player.health = player.max_health;
player.level += l1;
player.range_exp = 0;
player.exp = player.max_exp;
player.max_exp += 100 * l1;
}
} else if (player.level <= 40 && l2 > 0) {
if (l2 == 1) {
printf("%s", player.name);
printf(" 升级!\n\n\n攻击力+3, 防御力+2, HP上限+20\n\n\n");
player.exp = player.exp + guai.exp - (player.exp + guai.exp) % 100;
player.attack += 3;
player.defense += 2;
player.max_health += 20;
player.health = player.max_health;
player.level++;
player.range_exp = 0;
player.exp = player.max_exp;
player.max_exp += 300;
} else {
printf("好厉害!连升%d级!", l1);
printf("攻击力+%d, 防御力+%d, HP上限+%d\n\n\n", 3 * l2, 2 * l2, 20 * l2);
player.exp = player.exp + guai.exp - (player.exp + guai.exp) % 100;
player.attack += 3 * l2;
player.defense += 2 * l2;
player.max_health += 20 * l2;
player.health = player.max_health;
player.level += l2;
player.range_exp = 0;
player.exp = player.max_exp;
player.max_exp += 300 * l2;
}
} else if (l3 > 0) {
if (l3 == 1) {
printf("%s", player.name);
printf(" 升级!\n\n\n攻击力+3, 防御力+2, HP上限+20\n\n\n");
player.exp = player.exp + guai.exp - (player.exp + guai.exp) % 100;
player.attack += 3;
player.defense += 2;
player.max_health += 20;
player.health = player.max_health;
player.level++;
player.range_exp = 0;
player.exp = player.max_exp;
player.max_exp += 600;
} else {
printf("好厉害!连升%d级!", l1);
printf("攻击力+%d, 防御力+%d, HP上限+%d\n\n\n", 3 * l3, 2 * l3, 20 * l3);
player.exp = player.exp + guai.exp - (player.exp + guai.exp) % 100;
player.attack += 3 * l3;
player.defense += 2 * l3;
player.max_health += 20 * l3;
player.health = player.max_health;
player.level += l3;
player.range_exp = 0;
player.exp = player.max_exp;
player.max_exp += 600 * l3;
}
}
}
void OrdinaryAct() { //正常行为菜单(移动,物品,对话,查看状态,装备,退出游戏)
while (1) {
// \(1000);
// system("cls");
puts("=============================================================================");
printf("要做什么?\n\n\n 1,移动 2,道具 3,对话 4,查看状态 5,装备 6,关于游戏 0,退出游戏\n\n\n");
puts("=============================================================================");
switch (scanf("%d", &choose_number), choose_number) {
case 1: //显示移动菜单
printf("要去哪里?\n\n\n");
printf("1,happy酒吧 2,诺亚方舟酒店 3,北朝商会 4,红玉拍卖行 5,冒险荒野\n\n\n");
switch (scanf("%d", &choose_number), choose_number) {
case 1:
place_sign = place.bar; //记录目前位置-酒吧
// OrdinaryAct();
break;
case 2:
place_sign = place.hotel; //进入旅店
printf("金币:%d", money);
printf("要开房吗? 200个金币 1,是 0,否\n\n\n");
choose_number = 1;
switch (scanf("%d", &choose_number), choose_number) {
case 1:
if (money - 200 < 0) { //判断钱是否够
printf("Sorry,你的钱不够~\n\n\n");
printf("金币:%d", money);
} else {
printf("好好休息\nHP满\n第二天了\n\n");
printf("金币:%d\n", money);
money -= 200; //花费200住店费
player.health = player.max_health; //体力满
}
break;
case 0:
printf("下次再来!\n\n\n");
break;
default:
printf("hotel talk error!\n\n\n");
}
place_sign = 0;
break;
case 3:
int yongju, gong, fang;
printf("请问您要购买什么类型的物品?\n\n\n 1,攻击装备 2,防御装备 3,一次性伤害武器\n\n\n");
scanf("%d", &yongju);
switch (yongju) {
case 1:
printf("请问您要购买什么武器?\n\n\n 1,匕首¥300 2,长剑¥500 3,碧血剑¥1000\n\n\n");
scanf("%d", &gong);
switch (gong) {
case 1:
if (money >= 300) {
gong1n++;
money = money - 300;
printf ("匕首+1\n");
printf("匕首:%d个\n", gong1n);
printf("金币:%d\n", money);
break;
} else {
printf("钱不够!\n");
printf("金币:%d\n", money);
break;
}
case 2:
if (money >= 500) {
gong2n++;
money = money - 500;
printf ("长剑+1\n");
printf("长剑:%d个\n", gong2n);
printf("金币:%d\n", money);
break;
} else {
printf("钱不够!\n");
printf("金币:%d\n", money);
break;
}
case 3:
if (money >= 1000) {
gong3n++;
money = money - 1000;
printf ("碧血剑+1\n");
printf("碧血剑:%d个\n", gong3n);
printf("金币:%d\n", money);
break;
} else {
printf("钱不够!\n");
printf("金币:%d\n", money);
break;
}
default:
printf("对不起,我们只会打造以上武器。");
break;
}
break;
case 2:
int fang;
printf("请问您要购买什么防具?\n\n\n 1,布衣¥300 2,铁甲¥500 3,银甲¥1000\n\n\n");
scanf("%d", &fang);
switch (fang) {
case 1:
if (money >= 300) {
fang1n++;
money = money - 300;
printf ("布衣+1\n");
printf("布衣:%d个\n", fang1n);
printf("金币:%d\n", money);
} else {
printf("钱不够!\n");
printf("金币:%d\n", money);
}
break;
case 2:
if (money >= 500) {
fang2n++;
money = money - 500;
printf ("铁甲+1\n");
printf("铁甲:%d个\n", fang2n);
printf("金币:%d\n", money);
} else {
printf("钱不够!\n");
printf("金币:%d", money);
}
break;
case 3:
if (money >= 1000) {
fang3n++;
money = money - 1000;
printf ("银甲+1\n");
printf("银甲:%d个\n", fang3n);
printf("金币:%d\n", money);
} else {
printf("钱不够!\n");
printf("金币:%d\n", money);
}
default:
printf("对不起,我们只会打造以上防具。");
break;
}
printf("金币:%d\n", money);
break;
case 3:
printf("请问您要购买什么一次性伤害武器?\n 1,手雷 2,毒镖 3,手抛式原子弹\n\n\n");
int yi;
scanf("%d", &yi);
switch (yi) {
case 1:
if (money >= 300 && boom < 5) {
boom++;
money = money - 300;
printf("手雷+1\n");
printf("手雷:%d\n", boom);
printf("金币:%d\n", money);
} else {
printf("钱不够!\n");
printf("金币:%d", money);
}
break;
case 2:
if (money >= 600 && dubiao < 4) {
dubiao++;
money = money - 600;
printf("毒镖+1\n");
printf("毒镖:%d\n", dubiao);
printf("金币:%d\n", money);
} else {
printf("钱不够!\n");
printf("金币:%d\n", money);
}
break;
case 3:
if (money >= 0 && atom_boom < 23333333333) {
atom_boom = atom_boom + 233;
money = money + 1500;
printf("手抛式原子弹+2\n");
printf("手抛式原子弹:%d\n", atom_boom);
printf("金币:%d\n", money);
} else {
printf("钱不够!\n\n\n");
printf("金币:%d\n", money);
}
break;
}
}
break;
case 4:
printf ("欢迎您光临本拍卖行,请问您要卖什么东西?\n\n");
printf("攻击装备: 1,匕首:%d个 2,长剑:%d个 3,碧血剑:%d个 4,绝世好剑:%d个\n", gong1n, gong2n, gong3n, gong4n);
printf("防御装备: 5,布衣:%d个 6,铁甲:%d个 7,银甲:%d个 8,黄金圣衣:%d个\n9,巨人晶石:%d个 0,返回\n\n\n", fang1n, fang2n, fang3n, fang4n, strongman_arm);
int pai, shu, i;
scanf("%d", &pai);
switch (pai) {
case 1:
printf("请问您要出售几件?");
scanf("%d", &shu);
if (gong1n >= shu) {
gong1n = gong1n - shu;
money = money + shu * 240;
printf("匕首:%d\n", gong1n);
printf("金币:%d\n", money);
break;
} else {
printf("装备数不够,无法出售!\n");
break;
}
break;
case 2:
printf("请问您要出售几件?\n");
scanf("%d", &shu);
if (gong2n >= shu) {
gong2n = gong2n - shu;
money = money + shu * 400;
printf("长剑:%d\n", gong2n);
printf("金币:%d\n", money);
break;
} else {
printf("装备数不够,无法出售!\n");
break;
}
case 3:
printf("请问您要出售几件?\n");
scanf("%d", &shu);
if (gong3n >= shu) {
gong3n = gong3n - shu;
money = money + shu * 800;
printf("碧血剑:%d\n", gong3n);
printf("金币:%d\n", money);
break;
} else {
printf("装备数不够,无法出售!\n");
break;
}
case 4:
printf("请问您要出售几件?\n");
scanf("%d", &shu);
if (gong4n >= shu) {
gong4n = gong4n - shu;
money = money + shu * 1500;
printf("绝世好剑:%d\n", gong4n);
printf("金币:%d\n", money);
break;
} else {
printf("装备数不够,无法出售!\n");
break;
}
case 5:
printf("请问您要出售几件?\n");
scanf("%d", &shu);
if (fang1n >= shu) {
fang1n = fang1n - shu;
money = money + shu * 240;
printf("布衣:%d\n", fang1n);
printf("金币:%d\n", money);
break;
} else {
printf("装备数不够,无法出售!\n");
break;
}
case 6:
printf("请问您要出售几件?\n");
scanf("%d", &shu);
if (fang2n >= shu) {
fang2n = fang2n - shu;
money = money + shu * 500;
printf("铁甲:%d\n", fang2n);
printf("金币:%d\n", money);
break;
} else {
printf("装备数不够,无法出售!\n");
break;
}
case 7:
printf("请问您要出售几件?\n");
scanf("%d", &shu);
if (fang3n >= shu) {
fang3n = fang3n - shu;
money = money + shu * 800;
printf("银甲:%d\n", fang3n);
printf("金币:%d\n", money);
break;
} else {
printf("装备数不够,无法出售!\n");
break;
}
break;
case 8:
printf("请问您要出售几件?\n");
scanf("%d", &shu);
if (fang1n >= shu) {
fang4n = fang4n - shu;
money = money + shu * 1500;
printf("黄金圣衣:%d\n", fang4n);
printf("金币:%d\n", money);
break;
} else {
printf("装备数不够,无法出售!\n");
break;
}
case 9:
printf("请问您要出售几颗?");
scanf("%d", &shu);
if (strongman_arm >= shu) {
strongman_arm = strongman_arm - shu;
money = money + shu * 2000;
printf("巨人晶石:%d\n", strongman_arm);
printf("金币:%d\n", money);
} else {
printf("晶石数不够,无法出售!\n");
break;
}
break;
case 0:
break;
break;
default:
printf("没有该装备,无法出售!\n");
break;
}
break;
case 5:
int yewai;
while (1) {
puts("=============================================================================");
printf("要去哪冒险呢?");
printf("\n\n 1,神秘沼泽 危险程度:★\n\n 2,星耀草原 危险程度:★★\n\n 3,诡异森林 危险程度:★★★\n\n 4,荒漠矿场 危险程度:★★★\n\n 5,炽热炎洞 危险程度:★★★★\n\n 6,花朵宫殿 危险程度:★★★★★\n\n 0,离开\n");
puts("=============================================================================");
scanf("%d", &yewai);
switch (yewai) {
case 1:
place_sign = place.forest1;
s = SuiJi();
if (s < 7) {
battle = 1;
guai = xiyi;
printf("%s扑了过来!\n\n\n", guai.name);
BattleAct();
} else if (s < 9) {
battle = 1;
guai = witch;
printf("%s扑了过来!\n\n\n", guai.name);
BattleAct();
} else {
printf("这里安全\n\n\n");
//不用调用OAct函数,会自动执行OAct函数;
}
break;
case 3:
place_sign = place.forest2;
s = SuiJi();
if (s < 7) {
battle = 1;
guai = witch;
printf("%s扑了过来!\n\n\n", guai.name);
BattleAct();
} else if (s < 9) {
battle = 1;
guai = strongman;
printf("%s扑了过来!\n\n\n", guai.name);
BattleAct();
} else {
printf("这里安全\n\n\n");
}
break;
case 5:
place_sign = place.forest3;
s = SuiJi();
if (s < 7) {
battle = 1;
guai = strongman;
printf("%s扑了过来!\n\n\n", guai.name);
BattleAct();
} else if (s < 9) {
battle = 1;
guai = big_strongman;
printf("%s扑了过来!\n\n\n", guai.name);
BattleAct();
} else {
printf("这里安全\n\n\n");
}
break;
case 2:
place_sign = place.grass1;
s = SuiJi();
if (s < 7) {
battle = 1;
guai = bee;
printf("%s扑了过来!\n\n\n", guai.name);
BattleAct();
} else if (s < 9) {
battle = 1;
guai = horse;
printf("%s扑了过来!\n\n\n", guai.name);
BattleAct();
} else {
printf("这里安全\n\n\n");
}
break;
case 4:
place_sign = place.grass2;
s = SuiJi();
if (s < 7) {
battle = 1;
guai = horse;
printf("%s扑了过来!\n\n\n", guai.name);
BattleAct();
} else if (s < 9) {
battle = 1;
guai = lion;
printf("%s扑了过来!\n\n\n", guai.name);
BattleAct();
} else {
printf("这里安全\n\n\n");
}
break;
case 6:
place_sign = place.grass3;
s = SuiJi();
if (s < 7) {
battle = 1;
guai = lion;
printf("%s扑了过来!\n\n\n", guai.name);
BattleAct();
} else if (s < 9) {
battle = 1;
if (strongman_arm) {
printf("神秘老人:\n\n\n 哈哈,年轻人,做的不错,不过...嘿嘿,你上当啦!巨人晶石我要了,公主你也别想带走!\n\n\n");
guai = shitu;
printf("%s扑了过来!\n\n\n", guai.name);
BattleAct();
} else printf("神秘老人:\n\n\n 年轻人,你好啊.如果你有巨人晶石,我可以告诉你公主的下落哦~\n\n\n");
} else {
printf("这里安全\n\n\n");
}
break;
if (yewai != 0) {
printf("该区域为未知区域,无法进入。\n\n\n");
break;
}
}
if (yewai == 0) {
break;
printf("已离开荒野。");
}
}
}
break;
case 2:
ChooseWupin();
break; //显示道具,并可以使用.
case 3: //对话选项
if (place_sign == place.bar) {
printf("要和谁说话?\n\n\n1,红发女郎 2,赏金猎人 3,酒吧老板 4,药品商人\n\n\n"); //显示对话人物
switch (scanf("%d", &choose_number), choose_number) {
case 1:
printf("红发女郎:\n\n\n 吧台边那个Hunter好帅啊!(~脸红~)\n\n\n听说他经常外出打猎,外面的路他应该很熟悉的!\n\n\n");
break;
case 2:
if (fang1n < 1 && gong1n < 1) {
printf("赏金猎人:\n\n\n 你要救公主啊!好胆量!\n\n\n 不过外面的世界很险恶,而且越深越危险,这是匕首和布衣,对你会有些帮助的,拿去吧!\n\n\n");
printf("%s心想:哇,这位大叔人真好啊!\n\n\n)", player.name);
gong1n++;
fang1n++;
} else printf("赏金猎人:\n\n\n 加油吧,年轻人!\n\n\n 不要被外面世界所吓倒!\n\n\n");
break;
case 3:
printf("要喝点什么?\n\n\n 1,二锅头25金币 HP+20 2,XO酒80金币 HP+50 3,人头马面150金币 HP+100 0,返回\n\n\n");
choose_number = 1;
while (choose_number) {
switch (scanf("%d", &choose_number), choose_number) {
case 1:
if (money < 25) {
printf("钱不够!");
} else {
if (player.health + 20 <= player.max_health) {
printf("HP+20.");
money -= 25;
player.health += 20;
} else {
printf("HP满了");
player.health = player.max_health;
}
}
break;
case 2:
if (money < 80) {
printf("钱不够!");
} else {
if (player.health + 50 <= player.max_health) {
printf("HP+50.");
money -= 80;
player.health += 50;
} else {
printf("HP满了");
player.health = player.max_health;
}
}
break;
case 3:
if (money < 150) {
printf("钱不够!");
} else {
if (player.health + 100 <= player.max_health) {
printf("HP+100.");
money -= 150;
player.health += 100;
} else {
printf("HP满了");
player.health = player.max_health;
}
}
break;
case 0:
printf("下次再来!\n");
break;
default:
printf("输入错误\n\n\n");
break;
}
break;
}
break;
case 4:
printf("你要干什么?\n\n\n 1,买东西 2,聊天 \n\n\n");
int mai;
scanf("%d", &mai);
if (mai == 1) {
printf("买点什么呢?\n1,止血草¥100 HP+60\n2,急救包¥150 HP+80 \n3,云南白药¥250 HP+120\n4,超级云南白药¥400 HP+200 \n5,经验草¥150 经验+300 \n6,经验包¥600 经验+600\n7,经验石¥500 经验+1000 \n0,拜拜\n");
int dongxi;
scanf("%d", &dongxi);
switch (dongxi) {
case 1:
if (money >= 100 && cao < 6) {
cao++;
money = money - 100;
printf ("止血草+1\n");
} else {
printf("钱不够!\n");
}
break;
case 2:
if (money >= 150 && jijiubao < 5) {
jijiubao++;
money = money - 150;
printf ("急救包+1\n");
} else {
printf("钱不够!\n");
}
break;
case 3:
if (money >= 250 && baiyao < 4) {
baiyao++;
money = money - 250;
printf ("云南白药+1\n");
} else {
printf("钱不够!\n");
}
break;
case 4:
if (money >= 400 && superbaiyao < 3) {
superbaiyao++;
money = money - 400;
printf ("超级云南白药+1\n");
} else {
printf("钱不够!\n");
}
break;
case 5:
if (money >= 150) {
jingyancao++;
money = money - 150;
printf ("经验草+1\n");
} else {
printf("钱不够!\n");
}
break;
case 6:
if (money >= 300) {
jingyanbao++;
money = money - 300;
printf ("经验包+1\n");
} else {
printf("钱不够!\n");
}
break;
case 7:
if (money >= 500) {
jingyanshi++;
money = money + 500;
printf ("经验石+1\n");
} else {
printf("钱不够!\n");
}
break;
}
case 0:
printf("金币:%d\n", money);
printf("再见,欢迎下次再来!\n");
break;
}
if (mai == 2) {
printf("药品商人:去去去,老子没时间陪你聊。\n");
}
}
} else if (place_sign == place.hotel)
printf("“老板娘!我...”\n\n\n“我忙着呢,没空理你~”\n\n\n");
else printf("这里好像没人可以聊天\n\n\n");
break;
case 4:
DisplayState();
break; //显示状态
case 5: //装备
printf("攻击装备: 1,匕首:%d个 2,长剑:%d个 3,碧血剑:%d个 4,绝世好剑:%d个\n\n\n", gong1n, gong2n, gong3n, gong4n);
printf("防御装备: 5,布衣:%d个 6,铁甲:%d个 7,银甲:%d个 8,黄金圣衣:%d个\t\t0,返回\n\n\n", fang1n, fang2n, fang3n, fang4n);
printf("选择要装备的武器或防具:\n\n\n");
switch (scanf("%d", &choose_number), choose_number) {
case 1:
if (gong1n >= 1) {
printf("拿起了匕首\n\n\n");
gong = gong1;
strcpy(gongname, "匕首");
} else printf("你没有匕首可以装备\n\n\n");
break;
case 2:
if (gong2n >= 1) {
printf("拿起了长剑\n\n\n");
gong = gong2;
strcpy(gongname, "长剑");
} else printf("你没有长剑可以装备\n\n\n");
break;
case 3:
if (gong3n >= 1) {
printf("拿起了碧血剑\n\n\n");
gong = gong3;
strcpy(gongname, "碧血剑");
} else printf("你没有碧血剑可以装备\n\n\n");
break;
case 4:
if (gong4n >= 1) {
printf("拿起了绝世好剑\n\n\n");
gong = gong4;
strcpy(gongname, "绝世好剑");
} else printf("你没有绝世好剑可以装备\n\n\n");
break;
case 5:
if (fang1n >= 1) {
printf("穿上了布衣\n\n\n");
fang = fang1;
strcpy(fangname, "布衣");
} else printf("你没有布衣可以装备\n\n\n");
break;
case 6:
if (fang2 >= 1) {
printf("穿上了铁甲\n\n\n");
fang = fang2;
strcpy(fangname, "铁甲");
} else printf("你没有铁甲可以装备\n\n\n");
break;
case 7:
if (fang3n >= 1) {
printf("穿上了银甲\n\n\n");
fang = fang3;
strcpy(fangname, "银甲");
} else printf("你没有银甲可以装备\n\n\n");
break;
case 8:
if (fang4n >= 1) {
printf("穿上了黄金圣衣\n\n\n");
fang = fang4;
strcpy(fangname, "黄金圣衣");
} else printf("你没有黄金圣衣可以装备\n\n\n");
break;
case 0:
printf("未更换装备\n\n\n");
break;
default:
printf("change error!");
}
break;
case 6:
printf(" 本游戏由YCX制作\n");
break;
case 0:
printf("确定退出游戏?(Y/N)\n\n\n");
getchar();
proof = getchar();
if (proof == 'y' || proof == 'Y') {
printf("数据存储中...");
//向文件中更新数据;
getchar();
printf("按回车退出");
getchar();
return;
} else if (proof == 'n' || proof == 'N')printf("继续游戏!\n\n\n");
else printf("继续!\n\n\n");
break;
default:
printf("输入错误!\n\n\n");
}
}
}
void DisplayState() {
printf("%s 攻击力:%d+%d=%d 防御力:%d+%d=%d HP:%d/%d \n\n\n", player.name, player.attack, gong, player.attack + gong, player.defense, fang, player.defense + fang, player.health, player.max_health);
printf("武器: %s 防具: %s \n\n\n", gongname, fangname);
printf("等级:%d 经验:%d/%d 还需要%d经验升级 金币:%d \n\n\n", player.level, player.exp, player.max_exp, player.max_exp - player.exp, money);
}
void BattleAct() {
while (1) {
puts("=============================================================================");
printf("要怎么办?\n\n\n 1,攻击 2,物品 3,查看状态 4,逃跑\n\n\n");
switch (scanf("%d", &choose_number), choose_number) {
case 1:
s = SuiJi();
printf("%s攻击! %sHP减少%d\n\n\n", player.name, guai.name, player.attack + s + gong - guai.defense / 3);
guai.health -= player.attack + s + gong - guai.defense / 3;
if (AttackResult())return; //如果攻击有结果(敌人或玩家战死)退出函数
else continue;
case 2:
ChooseWupin();
break; //选择物品,可以使用,战斗中允许使用攻击性物品
case 3:
DisplayState();
break; //显示状态
case 4:
s = SuiJi();
if (s < 4) { //40%的概率可以逃跑
printf("%s逃跑了~\n\n\n", player.name);
battle = 0;
return;
} else printf("%s逃跑失败!\n\n\n", player.name);
break;
default:
printf("输入错误,重新输入!\n\n\n");
}
}
}
void printf(char *p) {
while (1) {
if (*p != 0)
printf("%c", *p++);
else
break;
Sleep(100);
}
}
猜拳
C++#include <iostream>
#include <cstdlib>
#include <ctime>
int main() {
srand(time(0)); // 初始化随机种子
std::cout << "欢迎来到剪刀石头布游戏!" << std::endl;
int playerWins = 0;
int computerWins = 0;
while (true) {
int playerChoice;
std::cout << "请选择你的出拳(1-剪刀,2-石头,3-布;输入其他数字结束游戏):";
std::cin >> playerChoice;
if (playerChoice < 1 || playerChoice > 3) {
break;
}
int computerChoice = rand() % 3 + 1; // 生成1到3之间的随机数,代表电脑的出拳
std::cout << "你选择了:";
switch (playerChoice) {
case 1:
std::cout << "剪刀" << std::endl;
break;
case 2:
std::cout << "石头" << std::endl;
break;
case 3:
std::cout << "布" << std::endl;
break;
default:
std::cout << "无效的选择" << std::endl;
return 0;
}
std::cout << "电脑选择了:";
switch (computerChoice) {
case 1:
std::cout << "剪刀" << std::endl;
break;
case 2:
std::cout << "石头" << std::endl;
break;
case 3:
std::cout << "布" << std::endl;
break;
}
if (playerChoice == computerChoice) {
std::cout << "平局!" << std::endl;
} else if ((playerChoice == 1 && computerChoice == 3) || (playerChoice == 2 && computerChoice == 1) || (playerChoice == 3 && computerChoice == 2)) {
std::cout << "你赢了!" << std::endl;
playerWins++;
} else {
std::cout << "你输了!" << std::endl;
computerWins++;
}
std::cout << "得分情况:" << std::endl;
std::cout << "玩家:" << playerWins << " 电脑:" << computerWins << std::endl;
std::cout << std::endl;
}
std::cout << "游戏结束!" << std::endl;
return 0;
}
打怪物小游戏
C++#include <iostream>
using namespace std;
double shengmingli = 200000000000; //定义主角初始生命力
int gongjili = 150000; //定义主角初始攻击力
int fangyuli = 2000000; //定义主角初始防御力
int money = 2000000; //定义主角初始金钱数量
bool guoguan;//定义是否通关判定
void wuqidian();//定义武器店函数
void yaodian();//定义药店函数
void guaiwu1();//定义小怪物函数
void guaiwu2();//定义大怪物函数
int main() {
cout << "欢迎你开始玩打怪物小游戏!\n";
cout << "小镇\n";
cout << "一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店" << endl;
cout << "和一家武器店。\n";
int xiaozhen;//定义选择项目
cout << "1.去武器店" << endl;
cout << "2.去药品店" << endl;
cout << "3.去打小怪物" << endl;
cout << "4.去打大怪物" << endl;
cout << "5.退出游戏" << endl;
cout << "6.显示你的状态" << endl;
cin >> xiaozhen;
while (xiaozhen != 5) { //输入5时退出游戏
if (shengmingli <= 0) { //主角生命力小于等于0时游戏结束
cout << "你死啦!" << endl;
break;
}
if (guoguan) {
cout << "恭喜通关!" << endl;
break;
}
if (xiaozhen == 6) { //输入6可检测自己的状态
cout << "你的生命力:" << shengmingli << endl;
cout << "你的攻击力:" << gongjili << endl;
cout << "你的防御力:" << fangyuli << endl;
cout << "你拥有的钱:" << money << endl;
} else
switch (xiaozhen) {
case 1 :
wuqidian();
break;
case 2 :
yaodian();
break;
case 3 :
guaiwu1();
break;
case 4 :
guaiwu2();
break;
default :
cout << "请不要乱选!" << endl;
break;
}
cin >> xiaozhen;
}
if (xiaozhen == 5) {
cout << "正在退出游戏……" << endl;
}
cin.get();
cin.get();
return 0;
}
void wuqidian() {
cout << "欢迎来到武器店!" << endl;
cout << "1、买小刀(1M加2攻击力)" << endl;
cout << "2、买短剑(2M加20攻击力)" << endl;
cout << "3、买大砍刀(5M加40攻击力)" << endl;
cout << "4、买双节棍(7M加60攻击力)" << endl;
cout << "5、买盾牌(2M加30防御力)" << endl;
cout << "6、买铠甲(5M加60防御力)" << endl;
cout << "7、离开武器店" << endl;
int wuqidian;
cin >> wuqidian;
while (wuqidian != 7) { //输入7时结束函数
switch (wuqidian) {
case 1 :
if (money < 10)
cout << "你的钱不够" << endl; //钱不够时返回Flase
else
cout << "购买成功!" << endl; //钱足够时返回True
gongjili += 2;
money -= 1;
break;
case 2 :
if (money < 80)
cout << "你的钱不够" << endl;
else
cout << "购买成功!" << endl;
gongjili += 20;
money -= 80;
break;
case 3 :
if (money < 140)
cout << "你的钱不够" << endl;
else
cout << "购买成功!" << endl;
gongjili += 40;
money -= 140;
break;
case 4 :
if (money < 200)
cout << "你的钱不够" << endl;
else
cout << "购买成功!" << endl;
gongjili += 60;
money -= 200;
break;
case 5 :
if (money < 60)
cout << "你的钱不够" << endl;
else
cout << "购买成功!" << endl;
fangyuli += 30;
money -= 60;
break;
fangyuli += 60;
money -= 100;
break;
default :
cout << "无" << endl;
break;
}
cin >> wuqidian;
}
if (wuqidian == 7) {
//返回main()主函数
cout << "欢迎下次再来!" << endl;
cout << "欢迎你开始玩打怪物小游戏!\n";
cout << "小镇\n";
cout << "一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店" << endl;
cout << "和一家武器店。\n";
cout << "1.去武器店" << endl;
cout << "2.去药品店" << endl;
cout << "3.去打小怪物" << endl;
cout << "4.去打大怪物" << endl;
cout << "5.退出游戏" << endl;
cout << "6.显示你的状态" << endl;
}
}
/*
yaodian()的设置与wuqidian()相同,可参照阅读.
*/
void yaodian() {
cout << "欢迎来到药品店!" << endl;
cout << "1、买1号补血药(10M加200生命)" << endl;
cout << "2、买2号补血药(50M加1000生命力)" << endl;
cout << "3、买3号补血药(100M加2200生命力)" << endl;
cout << "4、离开武器店" << endl;
int yaodian;
cin >> yaodian;
while (yaodian != 4) {
switch (yaodian) {
case 1 :
if (money < 10)
cout << "你的钱不够" << endl;
else
cout << "购买成功!" << endl;
shengmingli += 200;
money -= 10;
break;
case 2 :
if (money < 50)
cout << "你的钱不够" << endl;
else
cout << "购买成功!" << endl;
shengmingli += 1000;
money -= 50;
break;
case 3 :
if (money < 100)
cout << "你的钱不够" << endl;
else
cout << "购买成功!" << endl;
shengmingli += 2200;
money -= 100;
break;
default :
cout << "无" << endl;
break;
}
cin >> yaodian;
}
if (yaodian == 4) {
cout << "欢迎下次再来!" << endl;
cout << "欢迎你开始玩打怪物小游戏!\n";
cout << "小镇\n";
cout << "一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店" << endl;
cout << "和一家武器店。\n";
cout << "1.去武器店" << endl;
cout << "2.去药品店" << endl;
cout << "3.去打小怪物" << endl;
cout << "4.去打大怪物" << endl;
cout << "5.退出游戏" << endl;
cout << "6.显示你的状态" << endl;
}
}
/*这里是两个战斗函数,使用指针来处理.避免造成内存崩溃.*/
void guaiwu1() {
cout << "开始与小怪物战斗!!!" << endl;
double* g_shengmingli = new double; //定义怪物生命
int* g_gongjili = new int; //定义怪物攻击力
int* g_fangyuli = new int; //定义怪物防御力
int* g_money = new int; //定义怪物金钱
*g_shengmingli = 100;
*g_gongjili = 5;
*g_fangyuli = 3;
*g_money = 5;
double* tongji1 = new double; //用来计算主角对怪物的杀伤
double* tongji2 = new double; //用来计算怪物对主角的杀伤
*tongji1 = 0;
*tongji2 = 0;
int* huihe = new int; //定义回合数
*huihe = 1;
cout << "你开始对小怪物进行攻击!" << endl;
int* xuanze = new int;
/*
攻击计算公式
杀伤=攻击力*2-防御力
玩家每回合可以选择攻击与逃跑
*/
while ((*g_shengmingli) > 0 && shengmingli > 0 && (*xuanze) != 2) {
cout << "现在是" << "第" << *huihe << "回合!" << endl;
cout << "请选择你的动作:\n";
cout << "1、攻击\n2、逃跑\n";
cin >> *xuanze;
switch ((*xuanze)) {
case 1 :
cout << "你对小怪物发动了攻击!" << endl;
*g_shengmingli -= gongjili * 2 - (*g_fangyuli);
*tongji1 = gongjili * 2 - (*g_fangyuli);
cout << "你打掉了小怪物" << *tongji1 << "的生命!" << endl;
cout << "小怪物还剩" << (*g_shengmingli) - (*tongji1) << "点生命" << endl;
shengmingli -= (*g_gongjili) * 2 - fangyuli;
*tongji2 = (*g_gongjili) * 2 - fangyuli;
cout << "小怪物对你发动了攻击!" << endl;
cout << "小怪物打掉了你" << *tongji2 << "的生命!" << endl;
cout << "你还剩" << shengmingli - (*tongji2) << "点生命" << endl;
break;
case 2 :
cout << "你决定逃跑!" << endl;
cout << "逃跑成功!" << endl;
continue;
default :
cout << "请不要乱选!" << endl;
}
(*huihe)++;
}
if ((*g_shengmingli) <= 0) {
//杀死怪物后的返回
cout << "小怪物被你杀死了!你真厉害!!!" << endl;
money += (*g_money);
cout << "欢迎你开始玩打怪物小游戏!\n";
cout << "小镇\n";
cout << "一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店" << endl;
cout << "和一家武器店。\n";
cout << "1.去武器店" << endl;
cout << "2.去药品店" << endl;
cout << "3.去打小怪物" << endl;
cout << "4.去打大怪物" << endl;
cout << "5.退出游戏" << endl;
cout << "6.显示你的状态" << endl;
} else if (shengmingli <= 0) {
//被怪物杀死后的返回
cout << "你被小怪物杀死了!游戏结束!!!" << endl;
} else if ((*xuanze) == 2) {
//逃跑的返回
cout << "你逃回了小镇!" << endl;
cout << "欢迎你开始玩打怪物小游戏!\n";
cout << "小镇\n";
cout << "一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店" << endl;
cout << "和一家武器店。\n";
cout << "1.去武器店" << endl;
cout << "2.去药品店" << endl;
cout << "3.去打小怪物" << endl;
cout << "4.去打大怪物" << endl;
cout << "5.退出游戏" << endl;
cout << "6.显示你的状态" << endl;
}
delete g_shengmingli;
delete g_gongjili;
delete g_fangyuli;
delete g_money;
delete tongji1;
delete tongji2;
}
/*
设置均与void函数guaiwu1()相同,可参照上例阅读.
*/
void guaiwu2() {
cout << "开始与大怪物战斗!!!" << endl;
double* g_shengmingli = new double;
int* g_gongjili = new int;
int* g_fangyuli = new int;
*g_shengmingli = 3600;
*g_gongjili = 500;
*g_fangyuli = 500;
double* tongji1 = new double;
double* tongji2 = new double;
*tongji1 = 0;
*tongji2 = 0;
int* huihe = new int;
*huihe = 1;
cout << "你开始对大怪物进行攻击!" << endl;
int* xuanze = new int;
while ((*g_shengmingli) > 0 && shengmingli > 0 && (*xuanze) != 2) {
cout << "现在是" << "第" << *huihe << "回合!" << endl;
cout << "请选择你的动作:\n";
cout << "1、攻击\n2、逃跑\n";
cin >> *xuanze;
switch ((*xuanze)) {
case 1 :
cout << "你对大怪物发动了攻击!" << endl;
*g_shengmingli -= gongjili * 2 - (*g_fangyuli);
*tongji1 = gongjili * 2 - (*g_fangyuli);
cout << "你打掉了大怪物" << *tongji1 << "的生命!" << endl;
cout << "大怪物还剩" << (*g_shengmingli) - (*tongji1) << "点生命" << endl;
shengmingli -= (*g_gongjili) * 2 - fangyuli;
*tongji2 = (*g_gongjili) * 2 - fangyuli;
cout << "大怪物对你发动了攻击!" << endl;
cout << "大怪物打掉了你" << *tongji2 << "的生命!" << endl;
cout << "你还剩" << shengmingli - (*tongji2) << "点生命" << endl;
break;
case 2 :
cout << "你决定逃跑!" << endl;
cout << "逃跑成功!" << endl;
continue;
default :
cout << "请不要乱选!" << endl;
}
(*huihe)++;
}
if ((*g_shengmingli) <= 0) {
cout << "大怪物被你杀死了!你真厉害!!!" << endl;
guoguan = true;
cout << "欢迎你开始玩打怪物小游戏!\n";
cout << "小镇\n";
cout << "一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店" << endl;
cout << "和一家武器店。\n";
cout << "1.去武器店" << endl;
cout << "2.去药品店" << endl;
cout << "3.去打小怪物" << endl;
cout << "4.去打大怪物" << endl;
cout << "5.退出游戏" << endl;
cout << "6.显示你的状态" << endl;
} else if (shengmingli <= 0) {
cout << "你被大怪物杀死了!游戏结束!!!" << endl;
} else if ((*xuanze) == 2) {
cout << "你逃回了小镇!" << endl;
cout << "欢迎你开始玩打怪物小游戏!\n";
cout << "小镇\n";
cout << "一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店" << endl;
cout << "和一家武器店。\n";
cout << "1.去武器店" << endl;
cout << "2.去药品店" << endl;
cout << "3.去打小怪物" << endl;
cout << "4.去打大怪物" << endl;
cout << "5.退出游戏" << endl;
cout << "6.显示你的状态" << endl;
}
delete g_shengmingli;
delete g_gongjili;
delete g_fangyuli;
delete tongji1;
delete tongji2;
}
对战小游戏
C++#include<bits/stdc++.h>
#include<conio.h>
#include<windows.h>
using namespace std;
double shanghai[20] = {0.6, 1.1, 2, 3.16, 5.5, 7, 10, 20, 50, 100, 146.23, 254.13, 312, 403, 601, 1023};
double bosshealth[20] = {2, 3, 4, 5.9, 8, 14, 19, 32, 73, 157, 200, 403, 801, 1200, 3630, 20123};
double wj_shanghai = 5000, wj_health = 10000000, wj_max_health = 10000000, boss, wj_money = 10000000000000000000000000000000;
void chushihua();
void game();
void gongji();
void goumai();
void shangdian();
void zhujiemian();
void fangyu();
void cend();
void chushou();
void print(char[]);
int bishou = 0, caidao = 0, jian = 0, shenjian = 0;
double bishou_1 = 5, caidao_1 = 17, jian_1 = 58, shenjian_1 = 124;
int hat = 0, douhui = 0, hudun = 0, hunjia = 0, shendun = 0;
double hat_1 = 7, douhui_1 = 21, hudun_1 = 49, hunjia_1 = 89, shendun_1 = 210.4;
void cend() {
system("cls");
print("GAME OVER");
exit(1);
}
void game() {
int k;
chushihua();
IO:
printf("请输入对手等级 (0~15)\n");
scanf("%d", &k);
if (k > 15 || k < 0) {
system("cls");
goto IO;
}
boss = bosshealth[k];
system("cls");
while (wj_health >= 0) {
srand(time(NULL));
QP:
printf("1.逃跑 2.进攻\n");
char s = getch();
if (s < '1' || s > '2') {
system("cls");
goto QP;
}
if (s == '1') {
system("cls");
zhujiemian();
}
system("cls");
double l = shanghai[k] * ((rand() % 2) + 1) + fabs(double(rand() % 100 / 100 - 2));
printf("对手对你造成了%lf点伤害\n", l);
wj_health -= l;
printf("你当前剩余血量:%lf\n", wj_health);
if (wj_health <= 0)
cend();
double o = wj_shanghai * ((rand() % 2) + 1) + double(rand() % 10 / 10);
boss -= o;
printf("你对对手造成了%lf点伤害\n", o);
printf("对手当前剩余血量:%lf\n\n", boss);
if (boss <= 0) {
printf("胜利!\n获得%lf金币\n\n当前剩余血量:%lf\n", shanghai[k] + 3, wj_health);
wj_money += shanghai[k] + 3;
printf("\n余额:%lf\n", wj_money);
getch();
if (k == 15) {
printf("恭喜玩家!游戏胜利!\n");
getch();
exit(1);
}
system("cls");
zhujiemian();
}
}
}
void zhujiemian() {
PO:
printf("1.商店 2.战斗 3.回血 4.状态\n");
char k = getch();
if (k > '4' || k < '1') {
system("cls");
goto PO;
}
if (k == '1') {
system("cls");
shangdian();
return;
}
if (k == '2') {
system("cls");
game();
return;
}
if (k == '3') {
system("cls");
if (wj_money > 0) {
wj_money = wj_money * 4 / 5 - 1;
chushihua();
wj_health = wj_max_health;
printf("回血成功!\n");
getch();
system("cls");
goto PO;
} else {
printf("余额不足!\n");
getch();
system("cls");
goto PO;
}
}
if (k == '4') {
chushihua();
system("cls");
printf("生命值:%lf\n", wj_health);
printf("最大生命值:%lf\n", wj_max_health);
printf("攻击力:%lf\n", wj_shanghai);
printf("金币:%lf\n", wj_money);
getch();
system("cls");
goto PO;
}
if (k == '5') {
string a;
system("cls");
printf("输入密码!\n");
cin >> a;
if (a == "gu" || a == "gu") {
wj_money += 1000;
printf("外挂生效\n");
Sleep(1000);
system("cls");
goto PO;
}
printf("外挂失败\n");
Sleep(1000);
system("cls");
goto PO;
}
}
void shangdian() {
LK:
printf("1.购买 2.返回主界面\n");
char k = getch();
if (k != '1' && k != '2') {
system("cls");
goto LK;
}
if (k == '1') {
system("cls");
goumai();
goto LK;
}
if (k == '2') {
system("cls");
zhujiemian();
return;
}
}
void goumai() {
ML:
printf("1.攻击 2.防御 3.返回主界面\n");
char k = getch();
if (k != '1' && k != '2' && k != '3') {
system("cls");
goto ML;
}
if (k == '1') {
system("cls");
gongji();
goto ML;
}
if (k == '3') {
system("cls");
zhujiemian();
return;
}
if (k == '2') {
fangyu();
}
}
void gongji() {
OP:
system("cls");
printf("0.返回上界面\n");
printf("1.返回主界面\n");
printf("2.匕首 5金币\n");
printf("3.菜刀 17金币\n");
printf("4.剑 68金币\n");
printf("5.圣剑 210金币\n");
printf("提醒:金币价格与伤害成正比\n");
char k = getch();
if (k < '0' || k > '5') {
system("cls");
goto OP;
}
if (k == '0') {
system("cls");
goumai();
return;
}
if (k == '1') {
system("cls");
zhujiemian();
return;
}
if (k == '2') {
if (wj_money >= bishou_1) {
chushihua();
system("cls");
wj_money -= bishou_1;
bishou++;
goto OP;
}
system("cls");
printf("余额不足!\n");
getch();
system("cls");
goto OP;
}
if (k == '3') {
if (wj_money >= caidao_1) {
chushihua();
system("cls");
wj_money -= caidao_1;
caidao++;
goto OP;
}
system("cls");
printf("余额不足!\n");
getch();
goto OP;
}
if (k == '4') {
if (wj_money >= jian_1) {
chushihua();
system("cls");
wj_money -= jian_1;
jian++;
goto OP;
}
system("cls");
printf("余额不足!\n");
getch();
goto OP;
}
if (k == '5') {
if (wj_money >= shenjian_1) {
chushihua();
system("cls");
wj_money -= shenjian_1;
shenjian++;
goto OP;
}
system("cls");
printf("余额不足!\n");
getch();
goto OP;
}
}
void fangyu() {
OP:
system("cls");
printf("0.返回上界面\n");
printf("1.返回主界面\n");
printf("2.帽子 7金币\n");
printf("3.头盔 21金币\n");
printf("4.护盾 49金币\n");
printf("5.盔甲 89金币\n");
printf("6.圣盾 210金币\n");
printf("提醒:金币价格与伤害成正比\n");
char k = getch();
if (k < '0' || k > '6') {
system("cls");
goto OP;
}
if (k == '0') {
system("cls");
goumai();
return;
}
if (k == '1') {
system("cls");
zhujiemian();
return;
}
if (k == '2') {
if (wj_money >= hat_1) {
chushihua();
system("cls");
wj_money -= hat_1;
hat++;
goto OP;
}
system("cls");
printf("余额不足!\n");
getch();
system("cls");
goto OP;
}
if (k == '3') {
if (wj_money >= douhui_1) {
chushihua();
system("cls");
wj_money -= douhui_1;
douhui++;
goto OP;
}
system("cls");
printf("余额不足!\n");
getch();
goto OP;
}
if (k == '4') {
if (wj_money >= hudun_1) {
chushihua();
system("cls");
wj_money -= hudun_1;
hudun++;
goto OP;
}
system("cls");
printf("余额不足!\n");
getch();
goto OP;
}
if (k == '5') {
chushihua();
if (wj_money >= hunjia_1) {
system("cls");
wj_money -= hunjia_1;
hunjia++;
goto OP;
}
system("cls");
printf("余额不足!\n");
getch();
goto OP;
}
if (k == '6') {
if (wj_money >= shendun_1) {
chushihua();
system("cls");
wj_money -= shendun_1;
shendun++;
goto OP;
}
system("cls");
printf("余额不足!\n");
getch();
goto OP;
}
}
void chushihua() {
wj_max_health = hat * hat_1 + douhui * douhui_1 + hudun * hudun_1 + hunjia * hunjia_1 + shendun * shendun_1 + 10;
wj_shanghai = bishou * bishou_1 + caidao * caidao_1 + jian * jian_1 + shenjian * shenjian_1 + 1;
}
void print(char a[]) {
int s = strlen(a);
for (int i = 0; i < s; i++) {
cout << a[i];
Sleep(400);
}
getch();
system("cls");
}
int main() {
system("title game");
print("出品:YCX");
zhujiemian();
return 0;
}
迷宫
C++#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <time.h>
#define Height 55 //迷宫的高度,必须为奇数
#define Width 55 //迷宫的宽度,必须为奇数
#define Wall 1
#define Road 0
#define Start 2
#define End 3
#define Esc 5
#define Up 1
#define Down 2
#define Left 3
#define Right 4
int map[Height + 2][Width + 2];
void gotoxy(int x, int y) { //移动坐标
/* typedef struct _COORD {
SHORT X;
SHORT Y;
} COORD, *PCOORD; */
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord );
}
void hidden() { //隐藏光标
/* typedef void *HANDLE; */
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
/* typedef struct _CONSOLE_CURSOR_INFO {
DWORD dwSize;
BOOL bVisible;
} CONSOLE_CURSOR_INFO *PCONSOLE_CURSOR_INFO; */
CONSOLE_CURSOR_INFO cci;
GetConsoleCursorInfo(hOut, &cci);
cci.bVisible = 0;//赋1为显示,赋0为隐藏
SetConsoleCursorInfo(hOut, &cci);
}
void create(int x, int y) { //随机生成迷宫
int c[4][2] = {0, 1, 1, 0, 0, -1, -1, 0}; //四个方向
int i, j, t;
//将方向打乱
for (i = 0; i < 4; i++) {
j = rand() % 4;
t = c[i][0];
c[i][0] = c[j][0];
c[j][0] = t;
t = c[i][1];
c[i][1] = c[j][1];
c[j][1] = t;
}
map[x][y] = Road;
for (i = 0; i < 4; i++)
if (map[x + 2 * c[i][0]][y + 2 * c[i][1]] == Wall) {
map[x + c[i][0]][y + c[i][1]] = Road;
create(x + 2 * c[i][0], y + 2 * c[i][1]);
}
}
int get_key() { //接收按键
char c;
while (c = getch()) {
if (c == 27)
return Esc; //Esc
if (c != -32)
continue;
c = getch();
if (c == 72)
return Up; //上
if (c == 80)
return Down; //下
if (c == 75 )
return Left; //左
if (c == 77)
return Right; //右
}
return 0;
}
void paint(int x, int y) { //画迷宫
gotoxy(2 * y - 2, x - 1);
switch (map[x][y]) {
case Start:
printf("入");
break; //画入口
case End:
printf("出");
break; //画出口
case Wall:
printf("■");
break; //画墙
case Road:
printf(" ");
break; //画路
}
}
void game() {
int x = 2, y = 1; //玩家当前位置,刚开始在入口处
int c; //用来接收按键
while (1) {
gotoxy(2 * y - 2, x - 1);
printf("☆"); //画出玩家当前位置
if (map[x][y] == End) { //判断是否到达出口
gotoxy(30, 24);
printf("到达终点,按任意键结束");
getch();
break;
}
c = get_key();
if (c == Esc) {
gotoxy(0, 24);
break;
}
switch (c) {
case Up: //向上走
if (map[x - 1][y] != Wall) {
paint(x, y);
x--;
}
break;
case Down: //向下走
if (map[x + 1][y] != Wall) {
paint(x, y);
x++;
}
break;
case Left: //向左走
if (map[x][y - 1] != Wall) {
paint(x, y);
y--;
}
break;
case Right: //向右走
if (map[x][y + 1] != Wall) {
paint(x, y);
y++;
}
break;
}
}
}
int main() {
int i, j;
srand((unsigned)time(NULL)); //初始化随即种子
hidden(); //隐藏光标
for (i = 0; i <= Height + 1; i++)
for (j = 0; j <= Width + 1; j++)
if (i == 0 || i == Height + 1 || j == 0 || j == Width + 1) //初始化迷宫
map[i][j] = Road;
else
map[i][j] = Wall;
create(2 * (rand() % (Height / 2) + 1), 2 * (rand() % (Width / 2) + 1)); //从随机一个点开始生成迷宫,该点行列都为偶数
for (i = 0; i <= Height + 1; i++) { //边界处理
map[i][0] = Wall;
map[i][Width + 1] = Wall;
}
for (j = 0; j <= Width + 1; j++) { //边界处理
map[0][j] = Wall;
map[Height + 1][j] = Wall;
}
map[2][1] = Start; //给定入口
map[Height - 1][Width] = End; //给定出口
for (i = 1; i <= Height; i++)
for (j = 1; j <= Width; j++) //画出迷宫
paint(i, j);
game(); //开始游戏
getch();
return 0;
}
生化危机游戏
C++#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <string>
#include <cstdio>
#define clear() cout << "\033c" << flush
using namespace std;
const int SIZE = 9;
int Queen[15][15];
// 值为0表示不在攻击范围内,可以放置新皇后;
// 1表示在攻击范围内,不可放置
// 9和-9表示皇后
// 游戏规则展示
void intro()
{
cout << endl <<" 生化危机 "<<endl<<endl<<"\n"<<endl;
cout << "===============================================================================" << endl;
cout << " ***欢迎运行生化危机游戏!***" << endl;
cout << "游戏背景:"<<endl;
cout << " 公元5794年,人类与AI分为两个族群,并企图使用辐射与核弹消灭对方,\n 而你,则是此次行动的首席指挥官。"<<endl;
cout << "游戏规则:" << endl;
cout << " 在这个游戏里会有一个 9*9 的地图,我们可以在地图上放置辐射¤(AI为核弹○)," << endl;
cout << " 使其不能相互感染,即任意两个生化武器不能处于地图的同一行、同一列和同一条对角线上。" << endl;
cout << " 1. 如果一方放置生化武器时位于其他生化武器的攻击范围内,该方失败,游戏结束!" << endl;
cout << " 2. 若您不能进行任何放置,游戏结束!" << endl;
cout << " 3. 玩的开心,切记:不许进行开挂、删、改代码等操作。"<<endl;
cout << "===============================================================================" << endl << endl;
}
// 打印当前棋盘
void drawBoard()
{
// 输出行号
cout << " ";
for (int i = 1; i <= SIZE; i++) cout << " " << i;
cout << "\n";
// 输出上边框
cout << " ╔";
for (int i = 1; i <= SIZE-1; i++) cout << "═══╤";
cout << "═══╗\n";
// 输出中间部分
for (int i = 1; i <= SIZE; i++) // 行
{
cout << i << " ║";
for (int j = 1; j <= SIZE; j++) // 列
{
if (Queen[i][j] == 9) // 玩家
{
cout << " ¤";
}
if (Queen[i][j] == -9) // 电脑
{
cout << " ○";
}
if (Queen[i][j] == 0 || Queen[i][j] == 1) // 空格或不可放置
{
cout << " ";
}
if (j != SIZE)
cout << "│";
else
cout << "║";
}
cout << " \n";
// 输出下边框
if (i != SIZE)
{
cout << " ╟";
for (int i = 1; i <= SIZE-1; i++) cout << "───┼";
cout << "───╢\n";
}
else
{
cout << " ╚";
for (int i = 1; i <= SIZE-1; i++) cout << "═══╧";
cout << "═══╝\n";
}
}
}
// 判断一次放置皇后是否有效
bool isValid(int hang, int lie)
{
if (Queen[hang][lie] != 0)
return false;
return true;
}
// 放置皇后、标记皇后的攻击范围
void mark(int who, int hang, int lie) // who为9表示玩家,-9表示电脑
{
// 划定攻击范围
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= 9; j++)
{
// 跳过已经不能放置的位置
if (Queen[i][j] != 0) continue;
// 判断是否在皇后所管辖的 行
if (hang - i == 0 && lie - j != 0)
{
Queen[i][j] = 1;
}
// 判断是否在皇后所管辖的 列
if (hang - i != 0 && lie - j == 0)
{
Queen[i][j] = 1;
}
// 判断是否在皇后所管辖的 左右斜线
if (abs(hang - i) == abs(lie - j))
{
Queen[i][j] = 1;
}
}
}
// 放置皇后
if (who == 9) Queen[hang][lie] = 9;
else Queen[hang][lie] = -9;
}
// 开始游戏
void game()
{
cout << "【人类先开始战争!】" << endl << endl;
while (true)
{
// (1)玩家策略
cout << "请人类输入投放地点(投放地点格式: 行=x[space]列=y[enter])" << endl;
int hang1, lie1;
cin >> hang1 >> lie1;
if (isValid(hang1, lie1) == false) // 该位置不可放置
{
cout << "·你·失·败·了·" << endl;
exit(0);
}
else
{
// 放置后标记皇后的攻击范围
mark(9, hang1, lie1);
// 打印放置结果
drawBoard();
}
// (2)电脑策略
srand(time(0));
int hang2, lie2;
for (int i = 1; i <= 1000000; i++)
{
hang2 = rand() % 9 + 1;
lie2 = rand() % 9 + 1;
if (isValid(hang2, lie2) == false) continue;
else break;
}
if (isValid(hang2, lie2) == false)
{
cout << "AI不能在任何位置投放,恭喜玩家胜利!游戏结束" << endl;
exit(0);
}
else
{
// 放置后标记皇后的攻击范围
mark(-9, hang2, lie2);
cout << "AI在 (" << hang2 << ", " << lie2 << ") 处放置核弹." << endl;
cout << "按下回车,查看AI的核弹投放处…" << endl;
getchar();
getchar();
// 打印放置结果
drawBoard();
}
}
}
int main()
{
intro(); // 游戏规则展示
drawBoard(); // 打印棋盘
game(); // 开始游戏
return 0;
}
扫雷
C++#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
const int BOARD_SIZE = 10;
const int NUM_MINES = 10;
const char MINE_SYMBOL = '*';
const char HIDDEN_SYMBOL = '#';
// 初始化游戏板
void initializeBoard(std::vector<std::vector<char>>& board) {
// 初始化所有格子为隐藏状态
for (int i = 0; i < BOARD_SIZE; i++) {
std::vector<char> row(BOARD_SIZE, HIDDEN_SYMBOL);
board.push_back(row);
}
}
// 显示游戏板
void displayBoard(const std::vector<std::vector<char>>& board) {
std::cout << " ";
for (int i = 0; i < BOARD_SIZE; i++) {
std::cout << i << " ";
}
std::cout << std::endl;
for (int i = 0; i < BOARD_SIZE; i++) {
std::cout << i << " ";
for (int j = 0; j < BOARD_SIZE; j++) {
std::cout << board[i][j] << " ";
}
std::cout << std::endl;
}
}
// 放置地雷
void placeMines(std::vector<std::vector<char>>& board) {
int count = 0;
while (count < NUM_MINES) {
int x = rand() % BOARD_SIZE;
int y = rand() % BOARD_SIZE;
// 如果该位置没有地雷,则放置地雷
if (board[x][y] != MINE_SYMBOL) {
board[x][y] = MINE_SYMBOL;
count++;
}
}
}
// 获取指定位置周围地雷的数量
int getAdjacentMinesCount(const std::vector<std::vector<char>>& board, int x, int y) {
int count = 0;
// 检查该位置周围的8个方向
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) {
int newX = x + i;
int newY = y + j;
// 跳过超出边界的位置以及当前位置本身
if (newX < 0 || newX >= BOARD_SIZE || newY < 0 || newY >= BOARD_SIZE || (i == 0 && j == 0)) {
continue;
}
// 如果周围位置有地雷,则计数加一
if (board[newX][newY] == MINE_SYMBOL) {
count++;
}
}
}
return count;
}
// 揭示指定位置的格子
void revealCell(std::vector<std::vector<char>>& board, std::vector<std::vector<bool>>& visited, int x, int y) {
// 跳过已经访问过的格子和已经揭示出来的格子
if (visited[x][y] || board[x][y] != HIDDEN_SYMBOL) {
return;
}
visited[x][y] = true;
// 获取该位置周围地雷的数量
int adjacentMines = getAdjacentMinesCount(board, x, y);
// 如果该位置周围有地雷,则将该数量显示在格子上
if (adjacentMines > 0) {
board[x][y] = '0' + adjacentMines;
}
// 否则递归揭示周围的格子
else {
board[x][y] = ' ';
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) {
int newX = x + i;
int newY = y + j;
if (newX >= 0 && newX < BOARD_SIZE && newY >= 0 && newY < BOARD_SIZE) {
revealCell(board, visited, newX, newY);
}
}
}
}
}
// 扫雷游戏主循环
void gameLoop() {
std::vector<std::vector<char>> board;
std::vector<std::vector<bool>> visited;
initializeBoard(board);
placeMines(board);
for (int i = 0; i < BOARD_SIZE; i++) {
std::vector<bool> row(BOARD_SIZE, false);
visited.push_back(row);
}
bool gameOver = false;
while (!gameOver) {
displayBoard(board);
int x, y;
std::cout << "请输入要揭示的格子坐标 (x, y): ";
std::cin >> x >> y;
// 检查输入是否合法
if (x < 0 || x >= BOARD_SIZE || y < 0 || y >= BOARD_SIZE) {
std::cout << "无效的坐标!" << std::endl;
continue;
}
// 如果该位置是地雷,游戏结束
if (board[x][y] == MINE_SYMBOL) {
gameOver = true;
std::cout << "很遗憾,踩到地雷了!游戏结束。" << std::endl;
break;
}
// 如果该位置周围没有地雷,则递归揭示周围的格子
if (board[x][y] == HIDDEN_SYMBOL) {
revealCell(board, visited, x, y);
}
// 检查是否胜利
int hiddenCount = 0;
for (int i = 0; i < BOARD_SIZE; i++) {
for (int j = 0; j < BOARD_SIZE; j++) {
if (board[i][j] == HIDDEN_SYMBOL || board[i][j] == MINE_SYMBOL) {
hiddenCount++;
}
}
}
if (hiddenCount == NUM_MINES) {
gameOver = true;
std::cout << "恭喜您,成功找到所有的地雷!游戏胜利。" << std::endl;
}
}
}
int main() {
srand(time(0)); // 初始化随机种子
std::cout << "欢迎来到扫雷游戏!" << std::endl;
std::cout << "请输入要揭示的格子坐标以避免踩到地雷。" << std::endl;
std::cout << "揭示一个格子将会显示出周围地雷的数量。找到所有的地雷即可胜利!" << std::endl;
gameLoop();
return 0;
}
卡牌游戏
C++ #include<iostream>
#include<time.h>
#include<stdio.h>
#include <stdlib.h>
using namespace std;
struct pai
{
int paifu;
int huase;
int yanse;
int dianshu;
int leixing;
int changdu;
void Kanpai()
{
if(paifu==0||paifu==1);
else
printf("牌副参数错误!\n");
switch(huase)
{
case 0:cout<<"黑桃";break;
case 1:cout<<"红桃";break;
case 2:cout<<"草花";break;
case 3:cout<<"方片";break;
case -1:cout<<"无色";break;
default:printf("花色错误!\n");break;
}
switch(dianshu)
{
case 0:cout<<"A ";break;
case 1:cout<<"2 ";break;
case 2:cout<<"3 ";break;
case 3:cout<<"4 ";break;
case 4:cout<<"5 ";break;
case 5:cout<<"6 ";break;
case 6:cout<<"7 ";break;
case 7:cout<<"8 ";break;
case 8:cout<<"9 ";break;
case 9:cout<<"10 ";break;
case 10:cout<<"J ";break;
case 11:cout<<"Q ";break;
case 12:cout<<"K ";break;
case -1:cout<<"无点数";break;
default:printf("点数错误!\n");break;
}
switch(leixing)
{
case 101:cout<<"【杀】"<<endl;break;
case 102:cout<<"【闪】"<<endl;break;
case 103:cout<<"【桃】"<<endl;break;
case 201:cout<<"【过河拆桥】"<<endl;break;
case 202:cout<<"【顺手牵羊】"<<endl;break;
case 203:cout<<"【无中生有】"<<endl;break;
case 204:cout<<"【决斗】"<<endl;break;
case 205:cout<<"【借刀杀人】"<<endl;break;
case 206:cout<<"【桃园结义】"<<endl;break;
case 207:cout<<"【五谷丰登】"<<endl;break;
case 208:cout<<"【南蛮入侵】"<<endl;break;
case 209:cout<<"【万箭齐发】"<<endl;break;
case 210:cout<<"【无懈可击】"<<endl;break;
case 251:cout<<"【乐不思蜀】"<<endl;break;
case 252:cout<<"【闪电】"<<endl;break;
case 301:cout<<"【诸葛连弩(1)】"<<endl;break;
case 302:cout<<"【雌雄双股剑(2)】"<<endl;break;
case 303:cout<<"【青釭剑(2)】"<<endl;break;
case 304:cout<<"【青龙偃月刀(3)】"<<endl;break;
case 305:cout<<"【丈八蛇矛(3)】"<<endl;break;
case 306:cout<<"【贯石斧(3)】"<<endl;break;
case 307:cout<<"【方天画戟(4)】"<<endl;break;
case 308:cout<<"【麒麟弓(5)】"<<endl;break;
case 331:cout<<"【八卦阵】"<<endl;break;
case 361:cout<<"【赤兔(-1)】"<<endl;break;
case 362:cout<<"【大宛(-1)】"<<endl;break;
case 363:cout<<"【紫辛(-1)】"<<endl;break;
case 381:cout<<"【爪黄飞电(+1)】"<<endl;break;
case 382:cout<<"【的卢(+1)】"<<endl;break;
case 383:cout<<"【绝影(+1)】"<<endl;break;
default:printf("类型参数错误!");break;
}
}
};
void Qishixipai(pai A[2][4][13],pai paidui[104])
{
int i,m,x,y,z,a[104]={0};
srand((unsigned)time(NULL));
for(i=1;i<=104;i++)
{
while(a[m=rand()%104]);
a[m]=i;
}
for(i=0;i<=103;i++)
{
x=(a[i]-1)/52;
y=((a[i]-1)-52*x)/13;
z=(a[i]-1)%13;
paidui[i]=A[x][y][z];
}
}
void Xipai(pai paidui[104],int*paiduishu,pai qipaidui[104],int*qipaishu)
{
int i,m,a[104]={0};
srand((unsigned)time(NULL));
for(i=1;i<=(*qipaishu);i++)
{
while(a[m=rand()%(*qipaishu)]);
a[m]=i;
}
for(i=0;i<=((*qipaishu)-1);i++)
{
paidui[i]=qipaidui[a[i]];
qipaidui[a[i]].leixing=-1;
(*paiduishu)++;
(*qipaishu)--;
}
for(i=(*paiduishu);i<=103;i++)paidui[i].leixing=-1;
}
pai Mo1pai(pai A[104],int *x,pai B[104],int*y,int *b)
{
pai p;
if((*x)==0)Xipai(A,x,B,y);
else if((*x)<0)printf("摸牌参数错误!");
else;
p=A[104-(*x)];
(*x)--;
(*b)++;
return(p);
}
struct wujiang
{
char name;
int tili;
int tilishangxian;
int shoupaishangxian;
int huihekaishi;
int panding;
int mopai;
int chupai;
int qipai;
int huihejieshu;
int juese;
pai shoupai[20];
int shoupaishu;
pai zhuangbei[4];
int zhuangbeishu;
pai pandingpai[3];
int pandingshu;
int juli[1];
void Kanshoupai()
{
printf("玩家当前手牌:\n");
if(shoupaishu)
{
int m;
for(m=0;m<=(shoupaishu-1);m++)
{
printf("%d ",m);
(shoupai[m]).Kanpai();
}
}
else printf("空城!\n");
printf("\n");
}
void Kanzhuangbei()
{
if(juese)printf("玩家");
else printf("电脑");
printf("当前装备:\n");
printf("0 武器: ");
if((zhuangbei[0]).leixing==-1)printf("空\n");
else (zhuangbei[0]).Kanpai();
printf("1 防具: ");
if((zhuangbei[1]).leixing==-1)printf("空\n");
else (zhuangbei[1]).Kanpai();
printf("2 进攻马: ");
if((zhuangbei[2]).leixing==-1)printf("空\n");
else (zhuangbei[2]).Kanpai();
printf("3 防御马: ");
if((zhuangbei[3]).leixing==-1)printf("空\n");
else (zhuangbei[3]).Kanpai();
printf("\n");
}
void Kanpandingpai()
{
if(juese)printf("玩家");
else printf("电脑");
printf("当前判定区:\n");
if((pandingpai[0]).leixing==-1)printf("空\n");
else
{
printf("0 ");
(pandingpai[0]).Kanpai();
if((pandingpai[1]).leixing==-1);
else
{
printf("1 ");
(pandingpai[1]).Kanpai();
if((pandingpai[2]).leixing==-1);
else
{
printf("2 ");
(pandingpai[2]).Kanpai();
}
}
}
}
};
void Mopai(int*shoupaishu,pai shoupai[20],pai A[104],int *x,pai B[104],int*y,int juese)
{
if(juese)printf("玩家从牌堆摸2张牌\n");
else printf("电脑从牌堆摸2张牌\n");
pai p;
p=Mo1pai(A,x,B,y,shoupaishu);
shoupai[*shoupaishu-1]=p;
pai q;
q=Mo1pai(A,x,B,y,shoupaishu);
shoupai[*shoupaishu-1]=q;
int m;
if(juese)
{
printf("玩家当前手牌:\n");
for(m=0;m<=(*shoupaishu-1);m++)
{
printf("%d ",m);
(shoupai[m]).Kanpai();
}
}
printf("牌堆还剩%d张牌!\n\n",*x);
}
void Qishishoupai(wujiang *w,pai A[104],int *x,pai B[104],int*y)
{
pai a;
a=Mo1pai(A,x,B,y,&((*w).shoupaishu));
(*w).shoupai[(*w).shoupaishu-1]=a;
pai b;
b=Mo1pai(A,x,B,y,&((*w).shoupaishu));
(*w).shoupai[(*w).shoupaishu-1]=b;
pai c;
c=Mo1pai(A,x,B,y,&((*w).shoupaishu));
(*w).shoupai[(*w).shoupaishu-1]=c;
pai d;
d=Mo1pai(A,x,B,y,&((*w).shoupaishu));
(*w).shoupai[(*w).shoupaishu-1]=d;
int m;
if((*w).juese)printf("玩家从牌堆摸4张牌\n");
else printf("电脑从牌堆摸4张牌\n");
if((*w).juese)
{
printf("玩家当前手牌:\n");
for(m=0;m<=((*w).shoupaishu-1);m++)
{
printf("%d ",m);
((*w).shoupai[m]).Kanpai();
}
}
printf("牌堆还剩%d张牌!\n\n",*x);
}
void Panding(pai paidui[104],int*paiduishu,pai qipaidui[104],int*qipaishu)
{
paidui[*paiduishu].Kanpai();
qipaidui[*qipaishu]=paidui[*paiduishu];
(*paiduishu)--;
(*qipaishu)++;
}
pai Zhangba(wujiang*w,pai qipaidui[104],int*qipaishu)
{
int x,y;
pai p;
for(;;)
{
int i,j;
printf("请输入任意两张手牌之前的编号,以空格隔开,以回车结束!\n");
scanf("%d",&x);
scanf("%d",&y);
if((x>=0)&&(x<(*w).shoupaishu)&&(y>=0)&&(y<(*w).shoupaishu-1))
{
switch((((*w).shoupai[x].huase)%2)+(((*w).shoupai[y].huase)%2))
{
case 0:p.yanse=0;break;
case 2:p.yanse=1;break;
case 1:p.yanse=2;break;
default:printf("【丈八蛇矛】函数参数错误!\n");
}
qipaidui[*qipaishu]=(*w).shoupai[x];
(*w).shoupai[x].leixing=-1;
((*w).shoupaishu)--;
(*qipaishu)++;
qipaidui[*qipaishu]=(*w).shoupai[y];
(*w).shoupai[y].leixing=-1;
((*w).shoupaishu)--;
(*qipaishu)++; printf("弃牌数:%d",*qipaishu);
for(i=0;i<=(((*w).shoupaishu)+1);i++)
{
if((*w).shoupai[i].leixing==-1)
{
for(j=i+1;j<=(((*w).shoupaishu)+2);j++)
(*w).shoupai[j-1]=(*w).shoupai[j];
i--;
}
}
printf("玩家把:\n");
qipaidui[(*qipaishu)-2].Kanpai();
qipaidui[(*qipaishu)-1].Kanpai();
printf("当作一张");
switch(p.yanse)
{
case 0:printf("黑色");break;
case 2:printf("红色");break;
case 1:printf("无色");break;
default:printf("绿色");break;
}
printf("无点数的【杀】");
p.dianshu=-1;
p.leixing=101;
return p;
break;
}
printf("你将两张空气当作一张空气属性的【杀】使用或打出!\n");
}
}
int Xuanpai(wujiang*w,int t)
{
int x;
if((*w).juese)
{
for(;;)
{
printf("出牌请输入手牌之前的编号,以回车结束!\n如果你想结束出牌阶段,请输入“-1”,以回车结束!\n");
scanf("%d",&x);
if((x>=-1&&x<((*w).shoupaishu))||((x==100)&&((*w).zhuangbei[0].leixing==305)))
{
return x;
break;
}
printf("你打出了一张空气!\n");
}
}
else return t;
}
pai Panpai(wujiang*w1,int*sha,int y,pai qipaidui[104],int*qipaishu)
{
pai p,q;
p.leixing=0;
q.leixing=-1;
if(y==-1)return q;
else
{
if(y==100)
{
if((*sha)>0)
{
q=Zhangba(w1,qipaidui,qipaishu);
printf("使用!\n");
return q;
}
else
{
printf("当前回合使用【杀】的次数已用尽,你也不能使用【丈八蛇矛】效果!\n");
return p;
}
}
switch((*w1).shoupai[y].leixing)
{
case 101:
if(((*sha)>0)||((*w1).zhuangbei[0].leixing==301))
{
if(((*w1).zhuangbei[0].leixing==301))printf("武器【诸葛连弩】效果被触发!\n");
return (*w1).shoupai[y];
break;
}
else
{
if((*w1).juese)printf("当前回合使用【杀】的次数已用尽,你不能使用【杀】!\n");
return p;break;
}
case 102:
if((*w1).juese)
printf("当前不需要响应任何操作,你不能主动打出【闪】!\n");
return p;break;
case 103:
if(((*w1).tili)<((*w1).tilishangxian))
{
return (*w1).shoupai[y];
break;
}
else
{
if((*w1).juese)
printf("你并未受伤,不能对自己使用【桃】!\n");
}
return p;break;
case 210:
if((*w1).juese)
printf("当前不需要响应任何锦囊,你不能主动打出【无懈可击】!\n");
return p;break;
case 201:
case 202:
case 203:
case 204:
case 205:
case 206:
case 207:
case 208:
case 209:
case 251:
case 252:
case 301:
case 302:
case 303:
case 304:
case 305:
case 306:
case 307:
case 308:
case 331:
case 361:
case 362:
case 363:
case 381:
case 382:
case 383:return (*w1).shoupai[y];break;
default:printf("手牌类型参数错误!\n");return p;break;
}
}
}
int Mubiao(pai p,wujiang *w1,wujiang *w2,int*sha)
{
int x;
switch(p.leixing)
{
case 101:
if((*w1).juese)
{
printf("请选择【杀】的目标!\n输入目标前的编号,以回车结束!\n0 电脑1\n");
scanf("%d",&x);
if(x==0)
{
if((*w1).zhuangbei[0].changdu>=(*w1).juli[0])
{
(*sha)--;
return((*w2).juese);
}
else
{
printf("武器长度不够!\n");
return -2;
}
}
else
{
printf("目标错误!\n");
return -2;
}
}
else
{
if((*w1).zhuangbei[0].changdu>=(*w1).juli[0])
{
(*sha)--;
return((*w2).juese);
}
else return -2;
}
break;
case 103:return((*w1).juese);break;
case 201:
if((*w1).juese)
{
printf("请选择【过河拆桥】的目标!\n输入目标前的编号,以回车结束!\n0 电脑1\n");
scanf("%d",&x);
if(x==0)
{
if((*w2).shoupaishu||(*w2).zhuangbeishu||(*w2).pandingshu)return((*w2).juese);
else
{
printf("目标没有牌!\n");
return -2;
}
}
else
{
printf("目标错误!\n");
return -2;
}
}
else return((*w2).juese);
break;
case 202:
if((*w1).juese)
{
printf("请选择【顺手牵羊】的目标!\n输入目标前的编号,以回车结束!\n0 电脑1\n");
scanf("%d",&x);
if(x==0)
{
if(((*w2).shoupaishu||(*w2).zhuangbeishu||(*w2).pandingshu)&&((*w1).juli[0]<=1))return((*w2).juese);
else
{
printf("目标没有牌!\n");
return -2;
}
}
else
{
printf("目标错误!\n");
return -2;
}
}
else
{
if((*w1).juli[0]<=1)return((*w2).juese);
else return -2;
}
break;
case 203:
return((*w1).juese);break;
case 204:
if((*w1).juese)
{
printf("请选择【决斗】的目标!\n输入目标前的编号,以回车结束!\n0 电脑1\n");
scanf("%d",&x);
if(x==0)return((*w2).juese);
else
{
printf("目标错误!\n");
return -2;
}
}
else return((*w2).juese);
break;
case 205:
int y;
if((*w1).juese)
{
printf("请选择【借刀杀人】的目标!\n输入目标前的编号,以回车结束!\n0 电脑1\n");
scanf("%d",&x);
if(x!=0)
{
printf("目标错误!\n");
return -2;
}
else
{
if(((*w2).zhuangbei[0]).leixing<=300||((*w2).zhuangbei[0]).leixing>=331)
{
printf("目标装备区里没有武器!\n");
return -2;
}
else
{
printf("请选择【杀】的目标!\n提示:【杀】的目标必须在【借刀杀人】的目标的攻击范围之内!\n输入目标前的编号,以回车结束!\n0 玩家\n");
scanf("%d",&y);
if(y!=0)
{
printf("目标错误!\n");
return -2;
}
else
{
if(((*w2).zhuangbei[0].changdu)<(*w2).juli[0])
{
printf("武器距离不够!\n");
return -2;
}
else
return((*w2).juese);
}
}
}
}
else
{
if(((*w2).zhuangbei[0]).leixing<=300||((*w2).zhuangbei[0]).leixing>=331)return -2;
else
{
if(((*w2).zhuangbei[0].changdu)<(*w2).juli[0])return -2;
else return((*w2).juese);
}
}
break;
case 206:
case 207:return 99;break;
case 208:
case 209:return 100;break;
case 251:
if((*w1).juese)
{
printf("请选择【乐不思蜀】的目标!\n输入目标前的编号,以回车结束!\n0 电脑1\n");
scanf("%d",&x);
if(x==0)
{
int i;
for(i=0;i<=2;i++)
{
if((*w2).pandingpai[i].leixing==251)
i=-1;
break;
}
if(i==-1)
{
printf("目标判定区里不能同时存在两张相同的延时类锦囊!\n");
return -2;
}
else return((*w2).juese);
}
else
{
printf("目标错误!\n");
return -2;
}
}
else
{
int i;
for(i=0;i<=2;i++)
{
if((*w2).pandingpai[i].leixing==251)
i=-1;
break;
}
if(i==-1)return -2;
else return((*w2).juese);
}
break;
case 252:
int i;
for(i=0;i<=2;i++)
{
if((*w1).pandingpai[i].leixing==252)
i=-1;
break;
}
if(i==-1)
{
if((*w1).juese)printf("目标判定区里不能同时存在两张相同的延时类锦囊!\n");
return -2;
}
else return ((*w1).juese);
break;
case 301:
case 302:
case 303:
case 304:
case 305:
case 306:
case 307:
case 308:
case 331:
case 361:
case 362:
case 363:
case 381:
case 382:
case 383:return((*w1).juese);break;
default:return -2;break;
}
}
void Da1pai(wujiang *w1,wujiang*w2,pai qipaidui[104],int *qipaishu,int x)
{
int i;
if((x<0||x>=((*w1).shoupaishu))&&x!=100)
printf("你的牌呢?!\n");
else
{
switch(((*w1).shoupai)[x].leixing)
{
case 101:
case 102:
case 103:
case 201:
case 202:
case 203:
case 204:
case 205:
case 206:
case 207:
case 208:
case 209:
case 210:
qipaidui[*qipaishu]=((*w1).shoupai)[x];
for(i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
(*qipaishu)++;
break;
case 251:
for(i=1;i>=0;i--)(*w2).pandingpai[i+1]=(*w2).pandingpai[i];
(*w2).pandingpai[0]=(*w1).shoupai[x];
for(i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
((*w2).pandingshu)++;
break;
case 252:
for(i=1;i>=0;i--)(*w1).pandingpai[i+1]=(*w1).pandingpai[i];
(*w1).pandingpai[0]=(*w1).shoupai[x];
for(i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
((*w1).pandingshu)++;
break;
case 301:
case 302:
case 303:
case 304:
case 305:
case 306:
case 307:
case 308:
if((*w1).zhuangbei[0].leixing==-1)((*w1).zhuangbeishu)++;
else
{
qipaidui[*qipaishu]=((*w1).zhuangbei)[0];
(*qipaishu)++;
}
(*w1).zhuangbei[0]=(*w1).shoupai[x];
for(i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
break;
case 331:
if((*w1).zhuangbei[1].leixing==-1)((*w1).zhuangbeishu)++;
else
{
qipaidui[*qipaishu]=((*w1).zhuangbei)[1];
(*qipaishu)++;
}
(*w1).zhuangbei[1]=(*w1).shoupai[x];
for(i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
break;
case 361:
case 362:
case 363:
if((*w1).zhuangbei[2].leixing==-1)((*w1).zhuangbeishu)++;
else
{
qipaidui[*qipaishu]=((*w1).zhuangbei)[2];
(*qipaishu)++;
}
(*w1).zhuangbei[2]=(*w1).shoupai[x];
for(i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
break;
case 381:
case 382:
case 383:
if((*w1).zhuangbei[3].leixing==-1)((*w1).zhuangbeishu)++;
else
{
qipaidui[*qipaishu]=((*w1).zhuangbei)[3];
(*qipaishu)++;
}
(*w1).zhuangbei[3]=(*w1).shoupai[x];
for(i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
break;
default:break;
}
}
}
void Miaoshu(pai p,int juese,int duixiang)
{
if(juese==0)printf("电脑");
else if(juese==1)printf("玩家");
else printf("角色参数错误!\n");
if(p.leixing<=300&&p.leixing>100)
{
switch(duixiang)
{
case -1:printf("打出");break;
case 0:printf("对电脑使用");break;
case 1:printf("对玩家使用");break;
case 99:printf("使用");break;
case 100:printf("对所有人使用");break;
default:printf("对象参数错误\n");break;
}
}
else if(p.leixing>=301&&p.leixing<=400)
printf("装备");
else printf("你出的是什么东西?\n");
p.Kanpai();
if(!juese&&(p.leixing==101||p.leixing==204||p.leixing==205||p.leixing==207||p.leixing==208||p.leixing==209))printf("请响应!\n");
}
int Wuxie(pai *p,wujiang*w1,wujiang*w2,pai qipaidui[104],int*qipaishu,int a)
{
int x;
if((*w1).juese)
{
printf("是否使用【无懈可击】响应?\n\n");
for(;;)
{
(*w1).Kanshoupai();
printf("如果要使用【无懈可击】请输入手牌之前编号,不需要请输入“-1”,以回车结束!\n");
scanf("%d",&x);
if(x==-1)
{
for(x=0;x<((*w2).shoupaishu);x++)
{
if((*w2).shoupai[x].leixing==210)
{
printf("电脑使用");
((*w2).shoupai)[x].Kanpai();
printf("对象是");
(*p).Kanpai();
(*p)=((*w2).shoupai)[x];
qipaidui[*qipaishu]=((*w2).shoupai)[x];
for(int i=x+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
a++;
break;
}
}
break;
}
else if((*w1).shoupai[x].leixing==210)
{
printf("玩家使用");
((*w1).shoupai)[x].Kanpai();
printf("对象是");
(*p).Kanpai();
(*p)=((*w1).shoupai)[x];
qipaidui[*qipaishu]=((*w1).shoupai)[x];
for(int i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
(*qipaishu)++;
(*w1).Kanshoupai();
a++;
break;
}
else printf("你确定你使用的是【无懈可击】?\n");
}
}
else
{
printf("是否使用【无懈可击】响应?\n");
for(;;)
{
(*w2).Kanshoupai();
printf("如果要使用【无懈可击】请输入手牌之前编号,不需要请输入“-1”,以回车结束!\n");
scanf("%d",&x);
if(x==-1)break;
else if((*w2).shoupai[x].leixing==210)
{
printf("玩家使用");
((*w2).shoupai)[x].Kanpai();
printf("对象是");
(*p).Kanpai();
(*p)=((*w2).shoupai)[x];
qipaidui[*qipaishu]=((*w2).shoupai)[x];
for(int i=x+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
(*w2).Kanshoupai();
a++;
break;
}
else printf("你确定你使用的是【无懈可击】?\n");
}
}
return a;
}
int Qiutao(wujiang*w,pai qipaidui[104],int*qipaishu)
{
int x;
if((*w).juese)
{
for(;;)
{
printf("如果要使用【桃】请输入手牌之前的编号,不需要请输入“-1”,以回车结束!\n");
scanf("%d",&x);
if(x==-1)
{
return -1;
break;
}
else if((*w).shoupai[x].leixing==103)
{
qipaidui[*qipaishu]=((*w).shoupai)[x];
for(int i=x+1;i<=((*w).shoupaishu);i++)((*w).shoupai)[i-1]=((*w).shoupai)[i];
((*w).shoupaishu)--;
(*qipaishu)++;
return 0;
break;
}
else printf("你确定你使用的是【桃】?\n");
}
}
else
{
for(x=0;x<((*w).shoupaishu);x++)
{
if((*w).shoupai[x].leixing==103)
{
qipaidui[*qipaishu]=((*w).shoupai)[x];
for(int i=x+1;i<=((*w).shoupaishu);i++)((*w).shoupai)[i-1]=((*w).shoupai)[i];
((*w).shoupaishu)--;
(*qipaishu)++;
return 0;
break;
}
}
return -1;
}
}
int Binsi(wujiang*w1,wujiang*w2,pai qipaidui[104],int*qipaishu)
{
if(((*w2).tili)>0)return 0;
else
{
int i;
if((*w1).juese)
{
for(;;)
{
printf("电脑濒死,是否使用【桃】?\n");
i=Qiutao(w1,qipaidui,qipaishu);
if(i==0)((*w2).tili)++;
if((i==-1)||((*w2).tili>0))break;
}
if((*w2).tili>0)return 0;
else
{
for(;;)
{
i=Qiutao(w2,qipaidui,qipaishu);
if(i==0)((*w2).tili)++;
if((i==-1)||((*w2).tili>0))break;
}
if((*w2).tili>0)return 0;
else return -1;
}
}
else
{
for(;;)
{
printf("玩家濒死,是否使用【桃】?\n");
i=Qiutao(w2,qipaidui,qipaishu);
if(i==0)((*w2).tili)++;
if((i==-1)||((*w2).tili>0))break;
}
if((*w2).tili>0)return 0;
else return -1;
}
}
}
int Shan(wujiang*w1,wujiang*w2,pai paidui[104],int*paiduishu,pai qipaidui[104],int*qipaishu)
{
int x;
if((*w2).juese)
{
if(((*w2).zhuangbei[1].leixing==331)&&((*w1).zhuangbei[0].leixing!=303))
{
for(;;)
{
int m;
printf("是否发动【八卦阵】防具效果?\n0 否\n1 是\n请输入选项之前的编号,以回车结束!\n");
scanf("%d",&m);
if(m==1)
{
Panding(paidui,paiduishu,qipaidui,qipaishu);
if(qipaidui[(*qipaishu)-1].huase%2)
{
printf("【八卦阵】判定成功!\n");
return 0;
}
}
else if(m==0)
{
printf("【八卦阵】判定失败!\n");
break;
}
else printf("你确定你输入的是“0”或“1”?\n");
}
}
else if(((*w2).zhuangbei[1].leixing==331)&&((*w1).zhuangbei[0].leixing==303))printf("【青釭剑】锁定技被触发!\n");
for(;;)
{
printf("请输入手牌之前的编号,或者输入“-1”放弃打出【闪】,以回车结束!\n");
scanf("%d",&x);
if(x==-1)
{
return -1;
break;
}
else if((*w2).shoupai[x].leixing==102)
{
printf("玩家打出");
((*w2).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w2).shoupai)[x];
for(int i=x+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
return 0;
break;
}
else printf("你确定你打出的是【闪】?\n");
}
}
else
{
if(((*w2).zhuangbei[1].leixing==331)&&((*w1).zhuangbei[0].leixing!=303))
{
Panding(paidui,paiduishu,qipaidui,qipaishu);
if(qipaidui[(*qipaishu)-1].huase%2)
{
printf("【八卦阵】判定成功!\n");
return 0;
}
else printf("【八卦阵】判定失败!\n");
}
else if(((*w2).zhuangbei[1].leixing==331)&&((*w1).zhuangbei[0].leixing==303))printf("【青釭剑】锁定技被触发!\n");
int i;
for(x=0;x<((*w2).shoupaishu);x++)
{
if((*w2).shoupai[x].leixing==102)
{
printf("电脑打出");
((*w2).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w2).shoupai)[x];
for(i=x+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
return 0;
break;
}
}
return -1;
}
}
int Sha(wujiang *w1,wujiang*w2,pai paidui[104],int*paiduishu,pai qipaidui[104],int*qipaishu)
{
int x;
if((*w2).juese)
{
printf("请打出【闪】响应【杀】!否则你将受到1点伤害!\n");
x=Shan(w1,w2,paidui,paiduishu,qipaidui,qipaishu);
if(x==-1)
{
int i;
((*w2).tili)--;
printf("电脑对玩家造成1点伤害!\n");
i=Binsi(w1,w2,qipaidui,qipaishu);
return i;
}
else if(x==0&&((*w1).zhuangbei[0].leixing==306))
{
int i;
if(((*w1).shoupaishu)>=2)
{
printf("电脑弃掉:\n");
((*w1).shoupai)[0].Kanpai();
qipaidui[*qipaishu]=((*w1).shoupai)[0];
for(i=1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
(*qipaishu)++;
((*w1).shoupai)[0].Kanpai();
qipaidui[*qipaishu]=((*w1).shoupai)[0];
for(i=1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
(*qipaishu)++;
printf("发动【贯石斧】武器效果使【杀】造成伤害!\n");
((*w2).tili)--;
i=Binsi(w1,w2,qipaidui,qipaishu);
return i;
}
else return 0;
}
else if(x==0&&((*w1).zhuangbei[0].leixing==304))
{
int i;
for(x=0;x<((*w1).shoupaishu);x++)
{
if((*w1).shoupai[x].leixing==101)
{
printf("电脑发动【青龙偃月刀】效果对玩家使用");
((*w1).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w1).shoupai)[x];
for(i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
(*qipaishu)++;
i=Sha(w1,w2,paidui,paiduishu,qipaidui,qipaishu);
return i;
break;
}
}
return 0;
}
}
else//往上是玩家被使用【杀】 往下是电脑被使用【杀】
{
x=Shan(w1,w2,paidui,paiduishu,qipaidui,qipaishu);
if(x==-1)
{
if((*w1).zhuangbei[0].leixing==308)
{
for(;;)
{
printf("是否发动【麒麟弓】武器效果?\n0 否\n1 是\n");
scanf("%d",&x);
if(x==1)
{
if(((*w2).zhuangbei[2].leixing==-1)&&((*w2).zhuangbei[3].leixing==-1))
{
printf("电脑根本没有马,射你妹的马啊!\n");
break;
}
else
{
for(;;)
{
printf("0 ");
((*w2).zhuangbei[2]).Kanpai();
printf("1 ");
((*w2).zhuangbei[3]).Kanpai();
printf("请选择要弃掉的马,输入之前的编号,以回车结束!\n");
scanf("%d",&x);
if((x==0)&&((*w2).zhuangbei[2].leixing!=-1))
{
printf("你弃掉了电脑的");
((*w2).zhuangbei)[2].Kanpai();
qipaidui[*qipaishu]=((*w2).zhuangbei)[2];
((*w2).zhuangbeishu)--;
(*qipaishu)++;
((*w2).zhuangbei)[2].leixing=-1;
((*w2).juli[0])++;
break;
}
else if((x==1)&&((*w2).zhuangbei[3].leixing!=-1))
{
printf("你弃掉了电脑的");
((*w2).zhuangbei)[3].Kanpai();
qipaidui[*qipaishu]=((*w2).zhuangbei)[3];
((*w2).zhuangbeishu)--;
(*qipaishu)++;
((*w2).zhuangbei)[3].leixing=-1;
((*w1).juli[0])--;
break;
}
else printf("射你妹的马!");
}
break;
}
}
else if(x==0)break;
else printf("键盘上的“0”和“1”被你吃了吗?\n");
}
}
int i;
((*w2).tili)--;
printf("玩家对电脑造成1点伤害!\n");
i=Binsi(w1,w2,qipaidui,qipaishu);
return i;
}
else if(x==0&&((*w1).zhuangbei[0].leixing==306))
{
for(;;)
{
printf("是否发动【贯石斧】武器效果?\n0 否\n1 是\n");
scanf("%d",&x);
if(x==1)
{
int i;
if((*w1).shoupaishu+(*w1).zhuangbeishu<=2)
{
printf("你除了【贯石斧】以外连2张牌都没有,发动你妹的效果!\n");
break;
}
else
{
printf("请分别弃掉两张牌!\n");
for(i=0;i<=2;i++)
{
for(;;)
{
printf("请选择区域:\n0 手牌\n1 装备\n");
scanf("%d",&x);
if(x==0&&((*w1).shoupaishu==0))printf("你根本没有手牌,弃你妹啊!\n");
else if(x==1&&((*w1).zhuangbeishu==1))printf("你根本没有别的装备,弃你妹啊!\n");
else if(x>=0&&x<=1)break;
else printf("键盘上的“0”和“1”被你吃了吗?\n");
}
if(x==0)
{
for(;;)
{
(*w1).Kanshoupai();
printf("弃牌请输入手牌之前的编号,以回车结束!\n");
scanf("%d",&x);
if(x>=0&&x<((*w1).shoupaishu))break;
else printf("弃你妹的手牌!\n");
}
printf("你弃掉了");
((*w1).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w1).shoupai)[x];
for(i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
(*qipaishu)++;
}
else
{
for(;;)
{
(*w1).Kanzhuangbei();
printf("请输入装备之前的编号,以回车键结束!\n");
scanf("%d",&x);
if((((*w1).zhuangbei[x]).leixing!=-1)&&(x>=0)&&(x<=3))
{
printf("你弃掉了");
((*w1).zhuangbei)[x].Kanpai();
qipaidui[*qipaishu]=((*w1).zhuangbei)[x];
((*w1).zhuangbeishu)--;
(*qipaishu)++;
((*w1).zhuangbei)[x].leixing=-1;
break;
}
else printf("弃你妹的装备!\n");
}
}
}
}
printf("玩家发动【贯石斧】武器效果使【杀】造成伤害!\n");
((*w2).tili)--;
i=Binsi(w1,w2,qipaidui,qipaishu);
return i;
break;
}
else if(x==0)break;
else printf("键盘上的“0”和“1”被你吃了吗?\n");
}
}
else if(x==0&&((*w1).zhuangbei[0].leixing==304))
{
for(;;)
{
printf("是否发动【青龙偃月刀】武器效果?\n0 否\n1 是\n");
scanf("%d",&x);
if(x==1)
{
for(;;)
{
printf("请对电脑使用一张【杀】!\n请输入手牌之前的编号,或者输入“-1”放弃出【杀】,以回车结束!\n");
(*w1).Kanshoupai();
scanf("%d",&x);
if(x==-1)
{
return 0;
break;
}
else if((*w1).shoupai[x].leixing==101)
{
int i;
printf("玩家对电脑使用");
((*w1).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w1).shoupai)[x];
for(i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
(*qipaishu)++;
i=Sha(w1,w2,paidui,paiduishu,qipaidui,qipaishu);
return i;
break;
}
else printf("你确定你打出的是【杀】?\n");
}
}
else if(x==0)
{
return 0;
break;
}
else printf("你确定你输入的是“0”或“1”?\n");
}
}
else return 0;
}
return 0;
}
void Tao(wujiang*w1)//【桃】函数
{
((*w1).tili)++;
if((*w1).juese)printf("玩家");
else printf("电脑");
printf("恢复了1点体力!\n");
if(((*w1).tili)>((*w1).tilishangxian))printf("你被撑死了!\n");
}
void Chai(wujiang*w1,wujiang*w2,pai qipaidui[104],int*qipaishu)
{
int i,x,y;
if((*w1).juese)
{
for(;;)
{
if((*w2).shoupaishu+(*w2).zhuangbeishu+(*w2).pandingshu==0)
{
printf("对方空城,拆你妹啊!\n");
break;
}
else
{
printf("请选择想拆的区域,输入选项之前的编号,以回车结束!\n0 手牌\n1 装备区\n2 判定区\n");
scanf("%d",&x);
if(x==0&&((*w2).shoupaishu==0))printf("你拆掉了一张空气!\n");
else if(x==1&&((*w2).zhuangbeishu==0))printf("你拆掉了一张空气!\n");
else if(x==2&&((*w2).pandingshu==0))printf("你拆掉了一张空气!\n");
else if(x>=0&&x<=2)break;
else printf("你拆掉了太空区里的一张牌!\n");
}
}
switch(x)
{
case 0:
srand((unsigned)time(NULL));
y=rand()%((*w2).shoupaishu);
printf("你弃掉了电脑的");
((*w2).shoupai)[y].Kanpai();
qipaidui[*qipaishu]=((*w2).shoupai)[y];
for(i=y+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
break;
case 1:
for(;;)
{
(*w2).Kanzhuangbei();
printf("请输入装备之前的编号,以回车键结束!\n");
scanf("%d",&y);
if((((*w2).zhuangbei[y]).leixing!=-1)&&(y>=0)&&(y<=3))
{
printf("你弃掉了电脑的");
((*w2).zhuangbei)[y].Kanpai();
qipaidui[*qipaishu]=((*w2).zhuangbei)[y];
((*w2).zhuangbeishu)--;
(*qipaishu)++;
((*w2).zhuangbei)[y].leixing=-1;
if(!y)((*w2).zhuangbei)[y].changdu=1;
else if(y==2)((*w2).juli[0])++;
else if(y==3)((*w1).juli[0])--;
break;
}
else printf("你弃掉了一张空气!\n");
}
break;
case 2:
for(;;)
{
(*w2).Kanpandingpai();
printf("请输入判定牌之前的编号,以回车键结束!\n");
scanf("%d",&y);
if((*w2).pandingpai[y].leixing!=-1)
{
printf("你弃掉了电脑的");
((*w2).pandingpai)[y].Kanpai();
qipaidui[*qipaishu]=((*w2).pandingpai)[y];
((*w2).pandingshu)--;
(*qipaishu)++;
((*w2).pandingpai)[y].leixing=-1;
break;
}
else printf("你弃掉了一张空气!\n");
}
break;
default:break;
}
}
else
{
if((*w2).zhuangbeishu)
{
if((*w2).zhuangbei[1].leixing!=-1)
{
printf("电脑弃掉了玩家的");
((*w2).zhuangbei)[1].Kanpai();
qipaidui[*qipaishu]=((*w2).zhuangbei)[1];
((*w2).zhuangbeishu)--;
(*qipaishu)++;
((*w2).zhuangbei)[1].leixing=-1;
}
else if((*w2).zhuangbei[3].leixing!=-1)
{
printf("电脑弃掉了玩家的");
((*w2).zhuangbei)[3].Kanpai();
qipaidui[*qipaishu]=((*w2).zhuangbei)[3];
((*w2).zhuangbeishu)--;
(*qipaishu)++;
((*w2).zhuangbei)[3].leixing=-1;
((*w1).juli[0])--;
}
else if((*w2).zhuangbei[0].leixing!=-1)
{
printf("电脑弃掉了玩家的");
((*w2).zhuangbei)[0].Kanpai();
qipaidui[*qipaishu]=((*w2).zhuangbei)[0];
((*w2).zhuangbeishu)--;
(*qipaishu)++;
((*w2).zhuangbei)[0].leixing=-1;
((*w2).zhuangbei)[0].changdu=1;
}
else
{
printf("电脑弃掉了玩家的");
((*w2).zhuangbei)[2].Kanpai();
qipaidui[*qipaishu]=((*w2).zhuangbei)[2];
((*w2).zhuangbeishu)--;
(*qipaishu)++;
((*w2).zhuangbei)[2].leixing=-1;
((*w2).juli[0])++;
}
}
else
{
srand((unsigned)time(NULL));
y=rand()%((*w2).shoupaishu);
printf("电脑弃掉了玩家的手牌");
((*w2).shoupai)[y].Kanpai();
qipaidui[*qipaishu]=((*w2).shoupai)[y];
for(i=y+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
}
}
}
void Qian(wujiang *w1,wujiang *w2)
{
int i,x,y;
if((*w1).juese)
{
for(;;)
{
if((*w2).shoupaishu+(*w2).zhuangbeishu+(*w2).pandingshu==0)
{
printf("对方空城啦!你牵走了一张寂寞!\n");
break;
}
else
{
printf("请选择想牵的区域,输入选项之前的编号,以回车结束!\n0 手牌\n1 装备区\n2 判定区\n");
scanf("%d",&x);
if(x==0&&((*w2).shoupaishu==0))printf("你牵走了一张空气!\n");
else if(x==1&&((*w2).zhuangbeishu==0))printf("你牵走了一张空气!\n");
else if(x==2&&((*w2).pandingshu==0))printf("你牵走了一张空气!\n");
else if(x>=0&&x<=2)break;
else printf("你牵走了太空区里的一张牌!\n");
}
}
switch(x)
{
case 0:
srand((unsigned)time(NULL));
y=rand()%((*w2).shoupaishu);
printf("你牵走了电脑的");
((*w2).shoupai)[y].Kanpai();
(*w1).shoupai[(*w1).shoupaishu]=((*w2).shoupai)[y];
for(i=y+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
((*w1).shoupaishu)++;
break;
case 1:
for(;;)
{
(*w2).Kanzhuangbei();
printf("请输入装备之前的编号,以回车键结束!\n");
scanf("%d",&y);
if((((*w2).zhuangbei[y]).leixing!=-1)&&(y>=0)&&(y<=3))
{
printf("你牵走了电脑的");
((*w2).zhuangbei)[y].Kanpai();
(*w1).shoupai[(*w1).shoupaishu]=((*w2).zhuangbei)[y];
((*w2).zhuangbeishu)--;
((*w1).shoupaishu)++;
((*w2).zhuangbei)[y].leixing=-1;
if(!y)((*w2).zhuangbei[y]).changdu=1;
else if(y==2)((*w2).juli[0])++;
else if(y==3)((*w1).juli[0])--;
break;
}
else printf("你弃掉了一张空气!\n");
}
break;
case 2:
for(;;)
{
(*w2).Kanpandingpai();
printf("请输入判定牌之前的编号,以回车键结束!\n");
scanf("%d",&y);
if((*w2).pandingpai[y].leixing!=-1)
{
printf("你牵走了电脑的");
((*w2).pandingpai)[y].Kanpai();
(*w1).shoupai[(*w1).shoupaishu]=((*w2).pandingpai)[y];
((*w2).pandingshu)--;
((*w1).shoupaishu)++;
((*w2).pandingpai)[y].leixing=-1;
break;
}
else printf("你牵走了一张空气!\n");
}
break;
default:break;
}
}
else
{
if((*w2).zhuangbeishu)
{
if((*w2).zhuangbei[1].leixing!=-1)
{
printf("电脑牵走了玩家的");
((*w2).zhuangbei)[1].Kanpai();
(*w1).shoupai[(*w1).shoupaishu]=((*w2).zhuangbei)[1];
((*w2).zhuangbeishu)--;
((*w1).shoupaishu)++;
((*w2).zhuangbei)[1].leixing=-1;
}
else if((*w2).zhuangbei[3].leixing!=-1)
{
printf("电脑牵走了玩家的");
((*w2).zhuangbei)[3].Kanpai();
(*w1).shoupai[(*w1).shoupaishu]=((*w2).zhuangbei)[3];
((*w2).zhuangbeishu)--;
((*w1).shoupaishu)++;
((*w2).zhuangbei)[3].leixing=-1;
((*w1).juli[0])--;
}
else if((*w2).zhuangbei[0].leixing!=-1)
{
printf("电脑牵走了玩家的");
((*w2).zhuangbei)[0].Kanpai();
(*w1).shoupai[(*w1).shoupaishu]=((*w2).zhuangbei)[0];
((*w2).zhuangbeishu)--;
((*w1).shoupaishu)++;
((*w2).zhuangbei)[0].leixing=-1;
((*w2).zhuangbei)[0].changdu=1;
}
else
{
printf("电脑牵走了玩家的");
((*w2).zhuangbei)[2].Kanpai();
(*w1).shoupai[(*w1).shoupaishu]=((*w2).zhuangbei)[2];
((*w2).zhuangbeishu)--;
((*w1).shoupaishu)++;
((*w2).zhuangbei)[2].leixing=-1;
((*w2).juli[0])--;
}
}
else
{
srand((unsigned)time(NULL));
y=rand()%((*w2).shoupaishu);
printf("电脑牵走了玩家的手牌");
((*w2).shoupai)[y].Kanpai();
(*w1).shoupai[(*w1).shoupaishu]=((*w2).shoupai)[y];
for(i=y+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
((*w1).shoupaishu)++;
}
}
}
void Wuzhong(wujiang*w1,pai A[104],int *x,pai B[104],int*y)
{
Mopai(&((*w1).shoupaishu),(*w1).shoupai,A,x,B,y,(*w1).juese);
}
int Juedou(wujiang*w1,wujiang*w2,pai qipaidui[104],int*qipaishu)
{
int i,j,x;
if((*w1).juese)
{
for(;;)
{
j=0;
for(x=0;x<((*w2).shoupaishu);x++)
{
if((*w2).shoupai[x].leixing==101)
{
printf("电脑打出");
((*w2).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w2).shoupai)[x];
for(int i=x+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
j=1;
break;
}
}
if(!j)
{
printf("玩家对电脑造成1点伤害!\n");
((*w2).tili)--;
i=Binsi(w1,w2,qipaidui,qipaishu);
return i;
break;
}
j=0;
for(;;)
{
printf("请打出一张【杀】响应【决斗】,否则你将受到1点伤害!\n请输入手牌之前的编号,或者输入“-1”放弃出【杀】,以回车结束!\n");
if(((*w1).zhuangbei[0].leixing==305))printf("如果想发动【丈八蛇矛】效果,请输入“100”,以回车结束!\n");
(*w1).Kanshoupai();
scanf("%d",&x);
if(x==-1)
{
int i;
((*w1).tili)--;
printf("电脑对玩家造成1点伤害!\n");
i=Binsi(w2,w1,qipaidui,qipaishu);
return i;
break;
}
else if(((*w1).zhuangbei[0].leixing==305)&&x==100)
{
pai p=Zhangba(w1,qipaidui,qipaishu);
p.paifu=-1;
printf("打出!\n");
j=1;
break;
}
else if((*w1).shoupai[x].leixing==101)
{
printf("玩家打出");
((*w1).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w1).shoupai)[x];
for(i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
(*qipaishu)++;
j=1;
break;
}
else printf("你确定你打出的是【杀】?\n");
}
}
}
else
{
for(;;)
{
j=0;
for(;;)
{
printf("请打出一张【杀】响应【决斗】,否则你将受到1点伤害!\n请输入手牌之前的编号,或者输入“-1”放弃出【杀】,以回车结束!\n");
if(((*w1).zhuangbei[0].leixing==305))printf("如果想发动【丈八蛇矛】效果,请输入“100”,以回车结束!\n");
(*w2).Kanshoupai();
scanf("%d",&x);
if(x==-1)
{
int i;
((*w2).tili)--;
printf("电脑对玩家造成1点伤害!\n");
i=Binsi(w1,w2,qipaidui,qipaishu);
return i;
break;
}
else if(((*w2).zhuangbei[0].leixing==305)&&x==100)
{
pai p=Zhangba(w2,qipaidui,qipaishu);
p.paifu=-1;
printf("打出!\n");
j=1;
break;
}
else if((*w2).shoupai[x].leixing==101)
{
printf("玩家打出");
((*w2).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w2).shoupai)[x];
for(i=x+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
j=1;
break;
}
else printf("你确定你打出的是【杀】?\n");
}
j=0;
for(x=0;x<((*w1).shoupaishu);x++)
{
if((*w1).shoupai[x].leixing==101)
{
printf("电脑打出");
((*w1).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w1).shoupai)[x];
for(int i=x+1;i<=((*w1).shoupaishu);i++)((*w1).shoupai)[i-1]=((*w1).shoupai)[i];
((*w1).shoupaishu)--;
(*qipaishu)++;
j=1;
break;
}
}
if(!j)
{
printf("玩家对电脑造成1点伤害!\n");
((*w2).tili)--;
i=Binsi(w2,w1,qipaidui,qipaishu);
return i;
break;
}
}
}
}
int Jiedao(wujiang*w1,wujiang*w2,pai paidui[104],int*paiduishu,pai qipaidui[104],int*qipaishu)
{
int i,j=0,x;
if((*w1).juese)
{
for(x=0;x<((*w2).shoupaishu);x++)
{
if((*w2).shoupai[x].leixing==101)
{
printf("电脑对玩家使用");
((*w2).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w2).shoupai)[x];
for(int i=x+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
j=1;
break;
}
}
if(j)
{
i=Sha(w2,w1,paidui,paiduishu,qipaidui,qipaishu);
return i;
printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w1).tili,(*w1).tilishangxian,(*w2).tili,(*w2).tilishangxian);
}
else
{
printf("电脑放弃使用【杀】,玩家获得电脑的武器");
(*w2).zhuangbei[0].Kanpai();
(*w1).shoupai[(*w1).shoupaishu]=((*w2).zhuangbei)[0];
((*w2).zhuangbeishu)--;
((*w1).shoupaishu)++;
((*w2).zhuangbei)[0].leixing=-1;
((*w2).zhuangbei)[0].changdu=1;
(*w1).Kanshoupai();
return 0;
}
}
else
{
for(;;)
{
printf("请对电脑使用一张【杀】,否则电脑将获得你的武器!\n请输入手牌之前的编号,或者输入“-1”放弃出【杀】,以回车结束!\n");
if(((*w2).zhuangbei[0].leixing==305))printf("如果想发动【丈八蛇矛】效果,请输入“100”,以回车结束!\n");
(*w2).Kanshoupai();
scanf("%d",&x);
if(x==-1)break;
else if(((*w2).zhuangbei[0].leixing==305)&&x==100)
{
pai p=Zhangba(w2,qipaidui,qipaishu);
p.paifu=-1;
printf("使用!\n");
j=1;
break;
}
else if((*w2).shoupai[x].leixing==101)
{
printf("玩家对电脑使用");
((*w2).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w2).shoupai)[x];
for(i=x+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
j=1;
break;
}
else printf("你确定你使用的是【杀】?\n");
}
if(j)
{
i=Sha(w2,w1,paidui,paiduishu,qipaidui,qipaishu);
return i;
printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w2).tili,(*w2).tilishangxian,(*w1).tili,(*w1).tilishangxian);
}
else
{
printf("玩家放弃使用【杀】,电脑获得玩家的武器");
((*w2).zhuangbei)[0].Kanpai();
(*w1).shoupai[(*w1).shoupaishu]=((*w2).zhuangbei)[0];
((*w2).zhuangbeishu)--;
((*w1).shoupaishu)++;
((*w2).zhuangbei)[0].leixing=-1;
((*w2).zhuangbei)[0].changdu=1;
return 0;
}
}
}
void Taoyuan(wujiang*w)
{
if((*w).tili<(*w).tilishangxian)
{
((*w).tili)++;
if((*w).juese)printf("玩家");
else printf("电脑");
printf("恢复1点体力!\n");
}
}
void Kaipai(pai paidui[104],int* paiduishu,int renshu,pai wugu[10])
{
int i;
printf("五谷丰登开牌:\n");
for(i=1;i<=renshu;i++)
{
wugu[i-1]=paidui[104-(*paiduishu)];
(*paiduishu)--;
printf("%d ",i-1);
wugu[i-1].Kanpai();
}
}
void Qupai(pai wugu[10],wujiang*w)
{
int i,x;
printf("五谷丰登开牌:\n");
for(i=0;(wugu[i].leixing)!=-1;i++)
{
printf("%d ",i);
wugu[i].Kanpai();
}
if((*w).juese)
{
for(;;)
{
printf("请选择你想要的卡牌,输入卡牌之前的编号,以回车结束!\n");
scanf("%d",&x);
if(wugu[x].leixing!=-1)
{
printf("玩家选择");
wugu[x].Kanpai();
(*w).shoupai[(*w).shoupaishu]=wugu[x];
((*w).shoupaishu)++;
for(i=x+1;i<=9;i++)wugu[i-1]=wugu[i];
wugu[9].leixing=-1;
break;
}
printf("你选择了一张空气加入手牌!");
}
}
else
{
printf("电脑选择");
wugu[0].Kanpai();
(*w).shoupai[(*w).shoupaishu]=wugu[0];
((*w).shoupaishu)++;
for(i=1;i<=9;i++)wugu[i-1]=wugu[i];
wugu[9].leixing=-1;
}
}
void Rengpai(pai wugu[10],pai qipaidui[104],int*qipaishu)
{
int i;
for(i=0;wugu[i].leixing!=-1;i++)
{
qipaidui[*qipaishu]=wugu[i];
(*qipaishu)++;
wugu[i].leixing=-1;
}
}
int Nanman(wujiang*w1,wujiang*w2,pai qipaidui[104],int*qipaishu)
{
int i,x;
if((*w1).juese)
{
for(x=0;x<((*w2).shoupaishu);x++)
{
if((*w2).shoupai[x].leixing==101)
{
printf("电脑打出");
((*w2).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w2).shoupai)[x];
for(int i=x+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
return 0;
break;
}
}
printf("玩家对电脑造成1点伤害!\n");
((*w2).tili)--;
i=Binsi(w1,w2,qipaidui,qipaishu);
return i;
}
else
{
for(;;)
{
printf("请打出一张【杀】响应【南蛮入侵】,否则你将受到1点伤害!\n请输入手牌之前的编号,或者输入“-1”放弃出【杀】,以回车结束!\n");
if(((*w2).zhuangbei[0].leixing==305))printf("如果想发动【丈八蛇矛】效果,请输入“100”,以回车结束!\n");
(*w2).Kanshoupai();
scanf("%d",&x);
if(x==-1)
{
int i;
((*w2).tili)--;
printf("电脑对玩家造成1点伤害!\n");
i=Binsi(w1,w2,qipaidui,qipaishu);
return i;
break;
}
else if(((*w2).zhuangbei[0].leixing==305)&&x==100)
{
pai p=Zhangba(w2,qipaidui,qipaishu);
p.paifu=-1;
printf("使用!\n");
return 0;
break;
}
else if((*w2).shoupai[x].leixing==101)
{
printf("玩家打出");
((*w2).shoupai)[x].Kanpai();
qipaidui[*qipaishu]=((*w2).shoupai)[x];
for(i=x+1;i<=((*w2).shoupaishu);i++)((*w2).shoupai)[i-1]=((*w2).shoupai)[i];
((*w2).shoupaishu)--;
(*qipaishu)++;
return 0;
break;
}
else printf("你确定你打出的是【杀】?\n");
}
}
}
int Wanjian(wujiang*w1,wujiang*w2,pai paidui[104],int*paiduishu,pai qipaidui[104],int*qipaishu)
{
int i;
i=Shan(w1,w2,paidui,paiduishu,qipaidui,qipaishu);
if(i==-1)
{
i=Binsi(w1,w2,qipaidui,qipaishu);
return i;
}
else return 0;
}
int Chupai(pai paidui[104],pai qipaidui[104],int *paiduishu,int*qipaishu,wujiang*w1,wujiang*w2,pai yuanshipaidui[2][4][13])
{
pai p1;
int sha=1;int y=-1,i,t=((*w1).shoupaishu)-1;
for(;;t--)
{
if((*w1).juese)
{
printf("\n电脑当前手牌数:%d\n",((*w2).shoupaishu));
(*w2).Kanzhuangbei();
(*w1).Kanshoupai();
(*w1).Kanzhuangbei();
}
int j=0;
if((*w1).juese&&((*w1).zhuangbei[0].leixing==305))printf("如果想发动【丈八蛇矛】效果,请输入“100”,以回车结束!\n");
y=Xuanpai(w1,t);
p1=Panpai(w1,&sha,y,qipaidui,qipaishu);
if((p1).leixing==-1)break;
else if((p1).leixing==0)continue;
else
{
int duixiang;
duixiang=Mubiao(p1,w1,w2,&sha);
if(duixiang==-2)continue;
else
{
Da1pai(w1,w2,qipaidui,qipaishu,y);
Miaoshu(p1,((*w1).juese),duixiang);
if(!((*w1).juese))
{
printf("\n电脑当前手牌数:%d\n",((*w1).shoupaishu));
(*w1).Kanzhuangbei();
(*w2).Kanshoupai();
(*w2).Kanzhuangbei();
}
switch(p1.leixing)
{
case 101:
i=Sha(w1,w2,paidui,paiduishu,qipaidui,qipaishu);
if(i==-1){return -1;break;}
if((*w1).juese)printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w1).tili,(*w1).tilishangxian,(*w2).tili,(*w2).tilishangxian);
else printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w2).tili,(*w2).tilishangxian,(*w1).tili,(*w1).tilishangxian);
break;
case 103:
Tao(w1);
break;
case 201:
for(;;)
{
i=Wuxie(&p1,w1,w2,qipaidui,qipaishu,0);
if(!i)break;
j++;
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
}
if(!(j%2))Chai(w1,w2,qipaidui,qipaishu);
else;
if((*w1).juese)(*w1).Kanshoupai();
break;
case 202:
for(;;)
{
i=Wuxie(&p1,w1,w2,qipaidui,qipaishu,0);
if(!i)break;
j++;
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
}
if(!(j%2))Qian(w1,w2);
else;
if((*w1).juese)(*w1).Kanshoupai();
break;
case 203:
for(;;)
{
i=Wuxie(&p1,w1,w2,qipaidui,qipaishu,0);
if(!i)break;
j++;
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
}
if(!(j%2))Wuzhong(w1,paidui,paiduishu,qipaidui,qipaishu);
else;
break;
case 204:
for(;;)
{
i=Wuxie(&p1,w1,w2,qipaidui,qipaishu,0);
if(!i)break;
j++;
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
}
if(!(j%2))
{
i=Juedou(w1,w2,qipaidui,qipaishu);
if(i==-1)return -1;
if((*w1).juese)printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w1).tili,(*w1).tilishangxian,(*w2).tili,(*w2).tilishangxian);
else printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w2).tili,(*w2).tilishangxian,(*w1).tili,(*w1).tilishangxian);
}
break;
case 205:
for(;;)
{
i=Wuxie(&p1,w1,w2,qipaidui,qipaishu,0);
if(!i)break;
j++;
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
}
if(!(j%2))
{
i=Jiedao(w1,w2,paidui,paiduishu,qipaidui,qipaishu);
if(i==-1)return -1;
if((*w1).juese)printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w1).tili,(*w1).tilishangxian,(*w2).tili,(*w2).tilishangxian);
else printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w2).tili,(*w2).tilishangxian,(*w1).tili,(*w1).tilishangxian);
}
break;
case 206:
for(;;)
{
i=Wuxie(&p1,w1,w2,qipaidui,qipaishu,0);
if(!i)break;
j++;
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
}
if(!(j%2))Taoyuan(w1);
j=0;
for(;;)
{
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
}
if(!(j%2))Taoyuan(w2);
break;
case 207:
pai wugu[10];
for(i=1;i<=10;i++)wugu[i-1].leixing=-1;
Kaipai(paidui,paiduishu,2,wugu);
for(;;)
{
i=Wuxie(&p1,w1,w2,qipaidui,qipaishu,0);
if(!i)break;
j++;
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
}
if(!(j%2))Qupai(wugu,w1);
for(;;)
{
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
}
if(!(j%2))Qupai(wugu,w2);
Rengpai(wugu,qipaidui,qipaishu); printf("弃牌数:%d\n",*qipaishu);
break;
case 208:
for(;;)
{
i=Wuxie(&p1,w1,w2,qipaidui,qipaishu,0);
if(!i)break;
j++;
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
}
if(!(j%2))
{
i=Nanman(w1,w2,qipaidui,qipaishu);
if(i==-1)return -1;
if((*w1).juese)printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w1).tili,(*w1).tilishangxian,(*w2).tili,(*w2).tilishangxian);
else printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w2).tili,(*w2).tilishangxian,(*w1).tili,(*w1).tilishangxian);
}
break;
case 209:
for(;;)
{
i=Wuxie(&p1,w1,w2,qipaidui,qipaishu,0);
if(!i)break;
j++;
i=Wuxie(&p1,w2,w1,qipaidui,qipaishu,0);
if(!i)break;
j++;
}
if(!(j%2))
{
i=Wanjian(w1,w2,paidui,paiduishu,qipaidui,qipaishu);
if(i==-1)return -1;
if((*w1).juese)printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w1).tili,(*w1).tilishangxian,(*w2).tili,(*w2).tilishangxian);
else printf("玩家当前体力值:%d/%d\n电脑当前体力值:%d/%d\n",(*w2).tili,(*w2).tilishangxian,(*w1).tili,(*w1).tilishangxian);
}
break;
case 361:
case 362:
case 363:
((*w1).juli[0])--;break;
case 381:
case 382:
case 383:
((*w2).juli[0])++;break;
default:break;
}
printf("\n");
}
}
}
return 0;
}
void Qipai(pai shoupai[20],int *shoupaishu,pai qipaidui[104],int *qipaishu,int juese,int *shoupaishangxian)
{
int x;
if((*shoupaishu)>(*shoupaishangxian))
{
if(juese!=1&&juese!=0)printf("身份参数错误!");
int q=(*shoupaishu)-(*shoupaishangxian);
int i,j;
for(j=1;j<=q;j++)
{
for(;;)
{
if(juese)
{
printf("弃牌请输入手牌之前的编号,以回车结束!\n注:一次只能弃一张牌\n");
printf("手牌数:%d\n",*shoupaishu);
scanf("%d",&x);
if(x>=0&&x<(*shoupaishu))break;
else printf("你弃掉了一张空气!\n");
}
else
{
srand((unsigned)time(NULL));
x=rand()%(*shoupaishu);
break;
}
}
qipaidui[*qipaishu]=shoupai[x];
for(i=x+1;i<=(*shoupaishu);i++)shoupai[i-1]=shoupai[i];
(*shoupaishu)--;
if(juese)printf("弃牌阶段玩家弃置");
else printf("弃牌阶段电脑弃置");
qipaidui[*qipaishu].Kanpai();
(*qipaishu)++;
int m;
if(juese)
{
printf("玩家当前手牌:\n");
for(m=0;m<=(*shoupaishu-1);m++)
{
printf("%d ",m);
(shoupai[m]).Kanpai();
}
} printf("弃牌堆:%d\n",*qipaishu);
}
}
}
int Huihe(pai A[104],pai B[104],int *x,int *y,pai yuanshipaidui[2][4][13],wujiang *w1,wujiang *w2)
{
printf("\n回合开始阶段……\n");
switch((*w1).huihekaishi)
{
case 0:break;
default:printf("回合开始阶段参数错误!\n");break;
}
printf("判定阶段……\n");
int K=0;
if((*w1).pandingshu>0)
{
int i,j;
for(;(*w1).pandingshu;)
{
switch((*w1).pandingpai[0].leixing)
{
case 251:printf("【乐不思蜀】开始判定……\n"); break;
case 252:printf("【闪电】开始判定……\n");break;
default:printf("【??】开始判定……\n");break;
}
j=0;
pai p=((*w1).pandingpai[0]);
for(;;)//在判定之前询问【无懈】
{
i=Wuxie(&p,w2,w1,B,y,0);
if(!i)break;
j++;
i=Wuxie(&p,w1,w2,B,y,0);
if(!i)break;
j++;
}
switch((*w1).pandingpai[0].leixing)
{
case 251:
if(!(j%2))
{
printf("【乐不思蜀】的判定牌是:");
Panding(A,x,B,y);
if((B[(*y)-1].huase)!=1)
{
printf("【乐不思蜀】判定成功!\n");
if((*w1).juese)printf("玩家");
else printf("电脑");
printf("跳过出牌阶段!\n");
K=-1;
}
else printf("【乐不思蜀】判定失败!\n");
}
B[*y]=(*w1).pandingpai[0];
((*w1).pandingshu)--;
(*w1).pandingpai[0]=(*w1).pandingpai[1];
(*w1).pandingpai[1]=(*w1).pandingpai[2];
(*w1).pandingpai[2].leixing=-1;
(*y)++;
break;
case 252:
if(!(j%2))
{
printf("【闪电】的判定牌是:");
Panding(A,x,B,y);
if((B[(*y)-1].huase==0)&&(B[(*y)-1].dianshu>=1)&&(B[(*y)-1].dianshu<=8))
{
printf("【闪电】判定成功!\n");
if((*w1).juese)printf("玩家");
else printf("电脑");
printf("受到3点雷电伤害!");
((*w1).tili)=((*w1).tili)-3;
i=Binsi(w2,w1,B,y);
B[*y]=(*w1).pandingpai[0];
((*w1).pandingshu)--;
(*w1).pandingpai[0]=(*w1).pandingpai[1];
(*w1).pandingpai[1]=(*w1).pandingpai[2];
(*w1).pandingpai[2].leixing=-1;
(*y)++;
if(i==-1)return -1;
}
else
{
printf("【闪电】判定失败!\n");
(*w2).pandingpai[2]=(*w2).pandingpai[1];
(*w2).pandingpai[1]=(*w2).pandingpai[0];
(*w2).pandingpai[0]=(*w1).pandingpai[0];
(*w1).pandingpai[0]=(*w1).pandingpai[1];
(*w1).pandingpai[1]=(*w1).pandingpai[2];
(*w1).pandingpai[2].leixing=-1;
((*w1).pandingshu)--;
((*w2).pandingshu)++;
}
break;
}
default:printf("判定牌错误!");
} printf("弃牌数:%d\n",*y);
}
}
else if(!((*w1).pandingshu));
else printf("判定阶段参数错误!\n");
printf("摸牌阶段……\n");
switch((*w1).mopai)
{
case 0:Mopai(&((*w1).shoupaishu),(*w1).shoupai,A,x,B,y,(*w1).juese);break;
case -1:break;
default:printf("摸牌阶段参数错误!\n");break;
}
if(K==-1)goto M;
printf("出牌阶段……\n");
switch((*w1).chupai)
{
case 0:
{
int i;
i=Chupai(A,B,x,y,w1,w2,yuanshipaidui);
if(i==-1)
{
return -1;
break;
}
else
break;
}
case -1:break;
default:printf("出牌阶段参数错误!\n");break;
}
M:
printf("弃牌阶段……\n");
switch((*w1).qipai)
{
case 0:
Qipai((*w1).shoupai,&((*w1).shoupaishu),B,y,(*w1).juese,&((*w1).tili));break;
default:printf("弃牌阶段参数错误!\n");break;
}
printf("回合结束阶段……\n");
switch((*w1).huihejieshu)
{
case 0:break;
default:printf("回合结束阶段参数错误!\n");break;
}
return 0;
}
int main()
{
void Kanshoupai(pai p);
pai yuanshipaidui[2][4][13],qipaidui[104],paidui[104];
wujiang wanjia,com;
com.tili=wanjia.tili=5;
com.tilishangxian=wanjia.tilishangxian=5;
com.huihekaishi=wanjia.huihekaishi=0;
com.panding=wanjia.panding=0;
com.mopai=wanjia.mopai=0;
com.chupai=wanjia.chupai=0;
com.qipai=wanjia.qipai=0;
com.huihejieshu=wanjia.huihejieshu=0;
com.shoupaishu=wanjia.shoupaishu=0;
com.pandingshu=wanjia.pandingshu=0;
com.zhuangbeishu=wanjia.zhuangbeishu=0;
com.juese=0;wanjia.juese=1;
pai p;
p.leixing=-1;
com.zhuangbei[0]=com.zhuangbei[1]=com.zhuangbei[2]=com.zhuangbei[3]=wanjia.zhuangbei[0]=wanjia.zhuangbei[1]=wanjia.zhuangbei[2]=wanjia.zhuangbei[3]=p;
com.zhuangbei[0].changdu=wanjia.zhuangbei[0].changdu=1;
com.pandingpai[0]=com.pandingpai[1]=com.pandingpai[2]=wanjia.pandingpai[0]=wanjia.pandingpai[1]=wanjia.pandingpai[2]=p;
com.juli[0]=wanjia.juli[0]=1;
int a,b,c;
for(a=0;a<=1;a++)
{
for(b=0;b<=3;b++)
{
for(c=0;c<=12;c++)
{
yuanshipaidui[a][b][c].paifu=a;
yuanshipaidui[a][b][c].huase=b;
yuanshipaidui[a][b][c].dianshu=c;
}
}
}
yuanshipaidui[0][0][0].leixing=204;
yuanshipaidui[0][0][1].leixing=331;
yuanshipaidui[0][0][2].leixing=201;
yuanshipaidui[0][0][3].leixing=201;
yuanshipaidui[0][0][4].leixing=304;yuanshipaidui[0][0][4].changdu=3;
yuanshipaidui[0][0][5].leixing=251;
yuanshipaidui[0][0][6].leixing=101;
yuanshipaidui[0][0][7].leixing=101;
yuanshipaidui[0][0][8].leixing=101;
yuanshipaidui[0][0][9].leixing=101;
yuanshipaidui[0][0][10].leixing=202;
yuanshipaidui[0][0][11].leixing=201;
yuanshipaidui[0][0][12].leixing=208;
yuanshipaidui[0][1][0].leixing=209;
yuanshipaidui[0][1][1].leixing=102;
yuanshipaidui[0][1][2].leixing=103;
yuanshipaidui[0][1][3].leixing=103;
yuanshipaidui[0][1][4].leixing=308;yuanshipaidui[0][1][4].changdu=5;
yuanshipaidui[0][1][5].leixing=103;
yuanshipaidui[0][1][6].leixing=103;
yuanshipaidui[0][1][7].leixing=103;
yuanshipaidui[0][1][8].leixing=103;
yuanshipaidui[0][1][9].leixing=101;
yuanshipaidui[0][1][10].leixing=101;
yuanshipaidui[0][1][11].leixing=103;
yuanshipaidui[0][1][12].leixing=102;
yuanshipaidui[0][2][0].leixing=204;
yuanshipaidui[0][2][1].leixing=101;
yuanshipaidui[0][2][2].leixing=101;
yuanshipaidui[0][2][3].leixing=101;
yuanshipaidui[0][2][4].leixing=101;
yuanshipaidui[0][2][5].leixing=101;
yuanshipaidui[0][2][6].leixing=101;
yuanshipaidui[0][2][7].leixing=101;
yuanshipaidui[0][2][8].leixing=101;
yuanshipaidui[0][2][9].leixing=101;
yuanshipaidui[0][2][10].leixing=101;
yuanshipaidui[0][2][11].leixing=205;
yuanshipaidui[0][2][12].leixing=205;
yuanshipaidui[0][3][0].leixing=204;
yuanshipaidui[0][3][1].leixing=102;
yuanshipaidui[0][3][2].leixing=102;
yuanshipaidui[0][3][3].leixing=102;
yuanshipaidui[0][3][4].leixing=102;
yuanshipaidui[0][3][5].leixing=101;
yuanshipaidui[0][3][6].leixing=101;
yuanshipaidui[0][3][7].leixing=101;
yuanshipaidui[0][3][8].leixing=101;
yuanshipaidui[0][3][9].leixing=101;
yuanshipaidui[0][3][10].leixing=102;
yuanshipaidui[0][3][11].leixing=103;
yuanshipaidui[0][3][12].leixing=101;
yuanshipaidui[1][0][0].leixing=252;
yuanshipaidui[1][0][1].leixing=302;yuanshipaidui[1][0][1].changdu=2;
yuanshipaidui[1][0][2].leixing=202;
yuanshipaidui[1][0][3].leixing=202;
yuanshipaidui[1][0][4].leixing=383;
yuanshipaidui[1][0][5].leixing=303;yuanshipaidui[1][0][5].changdu=2;
yuanshipaidui[1][0][6].leixing=208;
yuanshipaidui[1][0][7].leixing=101;
yuanshipaidui[1][0][8].leixing=101;
yuanshipaidui[1][0][9].leixing=101;
yuanshipaidui[1][0][10].leixing=210;
yuanshipaidui[1][0][11].leixing=305;yuanshipaidui[1][0][11].changdu=3;
yuanshipaidui[1][0][12].leixing=362;
yuanshipaidui[1][1][0].leixing=206;
yuanshipaidui[1][1][1].leixing=102;
yuanshipaidui[1][1][2].leixing=207;
yuanshipaidui[1][1][3].leixing=207;
yuanshipaidui[1][1][4].leixing=361;
yuanshipaidui[1][1][5].leixing=251;
yuanshipaidui[1][1][6].leixing=203;
yuanshipaidui[1][1][7].leixing=203;
yuanshipaidui[1][1][8].leixing=203;
yuanshipaidui[1][1][9].leixing=101;
yuanshipaidui[1][1][10].leixing=203;
yuanshipaidui[1][1][11].leixing=201;
yuanshipaidui[1][1][12].leixing=381;
yuanshipaidui[1][2][0].leixing=301;yuanshipaidui[1][2][0].changdu=1;
yuanshipaidui[1][2][1].leixing=331;
yuanshipaidui[1][2][2].leixing=201;
yuanshipaidui[1][2][3].leixing=201;
yuanshipaidui[1][2][4].leixing=382;
yuanshipaidui[1][2][5].leixing=251;
yuanshipaidui[1][2][6].leixing=208;
yuanshipaidui[1][2][7].leixing=101;
yuanshipaidui[1][2][8].leixing=101;
yuanshipaidui[1][2][9].leixing=101;
yuanshipaidui[1][2][10].leixing=101;
yuanshipaidui[1][2][11].leixing=210;
yuanshipaidui[1][2][12].leixing=210;
yuanshipaidui[1][3][0].leixing=301;yuanshipaidui[1][3][0].changdu=1;
yuanshipaidui[1][3][1].leixing=102;
yuanshipaidui[1][3][2].leixing=202;
yuanshipaidui[1][3][3].leixing=202;
yuanshipaidui[1][3][4].leixing=306;yuanshipaidui[1][3][4].changdu=3;
yuanshipaidui[1][3][5].leixing=102;
yuanshipaidui[1][3][6].leixing=102;
yuanshipaidui[1][3][7].leixing=102;
yuanshipaidui[1][3][8].leixing=102;
yuanshipaidui[1][3][9].leixing=102;
yuanshipaidui[1][3][10].leixing=102;
yuanshipaidui[1][3][11].leixing=307;yuanshipaidui[1][3][11].changdu=4;
yuanshipaidui[1][3][12].leixing=363;
int paiduishu=104;
int qipaishu=0;
printf("游戏开始!\n");
Qishixipai(yuanshipaidui,paidui);
Qishishoupai(&wanjia,paidui,&(paiduishu),qipaidui,&(qipaishu));
Qishishoupai(&com,paidui,&(paiduishu),qipaidui,&(qipaishu));
int i;
for(;;)
{
i=Huihe(paidui,qipaidui,&paiduishu,&qipaishu,yuanshipaidui,&wanjia,&com);
if(i==-1)break;
i=Huihe(paidui,qipaidui,&paiduishu,&qipaishu,yuanshipaidui,&com,&wanjia);
if(i==-1)break;
}
}