C語言實現三子棋和猜數字遊戲

2021-10-10 03:05:46 字數 3401 閱讀 8160

實現的思路如下:

#ifndef _game_h_

#define _game_h_

#include

#include

#include

#include

#define correct_id "bit"

#define correct_passward "bits"

#define opportunity 3

#define col 3

#define row 3

#pragma warning(disable:4996)

void

shownumbermenu()

;//顯示猜數字遊戲的選單

void

gamenumber()

;//猜數字遊戲函式

intloginnumber()

;//登陸函式

void

showgamemenu()

;//顯示遊戲選擇選單

void

showchessmenu()

;//顯示三子棋選單

void

gamechess()

;//三子棋遊戲函式

#endif

在標頭檔案中寫了全部的標頭檔案呼叫,以及函式的宣告。

#include

"game.h"

void

showgamemenu()

intloginnumber()

else

}return0;

}void

shownumbermenu()

void

gamenumber()

else

if(your_num < random_number)

else}}

void

showboard

(char chessboard[

][col]

,int row,

int col)

printf

("\n---------------\n");

}}void

playergo

(char chessboard[

][col]

,int row,

int col)

else}}

char

judge

(char chessboard[

][col]

,int row,

int col)

}for

(int i =

0; i < col; i++)}

if(chessboard[0]

[0]== chessboard[1]

[1]&&\

chessboard[1]

[1]== chessboard[2]

[2]&&\

chessboard[0]

[0]!=

' ')

if(chessboard[0]

[2]== chessboard[1]

[1]&&\

chessboard[1]

[1]== chessboard[2]

[0]&&\

chessboard[0]

[2]!=

' ')

for(

int i =

0; i < row; i++)}

}if(null)

return

'p';

//平局

}void

computergo

(char chessboard[

][col]

,int row,

int col)}}

void

showchessmenu()

intporc()

elseif(

!(strcmp

(scissors, p)))

elseif(

!(strcmp

(cloth, p)))

else}if

(_p > _c)

else

if(_p < _c)

else

}void

gamechess()

else

//showboard(chessboard, row, col);

win =

judge

(chessboard, row, col)

;//reurn 'x' player win; return 'o' computer win; return 'p' 平局; return 'n' 繼續

if(win !=

'n')

return;}

if(who)

else

win =

judge

(chessboard, row, col);if

(win !=

'n')

return;}

}}

#include

"game.h"

intmain()

shownumbermenu()

;printf

("please enter your select# ");

scanf

("%d"

,&numberselect)

;while(1

)printf

("do you want to play again?\n");

shownumbermenu()

;printf

("please enter your select# ");

scanf

("%d"

,&numberselect);if

(numberselect ==2)

}}}break

;case2:

//三子棋遊戲

while

(!chessquit)

}break

;case3:

//退出

printf

("quit successful!\n");

quit =1;

break

;default:/

/輸入不合法

printf

("selectgame error,please enter again!");

break;}

}return0;

}

本文沒有過多的文字描述,只是單純的源**

作者部落格:

三子棋遊戲(c語言實現)

一說到寫個三子棋遊戲,首先我們得想到有個棋盤初始化和棋盤列印函式。接下來,玩遊戲階段,人玩遊戲,電腦玩遊戲,各寫乙個函式,每次下完棋都得判斷有沒有人贏了遊戲,若有人贏了,遊戲退出,否則繼續遊戲。在這過程中,還有可能棋盤滿 了,所以寫個判斷棋盤是否滿的的函式,棋盤滿了,程式結束,沒人贏,此時就平局。當...

C語言實現三子棋遊戲

三子棋是乙個簡單的人機對戰遊戲在3 3的棋盤上,只要有一方下的子連成一條直線則顯示遊戲獲勝,遊戲結束。例如 想要用c語言編寫三子棋其實不難,主要把程式設計的思想順利清楚就很容易實現了。編寫三子棋遊戲我們可以先建立乙個 game.h檔案作為標頭檔案,用來宣告函式和定義一些常亮,在定義乙個game.c檔...

C語言實現三子棋遊戲

先看一下最終效果 void chess board char arr row col int row,int col 初始化棋盤 void mimeograph char arr row col int row,int col 列印棋盤 void player char arr row col in...