真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

C程序三子棋-創(chuàng)新互聯(lián)

#ifndef_THREE_CHESS_H_
#define_THREE_CHESS_H_
#include 
#include 
#include 
#pragma warning(disable:4996)
#define ROW 3
#define COL 3
void ShowUI();//顯示
void Game();//游戲操作
void ComputerMove(char board[][COL], int row, int col);//電腦出琪
void ShowBoard(char board[][COL], int row, int col);//顯示棋盤
char Judge(char board[][COL], int row, int col);//判定
void PlayerMove(char board[][COL], int row, int col);//玩家出琪
#endif
#define  _CRT_SECURE_NO_WARNINGS 1
#include"three_chess.h"

int main()
{
    int select = 0;
    int quit = 0;
   while (!quit){
        ShowUI();
        scanf("%d", &select);
        switch (select){
        case 1:
            Game();
            break;
        case 2:
            quit = 1;
            printf("Bye,Bye!\n");
            break;
        default:
            printf("Please Enter Again!\n");
            break;
        }
    }

    system("pause");
    return 0;``
#define  _CRT_SECURE_NO_WARNINGS 1
#include "three_chess.h"

void ShowUI()
{
    printf("##################################\n");
    printf("## 1. Play              2. Exit ##\n");
    printf("##################################\n");
    printf("Please Select:> ");
}
void ComputerMove(char board[][COL], int row, int col)
{
   while (1){
        int x = rand() % row;//0 1 2
        int y = rand() % col;
        if (board[x][y] == ' '){
            board[x][y] = 'O';//如果有空格,電腦可以放棋子
            break;
        }
    }
}
void PlayerMove(char board[][COL], int row, int col)
{``
int x, y;
while (1){
    printf("Please Enter Your Pos(x,y):>  ");
    scanf("%d %d", &x, &y);
    if (x >= 1 && x <= row && y >= 1 && y <= col){//輸入1 2 3 
        if (board[x - 1][y - 1] == ' '){//對應(yīng)電腦上 0 1 2,空格處玩家放棋子
            board[x - 1][y - 1] = 'X';
            break;
        }
        else{
            printf("Enter Pos Is Not OK, Try Again!\n");//選的地方已被占據(jù)
        }
    }
    else{
        printf("Enter Error, Try Again!\n");
    }
}

}
char Judge(char board[][COL], int row, int col)
{
int i = 0;
int j = 0;
for (; i < row; i++){
if (board[i][0] == board[i][1] && board[i][1] == board[i][2] && \
board[i][0] != ' '){``
return board[i][0];
}
}
for (i = 0; i < col; i++){
if (board[0][i] == board[1][i] && board[1][i] == board[2][i] && \
board[0][i] != ' '){
return board[0][i];
}
}
if (board[0][0] == board[1][1] && board[1][1] == board[2][2] && \
board[1][1] != ' '){
return board[1][1];
}
if (board[0][2] == board[1][1] && board[1][1] == board[2][0] && \
board[1][1] != ' '){
return board[1][1];
}

成都創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司一直秉承“誠信做人,踏實(shí)做事”的原則,不欺瞞客戶,是我們最起碼的底線! 以服務(wù)為基礎(chǔ),以質(zhì)量求生存,以技術(shù)求發(fā)展,成交一個客戶多一個朋友!專注中小微企業(yè)官網(wǎng)定制,成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站,塑造企業(yè)網(wǎng)絡(luò)形象打造互聯(lián)網(wǎng)企業(yè)效應(yīng)。
for (i = 0; i < row; i++){
        for (j = 0; j < col; j++){
            if (board[i][j] == ' '){//仍有空格。繼續(xù)
                return 'N';
            }
        }
    }
    return 'E';//滿格
}
void ShowBoard(char board[][COL], int row, int col)
{
    printf("    1   2   3\n");
    printf("-----------------\n");
    int i = 0;
    int j = 0;
    for (; i < row; i++){
        printf("%d |", i + 1);
        for (j = 0; j < col; j++){
            printf(" %c |", board[i][j]);
        }
printf("\n-----------------\n");

}
printf("\n");
}
void Game()
{
    char board[ROW][COL];
    memset(board, ' ', sizeof(board)); 
    char result = 'N';
    srand((unsigned long)time(NULL));

   while (1){
        system("cls");//清屏
        ComputerMove(board, ROW, COL);
        ShowBoard(board, ROW, COL);
        result = Judge(board, ROW, COL);
        if (result != 'N'){//'X' 'O' 'E' 'N'
            break;
        }
        PlayerMove(board, ROW, COL);
        ShowBoard(board, ROW, COL);
        result = Judge(board, ROW, COL);
        if (result != 'N'){//'X' 'O' 'E' 'N'
            break;
        }
    }
    switch (result){
    case 'X':
        printf("You Win! :)\n");
        break;
    case 'O':
        printf("You Lose, Computer Win! :(\n");
        break;
    case 'E':
        printf("平局,恭喜!\n");
        break;
    default:
        break;
    }
}

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。


當(dāng)前標(biāo)題:C程序三子棋-創(chuàng)新互聯(lián)
標(biāo)題路徑:http://weahome.cn/article/ieghi.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部