python五子棋代码_python五子棋代码简单
C语言/C++求五子棋的程序代码和流程图还有模块设计,求求求,三者都要有~~~求大神帮忙。
int attr numericModifiers 0x7f0400ab#include
python五子棋代码_python五子棋代码简单
python五子棋代码_python五子棋代码简单
#include
#include
#include
#include
#define TEXTS 7
#define CURSOR 48
#define CHESSBOARD 352
#define WHITECHESS 103
#define SELECTEDWHITE 55
#define BLACKCHESS 96
#define SELECTEDBLACK 48
#define qx1_num 27
#define qx2_num 26
typedef struct node
{int step;
} NODE;
typedef struct point
{int x;
int y;
}_POINT;
typedef struct qixing
int value;
}QIXING;
HANDLE hOutput=GetStdHandle(STD_OUTPUT_HANDLE);
_POINT cursor;
int direction[8][2]={{0,-1},{0,1},{-1,0},{1,0},{-1,-1},{1,1},{-1,1},{1,-1}};
QIXING qx1[qx1_num]={{"x1111",200000},{"1x111",200000},{"11x11",200000},{"0x1110",6000},{"01x110",6000},{"101x101",6000},
{"0x111",1100},{"x0111",1100},{"0x1011",1100},{"0x1101",1100},{"01x11",1100},
{"011x1",1100},{"1x011",1100},{"10x11",1100},{"11x01",1100},{"1x101",1100},
{"x011102",},{"0x110",},{"01x10",},{"0x01102",240},{"0x101",240},
{"0x112",20},{"01x12",10},{"011x2",20},{"1x12",10},{"0x10",20},{"0x010",5}};
QIXING qx2[qx2_num]={{"x1111",2000000},{"1x111",2000000},{"11x11",2000000},{"0x1110",24000},{"01x110",24000},{"101x101",24000},
{"0x111",2000},{"x0111",1900},{"0x1011",1900},{"0x1101",2000},{"01x11",2000},
{"011x1",2000},{"1x011",1900},{"10x11",2000},{"1x101",2000},{"x01112",2000},
{"0x110",850},{"01x10",850},{"0x0110",840},{"0x101",840},
{"0x112",125},{"01x12",125},{"011x2",115},{"1x12",115},{"0x10",125},{"0x010",110}};
//------------------------------------------------------------------------------------------------------
void textcolor(int color)
{SetConsoleTextAttribute(hOutput, color);
}void gotoxy(int x, int y)
{COORD coordScreen={0,0};
coordScreen.X=x;
coordScreen.Y=y;
SetConsoleCursorPosition(hOutput,coordScreen);
}void printnode(NODE chesoard[][15], int x, int y)
{textcolor(CHESSBOARD);
if(chesoard[x][y].step==0)
{if(x==cursor.x&&y==cursor.y)
textcolor(CURSOR);
switch(x)
{case 0:
if(y==0)printf("┏");
else if(y==14)printf("┓");
else printf("┳");
break;
case 3:
if(y==0)printf("┣");
else if(y==3||y==11)printf("╬");
else if(y==14)printf("┫");
else printf("╋");
break;
case 7:
if(y==0)printf("┣");
else if(y==7)printf("╬");
else if(y==14)printf("┫");
else printf("╋");
break;
case 11:
if(y==0)printf("┣");
else if(y==3||y==11)printf("╬");
else if(y==14)printf("┫");
else printf("╋");
break;
case 14:
if(y==0)printf("┗");
else if(y==14)printf("┛");
break;
default:
if(y==0)printf("┣");
else if(y==14)printf("┫");
else printf("╋");
else if(chesoard[x][y].color==0)
{if(x==cursor.x&&y==cursor.y)
textcolor(SELECTEDWHITE);
else textcolor(WHITECHESS);
{if(x==cursor.x&&y==cursor.y)
textcolor(SELECTEDBLACK);
else textcolor(BLACKCHESS);
void printchesoard(NODE chesoard[][15])
{int i,j;
char letter[]={" A B C D E F G H I J K L M N On"};
for(i=0;i<15;i++)
{textcolor(TEXTS);
printf(img_b.src = "images/b.png";//白棋"%2d",15-i);
for(j=0;j<15;j++)
printnode(chesoard,i,j);
textcolor(TEXTS);
printf("n");
}textcolor(TEXTS);
printf("%s",letter);
printf("移动:方向键 下棋:ENTER 悔棋:U 退出:F12");
}void renew(NODE chesoard[][15],int x,int y)
{COORD coordScreen;
CONSOLE_SCREEN_BUFFER_INFO ci;
if(x<0||x>14||y<0||y>14)
return;
if(!GetConsoleScreenBufferInfo(hOutput,&ci))
return;
coordScreen=ci.dwCursorPosition;
gotoxy((y-1)2+4,x+1);
printnode(chesoard,x,y);
SetConsoleCursorPosition(hOutput,coordScreen);
}void showmenu()
{textcolor(TEXTS);
("cls");
printf("1.人机对战n2.双人对战n3.退出nn请选择[1~3]:");
}void showsubmenu()
{textcolor(TEXTS);
("cls");
}int getchoose(int min, int max)
{int choose;
do
{choose=getch()-48;
}while(choose
printf("%d",choose);
return choose;
}//-------------------------------------------------------------------------------------------------
bool quit;
bool regret;
bool getmove(NODE chesoard[][15])
for(;;)
{c=getch();
if(c==-32)
switch(getch())
{case 72:
if(cursor.x<0)cursor.x=0;
renew(chesoard,cursor.x+1,cursor.y);
renew(chesoard,cursor.x,cursor.y);
break;
case 80:
cursor.x++;
if(cursor.x>14)
cursor.x=14;
renew(chesoard,cursor.x-1,cursor.y);
renew(chesoard,cursor.x,cursor.y);
break;
case 75:
cursor.y--;
if(cursor.y<0)cursor.y=0;
renew(chesoard,cursor.x,cursor.y+1);
renew(chesoard,cursor.x,cursor.y);
break;
case 77:
cursor.y++;
if(cursor.y>14)cursor.y=14;
renew(chesoard,cursor.x,cursor.y-1);
renew(chesoard,cursor.x,cursor.y);
break;
case 134:
quit=true;
return true;
}else if(c==13&&chesoard[cursor.x][cursor.y].step==0)
return true;
else if(c=='U'||c=='u')
return true;
}void beback(NODE chesoard[][15], int step)
if(step==1)return;
if(step>2)
for(j=0;j<15;j++)
{if(chesoard[i][j].step==step-1)
renew(chesoard,i,j);
}else if(chesoard[i][j].step==step-2)
tempx=cursor.x;
tempy=cursor.y;
cursor.x=i;
cursor.y=j;
renew(chesoard,i,j);
renew(chesoard,tempx,tempy);
}else if(step==2)
for(j=0;j<15;j++)
if(chesoard[i][j].step==step-1)
renew(chesoard,i,j);
}tempx=cursor.x;
tempy=cursor.y;
cursor.x=7;
cursor.y=7;
renew(chesoard,i,j);
renew(chesoard,tempx,tempy);
//-----------------------------------------------------------------------------------------
bool inside(int x,int y)
{if(x<0||x>14||y<0||y>14)return false;
return true;
}int line(NODE chesoard[][15],int dirt,int x,int y,int color)
{int i;
for(i=0;chesoard[x+direction[dirt][0]][y+direction[dirt][1]].step>0&&
chesoard[x+direction[dirt][0]][y+direction[dirt][1]].color==color;i++)
{x=x+direction[dirt][0];
y=y+direction[dirt][1];
if(!inside(x,y))return i;
}return i;
}bool win(NODE chesoard[][15],int x,int y,int color)
{if(line(chesoard,0,x,y,color)+line(chesoard,1,x,y,color)>3)
return true;
if(line(chesoard,2,x,y,color)+line(chesoard,3,x,y,color)>3)
return true;
if(line(chesoard,4,x,y,color)+line(chesoard,5,x,y,color)>3)
return true;
if(line(chesoard,6,x,y,color)+line(chesoard,7,x,y,color)>3)
return true;
return false;
}//----------------------------------------------------------------------------------------------
int attacktrend,defenttrend;
bool macth1(NODE chesoard[][15],int x,int y,int dirt,int kind,int color)
{int k;
char c;
char p;
p=strchr(qx1[kind].qx,'x');
for(k=0;k<=p-qx1[kind].qx;k++)
{x-=direction[dirt][0];
y-=direction[dirt][1];
}for(k=0;(unsigned)k {x+=direction[dirt][0]; y+=direction[dirt][1]; if(!inside(x,y))return(false); if(chesoard[x][y].step>0&&chesoard[x][y].color==color)c='2'; else if(chesoard[x][y].step>0)c='1'; else c='0'; if(c=='0'&&qx1[kind].qx[k]=='x')continue; if(c!=qx1[kind].qx[k])return(false); }return true; }int value_qx1(NODE chesoard[][15],int x,int y,int dirt, int color) {int i; for(i=0;i if(macth1(chesoard,x,y,dirt,i,color)) return qx1[i].value; return 0; }bool macth2(NODE chesoard[][15],int x,int y,int dirt, int kind,int color) {int k; char c; char p; p=strchr(qx2[kind].qx,'x'); for(k=0;k<=p-qx2[kind].qx;k++) {x-=direction[dirt][0]; y-=direction[dirt][1]; }for(k=0;(unsigned)k {x+=direction[dirt][0]; y+=direction[dirt][1]; if(!inside(x,y))return false; if(chesoard[x][y].step>0&&chesoard[x][y].color==color)c='2'; else if(chesoard[x][y].step>0)c='1'; else c='0'; if(c=='0'&&qx2[kind].qx[k]=='x')continue; if(c!=qx2[kind].qx[k])return(false); }return true; }int value_qx2(NODE chesoard[][15],int x,int y,int dirt, int color) {int i; for(i=0;i if(macth2(chesoard,x,y,dirt,i,color)) return qx2[i].value; return 0; }void AI(NODE chesoard[][15], int x,int y,int color) {int max=0; int maxi,maxj; int i,j,k; int probability=1; int value[15][15]={0}; int valueattack[15][15]={{0}}; int valuedefent[15][15]={{0}}; for(i=0;i<15;i++) for(j=0;j<15;j++) {if(chesoard[i][j].step>0)continue; for(k=0;k<8;k++) valuedefent[i][j]+=value_qx1(chesoard,i,j,k,color); if(maxi maxi=valuedefent[i][j]; }for(i=0;i<15;i++) for(j=0;j<15;j++) {if(chesoard[i][j].step>0)continue; for(k=0;k<8;k++) valueattack[i][j]+=value_qx2(chesoard,i,j,k,color); if(maxj maxj=valuedefent[i][j]; }if(rand()%(maxi+maxj+1)>maxi) {attacktrend=1; defenttrend=1; {attacktrend=1; defenttrend=2; }for(i=0;i<15;i++) for(j=0;j<15;j++) {value[i][j]=valuedefent[i][j]defenttrend+valueattack[i][j]attacktrend; if(max {max=value[i][j]; maxi=i; probability=1; }else if(max==value[i][j]) {if(rand()%(probability+1) probability++; else {probability=1; max=value[i][j]; maxi=i; }x=maxi; y=maxj; }//------------------------------------------------------------------------------------------------- bool vshuman; void Vs(bool human) {int i,j; int color=1; int lastx,lasty; int comr; NODE chesoard[15][15]={{0,0}}; if(!human) {showsubmenu(); switch(getchoose(1,3)) {case 1: comr=0; attacktrend=1; defenttrend=1; break; case 2: comr=1}}; attacktrend=1; defenttrend=2; break; case 3:return; for(i=0;i<15;i++) for(j=0;j<15;j++) chesoard[i][j].step=0; cursor.x=7; cursor.y=7; quit=false; ("cls"); printf("n"); printchesoard(chesoard); for(i=1;i<=225;) {gotoxy(0,0); textcolor(TEXTS); printf(" 第%03d手, ",i); if(color==1)printf("黑棋下"); else printf("白棋下"); regret=false; if(i>1) {if(color!=comr||human)getmove(chesoard); else {lastx=cursor.x; lasty=cursor.y; AI(chesoard,&cursor.x,&cursor.y,color); renew(chesoard,lastx,lasty); if(quit)return; if(regret) {beback(chesoard,i); if(i>2)i-=2; else if(i==2) {i=1; color=(color+1)%2; else {chesoard[cursor.x][cursor.y].step=i++; chesoard[cursor.x][cursor.y].color=color; renew(chesoard,cursor.x,cursor.y); color=(color+1)%2; }if(win(chesoard,cursor.x,cursor.y,(color+1)%2)&&!regret) {textcolor(TEXTS); gotoxy(0,0); printf(" "); gotoxy(0,0); if(color==1)printf(" 白棋赢了!"); else printf(" 黑棋赢了!"); getch(); return; gotoxy(0,0); printf(" "); gotoxy(0,0); printf(" 平局!"); }int main() {srand((unsigned)time(NULL)); for(;;) {showmenu(); switch(getchoose(1,3)) {case 1:Vs(false);break; case 2:Vs(true);break; case 3:printf("n");return 0; return 0; } 我也正在写,流程图这不好发,还是自己写比较好,思路和关键点的话,你如果需要,我可以给你 以下是贪吃蛇源代码: #include #include #include #include #include #define N 21 void gotoxy(int x,int y)//位置函数 {COORD ; .X=2x; .Y=y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),); }void color(int a)//颜色函数 {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a); }void init(int apple[2])//初始化函数(初始化围墙、显示信息、苹果) {int i,j;//初始化围墙 int wall[N+2][N+2]={{0}}; for(i=1;i<=N;i++) {for(j=1;j<=N;j++) wall[i][j]=1; }color(11); for(i=0;i {for(j=0;j {if(wall[i][j]) cout<<"■"; else cout<<"□" ; }cout< }gotoxy(N+3,1);//显示信息 cout<<"按 W S A D 移动方向"< gotoxy(N+3,2); cout<<"按任意键暂停"< gotoxy(N+3,3); apple[0]=rand()%N+1;//苹果 apple[1]=rand()%N+1; gotoxy(apple[0],apple[1]); color(12); cout<<"●"< }int main() {int i,j; int snake=NULL; int apple[2]; int score=0; int tail[2]; int len=3; char ch='p'; srand((unsigned)time(NULL)); init(apple); snake=(int)realloc(snake,sizeof(int)len); for(i=0;i snake[i]=(int)malloc(sizeof(int)2); for(i=0;i {snake[i][0]=N/2; snake[i][1]=N/2+i; gotoxy(snake[i][0],snake[i][1]); color(14); cout<<"★"< }while(1)//进入消息循环 {tail[0]=snake[len-1][0]; tail[1]=snake[len-1][1]; gotoxy(tail[0],tail[1]); color(11); cout<<"■"< for(i=len-1;i>0;i--) {snake[i][0]=snake[i-1][0]; snake[i][1]=snake[i-1][1]; gotoxy(snake[i][0],snake[i][1]); color(14); cout<<"★"< }if(kbhit()) {gotoxy(0,N+2); ch=getche(); }switch(ch) {case 'w':snake[0][1]--;break; case 'a':snake[0][0]--;break; case 'd':snake[0][0]++;break; default: break; }gotoxy(snake[0][0],snake[0][1]); color(14); cout<<"★"< Sleep(abs(200-0.5score)); if(snake[0][0]==apple[0]&&snake[0][1]==apple[1])//吃掉苹果后蛇分数加1,蛇长加1 {score++; len++; snake=(int)realloc(snake,sizeof(int)len); snake[len-1]=(int)malloc(sizeof(int)2); apple[0]=rand()%N+1; apple[1]=rand()%N+1; gotoxy(apple[0],apple[1]); color(12); cout<<"●"< gotoxy(N+5,3); cout< }if(snake[0][1]==0||snake[0][1]==N||snake[0][0]==0||snake[0][0]==N)//撞到围墙后失败 {gotoxy(N/2,N/2); color(30); cout<<"失败!!!"< for(i=0;i free(snake[i]); Sleep(INFINITE); exit(0); return 0; }参考资料:从C++吧看来的 像素射击:int anim abc_fade_in 0x7f010001 int anim abc_fade_out 0x7f010002 int anim abc_grow_fade_in_from_bottom 0x7f010003 int anim abc_popup_enter 0x7f010004 int anim abc_popup_exit 0x7f010005 int anim abc_shrink_fade_out_from_bottom 0x7f010006 int anim abc_slide_in_bottom 0x7f010007 int anim abc_slide_in_top 0x7f010008 int anim abc_slide_out_bottom 0x7f010009 int anim abc_slide_out_top 0x7f01000a int anim abc_tooltip_enter 0x7f01000b int anim abc_tooltip_exit 0x7f01000c int attr actionBarDivider 0x7f040001 int attr actionBarItemBackground 0x7f040002 int attr actionBarPopupTheme 0x7f040003 int attr actionBarSize 0x7f040004 int attr actionBarSplitStyle 0x7f040005 int attr actionBarStyle 0x7f040006 int attr actionBarTabBarStyle 0x7f040007 int attr actionBarTabStyle 0x7f040008 int attr actionBarTabTextStyle 0x7f040009 int attr actionBarTheme 0x7f04000a int attr actionButtonStyle 0x7f04000c int attr actionDropDownStyle 0x7f04000d int attr actionLayout 0x7f04000e int attr actionMenuTextAppearance 0x7f04000f int attr actionMenuTextColor 0x7f040010 int attr actionModeBackground 0x7f040011 int attr actionModeCloseButtonStyle 0x7f040012 int attr actionModeCloseDrawable 0x7f040013 int attr actionModeCopyDrawable 0x7f040014 int attr actionModeCutDrawable 0x7f040015 int attr actionModeFindDrawable 0x7f040016 int attr actionModePasteDrawable 0x7f040017 int attr actionModePopupWindowStyle 0x7f040018 int attr actionModeSelectAllDrawable 0x7f040019 int attr actionModeShareDrawable 0x7f04001a int attr actionModeSplitBackground 0x7f04001b int attr actionModeStyle 0x7f04001c int attr actionModeWebSearchDrawable 0x7f04001d int attr actionOverflowButtonStyle 0x7f04001e int attr actionOverflowMenuStyle 0x7f04001f int attr actionProviderClass 0x7f040020 int attr actionViewClass 0x7f040021 int attr activityChooserViewStyle 0x7f040022 int attr alertDialogButtonGroupStyle 0x7f040023 int attr alertDialogCenterButtons 0x7f040024 int attr alertDialogStyle 0x7f040025 int attr alertDialogTheme 0x7f040026 int attr allowStacking 0x7f040027 int attr alpha 0x7f040028 int attr alphabeticModifiers 0x7f040029 int attr arrowHeadLength 0x7f04002a int attr arrowShaftLength 0x7f04002b int attr autoCompleteTextViewStyle 0x7f04002c int attr autoSizeMaxTextSize 0x7f04002d int attr autoSizeMinTextSize 0x7f04002e int attr autoSizePresetSizes 0x7f04002f int attr autoSizeStepGranularity 0x7f040030 int attr autoSizeTextType 0x7f040031 int attr background 0x7f040032 int attr backgroundSplit 0x7f040033 int attr backgroundStacked 0x7f040034 int attr backgroundTint 0x7f040035 int attr backgroundTintMode 0x7f040036 int attr barLength 0x7f040037 int attr borderlessButtonStyle 0x7f040038 int attr buttonBarButtonStyle 0x7f040039 int attr buttonBarNegativeButtonStyle 0x7f04003a int attr buttonBarNeutralButtonStyle 0x7f04003b int attr buttonBarPositiveButtonStyle 0x7f04003c int attr buttonBarStyle 0x7f04003d int attr buttonGrity 0x7f04003e int attr buttonIconDimen 0x7f04003f int attr buttonPanelSideLayout 0x7f040040 int attr buttonStyle 0x7f040041 int attr buttonStyleSmall 0x7f040042 int attr buttonTint 0x7f040043 int attr buttonTintMode 0x7f040044 int a{char qx[8];ttr checkboxStyle 0x7f040045 int attr checkedTextViewStyle 0x7f040046 int attr closeIcon 0x7f040047 int attr closeItemLayout 0x7f040048 int attr collapseContentDescription 0x7f040049 int attr collapseIcon 0x7f04004a int attr color 0x7f04004b int attr colorAccent 0x7f04004c int attr colorBackgroundFloating 0x7f04004d int attr colorButtonNormal 0x7f04004e int attr colorControlActivated 0x7f04004f int attr colorControlHighlight 0x7f040050 int attr colorControlNormal 0x7f040051 int attr colorError 0x7f040052 int attr colorPrimary 0x7f040053 int attr colorPrimaryDark 0x7f040054 int attr colorSwitchThumbNormal 0x7f040055 int attr commitIcon 0x7f040056 int attr contentDescription 0x7f040057 int attr contentInsetEnd 0x7f040058 int attr contentInsetEndWithActions 0x7f040059 int attr contentInsetLeft 0x7f04005a int attr contentInsetStart 0x7f04005c int attr contentInsetStartWithNigation 0x7f04005d int attr controlBackground 0x7f04005e int attr coordinatorLayoutStyle 0x7f04005f int attr customNigationLayout 0x7f040060 int attr defaultQueryHint 0x7f040061 int attr dialogCornerRadius 0x7f040062 int attr dialogPreferredPadding 0x7f040063 int attr dialogTheme 0x7f040064 int attr displayOptions 0x7f040065 int attr divider 0x7f040066 int attr dividerHorizontal 0x7f040067 int attr dividerPadding 0x7f040068 int attr dividerVertical 0x7f040069 int attr drawableSize 0x7f04006a int attr drawerArrowStyle 0x7f04006b int attr dropDownListViewStyle 0x7f04006c int attr dropdownListPreferredItemHeight 0x7f04006d int attr editTextBackground 0x7f04006e int attr editTextColor 0x7f04006f int attr editTextStyle 0x7f040070 int attr elevation 0x7f040071 int attr expandActivityOverflowButtonDrawable 0x7f040072 int attr firstBaselineToTopHeight 0x7f040073 int attr font 0x7f040074 int attr fontFamily 0x7f040075 int attr fontProviderAuthority 0x7f040076 int attr fontProviderCerts 0x7f040077 int attr fontProviderFetchStrategy 0x7f040078 int attr fontProviderFetchTimeout 0x7f040079 int attr fontProviderPackage 0x7f04007a int attr fontProviderQuery 0x7f04007b int attr fontStyle 0x7f04007c int attr fontVariationSettings 0x7f04007d int attr fontWeight 0x7f04007e int attr gapBetweenBars 0x7f04007f int attr goIcon 0x7f040080 int attr height 0x7f040081 int attr hideOnContentScroll 0x7f040082 int attr homeAsUpIndicator 0x7f040083 int attr homeLayout 0x7f040084 int attr icon 0x7f040085 int attr iconTint 0x7f040086 int attr iconTintMode 0x7f040087 int attr iconifiedByDefault 0x7f040088 int attr imageButtonStyle 0x7f040089 int attr indeterminateProgressStyle 0x7f04008a int attr initialActivityCount 0x7f04008b int attr isLightTheme 0x7f04008c int attr Padding 0x7f04008d int attr keylines 0x7f04008e int attr lastBaselineToBottomHeight 0x7f04008f int attr layout 0x7f040090 int attr layout_anchor 0x7f0400 int attr layout_anchorGrity 0x7f040092 int attr layout_behior 0x7f040093 int attr layout_insetEdge 0x7f040095 int attr layout_keyline 0x7f040096 int attr lineHeight 0x7f040097 int attr listChoBackgroundIndicator 0x7f040098 int attr listDividerAlertDialog 0x7f040099 int attr listItemLayout 0x7f04009a int attr listLayout 0x7f04009b int attr listMenuViewStyle 0x7f04009c int attr listPopupWindowStyle 0x7f04009d int attr listPreferredItemHeight 0x7f04009e int attr listPreferredItemHeightLarge 0x7f04009f int attr listPreferredItemHeightSmall 0x7f0400a0 int attr listPreferredItemPaddingLeft 0x7f0400a1 int attr listPreferredItemPaddingRight 0x7f0400a2 int attr logo 0x7f0400a3 int attr logoDescription 0x7f0400a4 int attr maxButtonHeight 0x7f0400a5 int attr measureWithLargestChild 0x7f0400a6 int attr multiChoItemLayout 0x7f0400a7 int attr nigationContentDescription 0x7f0400a8 int attr nigationIcon 0x7f0400a9 int attr nigationMode 0x7f0400aa int attr overlapAnchor 0x7f0400ac int attr paddingBottomNoButtons 0x7f0400ad int attr paddingEnd 0x7f0400ae int attr paddingTopNoTitle 0x7f0400b0 int attr panelBackground 0x7f0400b1 int attr panelMenuListTheme 0x7f0400b2 int attr popupMenuStyle 0x7f0400b4 int attr popupTheme 0x7f0400b5 int attr popupWindowStyle 0x7f0400b6 int attr preserveIconSpacing 0x7f0400b7 int attr progressBarPadding 0x7f0400b8 int attr progressBarStyle 0x7f0400b9 int attr queryBackground 0x7f0400ba int attr queryHint 0x7f0400bb int attr radioButtonStyle 0x7f0400bc int attr ratingBarStyle 0x7f0400bd int attr ratingBarStyleIndicator 0x7f0400be int attr ratingBarStyleSmall 0x7f0400bf int attr searchHintIcon 0x7f0400c0 int attr searchIcon 0x7f0400c1 int attr searchViewStyle 0x7f0400c2 int attr seekBarStyle 0x7f0400c3 int attr selectableItemBackground 0x7f0400c4 int attr selectableItemBackgroundBorderless 0x7f0400c5 int attr showAsAction 0x7f0400c6 int attr showDividers 0x7f0400c7 int attr showText 0x7f0400c8 int attr showTitle 0x7f0400c9 int attr singleChoItemLayout 0x7f0400ca int attr spinBars 0x7f0400cb int attr spinnerDropDownItemStyle 0x7f0400cc int attr spinnerStyle 0x7f0400cd int attr splitTrack 0x7f0400ce int attr srcCompat 0x7f0400cf int attr state_above_anchor 0x7f0400d0 int attr statusBarBackground 0x7f0400d1 int attr subMenuArrow 0x7f0400d2 int attr submitBackground 0x7f0400d3 int attr subtitle 0x7f0400d4 int attr subtitleTextAppearance 0x7f0400d5 int attr subtitleTextColor 0x7f0400d6 int attr subtitleTextStyle 0x7f0400d7 int attr suggestionRowLayout 0x7f0400d8 int attr switchMinWidth 0x7f0400d9 int attr switchPadding 0x7f0400da int attr switchStyle 0x7f0400db int attr switchTextAppearance 0x7f0400dc int attr textAllCaps 0x7f0400dd int attr textAppearanceLargePopupMenu 0x7f0400de int attr textAppearanceListItem 0x7f0400df int attr textAppearanceListItemSecondary 0x7f0400e0 int attr textAppearanceListItemSmall 0x7f0400e1 int attr textAppearancePopupMenuHeader 0x7f0400e2 int attr textAppearanceSearchResultSubtitle 0x7f0400e3 int attr textAppearanceSearchResultTitle 0x7f0400e4 int attr textAppearanceSmallPopupMenu 0x7f0400e5 int attr textColorAlertDialogListItem 0x7f0400e6 int attr textColorSearchUrl 0x7f0400e7 int attr theme 0x7f0400e8 int attr thickness 0x7f0400e9 int attr thumbTextPadding 0x7f0400ea int attr thumbTint 0x7f0400eb int attr thumbTintMode 0x7f0400ec int attr tickMark 0x7f0400ed int attr tickMarkTint 0x7f0400ee int attr tickMarkTintMode 0x7f0400ef int attr tint 0x7f0400f0 int attr tintMode 0x7f0400f1 int attr title 0x7f0400f2 int attr titleMargin 0x7f0400f3 int attr titleMarginBottom 0x7f0400f4 int attr titleMarginEnd 0x7f0400f5 int attr titleMarginStart 0x7f0400f6 int attr titleMarginTop 0x7f0400f7 int attr titleMargins 0x7f0400f8 int attr titleTextAppearance 0x7f0400f9 int attr titleTextColor 0x7f 想用这种c语言编写一个小游戏可以实现,但是非语言编写出的游戏一般的话都是比较大的,占内存比较短。 使用语言:C++使用工具:vs2019 用c++编写小程序的源代码,你可以找一个程序员用c++编写一个小程序,其实是很容易的。 用 “疯狂python讲义”这本书的内容/知识点很全面,有网络编程,多线程并发编程,数据库编程,大数据分析,GUI编程,py游戏编程,网络爬虫。书中的内容很容易看懂和理解,每章后都有大量的复习/编程题来巩固你学到的知识,书中也有很多例子,比如说五子棋,合金弹头,桌面弹球,反爬虫抵抗,爬取指定网站上的所有的,爬取指定网站上的所有的工作机会,指定地区的天气情况的数据分析case 's':snake[0][1]++;break;,各个的人均GDP数据分析 这有一个最简单的贪吃蛇的控制过程。 一般对于此类的游戏,都分为控制算法,显示算法,判定算法等几个大部分。 供参考: #include #include #include #include #include #include enum dir{up,down,left,right}; //枚举类型enum dir; //围墙; void InitFence(); void OutputF(); char [20][20]; //画框框; void InitFence(){ int i,j; for(i=0; i<20; i++) for(j=0; j<20; j++){ if(i==0||i==19||j==0||j==19) [i][j]= ''; else [i][j]= ' '; //显示框框; void OutputF(){ int i,j; for(i=0; i<20; i++){ for(j=0; j<20; j++) printf("%c ",[i][j]); printf("n"); //蛇结点; struct SnakeNode{ int x,y; struct SnakeNode prior,next; }head=NULL, tail =NULL; void add_head(int x,int y); int get_x(struct SnakeNode p); int get_y(struct SnakeNode p); void delete_tail(); //插入头结点; void add_head(int x,int y){ struct SnakeNode q= (struct SnakeNode )malloc(sizeof(struct SnakeNode)); q->x =xmaxj=j;; q->y =y; q->next =head; q->prior =NULL; if(head) head->prior =q; head =q; if(!tail) tail =head; [x][y]= ''; //f对象可以在定义Fence类时定义; 且Fence类在SnakeNode类前定义; }int get_x(struct SnakeNode p){ return p->x; }int get_y(struct SnakeNode p){ return p->y; }//删除尾结点; void delete_tail(){ struct SnakeNode p =tail; [get_x(tail)][get_y(tail)]= ' ';//把尾结点的坐标表示的''置为空格; if(tail==head) tail= head= NULL; else{ tail= tail->prior; tail->next= NULL; }free(p); }//move移动; struct move{ enum dir point; //枚举变量point: 控制方向; int food_x; int food_y; }; void moving(struct move m); void change_point(char,struct move m); //改变方向; void get_food(struct move m); void get_food(struct move m){ srand((unsigned int) time(NULL)); //做种子(程序运行时间); m->food_x= rand()%18+1; m->food_y= rand()%18+1; [m->food_x][m->food_y]= ''; }void moving(struct move m){ int a,b; a= get_x(head); //取得头结点横坐标 b= get_y(head); //头结点纵坐标 switch(m->point){ case up: --a; break; case down: ++a; break; case left: --b; break; case right: ++b; break; }if(a==19||b==19||a==0||b==0){ //判断是否撞墙; printf(" over!!!n"); exit(0); }if(a==m->food_x && b==m->food_y){ //吃food; add_head(a,b); get_food(m); }else{ add_head(a,b); //插入头结点; delete_tail(); //删除尾结点; void change_point(char keydown,struct move m){ switch(keydown){ // case 'w': m->point= up; break; // case 's': m->point= down; break; // case 'a': m->point= left; break; // case 'd': m->point= right; break; case 72: m->point= up; break; case 80: m->point= down; break; case 75: m->point= left; break; case 77: m->point= right; break; //main(); int main(){ struct move m; printf("Using 'w,s,a,d'to control direction!!!nnn"); InitFence(); add_head(4,3); add_head(4,4); add_head(4,5); OutputF(); while (1){ char keydown= getch(); //getch()返回键盘上读取的字符;包含头文件 change_point(keydown,&m); while(!kbhit()){ //判断有没有按键落下; ("cls"); //清屏函数; moving(&m); OutputF(); Sleep(200); return 0; } public partial class TransparentListBox : ListBox {public TransparentListBox() {this.SetStyle(ControlStyles.UserPaint, true); this.SetStyle(ControlStyles.SupportsTransparentBackColor{max.sum=w[i][j].sum;, true); }protected override void OnSelectedIndexChanged(EventArgs e) {this.Invalidate(); base.OnSelectedIndexChanged(e); }protected override void OnPaint(PaintEventArgs e) {if (this.Focused && this.SelectedItem != null) e.Graphics.FillRectangle(Brushes.Green, Rect); }for (int i = 0; i < Items.Count; i++) {e.Graphics.DrawString(this.GetItemText(Items[i]), this.Font, new SolidBrush(this.ForeColor), this.GetItemRectangle(i)); }base.OnPaincolor(20);t(e); /printf("●");/棋子枚举类 public enum Chesan {//枚举类行必须列出所有实例,这两个表示创建两个棋子视力,它们的棋子成员变量分别是●和○ BLACK_CHESS("●"), WHITE_CHESS("○"); //成员变量,决定这个棋子的类型 private String chesan; //构造器,枚举类的构造器只能提供给自己的实例使用,外部不能调用 private Chesan(String chesan) {this.chesan = chesan; }//获取棋子类型 public String getChesan() {return this.chesan; }}进行了一下小改动, 1、排版 2、我没记错的话枚举实例是不能使用中文的 这是mfc作成的 1010 棋盘. ////////////////////////////////////////////////////////// void CMainWnd::WhoWin(){ for(int i=0;i<11;i++) for(int j=0;j<11;j++){ {char c;if((i<7&&!(unQiPanBit[i][j]-(bNewQi+1)) &&!(unQiPanBit[i+1][j]-(bNewQi+1)) &&!(unQiPanBit[i+2][j]-(bNewQi+1)) &&!(unQiPanBit[i+3][j]-(bNewQi+1)) &&!(unQiPanBit[i+4][j]-(bNewQi+1))) || (j<7&&!(unQiPanBit[i][j]-(bNewQi+1)) &&!(unQiPanBit[i][j+1]-(bNewQi+1)) &&!(unQiPanBit[i][j+2]-(bNewQi+1)) &&!(unQiPanBit[i][j+3]-(bNewQi+1)) &&!(unQiPanBit[i][j+4]-(bNewQi+1))) || (i>3&&j<7&&!(unQiPanBit[i][j]-(bNewQi+1)) &&!(unQiPanBit[i-1][j+1]-(bNewQi+1)) &&!(unQiPanBit[i-2][j+2]-(bNewQi+1)) &&!(unQiPanBit[i-3][j+3]-(bNewQi+1)) &&!(unQiPanBit[i-4][j+4]-(bNewQi+1))) || (i<7&&j<7&&!(unQiPanBit[i][j]-(bNewQi+1)) &&!(unQiPanBit[i+1][j+1]-(bNewQi+1)) &&!(unQiPanBit[i+2][j+2]-(bNewQi+1)) &&!(unQiPanBit[i+3][j+3]-(bNewQi+1)) &&!(unQiPanBit[i+4][j+4]-(bNewQi+1))) )if(IDOK==MessageBox(TEXT(((bNewQi)?"白棋胜利":"黑棋胜利")))) PostQuitMessage(NULL); bNewQi=!bNewQi; } #include #include using namespace std; const int N=15; const int M=15; //c++中有常变量代替c中的宏定义,宏定义不错语法检查 //int main(); main函数是入口函数,不必提前声明,删掉 //貌似你后面调用了main函数,这不规范,看看我改的吧 void init(char flag[][M]) {for(int i=1;i {for(int j=1;j { flag[i][j]='_'; cout< cout<<"|"; }cout< void draw(char flag[][M]) {for(int i=1;i {for(int j=1;j {cout< cout<<'|';} cout< void ciin(char flag[][M],char t,char v) {cout<<"请"< int i,j; cout<<"请输入两个小于"< cin>>i; cin>>j; while(i>=N||i<1||j>=M||j<1||flag[i][j]=='#'||flag[i][j]=='0') {if(i>=N||i<1||j>=M||j<1) {cout<<"输入错误,请重新输入."; cout<<"请输入两个小于"< cin>>i; cin>>j; {cout<<"此处有棋子,请重新输入."; cout<<"请输入两个小于"< cin>>i; cin>>j; flag[i][j]=v; draw(flag); //这句可以删去了,没有意义 ("clear"); draw(flag); cout< }int test(char flag[][M],char t) //若是想再来一局返回1,否则返回0 {int i,j; for(i=1;i {for(j=1;j if((flag[i][j]=='#'&&flag[i][j+1]=='#'&&flag[i][j+2]=='#'&&flag[i][j+3]=='#'&&flag[i][j+4]=='#')|| (flag[i][j]=='0'&&flag[i][j+1]=='0'&&flag[i][j+2]=='0'&&flag[i][j+3]=='0'&&flag[i][j+4]=='0')|| (flag[i][j]=='#'&&flag[i+1][j]=='#'&&flag[i+2][j]=='#'&&flag[i+3][j]=='#'&&flag[i+4][j]=='#')|| (flag[i][j]=='0'&&flag[i+1][j]=='0'&&flag[i+2][j]=='0'&&flag[i+3][j]=='0'&&flag[i+4][j]=='0')|| (flag[i][j]=='#'&&flag[i+1][j+1]=='#'&&flag[i+2][j+2]=='#'&&flag[i+3][j+3]=='#'&&flag[i+4][j+4]=='#')|| (flag[i][j]=='0'&&flag[i+1][j+1]=='0'&&flag[i+2][j+2]=='0'&&flag[i+3][j+3]=='0'&&flag[i+4][j+4]=='0')|| (flag[i][j]=='#'&&flag[i+1][j-1]=='#'&&flag[i+2][j-2]=='#'&&flag[i+3][j-3]=='#'&&flag[i+4][j-4]=='#')|| (flag[i][j]=='0'&&flag[i+1][j-1]=='0'&&flag[i+2][j-2]=='0'&&flag[i+3][j-3]=='0'&&flag[i+4][j-4]=='0')) {cout< char c; cin>>c; if(c}}=='y'||c=='Y') //main(); //调用main函数,我没试过。。。你可以改变一下main函 return 1; //中的语句来实现,还是删掉吧 else return 0;} int main1() //将main函数改成main1,让main1封装所有功能。 {char flag[N][M]; init(flag); cout< for(int i=0;i<(N-1)(M-1);i++) {ciin(flag,'A','#'); if(test(flag,'A')==1) {return 1;} //这是还想再来一局的意思 ciin(flag,'B','0'); if(test(flag,'B')==1) {return 1;} }return 0; }void main() {while(1) {if(main1()==0) break; //如果不想继续,则退出循环结束程序 else continue; //如果想继续,则重新循环。 再说几句,C++的经典之处在与封装,他更倾向于面向对象程序设计,而你的思维还局限在C语言中,没有领悟到C++的经典之处,有待揣摩,其实,你可以做成一个class类,将所有的东西封装在里面,然后创建一个类对象就好了。这样做才是真正的C++ 鉴定完毕 我只给你判断输赢的算法,其他的你自己解决//全局变量 int curX,curY;//当前下}else棋的坐标 0 <= curX <= 15 0 <= curY <= 15 int onTable[16][16]; void WhoWin(int collor) { // 竖直方向 水平方向 右上到左下 左上到右下 if( SameLineNum(0,1) >= 5 ||SameLineNum(1,0) >= 5 ||SameLineNum(1,1) >= 5 ||SameLineNum(-1,1) >= 5) { printf("%s 方获胜n",collor); }}//判断当前棋子的某个方向上同色棋子有多少 int SameLineNum(int x,int y) {int tX,tY; int num;//同一线上相同颜色棋子数 tX = curX;tY = curY; do//计算落子一边同颜色的棋子数 (比如左边) { if( onTable(tX,tY) <> onTable(curX,curY) { num = Max(Abs(curX - tX),Abs(curY - tY);//Max求值,Abs求求 break; }tX = tX + x;tY = tY + y; }while (x < 0 || j < 0 || i > 15 || j > 15); {regret=true;do//计算落子一边同颜色的棋子数 (比如右边) { if( onTable(tX,tY) <> onTable(curX,curY) { num = num -1 + Max(Abs(curX - tX),Abs(curY - tY);//Max求值,Abs求求 break; }tX = tX - x;tY = tY - y; }while (x < 0 || j < 0 || i > 15 || j > 15); return num; } js代码: 定义canvas及黑白棋变量 var canvas; var context; var isWhite = true;//设置是否该轮到白棋 var isWell = false;//设置该局棋盘是否赢了,如果赢了就不能再走了 var img_b = new Image(); var img_w = new Image(); img_w.src = "images/c.png";//黑棋 为棋盘的二维数组用来保存棋盘信息 var chessData = new Array(15);//初始化0为没有走过的,1为白棋走的,2为黑棋走的 for (var x = 0; x < 15; x++) { chessData[x] = new Array(15); for (var y = 0; y < 15; y++) { chessDaint attr layout_dodgeInsetEdges 0x7f040094ta[x][y] = 0; }} 绘制棋盘的线 for (var i = 0; i <= 640; i += 40) { context.beginPath(); context.moveTo(0, i); context.lineTo(640, i); context.closePath(); context.stroke(); context.beginPath(); context.moveTo(i, 0); context.lineTo(i, 640); context.closePath(); context.stroke(); }} 判断该棋局的输赢 if (count1 >= 5 || count2 >= 5 || count3 >= 5 || count4 >= 5) { if (chess == 1) { alert("白棋赢了"); }else { alert("黑棋赢了"); }isWell = true;//设置该局棋盘已经赢了,不可以再走了 } html代码: #include #include #include #include #include #define CROSSRU 0xbf /右上角点/ #define CROSSLU 0xda /左上角点/ #define CROSSLD 0xc0 /左下角点/ #define CROSSRD 0xd9 /右下角点/ #define CROSSL 0xc3 /左边/ #define CROSSR 0xb4 /右边/ #define CROSSU 0xc2 /上边/ #define CROSSD 0xc1 /下边/ #define CROSS 0xc5 /十字交叉点/ #define MAPXOFT 5 #define MAPYOFT 2 /定义1号玩家的作键键码/ #define PLAY1UP 0x1157/上移--'W'/ #define PLAY1DOWN 0x1f53/下移--'S'/ #define PLAY1LEFT 0x1e41/左移--'A'/ #define PLAY1RIGHT 0x2044/右移--'D'/ #define PLAY1DO 0x3920/落子--空格键/ /定义2号玩家的作键键码/ #define PLAY2UP 0x4800/上移--方向键up/ #define PLAY2DOWN 0x5000/下移--方向键down/ #define PLAY2LEFT 0x4b00/左移--方向键left/ #define PLAY2RIGHT 0x4d00/右移--方向键right/ #define PLAY2DO 0x1c0d/落子--回车键Enter/ /若想在游戏中途退出, 可按 Esc 键/ #define ESCAPE 0x011b /定义棋盘上交叉点的状态, 即该点有无棋子 / /若有棋子, 还应能指出是哪个玩家的棋子 / #define CHESSNULL 0 /没有棋子/ #define CHESS1 'O'/一号玩家的棋子/ #define CHESS2 'X'/二号玩家的棋子/ /定义按键类别/ #define KEYEX99v 0/退出键/ #define KEYFALLCHESS 1/落子键/ #define KEYMOVECURSOR 2/光标移动键/ #define KEYINVALID 3/无效键/ /定义符号常量: 真, --- 真为1, 为0 / #define TRUE 1 #define FALSE 0 // / 定义数据结构 / /棋盘交叉点坐标的数据结构/ struct point {int x,y; };
或者下面这个: #include #include #include #include #define N 15 #define B 7 #define STOP -10000 #define OK 1 #define NO 0 #define UP 328 #define DOWN 336 #define LEFT 331 #define RIGHT 333 int a[N+1][N+1]; int zx,zy; int write=1,biaoji=0; struct zn{ long sum; int y; int x; }w[N+1][N+1],max,max1;
void cbar(int i,int x,int y,int r); void map(int a[][]); int getkey(); int key(); void zuobiao(int x,int y,int i); int tu(int a[][],int write); int wtu(int a[][],int write); int zhineng(int a[][]); int zh5(int y,int x,int a[][]); long zzh5(int b[][],int i); main() {int i,j; int gdriver=DETECT; int gmode; initgraph(&gdriver,&gmode,""); zx=(N+1)/2; zy=(N+1)/2; for(i=1;i<=N;i++) for(j=1;j<=N;j++) map(a); i=1; while(i) {int k,n; k=wtu(a,write); if(k==STOP) goto end; map(a); n=zhineng(a); if(n==STOP) goto end; map(a); }end: ;}
int zhineng(int a[N+1][N+1]) {int i,j; int k; max.sum=-1; for(i=0;i<=N;i++) for(j=0;j<+N;j++) {w[i][j].sum=0; w[i][j].x=i; w[i][j].y=j; }for(i=1;i<=N-4;i++) for(j=1;j<=N-4;j++) {k=zh5(i,j,a); if(k==STOP) return (STOP); }for(i=1;i<=N;i++) for(j=1;j<=N;j++) {if(max.sum max.y=i; max.x=j; }else if(max.sum==w[i][j].sum) {if(((max.y-zy)(max.y-zy)+(max.x-zx)(max.x-zx))>((i-zy)(i-zy)+(j-zx)(j-zx))) max.sum=w[i][j].sum; max.y=i; max.x=j; if(a[max.y][max.x]==0) {a[max.y][max.x]=-1; zy=max.y; zx=max.x; }}
int zh5(int y,int x,int a[N+1][N+1]) {int i,j; int b[6][6]; long c[13]; long d[6][6]; long temp; for(i=y;i<=y+4;i++) for(j=x;j<=x+4;j++) b[i+1-y][j+1-x]=a[i][j]; c[1]=b[1][1]+b[1][2]+b[1][3]+b[1][4]+b[1][5]; c[2]=b[2][1]+b[2][2]+b[2][3]+b[2][4]+b[2][5]; c[3]=b[3][1]+b[3][2]+b[3][3]+b[3][4]+b[3][5]; c[4]=b[4][1]+b[4][2]+b[4][3]+b[4][4]+b[4][5]; c[5]=b[5][1]+b[5][2]+b[5][3]+b[5][4]+b[5][5]; c[6]=b[1][1]+b[2][1]+b[3][1]+b[4][1]+b[5][1]; c[7]=b[1][2]+b[2][2]+b[3][2]+b[4][2]+b[5][2]; c[8]=b[1][3]+b[2][3]+b[3][3]+b[4][3]+b[5][3]; c[9]=b[1][4]+b[2][4]+b[3][4]+b[4][4]+b[5][4]; c[10]=b[1][5]+b[2][5]+b[3][5]+b[4][5]+b[5][5]; c[11]=b[1][1]+b[2][2]+b[3][3]+b[4][4]+b[5][5]; c[12]=b[1][5]+b[2][4]+b[3][3]+b[4][2]+b[5][1];
for(i=1;i<=12;i++) {switch(c[i]) {case 5:biaoji=1;return(STOP); case -5:biaoji=-1;return(STOP); case -4:c[i]=100000;break; case 4:c[i]=100000;break; case -3:c[i]=150;break; case 3:c[i]=150;break; case -2:c[i]=120;break; case 2:c[i]=100;break; case -1:c[i]=1;break; case 1:c[i]=1;break; default: c[i]=0; for(i=1;i<=12;i++) {if(c[i]==150) c[i]+=zzh5(b,i); }for(i=1;i<=5;i++) for(j=1;j<=5;j++) d[i][j]=0; for(i=1;i<=5;i++) for(j=1;j<=5;j++) {if(i==j) d[i][j]+=c[11]; if((i+j)==6) d[i][j]+=c[12]; d[i][j]+=c[i]+c[j+5]; }for(i=1;i<=5;i++) for(j=1;j<=5;j++) {if(b[i][j]!=0) d[i][j]=-2; }max1.sum=-1; max1.y=0; max1.x=0; for(i=1;i<=5;i++) for(j=1;j<=5;j++) {if(max1.sum {max1.sum=d[i][j]; max1.y=i; max1.x=j; w[i+y-1][j+x-1].sum+=max1.sum; }else if(max1.sum==d[i][j]) {if(((i+y-1-zy)(i+y-1-zy)+(j+x-1-zx)(j+x-1-zx))>((max1.y+y-1-zy)(max1.y+y-1-zy)+(max1.x+x-1-zx)(max1.x+x-1-zx))) {max1.sum=d[i][j]; max1.y=i; max1.x=j; long zzh5(int b[6][6],int n) {int i,j,k,l,m; switch(n) {case 1:i=b[1][1];j=b[1][2];k=b[1][3];l=b[1][4];m=b[1][5];break; case 2:i=b[2][1];j=b[2][2];k=b[2][3];l=b[2][4];m=b[2][5];break; case 3:i=b[3][1];j=b[3][2];k=b[3][3];l=b[3][4];m=b[3][5];break; case 4:i=b[4][1];j=b[4][2];k=b[4][3];l=b[4][4];m=b[4][5];break; case 5:i=b[5][1];j=b[5][2];k=b[5][3];l=b[5][4];m=b[5][5];break; case 6:i=b[1][1];j=b[2][1];k=b[3][1];l=b[4][1];m=b[5][1];break; case 7:i=b[1][2];j=b[2][2];k=b[3][2];l=b[4][2];m=b[5][2];break; case 8:i=b[1][3];j=b[2][3];k=b[3][3];l=b[4][3];m=b[5][3];break; case 9:i=b[1][4];j=b[2][4];k=b[3][4];l=b[4][4];m=b[5][4];break; case 10:i=b[1][5];j=b[2][5];k=b[3][5];l=b[4][5];m=b[5][5];break; case 11:i=b[1][1];j=b[2][2];k=b[3][3];l=b[4][4];m=b[5][5];break; case 12:i=b[1][5];j=b[2][4];k=b[3][3];l=b[4][2];m=b[5][1];break; }if((i==0&&j==1&&k==1&&l==1&&m==0)) return (900); if((i==0&&j==-1&&k==-1&&l==-1&&m==0)) return(1000); if((i==0&&j==0&&k==1&&l==1&&m==1)||(i==1&&j==1&&k==1&&l==0&&m==0)) return(20); if((i==0&&j==0&&k==-1&&l==-1&&m==-1)||(i==-1&&j==-1&&k==-1&&l==0&&m==0)) return(20); if((i==-1&&j==1&&k==1&&l==1&&m==1)||(i==1&&j==-1&&k==1&&l==1&&m==1)||(i==1&&j==1&&k==-1&&l==1&&m==1)||(i==1&&j==1&&k==1&&l==-1&&m==1)||(i==1&&j==1&&k==1&&l==1&&m==-1)) return(-60); if((i==1&&j==-1&&k==-1&&l==-1&&m==-1)||(i==-1&&j==1&&k==-1&&l==-1&&m==-1)||(i==-1&&j==1&&k==-1&&l==-1&&m==-1)||(i==-1&&j==-1&&k==-1&&l==1&&m==-1)||(i==-1&&j==-1&&k==-1&&l==-1&&m==1)) return(-60); }
int wtu(int a[N+1][N+1],int write) {int i=1; map(a); zuobiao(zx,zy,1); while(i) {int k; k=tu(a,write); if(k==OK) i=0; if(k==STOP) return (STOP); }}
int getkey() {int key,lo,hi; key=bioskey(0); lo=key&0x00ff; hi=(key&0xff00)>>8; return((lo==0) ? hi+256:lo); }
int key() {int k; k=getkey(); swit//自定义控件, 然后在工具箱拖过来用 再把BackColor 设置为Transparentch(k) {case 27: return (STOP); case 13: case ' ': return (OK); case 328: return (UP); case 336: return (DOWN); case 331: return (LEFT); case 333: return (RIGHT); default: return (NO); }}
void zuobiao(int x,int y,int i) {int r; if(i!=0) {setcolor(GREEN); for(r=1;r<=5;r++) circle(75+25x,25+25y,r);
} else {if(a[zy][zx]==1) {setcolor(8); for(r=1;r<=5;r++) circle(75+25x,25+25y,r); }else if(a[zy][zx]==-1) {setcolor(WHITE); for(r=1;r<=5;r++) circle(75+25x,25+25y,r); {setcolor(B); for(r=1;r<=5;r++) circle(75+25x,25+25y,r); setcolor(RED); line(75+25zx-5,25+25zy,75+25x+5,25+25zy); }
int tu(int a[N+1][N+1],int write) {int k; re: k=key(); if(k==OK) {if(a[zy][zx]==0) {a[zy][zx]=write; goto re; }if(k==STOP) return(STOP); if(k==NO) goto re; if(k==UP) {int i,j; if(zy==1) j=zy; else j=zy-1; zuobiao(zx,zy,0); zuobiao(zx,j,1); zy=j; goto re; }if(k==DOWN) {int i,j; if(zy==N) j=zy; else j=zy+1; zuobiao(zx,zy,0); zuobiao(zx,j,1); zy=j; goto re; }if(k==LEFT) {int i,j; if(zx==1) i=zx; else i=zx-1; zuobiao(zx,zy,0); zuobiao(i,zy,1); zx=i; goto re; }if(k==RIGHT) {int i,j; if(zx==N) i=zx; else i=zx+1; zuobiao(zx,zy,0); zuobiao(i,zy,1); zx=i; goto re; }}
void cbar(int i,int x,int y,int r) {if(i!=0) {if(i==1) setcolor(8); else if(i==-1) setcolor(WHITE); for(i=1;i<=r;i++) {circle(x,y,i); }
void map(int a[N+1][N+1]) {int i,j; cleardev(); setbkcolor(B); setcolor(RED); for(i=0;i {liline(75+25zx,25+25zy-5,75+25zx,25+25zy+5);ne(100,50+25i,75+N25,50+25i); line(100+25i,50,100+25i,25+N25); }for(i=1;i<=N;i++) for(j=1;j<=N;j++) cbar(a[i][j],75+25j,25+25i,10); }用C++编写的小游戏源代码
/定义棋盘左上角点在屏幕上的位置/如何学习python知乎
{for(i=0;i<15;i++)求经典小游戏(五子棋 贪吃蛇 方块等)c++ 源代码。能有软件设计过程 我想学思路
get_food(&m);c语言编的五子棋源代码
cursor.x--;关于ja五子棋的代码
{int i,j,tempx,tempy;有关五子棋的程序设计问题(好的追加)
int attr panelMenuListWidth 0x7f0400b3用c编写的五子棋代码,请高手点评
cout<<"得分:"<C语言五子棋算法
if(unQiPanBit[i][j]){五子棋源代码html
else printf("┻");c语言的五子棋代码(博弈算法)
{chesoard[i][j].step=0;
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系 836084111@qq.com 删除。