op大学生自己写了个斗地主小游戏ヾ(≧▽≦*)o,加关注支持一下吧
源码里写了不少注释,第一次写小游戏,用了easyx图形化界面,素材都是从原神里扣的,自己做着玩哈哈。
附源码,工程文件
安装包链接:链接:https://pan.baidu.com/s/1KYROrZRVxHutCGvem34Fhg
提取码:cyfs
工程文件链接:链接:https://pan.baidu.com/s/1AbvEGojJ1fEsVUknXbXD0Q
提取码:cyfs
安装包链接:链接:https://pan.baidu.com/s/1KYROrZRVxHutCGvem34Fhg
提取码:cyfs
工程文件链接:链接:https://pan.baidu.com/s/1AbvEGojJ1fEsVUknXbXD0Q
提取码:cyfs
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <easyx.h>
#include <windows.h>
#include <conio.h>
#include "tools.h"
#include<mmsystem.h>
#pragma comment(lib, "WINMM.LIB")
struct TabletNODE
{
int color;//牌的花色
int num;//牌的大小||头节点存储牌堆数量
IMAGE Tablet;//牌的本体
struct TabletNODE* next;
int x;//牌的x坐标
int y;//牌的y坐标
};
TabletNODE* Heap = new TabletNODE;//创建牌堆
TabletNODE* MyCards = new TabletNODE;//创建我的牌堆
TabletNODE* OnePlayerCard = new TabletNODE;//创建一号玩家牌堆
TabletNODE* TwoPlayerCard = new TabletNODE;//创建二号玩家1牌堆
TabletNODE* ThreePlayerCard = new TabletNODE;//创建三号玩家牌堆
TabletNODE* HandCards = new TabletNODE;//创建手牌卡区
TabletNODE* tempCards = new TabletNODE;//创建临时卡堆
IMAGE BeiJingPNG[110];//牌图片
IMAGE Claim[2];//地主图片
IMAGE ZL,HT,LH,XG;//图片渲染bg[1]{dfsgsd}
char bgmusic[19][64];//音乐变量bg[2]
int MusicNum = 1;//音乐顺序
int close = 0;//关闭变量
int KBNum = 1;//卡背顺序
#define WIDTH 1500//宽度
#define HIGH 800//长度
void MyCardGo();//运行我的出牌程序
void PCPlayerCardGo(TabletNODE*& Cards);//运行人机出牌程序
void PlayCards();//出牌主程序
void InitCards(TabletNODE*& p);//初始化链表头节点
void DealAllCards(TabletNODE*& p, TabletNODE*& Cards);//实现发牌
void DealCards();//实现地主发牌
void ShuffleCards(TabletNODE*& p);//实现打乱牌堆
void push();//加载牌堆图片资源
void init();//初始化程序
void freellist(TabletNODE*& head);//释放链表内容
void freeCards();//释放所有手牌
void Renovate();//渲染函数
void updateMycards();//渲染己方卡片
void updatePCcards(TabletNODE*& q, int j, int k);
void updateBg();//渲染背景
void InitCards(TabletNODE*& p);//初始化链表头节点
/*//*/
void MyCardGo()
{//备份函数
char ch = '}';
int sign = 0;
while (ch != '+')
{
TabletNODE* p = MyCards;
ch = _getch();
if (MyCards->color == 1 && ch > '{')
continue;
else if (MyCards->color == 0 && ch > 's')
continue;
for (int i = 0; i <= ch - '[' ; i++)
{
p = p->next;
}
if (p == 0)
break;
if (p->y == 0)
{
p->y = 30;
}
else
p->y = 0;
Renovate();
sign++;
}
freellist(tempCards->next);
InitCards(tempCards);
TabletNODE* tmp = tempCards;
TabletNODE* q = MyCards;
while (q->next != 0)
{
if (q->next->y != 0)
{
TabletNODE* m = q->next;
q->next = q->next->next;
m->next = tmp->next;
tmp->next = m;
MyCards->num--;
tempCards->num++;
}
else
q = q->next;
}
}
void MyCardsGo()
{//本家出卡程序
char ch;
int sign = 0;
TabletNODE* q = MyCards;
while (1)
{
ch = _getch();
if (ch == 'o')
{
close = 1;
return;
}
if (ch == 'd' && sign < MyCards->num - 1)
sign++;
else if (ch == 'a' && sign > 0)
sign--;
else if (ch == '+' && q->next != 0)
{//按‘+’号键,将所选卡牌存入链表
if (tempCards->color != 4 || tempCards->x == 1)
{
freellist(tempCards->next);
InitCards(tempCards);//此时清空临时卡牌
}
TabletNODE* m = q->next;
q->next = q->next->next;
m->next = tempCards->next;
tempCards->next = m;
MyCards->num--;
tempCards->num++;
tempCards->color = 4;
}
else if (ch == '-')
break;//按‘-’号键,带着临时卡牌离开循环
q = MyCards;
for (int i = 1; i <= sign; i++)
q = q->next;
if (q->next != 0)
q->next->y = 20;
Renovate();
if (tempCards->color == 3)
updatePCcards(tempCards->next, 300, 200);//渲染上一位玩家卡牌
else if (tempCards->color == 2)
{
updatePCcards(tempCards->next, 160, 500);//渲染上一位玩家卡牌
putimagePNG2(200, 300, &LH);
}
else if (tempCards->color == 1)
{
updatePCcards(tempCards->next, 300, 1000);//渲染上一位玩家卡牌
putimagePNG2(200, 300, &LH);
putimagePNG2(500, 160, &XG);
}
else if (tempCards->color == 4 && tempCards->x != 1)
updatePCcards(tempCards->next, 700, 700);//渲染本家卡牌
if (ch != '+' && q->next != 0)
q->next->y = 0;
}
tempCards->x = 1;//设置标记
}
void PCPlayerCardGo(TabletNODE* &Cards,int Which)
{
if (tempCards->color == Which)
{//此时循环玩一遍,无出牌玩家
tempCards->num = 0;
}
TabletNODE* p = Cards;
TabletNODE* temp = 0;
while (p->next != 0)
{
if (tempCards->num == 0)
{
freellist(tempCards->next);
InitCards(tempCards);
temp = p->next;
p->next = p->next->next;
temp->next = tempCards->next;
tempCards->num++;
Cards->num--;
tempCards->next = temp;
tempCards->color = Which;//储存玩家序号
return;
}
else if (tempCards->num == 1)
{
if (p->next->num > tempCards->next->num)
{
freellist(tempCards->next);
InitCards(tempCards);
temp = p->next;
p->next = p->next->next;
temp->next = tempCards->next;
tempCards->num++;
Cards->num--;
tempCards->next = temp;
tempCards->color = Which;//储存玩家序号
return;
}
}
else if (tempCards->num == 2)
{
if (p->next->next == 0)
return;
if (p->next->next != 0)
{
if (p->next->num > tempCards->next->num && p->next->num == p->next->next->num)
{
freellist(tempCards->next);
InitCards(tempCards);
temp = p->next;
p->next = p->next->next->next;
temp->next->next = tempCards->next;
tempCards->num += 2;
Cards->num -= 2;
tempCards->next = temp;
tempCards->color = Which;//储存玩家序号
return;
}
}
}
else if (tempCards->num == 3)
{
if (p->next->next->next == 0)
return;
if (p->next->next->next != 0)
{
if (p->next->num > tempCards->next->num && p->next->num == p->next->next->num && p->next->next->num == p->next->next->next->num)
{
freellist(tempCards->next);
InitCards(tempCards);
temp = p->next;
p->next = p->next->next->next->next;
temp->next->next->next = tempCards->next;
tempCards->num += 3;
Cards->num -= 3;
tempCards->next = temp;
tempCards->color = Which;//储存玩家序号
return;
}
}
}
else if (tempCards->num == 4)
{
if (p->next->next->next->next == 0)
return;
if (p->next->next->next->next != 0)
{
if (p->next->num > tempCards->next->num && p->next->num == p->next->next->num && p->next->next->num == p->next->next->next->num && p->next->next->next->num == p->next->next->next->next->num)
{
freellist(tempCards->next);
InitCards(tempCards);
temp = p->next;
p->next = p->next->next->next->next->next;
temp->next->next->next->next = tempCards->next;
tempCards->num += 4;
Cards->num -= 4;
tempCards->next = temp;
tempCards->color = Which;//储存玩家序号
return;
}
}
}
else if (tempCards->num == 4)
{
if (p->next->next->next->next->next == 0)
return;
if (p->next->next->next->next->next != 0)
{
if (p->next->num > tempCards->next->num && p->next->num == p->next->next->num && p->next->next->num == p->next->next->next->num && p->next->next->next->num == p->next->next->next->next->num && p->next->next->next->next->num == p->next->next->next->next->next->num)
{
freellist(tempCards->next);
InitCards(tempCards);
temp = p->next;
p->next = p->next->next->next->next->next->next;
temp->next->next->next->next->next = tempCards->next;
tempCards->num += 5;
Cards->num -= 5;
tempCards->next = temp;
tempCards->color = Which;//储存玩家序号
return;
}
}
}
p = p->next;
}
}
/*///*/
void PlayCards()
{
IMAGE WINPNG,PlayerWin;
mciSendString(bgmusic[MusicNum], NULL, 0, NULL);
mciSendString("play mmymusic", NULL, 0, NULL);
if (MyCards->color == 1)//本家出牌
{
MyCardsGo();
Renovate();
updatePCcards(tempCards->next, 430, 500);
if (close == 1)
return;
}
while (1)
{//开始出牌
Sleep(1000);
PCPlayerCardGo(OnePlayerCard,1);//一号出牌
if (tempCards->color == 1)
updatePCcards(tempCards->next, 300, 1000);
else
{
Renovate();
putimagePNG2(1000, 300, &ZL);//此时无打得过的牌
if (tempCards->color == 4)
updatePCcards(tempCards->next, 430, 500);
else if (tempCards->color == 3)
{
updatePCcards(tempCards->next, 300, 200);
putimagePNG2(500, 400, &HT);
}
else if (tempCards->color == 2)
{
updatePCcards(tempCards->next, 160, 500);
putimagePNG2(500, 430, &HT);//渲染胡桃
putimagePNG2(200, 300, &LH);
}
}
if (OnePlayerCard->num == 0)
{
updateBg();//渲染背景 //展示玩家一胜出
loadimage(&WINPNG, "扑克牌图片/钟离win.png");
loadimage(&PlayerWin, "扑克牌/钟离赢了.png");
putimagePNG2(600, 250, &PlayerWin);
putimagePNG2(700, 350, &WINPNG);
_getch();
break;
}// 判断剩余排数
Sleep(1000);
PCPlayerCardGo(TwoPlayerCard,2);//二号出牌
if (tempCards->color == 2)
updatePCcards(tempCards->next, 160, 500);
else
{
Renovate();
putimagePNG2(500, 160, &XG);//渲染宵宫
if (tempCards->color == 4)
{
updatePCcards(tempCards->next, 430, 500);
putimagePNG2(1000, 300, &ZL);//渲染钟离
}
else if (tempCards->color == 3)
{
updatePCcards(tempCards->next, 300, 200);
putimagePNG2(500, 430, &HT);//渲染胡桃
putimagePNG2(1000, 300, &ZL);//渲染钟离
}
else if (tempCards->color == 1)
updatePCcards(tempCards->next, 300, 1000);
}
if (TwoPlayerCard->num == 0)
{
updateBg();//渲染背景 //展示玩家二胜出
loadimage(&WINPNG, "扑克牌图片/宵宫win.png");
loadimage(&PlayerWin, "扑克牌/宵宫赢了.png");
putimagePNG2(600, 250, &PlayerWin);
putimagePNG2(700, 350, &WINPNG);
_getch();
break;
}// 判断剩余排数
Sleep(1000);
PCPlayerCardGo(ThreePlayerCard,3);//三号出牌
if(tempCards->color==3)
updatePCcards(tempCards->next, 300, 200);
else
{
Renovate();
putimagePNG2(200, 300, &LH);//渲染绫华
if (tempCards->color == 4)
{
updatePCcards(tempCards->next, 430, 500);
putimagePNG2(1000, 300, &ZL);
putimagePNG2(500, 160, &XG);//渲染宵宫
}
else if (tempCards->color == 2)
updatePCcards(tempCards->next, 160, 500);
else if (tempCards->color == 1)
{
updatePCcards(tempCards->next, 300, 1000);
putimagePNG2(500, 160, &XG);//渲染宵宫
}
}
if (ThreePlayerCard->num == 0)
{
updateBg();//渲染背景 //展示玩家三胜出
loadimage(&WINPNG, "扑克牌图片/绫华win.png");
loadimage(&PlayerWin, "扑克牌/绫华赢了.png");
putimagePNG2(600, 250, &PlayerWin);
putimagePNG2(700, 350, &WINPNG);
_getch();
break;
}//判断剩余排数
MyCardsGo();//本家出牌
Renovate();
if (close == 1)
return;
if (tempCards->color == 4)
updatePCcards(tempCards->next, 430, 500);
else
{
Renovate();
putimagePNG2(500, 430, &HT);//渲染胡桃
if (tempCards->color == 3)
updatePCcards(tempCards->next, 300, 200);//渲染上一位玩家卡牌
else if (tempCards->color == 2)
{
updatePCcards(tempCards->next, 160, 500);//渲染上一位玩家卡牌
putimagePNG2(200, 300, &LH);
}
else if (tempCards->color == 1)
{
updatePCcards(tempCards->next, 300, 1000);//渲染上一位玩家卡牌
putimagePNG2(200, 300, &LH);
putimagePNG2(500, 160, &XG);
}
}
if (MyCards->num == 0)
{
updateBg();//渲染背景
loadimage(&WINPNG, "扑克牌图片/胡桃win.png");
loadimage(&PlayerWin, "扑克牌/胡桃赢了.png");
putimagePNG2(600, 250, &PlayerWin);
putimagePNG2(700, 350, &WINPNG);
_getch();
break;
}
}
mciSendString("close mmymusic", NULL, 0, NULL);
}
//
void InitCards(TabletNODE* &p)
{//初始化结构体
p->color = 0;
p->next = 0;
p->num = 0;
p->Tablet = 0;
p->x = 0;
p->y = 0;
}
/// /
void DealAllCards(TabletNODE* &p,TabletNODE* &Cards)
{//实现发牌1
if (Cards->color == 1)
{
for (int i = 1; i <= 33; i++)
{//此时我是地主,分33张牌
TabletNODE* m = Cards;
TabletNODE* q = new TabletNODE;
q->x = p->x;
q->y = p->y;//创建临时节点,将卡牌数据复制进来
q->color = p->color;
q->num = p->num;
q->Tablet = p->Tablet;
while (1)
{
if (m->next == 0)
{//此时找到最后一位或链表内无元素
q->next = m->next;
m->next = q;
Cards->num++;
break;//
}
if (m->next->num < q->num)
{
m = m->next;
}
else
{
q->next = m->next;
m->next = q;
Cards->num++;
break;
}
}
p = p->next;//牌堆的牌往后走一位
}
Renovate();//渲染刷新
}
else if (Cards->color == 0)
{
for (int i = 1; i <= 25; i++)
{//此时我不是地主,分25张牌
TabletNODE* m = Cards;
TabletNODE* q = new TabletNODE;
q->x = p->x;
q->y = p->y;//创建临时节点,将卡牌数据复制进来
q->color = p->color;
q->num = p->num;
q->Tablet = p->Tablet;
while (1)
{
if (m->next == 0)
{//此时找到最后一位或链表内无元素
q->next = m->next;
m->next = q;
Cards->num++;
break;//
}
if (m->next->num < q->num)
{
m = m->next;
}
else
{
q->next = m->next;
m->next = q;
Cards->num++;
break;
}
}
p = p->next;//牌堆的牌往后走一位
}
Renovate();//渲染刷新
}
}
/
void DealCards()
{//实现发牌1
if (MyCards->color == 1)
{
TabletNODE* p = Heap->next;
for (int i = 1; i <= 33; i++)
{//此时我是地主,分33张牌
TabletNODE* m = MyCards;
TabletNODE* q = new TabletNODE;
q->x = p->x;
q->y = p->y;//创建临时节点,将卡牌数据复制进来
q->color = p->color;
q->num = p->num;
q->Tablet = p->Tablet;
while (1)
{
if (m->next == 0)
{//此时找到最后一位或链表内无元素
q->next = m->next;
m->next = q;
MyCards->num++;
break;//
}
if (m->next->num < q->num)
{
m = m->next;
}
else
{
q->next = m->next;
m->next = q;
MyCards->num++;
break;
}
}
p = p->next;//牌堆的牌往后走一位
}
DealAllCards(p, OnePlayerCard);
DealAllCards(p, TwoPlayerCard);
DealAllCards(p, ThreePlayerCard);
Renovate();//渲染刷新
}
else if (MyCards->color == 0)
{
TabletNODE* p = Heap->next;
for (int i = 1; i <= 25; i++)
{//此时我不是地主,分25张牌
TabletNODE* m = MyCards;
TabletNODE* q = new TabletNODE;
q->color = p->color;
q->num = p->num;
q->Tablet = p->Tablet;
q->x = p->x;
q->y = p->y;//创建临时节点,将卡牌数据复制进来
while (1)
{
if (m->next == 0)
{//此时找到最后一位或链表内无元素
q->next = m->next;
m->next = q;
MyCards->num++;
break;//
}
if (m->next->num < q->num)
{
m = m->next;
}
else
{
q->next = m->next;
m->next = q;
MyCards->num++;
break;
}
}
p = p->next;//牌堆的牌往后走一位
}
DealAllCards(p, OnePlayerCard);
DealAllCards(p, TwoPlayerCard);
DealAllCards(p, ThreePlayerCard);
Renovate();//渲染刷新
}
}
/// /
void ShuffleCards(TabletNODE* &p)
{//实现打乱牌堆
TabletNODE* q = p;
TabletNODE TheHeap[108];
for (int i = 0; i <= 107; i++)
{//将链表数据传入数组
TheHeap[i].color = q->color;
TheHeap[i].num = q->num;
TheHeap[i].Tablet = q->Tablet;
TheHeap[i].x = q->x;
TheHeap[i].y = q->y;
q = q->next;
}
TabletNODE tmp; int T = 1000;
srand(unsigned(time(NULL)));
while (T--)//随机打乱数组
{
int j = (rand()%107);
int k = (rand()%107);
tmp = TheHeap[k];
TheHeap[k] = TheHeap[j];
TheHeap[j] = tmp;
}
TabletNODE* x = p;
for (int j = 0; j <= 107; j++)
{//将数组数据重新传回
x->color = TheHeap[j].color;
x->num = TheHeap[j].num;
x->Tablet = TheHeap[j].Tablet;
x->x = TheHeap->x;
x->y = TheHeap->y;
x = x->next;
}
}
void push()
{//加载牌堆图片素材
InitCards(Heap);
for (int i = 1; i <= 4; i++)
{
for (int j = 1; j <= 13; j++)
{
//
TabletNODE* p = new TabletNODE;
p->next = 0;
p->color = i;
p->num = j;
p->Tablet = BeiJingPNG[j + (i - 1) * 13];
p->next = Heap->next;
p->x = 0;
p->y = 0;
Heap->next = p;
Heap->num++;//记录链表内元素数量
}
}
for (int k = 1; k <= 2; k++)
{
TabletNODE* p = new TabletNODE;
p->next = 0;
p->color = 5;
p->num = k + 13;
p->Tablet = BeiJingPNG[52 + k];
p->x = 0;
p->y = 0;
p->next = Heap->next;
Heap->next = p;
Heap->num++;//记录链表内元素数量
}
//
for (int i = 1; i <= 4; i++)
{//加载52张常规牌
for (int j = 1; j <= 13; j++)
{
//将牌面存入链表中
TabletNODE* p = new TabletNODE;
p->next = NULL;
p->color = i;
p->num = j;
p->Tablet = BeiJingPNG[j + (i - 1) * 13];
p->x = 0;
p->y = 0;
p->next = Heap->next;
Heap->next = p;
Heap->num++;//记录链表内元素数量
}
}
for (int k = 1; k <= 2; k++)
{//加载大小鬼
TabletNODE* p = new TabletNODE;
p->next = NULL;
p->color = 5;
p->num = k + 13;
p->Tablet = BeiJingPNG[52 + k];
p->x = 0;
p->y = 0;
p->next = Heap->next;
Heap->next = p;
Heap->num++;//记录链表内元素数量
}
///
}
void init()
{
//创建游戏窗口
initgraph(WIDTH, HIGH);//使用initgraph函数创建窗口
char name[64];//定义数组变量,将背景图片文件名存入数组
InitCards(MyCards);//初始化我的卡牌
InitCards(OnePlayerCard);//初始化人机卡牌
InitCards(TwoPlayerCard);
InitCards(ThreePlayerCard);
InitCards(HandCards);//初始化手牌卡区
InitCards(tempCards);
//加载背景资源
for (int i = 1; i <= 54; i++)
{
sprintf(name, "扑克牌图片/%02d.jpg", i );//把文件名打印至name数组中
loadimage(&BeiJingPNG[i], name);//加载背景文件
}
for (int i = 55; i <= 108; i++)
{
sprintf(name, "扑克牌图片/%02d.jpg", i-54);//把文件名打印至name数组中
loadimage(&BeiJingPNG[i], name);//加载背景文件
}
for (int k = 0; k <= 1; k++)
{
sprintf(name, "扑克牌图片/地主%d.png", k + 1);//把文件名打印至name数组中
loadimage(&Claim[k], name);
}
loadimage(&ZL, "扑克牌图片/钟离card.png");//加载文件
loadimage(&HT, "扑克牌图片/胡桃card.png");//加载文件
loadimage(&LH, "扑克牌图片/绫华card.png");//加载文件
loadimage(&XG, "扑克牌图片/宵宫card.png");//加载文件
sprintf(bgmusic[1], "open 音乐/卡农.mp3 alias mmymusic");
sprintf(bgmusic[2], "open 音乐/Nevada.mp3 alias mmymusic");
sprintf(bgmusic[3], "open 音乐/恋爱循环.mp3 alias mmymusic");
sprintf(bgmusic[4], "open 音乐/Rubia.mp3 alias mmymusic");
sprintf(bgmusic[5], "open 音乐/Unstoppable.mp3 alias mmymusic");
sprintf(bgmusic[6], "open 音乐/晨昏线.mp3 alias mmymusic");
sprintf(bgmusic[7], "open 音乐/Visions.mp3 alias mmymusic");
sprintf(bgmusic[8], "open 音乐/打上花火.mp3 alias mmymusic");
sprintf(bgmusic[9], "open 音乐/黑人抬棺.mp3 alias mmymusic");
sprintf(bgmusic[10], "open 音乐/空之律者.mp3 alias mmymusic");
sprintf(bgmusic[11], "open 音乐/Rubia.mp3 alias mmymusic");
sprintf(bgmusic[12], "open 音乐/千本樱.mp3 alias mmymusic");
sprintf(bgmusic[13], "open 音乐/庆云顶的夜晚.mp3 alias mmymusic");
sprintf(bgmusic[14], "open 音乐/让风告诉你.mp3 alias mmymusic");
sprintf(bgmusic[15], "open 音乐/如果突然想起我.mp3 alias mmymusic");
sprintf(bgmusic[16], "open 音乐/神女劈观.mp3 alias mmymusic");
sprintf(bgmusic[17], "open 音乐/只因你太美.mp3 alias mmymusic");
sprintf(bgmusic[18], "open 音乐/天使重构.mp3 alias mmymusic");
push();//将牌放入牌堆
}
///
void freellist(TabletNODE* &head)
{
TabletNODE *ptr;
while (head != 0)//走访链表
{
ptr = head;
head = head->next;//指向下一节点
free(ptr);//释回节点记忆体
}
}
void freeCards()
{
freellist(MyCards->next);
InitCards(MyCards);
freellist(OnePlayerCard->next);
InitCards(OnePlayerCard);
freellist(TwoPlayerCard->next);
InitCards(TwoPlayerCard);
freellist(ThreePlayerCard->next);
InitCards(ThreePlayerCard);
freellist(tempCards->next);
InitCards(tempCards);
close = 0;
}
/// /
void GoForMusic()
{
char ch='a',name[64];
IMAGE YinYuePNG;
IMAGE YYBGPNG[19];
for (int i = 1; i <= 18; i++)
{
sprintf(name, "音乐背景/%02d.png", i);//把文件名打印至name数组中
loadimage(&YYBGPNG[i], name);
}
loadimage(&YinYuePNG, "音乐/音乐背景plus.png");
putimage(0, 0, &YinYuePNG);
ch = _getch();
while (1)
{
mciSendString(bgmusic[ch-'a'+1], NULL, 0, NULL);
mciSendString("play mmymusic", NULL, 0, NULL);
MusicNum = ch - 'a' + 1;
putimage(0, 0, &YYBGPNG[MusicNum]);
ch = _getch();
mciSendString("close mmymusic", NULL, 0, NULL);
if (ch == '+')
break;
}
}
/*//*/
void ShowRule()
{//游戏说明
IMAGE rule1, rule2, rule3, rule4, rule5;
loadimage(&rule1, "扑克牌/01.png");
loadimage(&rule2, "扑克牌/02.png");
loadimage(&rule3, "扑克牌/03.png");
loadimage(&rule4, "扑克牌/04.png");
loadimage(&rule5, "扑克牌/05.png");
putimage(0, 0, &rule1);
_getch();
putimage(0, 0, &rule2);
_getch();
putimage(0, 0, &rule3);
_getch();
putimage(0, 0, &rule4);
_getch();
putimage(0, 0, &rule5);
_getch();
}
/*///*/
void ChooseKB()
{
char ch = 'a';
IMAGE KabeiPNG;//渲染本家卡牌
loadimage(&KabeiPNG, "扑克牌图片/卡背背景.png");
putimage(0, 0, &KabeiPNG);
while (1)
{
ch = _getch();
if (ch <= 'f' && ch >= 'a')
break;
}
KBNum = ch - 'a' + 1;//获取卡背序号
}
/*//*/
int menu()
{
char ch;
IMAGE BeginPNG;
mciSendString("open 扑克牌/音乐/m5.mp3 alias mmymusic", NULL, 0, NULL);
mciSendString("play mmymusic", NULL, 0, NULL);
while (1)
{
//system("pause");
loadimage(&BeginPNG, "扑克牌图片/斗地主背景.png");
putimage(0, 0, &BeginPNG);//渲染菜单图
ch = _getch();//从键盘读取字符
if (ch == 'm')
{
break;//当输入为‘m’时,跳出循环
}
else if (ch == 'n')
{
GoForMusic();//当输入为‘n’时,转进音乐设置函数
continue;
}
else if (ch == 'z')
{
ShowRule();
continue;//当输入为‘b’时,转进规则展示函数
}
else if (ch == 'x')
{
ChooseKB();
continue;//当输入为‘x’时,转进卡背选择函数
}
else if (ch == 'v')
{
exit(0);//当输入为‘v’时,跳出整个程序
}
}
mciSendString("close mmymusic", NULL, 0, NULL);
}
/
void updateBg()
{//渲染游戏背景
IMAGE BeginJPG;//渲染本家卡牌
loadimage(&BeginJPG, "扑克牌图片/木纹背景.png");
putimage(0, 0, &BeginJPG);//渲染菜单图//渲染背景图片
}
void updateMycards()
{//渲染我的卡牌
TabletNODE* q = MyCards->next;
for (int i = 0; i < MyCards->num; i++)
{
putimagePNG2(320 + i * 28, 650 -q->y, &q->Tablet);
q = q->next;
}
}
void updatePCcards(TabletNODE* &q,int j,int k)
{//渲染pc卡牌
int i = 0;
TabletNODE* p = q;
while (1)
{
if (p == 0)
break;
putimage(k + i * 28, j, &p->Tablet);
p = p->next;
i++;
}
}
void UpdatePCplayerCards()
{
IMAGE KabeiPNG;//渲染本家卡牌
char name[64];
sprintf(name, "扑克牌图片/卡背%d.png", KBNum);
loadimage(&KabeiPNG, name);
for (int i = 0; i <= ThreePlayerCard->num-1; i++)
{
putimage(10, 200+i*10, &KabeiPNG);//渲染绫华卡片
}
for (int i = 0; i <= TwoPlayerCard->num-1; i++)
{
putimage(440+i*28, 10, &KabeiPNG);//渲染宵宫卡片
}
for (int i = 0; i <= OnePlayerCard->num-1; i++)
{
putimage(1390, 200 + i * 10, &KabeiPNG);//渲染钟离卡片
}
}
/
void LandClaim()
{//实现地主的分配
putimagePNG(100 , 400, &Claim[0]);
putimagePNG(800 , 400, &Claim[1]);
while (1)
{//当输入j时抢地主,输入k时不抢
char ch = _getch();
if (ch == 'j') {
MyCards->color = 1;
OnePlayerCard->color = 0;
TwoPlayerCard->color = 0;
ThreePlayerCard->color = 0;
break;
}
else if (ch == 'k') {
MyCards->color = 0;
OnePlayerCard->color = 1;
TwoPlayerCard->color = 0;
ThreePlayerCard->color = 0;
break;
}
}
}
/// ///
void Renovate()
{//图像刷新函数
updateBg();//渲染背景
UpdatePCplayerCards();//渲染三角色卡片
updateMycards();//渲染己方卡片
}
/// /
int main()
{
init();//初始化函数
while (1)
{
menu();//实现菜单
ShuffleCards(Heap->next);//清洗牌堆
updateBg();//渲染背景
LandClaim();//实现抢地主
DealCards();//实现发牌
Renovate();//渲染刷新
PlayCards();//实现出牌
freeCards();//清空卡牌
}
return 0;
}