tools.hpp
#pragma once
#include
void drawImg(int x, int y,IMAGE *src)
{
// 变量初始化
DWORD* pwin = GetImageBuffer(); //窗口缓冲区指针
DWORD* psrc = GetImageBuffer(src); //图片缓冲区指针
int win_w = getwidth(); //窗口宽高
int win_h = getheight();
int src_w = src->getwidth(); //图片宽高
int src_h = src->getheight();
// 计算贴图的实际长宽
int real_w = (x + src_w > win_w) ? win_w - x : src_w; // 处理超出右边界
int real_h = (y + src_h > win_h) ? win_h - y : src_h; // 处理超出下边界
if (x < 0) { psrc += -x; real_w -= -x; x = 0; } // 处理超出左边界
if (y < 0) { psrc += (src_w * -y); real_h -= -y; y = 0; } // 处理超出上边界
// 修正贴图起始位置
pwin += (win_w * y + x);
// 实现透明贴图
for (int iy = 0; iy < real_h; iy++)
{
for (int ix = 0; ix < real_w; ix++)
{
byte a = (byte)(psrc[ix] >> 24);//计算透明通道的值[0,256) 0为完全透明 255为完全不透明
if (a > 100)
{
pwin[ix] = psrc[ix];
}
}
//换到下一行
pwin += win_w;
psrc += src_w;
}
}
void drawImg(int x, int y, int dstW, int dstH, IMAGE* src, int srcX, int srcY)
{
// 变量初始化
DWORD* pwin = GetImageBuffer(); //窗口缓冲区指针
DWORD* psrc = GetImageBuffer(src); //图片缓冲区指针
int win_w = getwidth(); //窗口宽高
int win_h = getheight();
int src_w = src->getwidth(); //图片宽高
int src_h = src->getheight();
// 计算贴图的实际长宽
int real_w = (x + dstW > win_w) ? win_w - x : dstW; // 处理超出右边界
int real_h = (y + dstH > win_h) ? win_h - y : dstH; // 处理超出下边界
if (x < 0) { psrc += -x; real_w -= -x; x = 0; } // 处理超出左边界
if (y < 0) { psrc += (dstW * -y); real_h -= -y; y = 0; } // 处理超出上边界
//printf("realw,h(%d,%d)\n", real_w, real_h);
// 修正贴图起始位置
pwin += (win_w * y + x);
// 实现透明贴图
for (int iy = 0; iy < real_h; iy++)
{
for (int ix = 0; ix < real_w; ix++)
{
byte a = (byte)(psrc[ix + srcX + srcY * src_w] >> 24);//计算透明通道的值[0,256) 0为完全透明 255为完全不透明
if (a > 100)
{
pwin[ix] = psrc[ix + srcX + srcY * src_w];
}
}
//换到下一行
pwin += win_w;
psrc += src_w;
}
}
源.cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include "tools.hpp"
#pragma comment(lib, "winmm.lib")
//定义全局变量
IMAGE img[55];//定义扑克牌图像数组
IMAGE img_bg;//定义背景图片
IMAGE img_start;//定义开始图片
IMAGE img_user0;//定义用户图片
IMAGE img_farmer1,img_landlord1;//定义地主农民图片
IMAGE img_rob_2,img_notrob_2,img_rob2,img_notrob2;//定义 是否抢与不抢地主的图片
IMAGE img_play2,img_notplay2;//定义出不出牌的图片
IMAGE img_123_2,img_132_2, img_231_2;//定义自动成为地主的提示图片
IMAGE img_left[21];//定义所剩牌数的图片 //定义出牌的特效
IMAGE img_san2,img_sandaiyi2,img_kingbomb2,img_sidaier2,img_plane2;
IMAGE img_bomb2;
IMAGE img_win2,img_lose2;//定义胜利或失败的场面
int user1[20] = { 0 };//定义用户1的手牌
int user2[20] = { 0 };//定义用户2的手牌
int user3[20] = { 0 };//定义用户3的手牌
int bottom_card[3] = { 0 };//定义3张底牌
int pile[55] = { 0 };//定义牌堆
int flag_card = 0;//定义标志牌,决定抢地主顺序
int first_rob = 0;//谁获得抢地主的机会
int who_is_landlord = 0;//保存谁是地主
int clicktimes[20] = { 0 };//保存是否被点击
int user1_card_number = 0;//保存玩家一所剩余的牌数
int user2_card_number = 0;//。。
int user3_card_number = 0;//。。
int user1_compare[20] = { 0 };//保存玩家牌的具体大小,例如牌为5-8,这保存为4
int user2_compare[20] = { 0 };//。。
int user3_compare[20] = { 0 };//。。
int temp[20] = { 0 }, temp_img[20] = { 0 }, temp_number = 0, flag = 0;//分别存放已经出的牌,已经出的牌的图像的,出的牌的数量,是否有人未出牌
int temp_card[18] = { 0 }, temp_card_type[15] = { 0 }, temp_card_type_number = 0;//分别存放已经出的牌的大小,已经出的牌的种类,已经出的牌的所有总数
int user1_card[18] = { 0 }, user2_card[18] = { 0 }, user3_card[18] = { 0 };//存放用户的牌的大小
MOUSEMSG m;//定义鼠标
void forword_pile(int i)//i表示从哪一张之后开始移
{
int j;
for (j = i; j < 54; j++)
{
pile[j] = pile[j + 1];
}//牌堆前移,避免产生重复的牌
}
void search_flag_card()//查找标志牌在哪位玩家的手上
{
int i;
for (i = 0; i < 17; i++)
{
if (user1[i] == flag_card)
{
first_rob = 1;
break;
}
if (user2[i] == flag_card)
{
first_rob = 2;
break;
}
if (user3[i] == flag_card)
{
first_rob = 3;
break;
}
}
}
void sort_cards(int* p, int n)//运用选择排序整理手牌
{
int i, j, temp, max, maxj;
for (i = 0; i < n - 1; i++)
{
max = *(p + i);
maxj = i;
for (j = i + 1; j < n; j++)
{
if (*(p + j) > max)
{
max = *(p + j);
maxj = j;
}
}
temp = *(p + i);
*(p + i) = *(p + maxj);
*(p + maxj) = temp;
}
}
void deal_cards()//发牌
{
int i, card_number;
i = rand() % 54 + 1;//先拿出3张作为底牌
bottom_card[0] = pile[i];
forword_pile(i);
i = rand() % 53 + 1;
bottom_card[1] = pile[i];
forword_pile(i);
i = rand() % 52 + 1;
bottom_card[2] = pile[i];
forword_pile(i);
//发标志牌,因为不能与底牌重复,否则不能确定谁抢地主,所以放在下面
i = rand() % 51 + 1;
flag_card = pile[i];//与标志牌重复没关系,所以不需要前移
for (card_number = 0; card_number < 17; card_number++)//再每人发17张牌
{
i = rand() % (51 - card_number * 3) + 1;
user1[card_number] = pile[i];
forword_pile(i);
i = rand() % (51 - card_number * 3 - 1) + 1;
user2[card_number] = pile[i];
forword_pile(i);
i = rand() % (51 - card_number * 3 - 2) + 1;
user3[card_number] = pile[i];
forword_pile(i);
}
}
void load_image()//加载图像
{
loadimage(&img[4], _T("梅花3.jpg"));
loadimage(&img[8], _T("梅花4.jpg"));
loadimage(&img[12], _T("梅花5.jpg"));
loadimage(&img[16], _T("梅花6.jpg"));
loadimage(&img[20], _T("梅花7.jpg"));
loadimage(&img[24], _T("梅花8.jpg"));
loadimage(&img[28], _T("梅花9.jpg"));
loadimage(&img[32], _T("梅花10.jpg"));
loadimage(&img[36], _T("梅花J.jpg"));
loadimage(&img[40], _T("梅花Q.jpg"));
loadimage(&img[44], _T("梅花K.jpg"));
loadimage(&img[48], _T("梅花A.jpg"));
loadimage(&img[52], _T("梅花2.jpg"));
loadimage(&img[1], _T("黑桃3.jpg"));
loadimage(&img[5], _T("黑桃4.jpg"));
loadimage(&img[9], _T("黑桃5.jpg"));
loadimage(&img[13], _T("黑桃6.jpg"));
loadimage(&img[17], _T("黑桃7.jpg"));
loadimage(&img[21], _T("黑桃8.jpg"));
loadimage(&img[25], _T("黑桃9.jpg"));
loadimage(&img[29], _T("黑桃10.jpg"));
loadimage(&img[33], _T("黑桃J.jpg"));
loadimage(&img[37], _T("黑桃Q.jpg"));
loadimage(&img[41], _T("黑桃K.jpg"));
loadimage(&img[45], _T("黑桃A.jpg"));
loadimage(&img[49], _T("黑桃2.jpg"));
loadimage(&img[3], _T("方块3.jpg"));
loadimage(&img[7], _T("方块4.jpg"));
loadimage(&img[11], _T("方块5.jpg"));
loadimage(&img[15], _T("方块6.jpg"));
loadimage(&img[19], _T("方块7.jpg"));
loadimage(&img[23], _T("方块8.jpg"));
loadimage(&img[27], _T("方块9.jpg"));
loadimage(&img[31], _T("方块10.jpg"));
loadimage(&img[35], _T("方块J.jpg"));
loadimage(&img[39], _T("方块Q.jpg"));
loadimage(&img[43], _T("方块K.jpg"));
loadimage(&img[47], _T("方块A.jpg"));
loadimage(&img[51], _T("方块2.jpg"));
loadimage(&img[2], _T("红桃3.jpg"));
loadimage(&img[6], _T("红桃4.jpg"));
loadimage(&img[10], _T("红桃5.jpg"));
loadimage(&img[14], _T("红桃6.jpg"));
loadimage(&img[18], _T("红桃7.jpg"));
loadimage(&img[22], _T("红桃8.jpg"));
loadimage(&img[26], _T("红桃9.jpg"));
loadimage(&img[30], _T("红桃10.jpg"));
loadimage(&img[34], _T("红桃J.jpg"));
loadimage(&img[38], _T("红桃Q.jpg"));
loadimage(&img[42], _T("红桃K.jpg"));
loadimage(&img[46], _T("红桃A.jpg"));
loadimage(&img[50], _T("红桃2.jpg"));
loadimage(&img[53], _T("小王.jpg"));
loadimage(&img[54], _T("大王.jpg"));
loadimage(&img[0], _T("牌背.png"), 100, 150);
loadimage(&img_bg, _T("背景.jpg"), 1440, 960);
loadimage(&img_user0, _T("用户1.png"), 100, 150);
loadimage(&img_start, _T("开始.png"), 1440, 960);
loadimage(&img_farmer1, _T("农民1.png"), 100, 150);
loadimage(&img_landlord1, _T("地主1.png"), 100, 150);
loadimage(&img_rob_2, _T("rob_2.jpg"), 100, 50);
loadimage(&img_notrob_2, _T("notrob_2.jpg"), 100, 50);
loadimage(&img_rob2, _T("rob2.jpg"), 50, 100);
loadimage(&img_notrob2, _T("notrob2.jpg"), 50, 100);
loadimage(&img_play2, _T("出牌2.jpg"), 100, 50);
loadimage(&img_notplay2, _T("不出2.jpg"), 100, 50);
loadimage(&img_123_2, _T("1+2=3 2.png"), 500, 100);
loadimage(&img_132_2, _T("1+3=2 2.png"), 500, 100);
loadimage(&img_231_2, _T("2+3=1 2.png"), 500, 100);
loadimage(&img_left[1], _T("1.jpg"), 30, 50);
loadimage(&img_left[2], _T("2.jpg"), 30, 50);
loadimage(&img_left[3], _T("3.jpg"), 30, 50);
loadimage(&img_left[4], _T("4.jpg"), 30, 50);
loadimage(&img_left[5], _T("5.jpg"), 30, 50);
loadimage(&img_left[6], _T("6.jpg"), 30, 50);
loadimage(&img_left[7], _T("7.jpg"), 30, 50);
loadimage(&img_left[8], _T("8.jpg"), 30, 50);
loadimage(&img_left[9], _T("9.jpg"), 30, 50);
loadimage(&img_left[10], _T("10.jpg"), 30, 50);
loadimage(&img_left[11], _T("11.jpg"), 30, 50);
loadimage(&img_left[12], _T("12.jpg"), 30, 50);
loadimage(&img_left[13], _T("13.jpg"), 30, 50);
loadimage(&img_left[14], _T("14.jpg"), 30, 50);
loadimage(&img_left[15], _T("15.jpg"), 30, 50);
loadimage(&img_left[16], _T("16.jpg"), 30, 50);
loadimage(&img_left[17], _T("17.jpg"), 30, 50);
loadimage(&img_left[18], _T("18.jpg"), 30, 50);
loadimage(&img_left[19], _T("19.jpg"), 30, 50);
loadimage(&img_left[20], _T("20.jpg"), 30, 50);
loadimage(&img_win2, _T("win2.png"),292,139);
loadimage(&img_lose2, _T("lose2.png"),292,139);
loadimage(&img_san2, _T("san2.png"));
loadimage(&img_sidaier2, _T("sidaier2.png"));
loadimage(&img_sandaiyi2, _T("sandaiyi2.png"));
loadimage(&img_kingbomb2, _T("kingbomb2.png"));
loadimage(&img_plane2, _T("plane2.png"));
loadimage(&img_bomb2, _T("bomb2.png"));
}
void load_music()//加载音乐
{
//mciSendString(_T("open music.mp3 alias mymusic"), NULL, 0, NULL);
//mciSendString(_T("play mymusic repeat"), NULL, 0, NULL);
}
void show_bottom_image()//显示底牌
{
drawImg(560, 50, &img[0]);
drawImg(660, 50, &img[0]);//全是牌背
drawImg(760, 50, &img[0]);
}
void show_mycard_image_first()//显示手牌一张一张生成的效果
{
int i;
for (i = 0; i < 17; i++)
{
drawImg(450 + 25 * i, 760, &img[user2[i]]);
drawImg(200, 160 + i * 25, &img[0]);
drawImg(1200, 160 + i * 25, &img[0]);
Sleep(80);
}
}
void show_mycard_image_after()//直接显示最终的手牌(17张)
{
int i;
for (i = 0; i < 17; i++)
{
drawImg(450 + 25 * i, 760, &img[user2[i]]);//输出玩家手牌
}
for (i = 0; i < 17; i++)
{
drawImg(200, 160 + i * 25, &img[0]);//输出左边用户的手牌(全为牌背)
}
for (i = 0; i < 17; i++)
{
drawImg(1200, 160 + i * 25, &img[0]);//输出右边用户的手牌(全为牌背)
}
}
void show_bg_and_user()//输出背景和用户
{
drawImg(0, 0, &img_bg);//输出背景
drawImg(0, 300, &img_user0);//输出用户1
drawImg(300, 760, &img_user0);//输出用户2
drawImg(1350, 300, &img_user0);//输出用户3
}
void show_flagcard_move()//显示标志牌移动的效果
{
int i;
for (i = 1; i <= 10; i++)//输出标志牌牌移动效果
{
show_bg_and_user();//输出背景和用户
show_mycard_image_after();//显示最终的手牌(17张)
show_bottom_image();//显示底牌
if (i == 1)
{
drawImg(660, 400, &img[0]);//一开始先出现在最中间
Sleep(1000);
}
else
{
drawImg(660 + 30 * i, 400 - 35 * i, &img[flag_card]);//接下来逐渐往右上方移动
}
Sleep(20);
}
}
void case_user1_is_landlord()//玩家一为地主时显示的画面
{
int i;
drawImg(0, 0, &img_bg);//输出背景
drawImg(0, 300, &img_landlord1);//输出用户1
drawImg(300, 760, &img_farmer1);//输出用户2
drawImg(1350, 300, &img_farmer1);//输出用户3
show_bottom_image();//显示底牌
drawImg(960, 50, &img[flag_card]);
for (i = 17; i < 20; i++)//将底牌给玩家一
{
user1[i] = bottom_card[i - 17];
}
sort_cards(user1, 20);//加入手牌之后,再次理牌
//显示手牌
for (i = 0; i < 17; i++)
{
drawImg(450 + 25 * i, 760, &img[user2[i]]);
}
for (i = 0; i < 17; i++)
{
drawImg(200, 160 + i * 25, &img[0]);
}
for (i = 0; i < 17; i++)
{
drawImg(1200, 160 + i * 25, &img[0]);
}
for (i = 0; i < 3; i++)
{
drawImg(200, 585 + i * 25, &img[0]);
Sleep(80);
}
Sleep(1000);
drawImg(560, 50, &img[bottom_card[0]]);//使底牌有掀开的效果
drawImg(660, 50, &img[bottom_card[1]]);
drawImg(760, 50, &img[bottom_card[2]]);
}
void case_user2_is_landlord()//玩家二为地主时显示的画面
{
int i;
drawImg(0, 0, &img_bg);//输出背景
drawImg(0, 300, &img_farmer1);//输出用户1
drawImg(300, 760, &img_landlord1);//输出用户2
drawImg(1350, 300, &img_farmer1);//输出用户3
show_bottom_image();//显示底牌
drawImg(960, 50, &img[flag_card]);
for (i = 17; i < 20; i++)//将底牌给玩家二
{
user2[i] = bottom_card[i - 17];
}
sort_cards(user2, 20);//加入手牌之后,再次理牌
//显示手牌
for (i = 0; i < 17; i++)
{
drawImg(200, 160 + i * 25, &img[0]);
}
for (i = 0; i < 17; i++)
{
drawImg(1200, 160 + i * 25, &img[0]);
}
for (i = 0; i < 20; i++)
{
drawImg(450 + 25 * i, 760, &img[user2[i]]);
Sleep(80);
}
Sleep(1000);
drawImg(560, 50, &img[bottom_card[0]]);
drawImg(660, 50, &img[bottom_card[1]]);
drawImg(760, 50, &img[bottom_card[2]]);
}
void case_user3_is_landlord()//玩家三为地主时显示的画面
{
int i;
drawImg(0, 0, &img_bg);//输出背景
drawImg(0, 300, &img_farmer1);//输出用户1
drawImg(300, 760, &img_farmer1);//输出用户2
drawImg(1350, 300, &img_landlord1);//输出用户3
show_bottom_image();//显示底牌
drawImg(960, 50, &img[flag_card]);
for (i = 17; i < 20; i++)//将手牌给玩家三
{
user3[i] = bottom_card[i - 17];
}
sort_cards(user3, 20);//加入手牌之后,再次理牌
//显示手牌
for (i = 0; i < 17; i++)
{
drawImg(450 + 25 * i, 760, &img[user2[i]]);
}
for (i = 0; i < 17; i++)
{
drawImg(200, 160 + i * 25, &img[0]);
}
for (i = 0; i < 17; i++)
{
drawImg(1200, 160 + i * 25, &img[0]);
}
for (i = 0; i < 3; i++)
{
drawImg(1200, 585 + i * 25, &img[0]);
Sleep(80);
}
Sleep(1000);
drawImg(560, 50, &img[bottom_card[0]]);
drawImg(660, 50, &img[bottom_card[1]]);
drawImg(760, 50, &img[bottom_card[2]]);
}
void case_user1_is_landlord_update()//更新用户的手牌
{
int i;
drawImg(0, 0, &img_bg);//输出背景
drawImg(0, 300, &img_landlord1);//输出用户1
drawImg(300, 760, &img_farmer1);//输出用户2
drawImg(1350, 300, &img_farmer1);//输出用户3
drawImg(960, 50, &img[flag_card]);
drawImg(560, 50, &img[bottom_card[0]]);
drawImg(660, 50, &img[bottom_card[1]]);
drawImg(760, 50, &img[bottom_card[2]]);
for (i = 0; i < user2_card_number; i++)
{
drawImg(450 + 25 * i, 760 - clicktimes[i] * 25, &img[user2[i]]);
}
for (i = 0; i < user1_card_number; i++)
{
drawImg(200, 160 + i * 25, &img[0]);
}
for (i = 0; i < user3_card_number; i++)
{
drawImg(1200, 160 + i * 25, &img[0]);
}
drawImg(40, 460, &img_left[user1_card_number]);//输出用户所剩余的牌
drawImg(950, 850, &img_left[user2_card_number]);
drawImg(1390, 460, &img_left[user3_card_number]);
}
void case_user2_is_landlord_update()//更新用户的手牌
{
int i;
drawImg(0, 0, &img_bg);//输出背景
drawImg(0, 300, &img_farmer1);//输出用户1
drawImg(300, 760, &img_landlord1);//输出用户2
drawImg(1350, 300, &img_farmer1);//输出用户3
drawImg(960, 50, &img[flag_card]);
drawImg(560, 50, &img[bottom_card[0]]);
drawImg(660, 50, &img[bottom_card[1]]);
drawImg(760, 50, &img[bottom_card[2]]);
for (i = 0; i < user2_card_number; i++)
{
drawImg(450 + 25 * i, 760 - clicktimes[i] * 25, &img[user2[i]]);
}
for (i = 0; i < user1_card_number; i++)
{
drawImg(200, 160 + i * 25, &img[0]);
}
for (i = 0; i < user3_card_number; i++)
{
drawImg(1200, 160 + i * 25, &img[0]);
}
drawImg(40, 460, &img_left[user1_card_number]);
drawImg(1050, 850, &img_left[user2_card_number]);
drawImg(1390, 460, &img_left[user3_card_number]);
}
void case_user3_is_landlord_update()//更新用户的手牌
{
int i;
drawImg(0, 0, &img_bg);//输出背景
drawImg(0, 300, &img_farmer1);//输出用户1
drawImg(300, 760, &img_farmer1);//输出用户2
drawImg(1350, 300, &img_landlord1);//输出用户3
drawImg(960, 50, &img[flag_card]);
drawImg(560, 50, &img[bottom_card[0]]);
drawImg(660, 50, &img[bottom_card[1]]);
drawImg(760, 50, &img[bottom_card[2]]);
for (i = 0; i < user2_card_number; i++)
{
drawImg(450 + 25 * i, 760 - clicktimes[i] * 25, &img[user2[i]]);
}
for (i = 0; i < user1_card_number; i++)
{
drawImg(200, 160 + i * 25, &img[0]);
}
for (i = 0; i < user3_card_number; i++)
{
drawImg(1200, 160 + i * 25, &img[0]);
}
drawImg(40, 460, &img_left[user1_card_number]);
drawImg(950, 850, &img_left[user2_card_number]);
drawImg(1390, 460, &img_left[user3_card_number]);
}
void temp_card_is_what()//把已经出的牌的特征找出来
{
int i, j, k;
for (i = 3; i < 18; i++)
{
temp_card[i] = 0; //重置未初值,避免后面改变影响这里
}
for (i = 0; i < 15; i++)
{
temp_card_type[i] = 0;重置未初值,避免后面改变影响这里
}
temp_card_type_number = 0;//重置未初值,避免后面改变影响这里
for (i = 0; i < temp_number; i++)
{
temp_card[temp[i]]++;//将牌的大小转换成每张牌的数量,比如说有两个3,这temp_card[3]=2;
}
for (i = 3; i < 18; i++)
{
if (temp_card[i] != 0)//如果拍的数量不等于0,就证明有牌
{
temp_card_type[temp_card_type_number] = i;//保存已有的牌的种类
temp_card_type_number++;//保存种类总数
}
}
for (i = 0; i < temp_card_type_number; i++)//利用冒泡排序,将数量多的牌排在前面,其余未从小到大
{
for (j = 0; j < temp_card_type_number - 1 - i; j++)
{
if (temp_card[temp_card_type[j]] < temp_card[temp_card_type[j + 1]])
{
k = temp_card_type[j];
temp_card_type[j] = temp_card_type[j + 1];
temp_card_type[j + 1] = k;
}
}
}
}
int type_is_what()
{
int i;
if (temp_number == 1)return 1;//出的牌为单牌时,返回为类型一
if (temp_number == 2 && temp_card_type_number == 1)return 2;//出的牌为对子时,返回为类型二
if (temp_number == 3 && temp_card_type_number == 1)return 3;//出的牌为三个时,返回为类型三
if (temp_number == 4 && temp_card_type_number == 1)return 4;//出的牌为炸弹时,返回为类型四
if (temp_card_type_number == 2 && (temp_card[16] == 1 && temp_card[17] == 1))return 5;//出的牌为王炸时,返回为类型五
if (temp_card_type_number == 2 && (temp_card[temp_card_type[0]] == 3 && temp_card[temp_card_type[1]] == 1))return 6;//出的牌为三带1时,返回为类型六
if (temp_card_type_number == 2 && (temp_card[temp_card_type[0]] == 3 && temp_card[temp_card_type[1]] == 2))return 7;//出的牌为三带二时,返回为类型七
if (temp_card_type_number == 3 && (temp_card[temp_card_type[0]] == 4 && temp_card[temp_card_type[1]] == 1 && temp_card[temp_card_type[2]] == 1))return 8;//出的牌为炸弹带二单时,返回为类型八
if (temp_card_type_number == 3 && (temp_card[temp_card_type[0]] == 4 && temp_card[temp_card_type[1]] == 2 && temp_card[temp_card_type[2]] == 2))return 9;//出的牌为炸弹带二双时,返回为类型九
if (temp_card_type_number == 4 && temp_card[temp_card_type[0]] == 3 && temp_card[temp_card_type[1]] == 3 && temp_card[temp_card_type[2]] == 1 && temp_card[temp_card_type[3]] == 1 && (temp_card_type[0] == (temp_card_type[1] - 1)))
return 10;//出的牌为飞机带二单时,返回为类型十
if (temp_card_type_number == 4 && temp_card[temp_card_type[0]] == 3 && temp_card[temp_card_type[1]] == 3 && temp_card[temp_card_type[2]] == 2 && temp_card[temp_card_type[3]] == 2 && (temp_card_type[0] == (temp_card_type[1] - 1)))
return 11;//出的牌为飞机带二双时,返回为类型十一
if (temp_card_type_number == temp_number)//出的牌位顺子时,返回位类似十二
{
for (i = 0; i < temp_number - 1; i++)
{
if (temp[i] != (temp[i + 1] - 1))break;
}
if (i == (temp_number - 1))return 12;
}
return 0;//都没有返回则为不合法类型
}
void user_change_to_user_compare()
{
int i, j;//将用户的手牌转换为牌的大小,例如牌53,为小王,转为17,牌1-4为3,转化为3
for (j = 0; j < user1_card_number; j++)
{
i = 0;
while (1)
{
if (user1[j] == 53)
{
user1_compare[j] = 16;
break;
}
if (user1[j] == 54)
{
user1_compare[j] = 17;
break;
}
if (user1[j] >= (1 + i * 4) && user1[j] <= (4 + i * 4))
{
user1_compare[j] = 3 + i;
break;
}
i++;
}
}
for (j = 0; j < user2_card_number; j++)
{
i = 0;
while (1)
{
if (user2[j] == 53)
{
user2_compare[j] = 16;
break;
}
if (user2[j] == 54)
{
user2_compare[j] = 17;
break;
}
if (user2[j] >= (1 + i * 4) && user2[j] <= (4 + i * 4))
{
user2_compare[j] = 3 + i;
break;
}
i++;
}
}
for (j = 0; j < user3_card_number; j++)
{
i = 0;
while (1)
{
if (user3[j] == 53)
{
user3_compare[j] = 16;
break;
}
if (user3[j] == 54)
{
user3_compare[j] = 17;
break;
}
if (user3[j] >= (1 + i * 4) && user3[j] <= (4 + i * 4))
{
user3_compare[j] = 3 + i;
break;
}
i++;
}
}
}
void update_with_play_card()//在出牌阶段,更新用户的手牌
{
int q;
switch (who_is_landlord)
{
case 1:case_user1_is_landlord_update(); break;
case 2:case_user2_is_landlord_update(); break;
case 3:case_user3_is_landlord_update(); break;
}
for (q = 0; q < temp_number; q++)
{
drawImg(660 + q * 25, 400, &img[temp_img[q]]);
}
Sleep(1000);
}
void user1_compare_change_to_user1_card()//把用户的牌的大小转为数量
{
int i;
for (i = 3; i < 18; i++)
{
user1_card[i] = 0;
}
for (i = 0; i < user1_card_number; i++)
{
user1_card[user1_compare[i]]++;
}
}
void user3_compare_change_to_user3_card()
{
int i;
for (i = 3; i < 18; i++)
{
user3_card[i] = 0;
}
for (i = 0; i < user3_card_number; i++)
{
user3_card[user3_compare[i]]++;
}
}
void user1_deal_and_play_card(int m, int n, int k)
{
int q, j;
for (q = m; q < n; q++)//k为所要出的牌,m为所要保存出牌数组中的小标,n也是下表,m为起始的保存下标,n为最终的保存下标
{
for (j = user1_card_number - 1; j >= 0; j--)//遍历手牌
{
if (user1_compare[j] == k)//找到用出的牌
{
temp_img[q] = user1[j];//把牌的图像保存
temp[q] = user1_compare[j];//把牌的大小保存
user1[j] = 0;//置为0表示已经出了
user1_compare[j] = 0; // 置为0表示已经出了
sort_cards(user1, user1_card_number);//整理手牌
sort_cards(user1_compare, user1_card_number);
user1_card_number--;//总牌数-1
flag = 0;//已经出牌,置为0
break;
}
}
}
}
void user3_deal_and_play_card(int m, int n, int k)
{
int q, j;
for (q = m; q < n; q++)
{
for (j = user3_card_number - 1; j >= 0; j--)
{
if (user3_compare[j] == k)
{
temp_img[q] = user3[j];
temp[q] = user3_compare[j];
user3[j] = 0;
user3_compare[j] = 0;
sort_cards(user3, user3_card_number);
sort_cards(user3_compare, user3_card_number);
user3_card_number--;
flag = 0;
break;
}
}
}
}
void user1_play_directly()//玩家一直接出牌
{
temp_number = 1;//机器人只能出一张
temp_img[0] = user1[user1_card_number - 1];//保存出牌的图像
temp[0] = user1_compare[user1_card_number - 1];//保存出牌的大小
user1[user1_card_number - 1] = 0;//置为0表示已经出牌
user1_compare[user1_card_number - 1] = 0;
sort_cards(user1, user1_card_number);//整理手牌
sort_cards(user1_compare, user1_card_number);
user1_card_number--;//总牌数-1
flag = 0;//已经出牌,置为0
update_with_play_card();//更新手牌以及出牌
}
void user1_play_compare()
{
int i, j, k, q, m, k1, n, k2;
temp_card_is_what();
if (type_is_what() == 1)//判断是否使单牌,建议比对type_is_what()函数看
{
for (j = user1_card_number - 1; j >= 0; j--)//如果时单牌,怎么出
{
if (user1_compare[j] > temp[0])
{
temp_number = 1;
temp_img[0] = user1[j];
temp[0] = user1_compare[j];
user1[j] = 0;
user1_compare[j] = 0;
sort_cards(user1, user1_card_number);
sort_cards(user1_compare, user1_card_number);
user1_card_number--;
flag = 0;
update_with_play_card();
break;
}
}
if (j == -1)flag++;
}
if (type_is_what() == 2)//同理,建议比对type_is_what()函数看
{
user1_compare_change_to_user1_card();
for (i = 3; i < 18; i++)
{
if (user1_card[i] >= 2 && i > temp[0])
{
k = i;
temp_number = 2;
user1_deal_and_play_card(0, temp_number, k);
update_with_play_card();
break;
}
}
if (i == 18)flag++;
}
if (type_is_what() == 3)
{
user1_compare_change_to_user1_card();
for (i = 3; i < 18; i++)
{
if (user1_card[i] >= 3 && i > temp[0])
{
k = i;
temp_number = 3;
user1_deal_and_play_card(0, temp_number, k);
update_with_play_card();
drawImg(500, 400, &img_san2);
Sleep(100);
break;
}
}
if (i == 18)flag++;
}
if (type_is_what() == 4)
{
user1_compare_change_to_user1_card();
for (i = 3; i < 18; i++)
{
if (user1_card[i] >= 4 && i > temp[0])
{
k = i;
temp_number = 4;
user1_deal_and_play_card(0, temp_number, k);
update_with_play_card();
drawImg(500, 400, &img_bomb2);
Sleep(100);
break;
}
}
if (i == 18)flag++;
}
if (type_is_what() == 5)
{
flag++;
}
if (type_is_what() == 6)
{
user1_compare_change_to_user1_card();
for (i = 3; i < 18; i++)
{
if (user1_card[i] >= 3 && i > temp_card_type[0])
{
k = i;
for (m = 3; m < 18; m++)
{
if (m != k && user1[m] >= 1)
{
k1 = m;
temp_number = 3;
user1_deal_and_play_card(0, temp_number, k);
temp_number++;
user1_deal_and_play_card(3, temp_number, k1);
update_with_play_card();
drawImg(500, 400, &img_sandaiyi2);
Sleep(100);
break;
}
}
if (m < 18)break;
}
}
if (i == 18)flag++;
}
if (type_is_what() == 7)
{
user1_compare_change_to_user1_card();
for (i = 3; i < 18; i++)
{
if (user1_card[i] >= 3 && i > temp_card_type[0])
{
k = i;
for (m = 3; m < 18; m++)
{
if (m != k && user1[m] >= 2)
{
k1 = m;
temp_number = 3;
user1_deal_and_play_card(0, temp_number, k);
temp_number++;
temp_number++;
user1_deal_and_play_card(3, temp_number, k1);
update_with_play_card();
break;
}
}
if (m < 18)break;
}
}
if (i == 18)flag++;
}
if (type_is_what() == 8)
{
user1_compare_change_to_user1_card();
for (i = 3; i < 18; i++)
{
if (user1_card[i] >= 4 && i > temp_card_type[0])
{
k = i;
for (m = 3; m < 18; m++)
{
if (m != k && user1[m] >= 1)
{
k1 = m;
for (n = 3; n < 18; n++)
{
if (n != k && n != k1 && user1[n] >= 1)
{
k2 = n;
temp_number = 4;
user1_deal_and_play_card(0, temp_number, k);
temp_number++;
user1_deal_and_play_card(4, temp_number, k1);
temp_number++;
user1_deal_and_play_card(5, temp_number, k2);
update_with_play_card();
break;
}
}
if (n < 18)break;
}
}
if (m < 18)break;
}
}
if (i == 18)flag++;
}
if (type_is_what() == 9)
{
user1_compare_change_to_user1_card();
for (i = 3; i < 18; i++)
{
if (user1_card[i] >= 4 && i > temp_card_type[0])
{
k = i;
for (m = 3; m < 18; m++)
{
if (m != k && user1[m] >= 2)
{
k1 = m;
for (n = 3; n < 18; n++)
{
if (n != k && n != k1 && user1[n] >= 2)
{
k2 = n;
temp_number = 4;
user1_deal_and_play_card(0, temp_number, k);
temp_number++;
temp_number++;
user1_deal_and_play_card(4, temp_number, k1);
temp_number++;
temp_number++;
user1_deal_and_play_card(6, temp_number, k2);
update_with_play_card();
drawImg(500, 400, &img_sidaier2);
Sleep(100);
break;
}
}
if (n < 18)break;
}
}
if (m < 18)break;
}
}
if (i == 18)flag++;
}
if (type_is_what() == 10)
{
user1_compare_change_to_user1_card();
for (i = 3; i < 18; i++)
{
if (user1_card[i] >= 3 && i > temp_card_type[0] && user1_card[i + 1] >= 3)
{
k = i;
for (m = 3; m < 18; m++)
{
if (m != k && m != (k + 1) && user1[m] >= 1)
{
k1 = m;
for (n = 3; n < 18; n++)
{
if (n != k && n != k1 && n != (k + 1) && user1[n] >= 1)
{
k2 = n;
temp_number = 3;
user1_deal_and_play_card(0, temp_number, k);
temp_number++;
temp_number++;
temp_number++;
user1_deal_and_play_card(3, temp_number, k + 1);
temp_number++;
user1_deal_and_play_card(6, temp_number, k1);
temp_number++;
user1_deal_and_play_card(7, temp_number, k2);
update_with_play_card();
drawImg(500, 400, &img_plane2);
Sleep(100);
break;
}
}
if (n < 18)break;
}
}
if (m < 18)break;
}
}
if (i == 18)flag++;
}
if (type_is_what() == 11)
{
user1_compare_change_to_user1_card();
for (i = 3; i < 18; i++)
{
if (user1_card[i] >= 3 && i > temp_card_type[0] && user1_card[i + 1] >= 3)
{
k = i;
for (m = 3; m < 18; m++)
{
if (m != k && m != (k + 1) && user1[m] >= 2)
{
k1 = m;
for (n = 3; n < 18; n++)
{
if (n != k && n != k1 && n != (k + 1) && user1[n] >= 2)
{
k2 = n;
temp_number = 3;
user1_deal_and_play_card(0, temp_number, k);
temp_number++;
temp_number++;
temp_number++;
user1_deal_and_play_card(3, temp_number, k + 1);
temp_number++;
temp_number++;
user1_deal_and_play_card(6, temp_number, k1);
temp_number++;
temp_number++;
user1_deal_and_play_card(8, temp_number, k2);
update_with_play_card();
drawImg(500, 400, &img_plane2);
Sleep(100);
break;
}
}
if (n < 18)break;
}
}
if (m < 18)break;
}
}
if (i == 18)flag++;
}
if (type_is_what() == 12)
{
user1_compare_change_to_user1_card();
for (i = temp[0] + 1; i < 18 - temp_number - 2; i++)
{
for (j = i; j < i + temp_number; j++)
{
if (user1_card[j] < 1)break;
}
if (j == (i + temp_number))
{
for (q = 0; q < temp_number; q++)
{
user1_deal_and_play_card(q, q + 1, i + q);
}
update_with_play_card();
break;
}
}
if (i == (18 - temp_number - 2))flag++;
}
}
void user2_play_directly()
{
int i;
while (1)//死循环直至人输入
{
//drawImg(650, 670, &img_play1);
drawImg(650, 670, &img_play2);//输出框架,只能出牌,不能不出
m = GetMouseMsg();
if (m.uMsg == WM_LBUTTONDOWN)//判断是否点击,点击时牌上移,点到出牌时退出
{
if (m.x >= 650 && m.x <= 750 && m.y >= 670 && m.y <= 720)
break;
if (m.x >= 450 && m.x <= (550 + (user2_card_number - 1) * 25))
{
if (m.x <= (450 + (user2_card_number - 1) * 25) && m.y >= (760 - clicktimes[(m.x - 450) / 25] * 25) && m.y <= (910 - clicktimes[(m.x - 450) / 25] * 25))
clicktimes[(m.x - 450) / 25] = (clicktimes[(m.x - 450) / 25] + 1) % 2;
else if (m.x > (450 + (user2_card_number - 1) * 25) && m.y >= (760 - clicktimes[16] * 25) && m.y <= (910 - clicktimes[16] * 25))
clicktimes[user2_card_number - 1] = (clicktimes[user2_card_number - 1] + 1) % 2;
}
switch (who_is_landlord)//输出更新之后的牌
{
case 1:case_user1_is_landlord_update(); break;
case 2:case_user2_is_landlord_update(); break;
case 3:case_user3_is_landlord_update(); break;
}
for (i = 0; i < temp_number; i++)
{
drawImg(660 + i * 25, 400, &img[temp_img[i]]);//与最开始的出牌不同,前面以及有人出牌
}
}
}
temp_number = 0;//置为0,使下面的代码成立
for (i = user2_card_number - 1; i >= 0; i--)
{
if (clicktimes[i] == 1)//如果牌时上移的,就代表时要出的
{
temp_img[temp_number] = user2[i];
temp[temp_number] = user2_compare[i];
user2[i] = 0;
user2_compare[i] = 0;
flag = 0;
clicktimes[i] = 0;
temp_number++;
}
}
sort_cards(user2, user2_card_number);
sort_cards(user2_compare, user2_card_number);
user2_card_number -= temp_number;
update_with_play_card();
temp_card_is_what();
if (type_is_what() == 3)//判断类形,输出效果
{
drawImg(500, 400, &img_san2);
}
if (type_is_what() == 4)
{
drawImg(500, 400, &img_bomb2);
}
if (type_is_what() == 5)
{
drawImg(500, 400, &img_kingbomb2);
}
if (type_is_what() == 6)
{
drawImg(500, 400, &img_sandaiyi2);
}
if (type_is_what() == 9)
{
drawImg(500, 400, &img_sidaier2);
}
if (type_is_what() == 10 || type_is_what() == 11)
{
drawImg(500, 400, &img_plane2);
}
Sleep(100);
}
void user2_play_compare()
{
int i, state = 0;
while (1)
{
drawImg(550, 670, &img_play2);
drawImg(750, 670, &img_notplay2);
m = GetMouseMsg();
if (m.uMsg == WM_LBUTTONDOWN)
{
if (m.x >= 550 && m.x <= 650 && m.y >= 670 && m.y <= 720)
{
state = 1;
break;
}
if (m.x >= 750 && m.x <= 850 && m.y >= 670 && m.y <= 720)
{
state = 0;
break;
}
if (m.x >= 450 && m.x <= (550 + (user2_card_number - 1) * 25))
{
if (m.x <= (450 + (user2_card_number - 1) * 25) && m.y >= (760 - clicktimes[(m.x - 450) / 25] * 25) && m.y <= (910 - clicktimes[(m.x - 450) / 25] * 25))
clicktimes[(m.x - 450) / 25] = (clicktimes[(m.x - 450) / 25] + 1) % 2;
else if (m.x > (450 + (user2_card_number - 1) * 25) && m.y >= (760 - clicktimes[16] * 25) && m.y <= (910 - clicktimes[16] * 25))
clicktimes[user2_card_number - 1] = (clicktimes[user2_card_number - 1] + 1) % 2;
}
switch (who_is_landlord)
{
case 1:case_user1_is_landlord_update(); break;
case 2:case_user2_is_landlord_update(); break;
case 3:case_user3_is_landlord_update(); break;
}
for (i = 0; i < temp_number; i++)
{
drawImg(660 + i * 25, 400, &img[temp_img[i]]);
}
}
}
if (state == 1)
{
temp_number = 0;
for (i = user2_card_number - 1; i >= 0; i--)
{
if (clicktimes[i] == 1)
{
temp_img[temp_number] = user2[i];
temp[temp_number] = user2_compare[i];
user2[i] = 0;
user2_compare[i] = 0;
flag = 0;
clicktimes[i] = 0;
temp_number++;
}
}
sort_cards(user2, user2_card_number);
sort_cards(user2_compare, user2_card_number);
user2_card_number -= temp_number;
}
else if (state == 0)
{
flag++;
}
update_with_play_card();
temp_card_is_what();
if (type_is_what() == 3)
{
drawImg(500, 400, &img_san2);
}
if (type_is_what() == 4)
{
drawImg(500, 400, &img_bomb2);
}
if (type_is_what() == 5)
{
drawImg(500, 400, &img_kingbomb2);
}
if (type_is_what() == 6)
{
drawImg(500, 400, &img_sandaiyi2);
}
if (type_is_what() == 9)
{
drawImg(500, 400, &img_sidaier2);
}
if (type_is_what() == 10 || type_is_what() == 11)
{
drawImg(500, 400, &img_plane2);
}
Sleep(100);
}
void user3_play_directly()
{
temp_number = 1;
temp_img[0] = user3[user3_card_number - 1];
temp[0] = user3_compare[user3_card_number - 1];
user3[user3_card_number - 1] = 0;
user3_compare[user3_card_number - 1] = 0;
sort_cards(user3, user3_card_number);
sort_cards(user3_compare, user3_card_number);
user3_card_number--;
flag = 0;
update_with_play_card();
}
void user3_play_compare()
{
int i, j, k, q, m, k1, n, k2;
temp_card_is_what();
if (type_is_what() == 1)
{
for (j = user3_card_number - 1; j >= 0; j--)
{
if (user3_compare[j] > temp[0])
{
temp_number = 1;
temp_img[0] = user3[j];
temp[0] = user3_compare[j];
user3[j] = 0;
user3_compare[j] = 0;
sort_cards(user3, user3_card_number);
sort_cards(user3_compare, user3_card_number);
user3_card_number--;
flag = 0;
update_with_play_card();
break;
}
}
if (j == -1)flag++;
}
if (type_is_what() == 2)
{
user3_compare_change_to_user3_card();
for (i = 3; i < 18; i++)
{
if (user3_card[i] >= 2 && i > temp[0])
{
k = i;
temp_number = 2;
user3_deal_and_play_card(0, temp_number, k);
update_with_play_card();
break;
}
}
if (i == 18)flag++;
}
if (type_is_what() == 3)
{
user3_compare_change_to_user3_card();
for (i = 3; i < 18; i++)
{
if (user3_card[i] >= 3 && i > temp[0])
{
k = i;
temp_number = 3;
user3_deal_and_play_card(0, temp_number, k);
update_with_play_card();
drawImg(500, 400, &img_san2);
Sleep(100);
break;
}
}
if (i == 18)flag++;
}
if (type_is_what() == 4)
{
user3_compare_change_to_user3_card();
for (i = 3; i < 18; i++)
{
if (user3_card[i] >= 4 && i > temp[0])
{
k = i;
temp_number = 4;
user3_deal_and_play_card(0, temp_number, k);
update_with_play_card();
drawImg(500, 400, &img_bomb2);
Sleep(100);
break;
}
}
if (i == 18)flag++;
}
if (type_is_what() == 5)
{
flag++;
}
if (type_is_what() == 6)
{
user3_compare_change_to_user3_card();
for (i = 3; i < 18; i++)
{
if (user3_card[i] >= 3 && i > temp_card_type[0])
{
k = i;
for (m = 3; m < 18; m++)
{
if (m != k && user3[m] >= 1)
{
k1 = m;
temp_number = 3;
user3_deal_and_play_card(0, temp_number, k);
temp_number++;
user3_deal_and_play_card(3, temp_number, k1);
update_with_play_card();
drawImg(500, 400, &img_sandaiyi2);
Sleep(100);
break;
}
}
if (m < 18)break;
}
}
if (i == 18)flag++;
}
if (type_is_what() == 7)
{
user3_compare_change_to_user3_card();
for (i = 3; i < 18; i++)
{
if (user3_card[i] >= 3 && i > temp_card_type[0])
{
k = i;
for (m = 3; m < 18; m++)
{
if (m != k && user3[m] >= 2)
{
k1 = m;
temp_number = 3;
user3_deal_and_play_card(0, temp_number, k);
temp_number++;
temp_number++;
user3_deal_and_play_card(3, temp_number, k1);
update_with_play_card();
break;
}
}
if (m < 18)break;
}
}
if (i == 18)flag++;
}
if (type_is_what() == 8)
{
user3_compare_change_to_user3_card();
for (i = 3; i < 18; i++)
{
if (user3_card[i] >= 4 && i > temp_card_type[0])
{
k = i;
for (m = 3; m < 18; m++)
{
if (m != k && user3[m] >= 1)
{
k1 = m;
for (n = 3; n < 18; n++)
{
if (n != k && n != k1 && user3[n] >= 1)
{
k2 = n;
temp_number = 4;
user3_deal_and_play_card(0, temp_number, k);
temp_number++;
user3_deal_and_play_card(4, temp_number, k1);
temp_number++;
user3_deal_and_play_card(5, temp_number, k2);
update_with_play_card();
break;
}
}
if (n < 18)break;
}
}
if (m < 18)break;
}
}
if (i == 18)flag++;
}
if (type_is_what() == 9)
{
user3_compare_change_to_user3_card();
for (i = 3; i < 18; i++)
{
if (user3_card[i] >= 4 && i > temp_card_type[0])
{
k = i;
for (m = 3; m < 18; m++)
{
if (m != k && user3[m] >= 2)
{
k1 = m;
for (n = 3; n < 18; n++)
{
if (n != k && n != k1 && user3[n] >= 2)
{
k2 = n;
temp_number = 4;
user3_deal_and_play_card(0, temp_number, k);
temp_number++;
temp_number++;
user3_deal_and_play_card(4, temp_number, k1);
temp_number++;
temp_number++;
user3_deal_and_play_card(6, temp_number, k2);
update_with_play_card();
drawImg(500, 400, &img_sidaier2);
Sleep(100);
break;
}
}
if (n < 18)break;
}
}
if (m < 18)break;
}
}
if (i == 18)flag++;
}
if (type_is_what() == 10)
{
user3_compare_change_to_user3_card();
for (i = 3; i < 18; i++)
{
if (user3_card[i] >= 3 && i > temp_card_type[0] && user3_card[i + 1] >= 3)
{
k = i;
for (m = 3; m < 18; m++)
{
if (m != k && m != (k + 1) && user3[m] >= 1)
{
k1 = m;
for (n = 3; n < 18; n++)
{
if (n != k && n != (k + 1) && n != k1 && user3[n] >= 1)
{
k2 = n;
temp_number = 3;
user3_deal_and_play_card(0, temp_number, k);
temp_number++;
temp_number++;
temp_number++;
user3_deal_and_play_card(3, temp_number, k + 1);
temp_number++;
user3_deal_and_play_card(6, temp_number, k1);
temp_number++;
user3_deal_and_play_card(7, temp_number, k2);
update_with_play_card();
drawImg(500, 400, &img_plane2);
Sleep(100);
break;
}
}
if (n < 18)break;
}
}
if (m < 18)break;
}
}
if (i == 18)flag++;
}
if (type_is_what() == 11)
{
user3_compare_change_to_user3_card();
for (i = 3; i < 18; i++)
{
if (user3_card[i] >= 3 && i > temp_card_type[0] && user3_card[i + 1] >= 3)
{
k = i;
for (m = 3; m < 18; m++)
{
if (m != k && m != (k + 1) && user3[m] >= 2)
{
k1 = m;
for (n = 3; n < 18; n++)
{
if (n != k && n != (k + 1) && n != k1 && user3[n] >= 2)
{
k2 = n;
temp_number = 3;
user3_deal_and_play_card(0, temp_number, k);
temp_number++;
temp_number++;
temp_number++;
user3_deal_and_play_card(3, temp_number, k + 1);
temp_number++;
temp_number++;
user3_deal_and_play_card(6, temp_number, k1);
temp_number++;
temp_number++;
user3_deal_and_play_card(8, temp_number, k2);
update_with_play_card();
drawImg(500, 400, &img_plane2);
Sleep(100);
break;
}
}
if (n < 18)break;
}
}
if (m < 18)break;
}
}
if (i == 18)flag++;
}
if (type_is_what() == 12)
{
user3_compare_change_to_user3_card();
for (i = temp[0] + 1; i < 18 - temp_number - 2; i++)
{
for (j = i; j < i + temp_number; j++)
{
if (user3_card[j] < 1)break;
}
if (j == (i + temp_number))
{
for (q = 0; q < temp_number; q++)
{
user3_deal_and_play_card(q, q + 1, q + i);
}
update_with_play_card();
break;
}
}
if (i == (18 - temp_number - 2))flag++;
}
}
void init()//初始化,为游戏启动做准备工作
{
int i;
for (i = 1; i < 55; i++)
{
pile[i] = i;//初始化牌堆
}
srand((unsigned int)time(NULL));//使发牌随机
load_image();//加载图片
load_music();//加载音乐并播放
deal_cards();//发牌
sort_cards(user1, 17);//理牌
sort_cards(user2, 17);//理牌
sort_cards(user3, 17);//理牌
}
void init_show()//显示选地主前的全部画面
{
int i;
drawImg(0, 0, &img_start);//输出开始界面
while (1)//判断是否点击屏幕
{
m = GetMouseMsg();
if (m.uMsg == WM_LBUTTONDOWN)
{
break;
}
}
show_bg_and_user();//显示背景和用户
show_mycard_image_first();//第一次显示手牌,一张张出来。
show_bottom_image();//显示底牌
show_flagcard_move();//显示标志牌移动效果
}
void choose_landlord_show()//显示抢地主的过程画面
{
search_flag_card();//查询哪位玩家获得了标志牌
if (first_rob == 1)
{
if (rand() % 2)//随机数为1,玩家一即抢得地主
{
//drawImg(320, 350, &img_rob1);//显示玩家一的抢地主画面
drawImg(320, 350, &img_rob2);//显示玩家一的抢地主画面
Sleep(1000);
who_is_landlord = 1;//保存谁是地主
}
else//顺延至下一位
{
drawImg(320, 350, &img_notrob2);//显示玩家一的不抢地主画面
Sleep(1000);
//输出抢地主与不抢的框架,供真人玩家点击
drawImg(550, 690, &img_rob_2);//显示玩家二的抢地主选项
drawImg(750, 690, &img_notrob_2);//显示玩家二的不抢地主选项
while (1)
{
m = GetMouseMsg();
if (m.uMsg == WM_LBUTTONDOWN)//检测鼠标点击事件
{
if (m.x >= 550 && m.x <= 650 && m.y >= 690 && m.y <= 740)//如果点击了抢地主的选项
{
//消除框架
show_bg_and_user();//展示背景和用户
show_bottom_image();//展示底牌
drawImg(960, 50, &img[flag_card]);//展示标志牌
show_mycard_image_after();//展示不移动的手牌
drawImg(320, 350, &img_notrob2);//显示玩家一的不抢地主画面
drawImg(650, 640, &img_rob_2);//显示玩家二抢地主的画面
Sleep(1000);
who_is_landlord = 2;//保存谁是地主
}
else if (m.x >= 750 && m.x <= 850 && m.y >= 690 && m.y <= 740)
{
//消除框架
show_bg_and_user();//展示背景和用户
show_bottom_image();//展示底牌
drawImg(960, 50, &img[flag_card]);//展示标志牌
show_mycard_image_after();//展示不移动的手牌
drawImg(320, 350, &img_notrob2);//显示玩家一的不抢地主画面
drawImg(650, 640, &img_notrob_2);//显示玩家二不抢地主的画面
Sleep(1000);
drawImg(500, 400, &img_123_2);
Sleep(1000);
who_is_landlord = 3;//保存谁是地主
}
//鼠标如果做出选择,退出循环
if (m.x >= 550 && m.x <= 650 && m.y >= 690 && m.y <= 740 || m.x >= 750 && m.x <= 850 && m.y >= 690 && m.y <= 740)
break;
}
}
}
}
if (first_rob == 2)
{
//输出抢地主与不抢的框架,供真人玩家点击
drawImg(550, 690, &img_rob_2);
drawImg(750, 690, &img_notrob_2);
while (1)
{
m = GetMouseMsg();
if (m.uMsg == WM_LBUTTONDOWN)//判断鼠标点击事件
{
if (m.x >= 550 && m.x <= 650 && m.y >= 690 && m.y <= 740)//如果点击到了抢地主的选项
{
//消除框架
show_bg_and_user();
show_bottom_image();
drawImg(960, 50, &img[flag_card]);
show_mycard_image_after();
drawImg(650, 640, &img_rob_2);//输出玩家二的抢地主画面
Sleep(1000);
who_is_landlord = 2;
}
else if (m.x >= 750 && m.x <= 850 && m.y >= 690 && m.y <= 740)//如果点击到了不抢地主的选项
{
//消除框架
show_bg_and_user();
show_bottom_image();
drawImg(960, 50, &img[flag_card]);
show_mycard_image_after();
drawImg(650, 640, &img_notrob_2);//输出玩家二的不抢地主画面
Sleep(1000);
if (rand() % 2)//随机数为1,玩家三即抢得地主
{
drawImg(1120, 350, &img_rob2);//输出玩家三抢地主的画面
Sleep(1000);
who_is_landlord = 3;
}
else
{
drawImg(1120, 350, &img_notrob2);//输出玩家三不抢地主的画面
Sleep(1000);
drawImg(500, 400, &img_231_2);
Sleep(1000);
who_is_landlord = 1;
}
}
//鼠标如果做出选择,退出循环
if (m.x >= 550 && m.x <= 650 && m.y >= 690 && m.y <= 740 || m.x >= 750 && m.x <= 850 && m.y >= 690 && m.y <= 740)
break;
}
}
}
if (first_rob == 3)
{
if (rand() % 2)//随机数为1,玩家三即抢得地主
{
drawImg(1120, 350, &img_rob2);//输出玩家三抢地主的画面
Sleep(1000);
who_is_landlord = 3;
}
else
{
drawImg(1120, 350, &img_notrob2);//输出玩家三不抢地主的画面
Sleep(1000);
if (rand() % 2)//随机数为1,玩家一即抢得地主
{
drawImg(320, 350, &img_rob2);//输出玩家一抢地主的画面
Sleep(1000);
who_is_landlord = 1;
}
else
{
drawImg(320, 350, &img_notrob2);//输出玩家一不抢地主的画面
Sleep(1000);
drawImg(500, 400, &img_132_2);
Sleep(1000);
who_is_landlord = 2;
}
}
}
switch (who_is_landlord)//展示成为地主的画面
{
case 1: case_user1_is_landlord(); break;
case 2: case_user2_is_landlord(); break;
case 3: case_user3_is_landlord(); break;
}
}
void with_input_show()
{
int i;
if (who_is_landlord == 1)
{
user1_card_number = 20;
user2_card_number = 17;
user3_card_number = 17;
user_change_to_user_compare();//将全部用户的手牌转化为直接大小的牌,比如说1-4转化为3
user1_play_directly();//玩家一直接出牌
while (1)
{
if (flag == 2)//flag中存放之前是否有人未出牌,如果有2次未出,这次直接为这位玩家获得出牌权
{
user2_play_directly();//玩家二直接出牌
}
else
{
user2_play_compare();//玩家二接牌
}
if (user1_card_number == 0 || user2_card_number == 0 || user3_card_number == 0)//判断是否有人出完全部牌
{
if (user2_card_number == 0 || user3_card_number == 0)//获胜,输出胜利画面
{
drawImg(500, 400, &img_win2);
}
else//失败输出失败画面
{
drawImg(500, 400, &img_lose2);
}
break;
}
if (flag == 2)
{
user3_play_directly();
}
else
{
user3_play_compare();
}
if (user1_card_number == 0 || user2_card_number == 0 || user3_card_number == 0)
{
if (user2_card_number == 0 || user3_card_number == 0)
{
drawImg(500, 400, &img_win2);
}
else
{
drawImg(500, 400, &img_lose2);
}
break;
}
if (flag == 2)
{
user1_play_directly();
}
else
{
user1_play_compare();
}
if (user1_card_number == 0 || user2_card_number == 0 || user3_card_number == 0)
{
if (user2_card_number == 0 || user3_card_number == 0)
{
drawImg(500, 400, &img_win2);
}
else
{
drawImg(500, 400, &img_lose2);
}
break;
}
}
}
else if (who_is_landlord == 2)
{
user1_card_number = 17;
user2_card_number = 20;
user3_card_number = 17;
user_change_to_user_compare();
while (1)//由于玩家二率先出牌的话,场面上是没有中间已经出的牌的,但是输出已经出的牌在函数中间,所以不能使用函数
{ //如不懂 可以仔细看下面代码与函数中的区别
//下面代码将在函数中介绍,请到函数中看
drawImg(650, 670, &img_play2);
m = GetMouseMsg();
if (m.uMsg == WM_LBUTTONDOWN)
{
if (m.x >= 650 && m.x <= 750 && m.y >= 670 && m.y <= 720)
break;
if (m.x >= 450 && m.x <= (550 + (user2_card_number - 1) * 25))
{
if (m.x <= (450 + (user2_card_number - 1) * 25) && m.y >= (760 - clicktimes[(m.x - 450) / 25] * 25) && m.y <= (910 - clicktimes[(m.x - 450) / 25] * 25))
clicktimes[(m.x - 450) / 25] = (clicktimes[(m.x - 450) / 25] + 1) % 2;
else if (m.x > (450 + (user2_card_number - 1) * 25) && m.y >= (760 - clicktimes[16] * 25) && m.y <= (910 - clicktimes[16] * 25))
clicktimes[user2_card_number - 1] = (clicktimes[user2_card_number - 1] + 1) % 2;
}
switch (who_is_landlord)
{
case 1:case_user1_is_landlord_update(); break;
case 2:case_user2_is_landlord_update(); break;
case 3:case_user3_is_landlord_update(); break;
}
}
}
temp_number = 0;
for (i = user2_card_number - 1; i >= 0; i--)
{
if (clicktimes[i] == 1)
{
temp_img[temp_number] = user2[i];
temp[temp_number] = user2_compare[i];
user2[i] = 0;
user2_compare[i] = 0;
flag = 0;
clicktimes[i] = 0;
temp_number++;
}
}
sort_cards(user2, user2_card_number);
sort_cards(user2_compare, user2_card_number);
user2_card_number -= temp_number;
update_with_play_card();
temp_card_is_what();
if (type_is_what() == 3)
{
drawImg(500, 400, &img_san2);
}
if (type_is_what() == 4)
{
drawImg(500, 400, &img_bomb2);
}
if (type_is_what() == 5)
{
drawImg(500, 400, &img_kingbomb2);
}
if (type_is_what() == 6)
{
drawImg(500, 400, &img_sandaiyi2);
}
if (type_is_what() == 9)
{
drawImg(500, 400, &img_sidaier2);
}
if (type_is_what() == 10 || type_is_what() == 11)
{
drawImg(500, 400, &img_plane2);
}
Sleep(100);
while (1)
{
if (flag == 2)
{
user3_play_directly();
}
else
{
user3_play_compare();
}
if (user1_card_number == 0 || user2_card_number == 0 || user3_card_number == 0)
{
if (user2_card_number == 0)
{
drawImg(500, 400, &img_win2);
}
else
{
drawImg(500, 400, &img_lose2);
}
break;
}
if (flag == 2)
{
user1_play_directly();
}
else
{
user1_play_compare();
}
if (user1_card_number == 0 || user2_card_number == 0 || user3_card_number == 0)
{
if (user2_card_number == 0)
{
drawImg(500, 400, &img_win2);
}
else
{
drawImg(500, 400, &img_lose2);
}
break;
}
if (flag == 2)
{
user2_play_directly();
}
else
{
user2_play_compare();
}
if (user1_card_number == 0 || user2_card_number == 0 || user3_card_number == 0)
{
if (user2_card_number == 0)
{
drawImg(500, 400, &img_win2);
}
else
{
drawImg(500, 400, &img_lose2);
}
break;
}
}
}
else if (who_is_landlord == 3)
{
user1_card_number = 17;
user2_card_number = 17;
user3_card_number = 20;
user_change_to_user_compare();
user3_play_directly();
while (1)
{
if (flag == 2)
{
user1_play_directly();
}
else
{
user1_play_compare();
}
if (user1_card_number == 0 || user2_card_number == 0 || user3_card_number == 0)
{
if (user1_card_number == 0 || user2_card_number == 0)
{
drawImg(500, 400, &img_win2);
}
else
{
drawImg(500, 400, &img_lose2);
}
break;
}
if (flag == 2)
{
user2_play_directly();
}
else
{
user2_play_compare();
}
if (user1_card_number == 0 || user2_card_number == 0 || user3_card_number == 0)
{
if (user1_card_number == 0 || user2_card_number == 0)
{
drawImg(500, 400, &img_win2);
}
else
{
drawImg(500, 400, &img_lose2);
}
break;
}
if (flag == 2)
{
user3_play_directly();
}
else
{
user3_play_compare();
}
if (user1_card_number == 0 || user2_card_number == 0 || user3_card_number == 0)
{
if (user1_card_number == 0 || user2_card_number == 0)
{
drawImg(500, 400, &img_win2);
}
else
{
drawImg(500, 400, &img_lose2);
}
break;
}
}
}
}
int main()
{
initgraph(1440, 960);//生成画布大小为1440×960
init();//初始化,为游戏启动做准备工作
while (1)
{
init_show();//显示选地主前的全部画面
choose_landlord_show();//显示抢地主的过程画面
with_input_show();//显示出牌阶段的画面
Sleep(3000);
}
_getch();//使程序不会马上退出
closegraph();//关闭画布
}