广告广告
  加入我的最爱 设为首页 风格修改
首页 首尾
 手机版   订阅   地图  繁体 
您是第 5380 个阅读者
 
发表文章 发表投票 回覆文章
  可列印版   加为IE收藏   收藏主题   上一主题 | 下一主题   
达摩 手机
个人文章 个人相簿 个人日记 个人地图
初露锋芒
级别: 初露锋芒 该用户目前不上站
推文 x0 鲜花 x46
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片
推文 x0
[C/C++][范例] 用Turbo C写的五子棋唷..
/*<<< 程式开始 >>>*/

#define DISPLAY 0

#include <bios.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "myfunc.h"

char yc, cc, player = 1, level = 3, true, computer, example;
char xy, enrollx, enrolly, tint;
int clickx, clicky, mousex, mousey, tused, frequency, crisisf, fmax, x, y;
time_t tstart, tend;

void undo_next();
void latitude();
void chessman();
void victor5();
void computer_estimate();
void analyze();
char conclude();
char com();
char rd5();
char rd6();
char rd7();
char hn345();
char com5();
char com4();
char com1011101();
char com121212();
char com45();
char com3();
char com1();

void inaugurate();
void draft();
void help();
char my_win_menu();

/*--- 主程式 ---*/

main()
{
char inkey, choice;
myinitgraph(); inaugurate();
while (1)
{
if (frequency == 225) /* 判断棋盘是否已满 */
{
my_win_reply("Draw Game !","Continue","","",1);
inaugurate();
}
if (button_press_mxy(0,&clickx,&clicky)) /* 按滑鼠左键选择要放棋子的位置 */
{
if (clickx > 10 && clickx < 310 && clicky > 50 && clicky < 350)
{
latitude(6);
if (clickx%20 < 10) x = clickx-clickx%20;
else x = clickx+20-clickx%20;
if (clicky%20 < 10) y = clicky-clicky%20;
else y = clicky+20-clicky%20;
chessman();
latitude(10);
}
}
if (button_press(1)) want(0); /* 按滑鼠右键离开 */

if (example == 1) computer = 1;
if (computer == 1 && player == 1) computer_estimate();

get_mxy(&mousex,&mousey); /* 侦测滑鼠的座标 */
if (mousey <= 21 || (bioskey(2) & 8)) /* 若滑鼠的座标小于22或按下 Alt 键, */
{ /* 则显示选单 */
if (mousey > 21) set_mxy(25,10);
choice = my_win_menu();
switch(choice)
{
case 11: inaugurate();
break;
case 12: want(0);
break;
case 21: if (player == 2) if (reset_ask() == 1) { player = 1; inaugurate(); }
break;
case 22: if (player == 1) if (reset_ask() == 1) { player = 2; inaugurate(); }
break;
case 31: undo_next(1);
break;
case 32: undo_next(2);
break;
case 41: level = 1;
break;
case 42: level = 2;
break;
case 43: level = 3;
break;
case 51: example = 1;
break;
case 52: true = 2; computer = 1;
break;
case 61: help();
break;
case 62: my_win_reply(" Version 2.82 Writer : Mr.Huang","OK","","",4);
break;
}
}
time( &tend );
tused = tend-tstart;
gotoxy(64,12); printf("Time %2d : %2d",tused/60,tused%60); /* 显示时间 */
gotoxy(64,13); printf("Times %3d",frequency); /* 显示棋数 */

/* 侦测键盘按下的按键 */

if (kbhit() && (inkey = getch()))
switch (inkey)
{
case 72 : /* 上 */
case Ǝ': if (y > 60)
{
latitude(6);
y-=20;
latitude(10);
}
break;
case 80 : /* 下 */
case Ƌ':
case ƈ': if (y < 340)
{
latitude(6);
y+=20;
latitude(10);
}
break;
case 75 : /* 左 */
case Ɗ': if (x > 20)
{
latitude(6);
x-=20;
latitude(10);
}
break;
case 77 : /* 右 */
case ƌ': if (x < 300)
{
latitude(6);
x+=20;
latitude(10);
}
break;
case 59 : help(); /* 显示说明 */
break;
case 'R': /* 游戏重来 */
case 'r': want(2);
break;
case 'U':
case 'u': undo_next(1);
break;
case 'N':
case 'n': undo_next(2);
break;
case 'E': /* 电脑示范 */
case 'e': if (example == 0) example = 1;
else example = 0;
break;
case 68 : true = 2; computer = 1; /* 提示 */
break;
case 27 : /* 离开游戏 */
case 'Q':
case 'q': want(0);
break;
case 13 : /* 放上棋子 */
case ' ': chessman();
break;
case 94 : xy = 15; draft();
break;
case 95 : xy = 0; draft();
break;
case 96 : xy = 1; draft();
break;
}
}
}
void undo_next(char ud)
{
if (ud == 1 && frequency > 0)
{
frequency--;
xy]] = 1;
cc = 15-cc;
if (player == 1)
{
frequency--;
xy]] = 1;
cc = 15-cc;
}
draft();
}
if (ud == 2 && frequency <= fmax)
{
xy]] = tint;
frequency++;
cc = 15-cc;
if (player == 1)
{
xy]] = tint;
frequency++;
cc = 15-cc;
}
draft();
}
}
void latitude(char co) /* 画出框框 */
{
cursor(2);
setcolor(co);
moveto(x-10,y-5); lineto(x-10,y-10); lineto(x-5,y-10);
moveto(x+5,y-10); lineto(x+10,y-10); lineto(x+10,y-5);
moveto(x+10,y+5); lineto(x+10,y+10); lineto(x+5,y+10);
moveto(x-5,y+10); lineto(x-10,y+10); lineto(x-10,y+5);
cursor(1);
}
void chessman(void) /* 画出棋子 */
{
char i, j;
cursor(2);
i = x/20-1;
j = y/20-3;
if (xy == 1)
{
xy = cc; fmax = frequency;
setfillstyle(1,cc); setcolor(cc);
circle(x,y,8);
floodfill(x,y,cc);
floodfill(x-7,y,cc);
floodfill(x+7,y,cc);
enrollx = i;
enrolly = j;
tint = cc;
frequency++;
if (cc == yc) computer = 1;
cc = (cc == 15)? 0:15;
}
gotoxy(64,13); printf("Times %3d",frequency);
gotoxy(64,10); printf("Next :");
setfillstyle(1,7);
bar(565,142,585,162);
setfillstyle(1,cc); setcolor(cc);
circle(575,152,8);
floodfill(575,152,cc);
cursor(1);
victor5(15-cc);
}
void victor5(char h) /* 判断是否有人已经赢了,并将那五颗棋子连成一线 */
{
char a, b;
void winline();
for (a=0;a<15;a++)
for (b=0;b<15;b++)
{
if (a <= 10)
if (xy==h && xy==h && xy==h && xy==h && xy==h)
winline(a,b,a+4,b);
if (b <= 10)
if (xy==h && xy==h && xy==h && xy==h && xy==h)
winline(a,b,a,b+4);
if (a <= 10 && b <= 10)
{
if (xy==h && xy==h && xy==h && xy==h && xy==h)
winline(a,b,a+4,b+4);
if (xy==h && xy==h && xy==h && xy==h && xy==h)
winline(a+4,b,a,b+4);
}
}
}
void winline(char a1, char b1, char a2, char b2)
{
void win();
cursor(2);
setlinestyle(0,1,3); setcolor(9+cc/15);
line(a1*20+20,b1*20+60,a2*20+20,b2*20+60);
cursor(1);
win();
}
void win(void) /* 画出胜利者的棋子 */
{
cursor(2);
setfillstyle(1,7);
bar(349,90,401,111);
setfillstyle(1,15-cc); setcolor(15-cc);
circle(360,100,8);
floodfill(360,100,15-cc);
setcolor(10);
outtextxy(375,97,"Win");
cursor(1);
mysleep(1);
if (player == 1 && 15-cc == yc && level == 3 && example == 0) analyze();
want(1);
}

/* 以下为电脑思考的程式 */

void computer_estimate(void)
{
if (level == 1) /* 等级一的电脑的判断项目 */
{
if (com5(1)) return;
if (com5(2)) return;
if (com4(1)) return;
if (com4(2)) return;
if (com45(1)) return;
if (com3(1)) return;
if (com45(2)) return;
if (com3(2)) return;
com1();
}
if (level == 2) /* 等级二的电脑的判断项目 */
{
if (com5(1)) return;
if (com5(2)) return;
if (com4(1)) return;
if (com4(2)) return;
if (com121212(1,1,0,4,4,0)) return;
if (com45(1)) return;
if (com121212(2,2,0,4,4,0)) return;
if (com3(1)) return;
if (com45(2)) return;
if (com3(2)) return;
com1();
}
if (level == 3) /* 等级三的电脑的判断项目 */
{
if (frequency < 5) goto fs5;
if (conclude()) return;
if (com5(1)) return;
if (com5(2)) return;
if (com121212(1,1,1,24,24,4)) return;
if (com121212(1,1,1,24,24,3)) return;
if (com121212(1,1,2,24,24,4)) return;
if (com121212(1,1,2,24,24,3)) return;
if (com121212(1,1,0,24,24,0)) return;
if (com121212(1,1,1,24,4,4)) return;
if (com121212(1,1,1,24,4,3)) return;
if (com121212(1,1,2,24,4,4)) return;
if (com121212(1,1,2,24,4,3)) return;
if (com121212(1,1,0,24,4,0)) return;
if (com121212(1,1,1,24,3,3)) return;
if (com121212(1,1,2,24,3,4)) return;
if (com121212(1,1,2,24,3,3)) return;
if (com121212(1,1,0,24,3,0)) return;
if (com1011101(1)) return;
if (com4(1)) return;
if (com121212(1,1,1,4,4,4)) return;
if (com121212(1,1,1,4,4,3)) return;
if (com121212(1,1,2,4,4,4)) return;
if (com121212(1,1,2,4,4,3)) return;
if (com121212(1,1,0,4,4,0)) return;
if (com121212(1,1,1,4,3,3)) return;
if (com121212(1,1,2,4,3,4)) return;
if (com121212(1,1,2,4,3,3)) return;
if (com121212(1,1,0,4,3,0)) return;
if (com121212(2,1,1,24,4,4)) return;
if (com121212(2,1,1,24,4,3)) return;
if (com121212(1,2,2,24,4,4)) return;
if (com121212(1,2,2,24,4,3)) return;
if (com121212(1,2,0,24,4,0)) return;
if (com121212(1,2,2,24,3,4)) return;
if (com121212(1,2,2,24,3,3)) return;
if (com121212(1,2,0,24,3,0)) return;
if (com121212(2,1,2,24,4,4)) return;
if (com121212(2,1,2,24,4,3)) return;
if (com121212(2,1,0,24,4,0)) return;
if (com121212(2,2,1,24,24,4)) return;
if (com121212(2,2,1,24,24,3)) return;
if (com121212(2,2,2,24,24,4)) return;
if (com121212(2,2,2,24,24,3)) return;
if (com121212(2,2,0,24,24,0)) return;
if (com121212(2,1,1,24,3,4)) return;
if (com121212(2,1,1,24,3,3)) return;
if (com121212(2,1,2,24,3,4)) return;
if (com121212(2,1,2,24,3,3)) return;
if (com121212(2,1,0,24,3,0)) return;
if (com121212(2,2,1,24,3,4)) return;
if (com121212(2,2,2,24,3,4)) return;
if (com121212(2,2,2,24,3,3)) return;
if (com121212(2,2,0,24,3,0)) return;
if (com121212(1,2,2,4,4,4)) return;
if (com121212(1,2,2,4,4,3)) return;
if (com121212(1,2,2,4,3,3)) return;
if (com4(2)) return;
if (com121212(2,2,1,4,4,3)) return;
if (com121212(2,2,2,4,4,4)) return;
if (com121212(2,2,2,4,4,3)) return;
if (com121212(2,2,0,4,4,0)) return;
if (com121212(2,2,1,4,3,3)) return;
if (com121212(2,2,2,4,3,3)) return;
if (com121212(2,2,0,4,3,0)) return;
if (com1011101(2)) return;
if (com121212(1,1,1,3,3,3)) return;
if (com121212(1,1,2,3,3,4)) return;
if (com121212(1,1,2,3,3,3)) return;
if (com121212(1,1,0,3,3,0)) return;
if (com121212(1,2,0,4,4,0)) return;
if (com121212(1,2,0,4,3,0)) return;
if (com45(1)) return;
if (com121212(1,2,0,3,4,0)) return;
if (com121212(1,2,2,3,3,3)) return;
if (com121212(1,2,0,3,3,0)) return;
fs5: if (com3(1)) return;
if (com121212(2,2,2,3,3,3)) return;
if (com121212(2,2,0,3,3,0)) return;
if (com45(2)) return;
if (com3(2)) return;
com1();
}
}
void analyze(void)
{
FILE *fp;
char xmin = 14, ymin = 14, xmax = 0, ymax = 0;
int i;
for (i=0;i<frequency;i++)
{
if (enrollx < xmin) ..

访客只能看到部份内容,免费 加入会员 或由脸书 Google 可以看到全部内容



[ 此文章被达摩在2006-11-18 00:55重新编辑 ]



献花 x0 回到顶端 [楼 主] From:未知地址 | Posted:2006-11-18 00:44 |

首页  发表文章 发表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.069281 second(s),query:15 Gzip disabled
本站由 瀛睿律师事务所 担任常年法律顾问 | 免责声明 | 本网站已依台湾网站内容分级规定处理 | 连络我们 | 访客留言