本篇內(nèi)容主要講解“C語言實(shí)現(xiàn)的簡易撲克牌游戲代碼分享”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“C語言實(shí)現(xiàn)的簡易撲克牌游戲代碼分享”吧!
目前創(chuàng)新互聯(lián)已為數(shù)千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬主機(jī)、網(wǎng)站改版維護(hù)、企業(yè)網(wǎng)站設(shè)計(jì)、珙縣網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
將一副撲克牌平均分成兩份,每人拿一份。a先拿出手中的第一張撲克牌放在桌上,然后b也拿出手中的第一張撲克牌,并放在a剛打出的撲克牌的上面,就像這樣兩人交替出牌。出牌時(shí),如果某人打出的牌與桌上某張牌的牌面相同,即可將兩張相同的牌及其中間所夾的牌全部取走,并依次放到自己手中牌的末尾。當(dāng)任意一人手中的牌全部出完時(shí),游戲結(jié)束,對(duì)手獲勝。
以下是代碼的實(shí)現(xiàn):
#define _crt_secure_no_deprecate#include<stdio.h>#include<stdlib.h> struct queue//定義隊(duì)列的結(jié)構(gòu)體{ int data[1000]; int head; int tail;};struct stack//定義棧的結(jié)構(gòu)體{ int data[10]; int top;}; void poker(){ struct queue q1; struct queue q2; struct stack s; int arr[10]; int i, t; q1.head = 1; q1.tail = 1; q2.head = 1; q2.tail = 1; s.top = 0; for (i = 1; i <= 9; i++) { arr[i] = 0;//對(duì)數(shù)組進(jìn)行初始化,全部為0 } for (i = 1; i <= 6; i++) { scanf("%d", &q1.data[q1.tail]); q1.tail++; } for (i = 1; i <= 6; i++) { scanf("%d", &q2.data[q2.tail]); q2.tail++; } while (q1.head < q1.tail&&q2.head < q2.tail) { t = q1.data[q1.head]; if (arr[t] == 0) { q1.head++; s.top++; s.data[s.top] = t; arr[t] = 1; } else { q1.head++; q1.data[q1.tail] = t; q1.tail++; while (s.data[s.top] != t) { arr[s.data[s.top]] = 0; q1.data[q1.tail] = s.data[s.top]; q1.tail++; s.top--; } } t = q2.data[q2.head]; if (arr[t] == 0) { q2.head++; s.top++; s.data[s.top] = t; arr[t] = 1; } else { q2.head++; q2.data[q2.tail] = t; q2.tail++; while (s.data[s.top] != t) { arr[s.data[s.top]] = 0; q2.data[q2.tail] = s.data[s.top]; q2.tail++; s.top--; } } } if (q2.head == q2.tail) { printf("a贏\n"); printf("a當(dāng)前手中的牌是:"); for (i = q1.head; i <= q1.tail - 1; i++) { printf(" %d", q1.data[i]); } if (s.top > 0) { printf("\n桌上的牌是:"); for (i = 1; i <= s.top; i++) { printf(" %d", s.data[i]); } printf("\n"); } else { printf("\n桌上已經(jīng)沒有牌了"); } } else { printf("b贏\n"); printf("b當(dāng)前手中的牌是:"); for (i = q2.head; i <= q2.tail - 1; i++) { printf(" %d", q2.data[i]); } if (s.top > 0) { printf("\n桌上的牌是:"); for (i = 1; i <= s.top; i++) { printf(" %d", s.data[i]); } printf("\n"); } else { printf("\n桌上已經(jīng)沒有牌了"); } }}int main(){ poker(); system("pause"); return 0;}
到此,相信大家對(duì)“C語言實(shí)現(xiàn)的簡易撲克牌游戲代碼分享”有了更深的了解,不妨來實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
分享文章:C語言實(shí)現(xiàn)的簡易撲克牌游戲代碼分享
標(biāo)題來源:http://m.kartarina.com/article4/jedioe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、面包屑導(dǎo)航、搜索引擎優(yōu)化、網(wǎng)站維護(hù)、品牌網(wǎng)站制作、云服務(wù)器
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)