/*////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
目前还存在的一些问题: //
//
1.玩家不能出连的三代; //
2.电脑一次只能出一张牌; //
3.电脑2不能作为地主,而且电脑2现在不能把牌全部出完,我估计是在循环是调用指针时候空指针没有处理好; //
4.玩家不能自主的选择pass. //
5.图形这次做的很成功但是当时做动态选择牌的时候失败了,否则效果应该与QQ斗地主一样的。 //
//
以上问题由于时间问题没有进一步改进。以后相信会做出一个高质量ai的斗地主。 //
//
编者:软件学院0603班 李超 //
QQ:402624979 //
E-mail:lcswr@126.com //
////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <malloc.h>
#include <bios.h>
#define UP 18432 /*向上的键盘输入标志*/
#define DOWN 20480 /*向下的键盘输入标志*/
#define LEFT 19200 /*向左的键盘输入标志*/
#define RIGHT 19712 /*向右的键盘输入标志*/
int bkcol, x, y;
int a[54];
int b[54];
int flag[20] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; /* flag[i] == 1表示第i张牌还没有出, flag[i] == 0表示这张牌这次之前就出出去了, flag[i] == -1表示这张牌在本次中出出去了 */
char card_value[26] = {'3', '\0', '4', '\0', '5', '\0', '6', '\0', '7', '\0', '8', '\0', '9', '\0', '0', '\0', 'J', '\0', 'Q', '\0', 'K', '\0', 'A', '\0', '2', '\0'};/*加一个'\0'是为了后面以字符串格式输出*/
struct card_node *s1 = NULL, *s2 = NULL;
struct card_node *com1;
struct card_node *com2;
struct card_node
{
int kind;
int num;
char *card;
struct card_node *next;
}card[54];
void first_look ()
{
settextjustify(CENTER_TEXT, CENTER_TEXT);
cleardevice();
x = getmaxx() / 2;
y = getmaxy() / 2;
setcolor (RED);
settextstyle (GOTHIC_FONT, 0, 8);
outtextxy (x, y - 70, "Lord Card");
settextstyle (3, 0, 1);
outtextxy (x + 110, y + 40, "Produced By Li Chao");
outtextxy (x + 110, y + 80, "Version 1.00");
getch ();
}
void table (int x1, int y1)
{
settextjustify(CENTER_TEXT, CENTER_TEXT);
bkcol = BLACK; /*MAGENTA*/
cleardevice();
setbkcolor(bkcol);
setfillstyle (SOLID_FILL, LIGHTRED);
bar (x1 - 140, y1 - 45, x1 + 136, y1 + 40);
setcolor (WHITE);
rectangle (x1 - 141, y1 - 46, x1 + 137, y1 + 41);
moveto (x1 , y1 - 8);
settextstyle (GOTHIC_FONT, 0, 6);
outtext ("Lord Card");
}
void delete_table (int x1, int y1)
{
setfillstyle (SOLID_FILL, BLACK);
bar (x1 - 141, y1 - 46, x1 + 137, y1 + 41);
}
void operation (int t)
{
settextstyle (3, 0, 2);
switch (t)
{
case 1:
setcolor (RED);
outtextxy (x - 10, 20, "START");
setcolor (WHITE);
outtextxy (x - 10, 50, "ABOUT PRODUCER");
outtextxy (x - 10, 80, "EXIT");
break;
case 2:
setcolor (WHITE);
outtextxy (x - 10, 20, "START");
outtextxy (x - 10, 80, "EXIT");
setcolor (RED);
outtextxy (x - 10, 50, "ABOUT PRODUCER");
break;
case 3:
setcolor (WHITE);
outtextxy (x - 10, 20, "START");
outtextxy (x - 10, 50, "ABOUT PRODUCER");
setcolor (RED);
outtextxy (x - 10, 80, "EXIT");
break;
}
}
int choose_operation ()
{
int key, t = 1;
operation (1);
while (1)
{
while ( bioskey(1) == 0 );
key = bioskey(0);
switch (key)
{
case UP:
if (t == 1)
operation (t);
else
operation (--t);
break;
case DOWN:
if (t == 3)
operation (t);
else
operation (++t);
break;
case LEFT:
break;
case RIGHT:
break;
default :
return t;
}
}
}
void init_graph ()
{
int gdriver = EGA, gmode = EGAHI, errorcode;
/* registerbgidriver(EGAVGA_driver); */
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
}
void player_name()
{
setcolor (RED);
settextstyle (3, 0, 1);
outtextxy (x - 260, 10, "COMPUTER 1 :");
outtextxy (x + 256, 10, "COMPUTER 2 :");
outtextxy (x - 180, y + 55, "PLAYER :");
}
void init_card ()
{
int i, j;
for (i = 0; i <= 3; i++)
for (j = 13 * i; j < 13 * i + 13; j++)
{
card[j].kind = i;
card[j].num = j - i * 13;
if (card[j].num == 7)
card[j].card = "10";
else
card[j].card = & card_value[2 * (j - i * 13)];
card[j].next = NULL;
}
card[52].kind = 5;
card[53].kind = 4;
card[52].num = 13;
card[53].num = 14;
card[52].card = "JOKER";
card[53].card = "JOKER";
card[53].next = NULL;
card[52].next = NULL;
}
struct card_node * back_up (struct card_node *head) /* 用来备份用的*/
{
struct card_node *p, *head1, *q;
head1 = (struct card_node *) malloc (sizeof (struct card_node));
head1 -> kind = head -> kind;
head1 -> num = head -> num;
head1 -> card = head -> card;
head1 -> next = NULL;
for (p = head -> next, q = head1; p != NULL; p = p -> next)
{
q -> next = (struct card_node *) malloc (sizeof (struct card_node));
q = q -> next;
q -> kind = p -> kind;
q -> num = p -> num;
q -> card = p -> card;
q -> next = NULL;
}
return head1;
}
void card_drawn (int x, int y, int kind, int num, int color) /*传递坐标和牌的花色以及大小,宽60,高80*/
{
char str[6];
setfillstyle (SOLID_FILL, color);
bar (x - 30, y - 40, x + 30, y + 40);
setcolor (BLUE);
rectangle (x - 29, y - 39, x + 29, y + 39);
switch (kind)
{
case 0:
setcolor (RED);
sprintf (str, "%c", 3);
break;
case 1:
setcolor (RED);
sprintf (str, "%c", 4);
break;
case 2:
setcolor (BLACK);
sprintf (str, "%c", 3);
break;
case 3:
setcolor (BLACK);
sprintf (str, "%c", 5);
break;
case 5:
setcolor (LIGHTGRAY);
sprintf (str, "%s", "JOKER");
break;
case 4:
setcolor (RED);
sprintf (str, "%s", "JOKER");
break;
}
if ( kind <= 3)
{
settextstyle (0, 0, 2);
outtextxy (x - 20, y - 29, str);
outtextxy (x + 21, y + 30, str);
if (num == 7)
{
settextstyle (0, 0, 1);
outtextxy (x - 21, y - 15, card[kind * 13 + num].card);
outtextxy (x + 21, y + 16, card[kind * 13 + num].card);
settextstyle (4, 0, 4);
outtextxy (x, y - 5, card[kind * 13 + num].card);
}
else
{
settextstyle (1, 0, 1);
outtextxy (x - 21, y - 15, card[kind * 13 + num].card);
outtextxy (x + 21, y + 10, card[kind * 13 + num].card);
settextstyle (4, 0, 5);
outtextxy (x - 1, y - 5, card[kind * 13 + num].card);
}
}
else
{
settextstyle (0, 1, 1);
outtextxy (x - 21, y - 18, str);
outtextxy (x + 21, y + 18, str);
settextstyle (4, 0, 5);
outtextxy (x, y - 3, "G");
}
}
void lord_choice (int q)
{
setcolor (BLUE);
settextst
- 1
- 2
前往页