纸牌游戏(数据结构 VC++)
一、纸牌游戏(数据结构 VC++)
#include iostream.h
#include stdlib.h
#define OK 1
#define ERROR 0
#define LIST_INIT_SIZE 100 //线性表存储空间的初始分配量
#define LISTINCREMENT 10 //线性表存储空间的分配增量
typedef int Status;
typedef int ElemType;
typedef struct{
ElemType *elem; //存储空间基址
int *data;
int length; //当前长度
int listsize; //当前分配的存储容量
}SqList;
Status InitList_Sq(SqList &L) {
// 算法2.3
// 构造一个空的线性表L。
L.elem = (ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if (!L.elem) return OK; // 存储分配失败
L.data = (int *)malloc(LIST_INIT_SIZE*sizeof(int));
if (!L.data) return OK; // 存储分配失败
L.length = 0; // 空表长度为0
L.listsize = LIST_INIT_SIZE; // 初始存储容量
return OK;
} // InitList_Sq
Status ListPrint_Sq(SqList L) { // 补充算法
//显示线性表中所有数据
for(int i=1;i<=L.length;i++)
{ if (L.data[i]==1) cout<<< ;} cout< return OK; } void zm (SqList L) { for (int i=1;i<=L.length;i++) L.data[i]=1; } void wn (SqList L,int n) { for (int i=2;i<=n;i++) for (int j=i;j<=L.length;j++) if (j%i==0){ if (L.data[j]==1) L.data[j]=0; else if (L.data[j]==0) L.data[j]=1; } } void main() { SqList L; int n=52; InitList_Sq(L); for(int i=1;i<=n;i++) { L.elem[i]=i; L.length++; } zm (L); cout<<牌的编号依次是:; ListPrint_Sq(L); cout<<正面向上的牌的编号是:< wn (L,n); ListPrint_Sq(L); }
二、微软WIN10纸牌游戏4月4日TriPeaks每日挑战专家级难度解答
目前只有电脑
如果需要,可电脑管家帮助升级的
电脑管家已在升级Windows 10版本中为用户打好全部补丁包。这意味着一旦装好Windows 10就不用检查还有什么驱动需要补装或者重装。过去,显卡、声卡等驱动在升级新系统后往往容易出现兼容性问题,现在通过电脑管家升级Windows 10就能解决得干干净净,用户不用再担心驱动“抽风”了。现在,用户还可以借助于电脑管家软件管理的云后台进行软件的备份和还原,无需惦记于新系统安装后逐一重装软件
三、扑克游戏:比大小 c++程序设计
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<windows.h>
int sum = 0;
int pc_win = 0;
int man_win = 0;
void swap(int a[],int m,int n,char s[] ){ //交换两个牌(用于洗牌)
int c = a[m];
a[m] = a[n];
a[n]= c;
char d = s[m];
s[m] = s[n];
s[n]= d;
}
void xipai(int a[],int n,char s[]){ //洗牌
int i =1,j = 1;
for(i = 0;i < n;i ++){
do{
j = rand()%52;
}while( j == i);
swap(a,i,j,s);
}
}
void fapai(int a[],int b[],int c[],char s[],char ps[],char ms[]){ //发牌
int i = 0,m = 25,n = 25;
for(i = 0;i < 52;i++){
if(i % 2) {
b[m] = a[i];
ps[m--] = s[i];
}
else {
ms[n] = s[i];
c[n--] = a[i];
}
}
}
void play(int b[],int c[],char* m[],char ps[],char ms[]){//游戏开始 int a1 = 0 ,a2 = 0;
int i = 0;
for( ;i < 26;i++){
if(b[i] == c[i])
printf(电脑出的牌是%c %s,\t你出的牌是%c %s,\t平了\n,ps[i],m[b[i]],ms[i],m[c[i]]);
else if(b[i] > c[i]){
a1++;
printf(电脑出的牌是%c %s,\t你出的牌是%c %s,\t电脑大\n, ps[i],m[b[i]],ms[i],m[c[i]]);
}else{
a2++;
printf(电脑出的牌是%c %s,\t你出的牌是%c %s,\t你大\n, ps[i],m[b[i]],ms[i],m[c[i]]);
}
Sleep(300);
}
sum ++;
if (a1 == a2)
printf(\n\n平局了\n);
if (a1 > a2){
pc_win ++;
printf(\n\n可惜你输了\n);
}
if(a1 < a2){
man_win ++;
printf(\n\n恭喜你赢了\n);
}
}
void show(int a[],char* m[],char ms[]){
int i = 0;
printf(你有的牌和顺序是:\n);
for (i = 0;i < 26; i++)
printf(%c%s|,ms[i],m[a[i]]);
printf(\n);
}
void showscore (){
if(sum == 0){
printf(还没比呢,着什么急啊);
return;
}
printf(现在的大比分是:%d:%d,man_win,pc_win);
if(man_win > pc_win)
printf(你领先呢,恭喜\n);
else if(man_win < pc_win)
printf(你落后呢,加油\n);
else if(man_win == pc_win)
printf(战局很焦灼,再接再厉\n);
}
void start(int a[],int b[],int c[],char* m[],char s[],char ps[],char ms[]){
char i = 0;
srand((unsigned int)time(0));
printf(欢迎来到比大小游戏中,请选择:\n1、开始游戏 2、显示比分 3、退出游戏 \n);
while(i = getch()){
switch(i){
case '1':
xipai(a,52,s);
fapai(a,b,c,s,ps,ms);
show(c,m,ms);
play(b,c,m,ps,ms);
break;
case '2':
showscore();
break;
case '3':
return;
}
printf(\n欢迎来到比大小游戏中,请选择:\n1、开始游戏 2、显示比分 3、退出游戏 \n);
}
}
int main(){
int a[60] = {0},pc[30] = {0},man[30] = {0};
char s[60] = {0},pc_s[30] = {0},man_s[30] = {0};
char* m[14] = {0,1,2,3,4,5,6,7,8,9,10,J,Q,K};
int i;
for(i = 0;i < 13;i ++){
s[i] = 3;
s[i+13] = 4;
s[i + 26] =5;
s[i+39] = 6;
a[i] = a[i +13] =a[i+26] = a[i + 39] = i+1;
}
start(a,pc,man,m,s,pc_s,man_s);
printf(欢迎再次来玩本游戏);
return 0;
}