廣告廣告
  加入我的最愛 設為首頁 風格修改
首頁 首尾
 手機版   訂閱   地圖  簡體 
您是第 5401 個閱讀者
04:00 ~ 4:30 資料庫備份中,需等較久的時間,請耐心等候
 
發表文章 發表投票 回覆文章
  可列印版   加為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.097023 second(s),query:15 Gzip disabled
本站由 瀛睿律師事務所 擔任常年法律顧問 | 免責聲明 | 本網站已依台灣網站內容分級規定處理 | 連絡我們 | 訪客留言