當前位置:首頁 » 操作系統 » android五子棋源碼

android五子棋源碼

發布時間: 2022-07-14 21:09:26

A. 五子棋人機簡單演算法,根據下面演算法描述寫代碼,代碼附解釋(android)

這是問題?還是論文?
是否考慮一下棋譜匹配演算法?

B. 請問怎麼用Android studio做一個五子棋小游戲,學藝不精環境配置也不太弄

作為一個初學者,想用Android Studio做一個簡易的五子棋,希望路過的大...
答:需要的話可以傳你份源碼

C. 求一個android五子棋的代碼,要求:能在兩台機器上聯網對戰,不需要機器人

同求,可以rmb收個

D. 請問我要用Android studio做一個五子棋的小游戲怎麼配置開發環境

第一步,不考慮AI的情況下,先簡單實現單人點擊落子,點一次換一次黑白,落一次子判斷一次輸贏。第二步,加入socket通信兩個人互落子。實現開局,落子,判斷輸贏,悔棋,認輸,重新開局基本操作。第三步,加入AI,人機對戰。

E. 找五子棋源代碼c++

devc++運行通過,含注釋

#include<bits/stdc++.h>

#include<windows.h>

#include<conio.h>

#include<ctime>

using namespace std;

void gotoxy(int x,int y) {

COORD pos = {x,y};

HANDLE hOut =GetStdHandle(STD_OUTPUT_HANDLE);

SetConsoleCursorPosition(hOut,pos);

}//將游標移動到x,y點上

int mp[16][16]= {0},x1=0,x2=0;//地圖,用來搜索五子連成的

void print(int x) {

gotoxy(x,1);

cout<<"┬";

for(int i=2; i<=14; i++) {

gotoxy(x,i);

cout<<"┼";

}

gotoxy(x,15);

cout<<"┴";

}//輸出棋盤的中間部分

void gotoc() {

system("cls");

gotoxy(55,10);

cout<<"五 子 棋";

gotoxy(56,20);

cout<<"載入中...";

gotoxy(55,21);

cout<<"作者:北辰";

for(int j=0; j<100; j++) {

Sleep(17);

gotoxy(j+3,15);

cout<<" "<<j<<"%";

gotoxy(j,15);

cout<<"■";

}

system("cls");

for(int i=0; i<100; i++) {

for(int j=0; j<40; j++) {

gotoxy(i,j);

cout<<"■";

//SetColor(rand()%10);

}

}

system("cls");

}//載入界面函數

int main() {

gotoc();//載入

for(int i=2; i<=30; i+=2) {

gotoxy(i,0);

cout<<i/2;

}//橫坐標

for(int i=1; i<=15; i++) {

gotoxy(0,i);

cout<<i;

}//縱坐標

gotoxy(2,1);

cout<<"┌";

for(int i=2; i<=14; i++) {

gotoxy(2,i);

cout<<"├";

}

gotoxy(2,15);

cout<<"└";//輸出棋盤左側

for(int i=4; i<=28; i+=2) {

print(i);

}//用一個循環來輸出棋盤中間部分

gotoxy(30,1);

cout<<"┐";

for(int i=2; i<=14; i++) {

gotoxy(30,i);

cout<<"┤";

}

gotoxy(30,15);

cout<<"┘";//輸出棋盤右側

bool l=0;//沒什麼用的flag

long long m=2;//這個很重要,用來判斷是該白棋走還是黑棋走,每次走完++,每次判斷是偶數,該白棋,是奇數,該黑棋(一般用flag判斷,這是我個人喜好)

gotoxy(0,17);

cout<<"游戲說明:白棋先走,落子請輸入坐標,其他的不用我說了吧";//說明,一定要看

while(l=1) {

gotoxy(32,16);

int x,y;

cin>>x>>y;//讀入xy坐標

gotoxy(32,16);

cout<<" ";

if(mp[x][y]!=0) {

gotoxy(32,16);

cout<<"此位置已有落子!";

Sleep(1000);

gotoxy(32,16);

cout<<" ";

continue;

}//很重要,用來判斷此位置有沒有落子

if(x>15&&y<=15) {

gotoxy(32,16);

cout<<"x坐標超出棋盤范圍!";

Sleep(1000);

gotoxy(32,16);

cout<<" ";

continue;

}

if(y>15&&x<=15) {

gotoxy(32,16);

cout<<"y坐標超出棋盤范圍!";

Sleep(1000);

gotoxy(32,16);

cout<<" ";

continue;

}

if(y>15&&x>15) {

gotoxy(32,16);

cout<<"x和y坐標均超出棋盤范圍!";

Sleep(1000);

gotoxy(32,16);

cout<<" ";

continue;

}//以上三個if用來判斷有沒有超出棋盤大小

gotoxy(x*2,y);

if(m%2==0) {//是偶數,該白棋

cout<<"●";//輸出棋子

mp[x][y]=1;

//橫坐標搜索有沒有連成五個

if(mp[x+1][y]==1&&mp[x+2][y]==1&&mp[x+3][y]==1&&mp[x+4][y]==1) {

gotoxy(32,16);

cout<<"白棋獲勝!";

return 0;

}

if(mp[x-1][y]==1&&mp[x+1][y]==1&&mp[x+2][y]==1&&mp[x+3][y]==1) {

gotoxy(32,16);

cout<<"白棋獲勝!";

return 0;

}

if(mp[x-2][y]==1&&mp[x-1][y]==1&&mp[x+1][y]==1&&mp[x+2][y]==1) {

gotoxy(32,16);

cout<<"白棋獲勝!";

return 0;

}

if(mp[x-3][y]==1&&mp[x-2][y]==1&&mp[x-1][y]==1&&mp[x+1][y]==1) {

gotoxy(32,16);

cout<<"白棋獲勝!";

return 0;

}

if(mp[x-4][y]==1&&mp[x-3][y]==1&&mp[x-2][y]==1&&mp[x-1][y]==1) {

gotoxy(32,16);

cout<<"白棋獲勝!";

return 0;

}

//豎

if(mp[x][y+1]==1&&mp[x][y+2]==1&&mp[x][y+3]==1&&mp[x][y+4]==1) {

gotoxy(32,16);

cout<<"白棋獲勝!";

return 0;

}

if(mp[x][y-1]==1&&mp[x][y+1]==1&&mp[x][y+2]==1&&mp[x][y+3]==1) {

gotoxy(32,16);

cout<<"白棋獲勝!";

return 0;

}

if(mp[x][y-2]==1&&mp[x][y-1]==1&&mp[x][y+1]==1&&mp[x][y+2]==1) {

gotoxy(32,16);

cout<<"白棋獲勝!";

return 0;

}

if(mp[x][y-3]==1&&mp[x][y-2]==1&&mp[x][y-1]==1&&mp[x][y+1]==1) {

gotoxy(32,16);

cout<<"白棋獲勝!";

return 0;

}

if(mp[x][y-4]==1&&mp[x][y-3]==1&&mp[x][y-2]==1&&mp[x][y-1]==1) {

gotoxy(32,16);

cout<<"白棋獲勝!";

return 0;

}

//斜''

if(mp[x+1][y+1]==1&&mp[x+2][y+2]==1&&mp[x+3][y+3]==1&&mp[x+4][y+4]==1) {

gotoxy(32,16);

cout<<"白棋獲勝!";

return 0;

}

if(mp[x-1][y-1]==1&&mp[x+1][y+1]==1&&mp[x+2][y+2]==1&&mp[x+3][y+3]==1) {

gotoxy(32,16);

cout<<"白棋獲勝!";

return 0;

}

if(mp[x-2][y-2]==1&&mp[x-1][y-1]==1&&mp[x+1][y+1]==1&&mp[x+2][y+2]==1) {

gotoxy(32,16);

cout<<"白棋獲勝!";

return 0;

}

if(mp[x-3][y-3]==1&&mp[x-2][y-2]==1&&mp[x-1][y-1]==1&&mp[x+1][y+1]==1) {

gotoxy(32,16);

cout<<"白棋獲勝!";

return 0;

}

if(mp[x-4][y-4]==1&&mp[x-3][y-3]==1&&mp[x-2][y-2]==1&&mp[x-1][y-1]==1) {

gotoxy(32,16);

cout<<"白棋獲勝!";

return 0;

}

//斜'/'

if(mp[x-1][y+1]==1&&mp[x-2][y+2]==1&&mp[x-3][y+3]==1&&mp[x-4][y+4]==1) {

gotoxy(32,16);

cout<<"白棋獲勝!";

return 0;

}

if(mp[x+1][y-1]==1&&mp[x-1][y+1]==1&&mp[x-2][y+2]==1&&mp[x-3][y+3]==1) {

gotoxy(32,16);

cout<<"白棋獲勝!";

return 0;

}

if(mp[x+2][y-2]==1&&mp[x+1][y-1]==1&&mp[x-1][y+1]==1&&mp[x-2][y+2]==1) {

gotoxy(32,16);

cout<<"白棋獲勝!";

return 0;

}

if(mp[x+3][y-3]==1&&mp[x+2][y-2]==1&&mp[x+1][y-1]==1&&mp[x-1][y+1]==1) {

gotoxy(32,16);

cout<<"白棋獲勝!";

return 0;

}

if(mp[x+4][y-4]==1&&mp[x+3][y-3]==1&&mp[x+2][y-2]==1&&mp[x+1][y-1]==1) {

gotoxy(32,16);

cout<<"白棋獲勝!";

return 0;

}

} else if(m%2==1) {//為奇數,該黑棋

cout<<"○";

mp[x][y]=2;

//橫

if(mp[x+1][y]==2&&mp[x+2][y]==2&&mp[x+3][y]==2&&mp[x+4][y]==2) {

gotoxy(32,16);

cout<<"黑棋獲勝!";

return 0;

}

if(mp[x-1][y]==2&&mp[x+1][y]==2&&mp[x+2][y]==2&&mp[x+3][y]==2) {

gotoxy(32,16);

cout<<"黑棋獲勝!";

return 0;

}

if(mp[x-2][y]==2&&mp[x-1][y]==2&&mp[x+1][y]==2&&mp[x+2][y]==2) {

gotoxy(32,16);

cout<<"黑棋獲勝!";

return 0;

}

if(mp[x-3][y]==2&&mp[x-2][y]==2&&mp[x-1][y]==2&&mp[x+1][y]==2) {

gotoxy(32,16);

cout<<"黑棋獲勝!";

return 0;

}

if(mp[x-4][y]==2&&mp[x-3][y]==2&&mp[x-2][y]==2&&mp[x-1][y]==2) {

gotoxy(32,16);

cout<<"黑棋獲勝!";

return 0;

}

//豎

if(mp[x][y+1]==2&&mp[x][y+2]==2&&mp[x][y+3]==2&&mp[x][y+4]==2) {

gotoxy(32,16);

cout<<"黑棋獲勝!";

return 0;

}

if(mp[x][y-1]==2&&mp[x][y+1]==2&&mp[x][y+2]==2&&mp[x][y+3]==2) {

gotoxy(32,16);

cout<<"黑棋獲勝!";

return 0;

}

if(mp[x][y-2]==2&&mp[x][y-1]==2&&mp[x][y+1]==2&&mp[x][y+2]==2) {

gotoxy(32,16);

cout<<"黑棋獲勝!";

return 0;

}

if(mp[x][y-3]==2&&mp[x][y-2]==2&&mp[x][y-1]==2&&mp[x][y+1]==2) {

gotoxy(32,16);

cout<<"黑棋獲勝!";

return 0;

}

if(mp[x][y-4]==2&&mp[x][y-3]==2&&mp[x][y-2]==2&&mp[x][y-1]==2) {

gotoxy(32,16);

cout<<"黑棋獲勝!";

return 0;

}

//斜''

if(mp[x+1][y+1]==2&&mp[x+2][y+2]==2&&mp[x+3][y+3]==2&&mp[x+4][y+4]==2) {

gotoxy(32,16);

cout<<"黑棋獲勝!";

return 0;

}

if(mp[x-1][y-1]==2&&mp[x+1][y+1]==2&&mp[x+2][y+2]==2&&mp[x+3][y+3]==2) {

gotoxy(32,16);

cout<<"黑棋獲勝!";

return 0;

}

if(mp[x-2][y-2]==2&&mp[x-1][y-1]==2&&mp[x+1][y+1]==2&&mp[x+2][y+2]==2) {

gotoxy(32,16);

cout<<"黑棋獲勝!";

return 0;

}

if(mp[x-3][y-3]==2&&mp[x-2][y-2]==2&&mp[x-1][y-1]==2&&mp[x+1][y+1]==2) {

gotoxy(32,16);

cout<<"黑棋獲勝!";

return 0;

}

if(mp[x-4][y-4]==2&&mp[x-3][y-3]==2&&mp[x-2][y-2]==2&&mp[x-1][y-1]==2) {

gotoxy(32,16);

cout<<"黑棋獲勝!";

return 0;

}

//斜'/'

if(mp[x-1][y+1]==2&&mp[x-2][y+2]==2&&mp[x-3][y+3]==2&&mp[x-4][y+4]==2) {

gotoxy(32,16);

cout<<"黑棋獲勝!";

return 0;

}

if(mp[x+1][y-1]==2&&mp[x-1][y+1]==2&&mp[x-2][y+2]==2&&mp[x-3][y+3]==2) {

gotoxy(32,16);

cout<<"黑棋獲勝!";

return 0;

}

if(mp[x+2][y-2]==2&&mp[x+1][y-1]==2&&mp[x-1][y+1]==2&&mp[x-2][y+2]==2) {

gotoxy(32,16);

cout<<"黑棋獲勝!";

return 0;

}

if(mp[x+3][y-3]==2&&mp[x+2][y-2]==2&&mp[x+1][y-1]==2&&mp[x-1][y+1]==2) {

gotoxy(32,16);

cout<<"黑棋獲勝!";

return 0;

}

if(mp[x+4][y-4]==2&&mp[x+3][y-3]==2&&mp[x+2][y-2]==2&&mp[x+1][y-1]==2) {

gotoxy(32,16);

cout<<"黑棋獲勝!";

return 0;

}

}

m++;//不要忘記++m

}

return 0;//這個沒什麼用了,不過比賽時不要忘記加哦,否則判0分

}

F. c語言五子棋代碼,

package day17.gobang;

import java.util.Arrays;

public class GoBangGame {
public static final char BLANK='*';
public static final char BLACK='@';
public static final char WHITE='O';

public static final int MAX = 16;
private static final int COUNT = 5;
//棋盤
private char[][] board;

public GoBangGame() {

}
//開始游戲
public void start() {
board = new char[MAX][MAX];
//把二維數組都填充『*』
for(char[] ary: board){
Arrays.fill(ary, BLANK);
}
}
public char[][] getChessBoard(){
return board;
}
public void addBlack(int x, int y) throws ChessExistException{
//@
//char blank = '*';
//System.out.println( x +"," + y + ":" + board[y][x] + "," + BLANK);
if(board[y][x] == BLANK){// x, y 位置上必須是空的才可以添棋子
board[y][x] = BLACK;
return;
}
throw new ChessExistException("已經有棋子了!");
}
public void addWhite(int x, int y)
throws ChessExistException{
if(board[y][x] == BLANK){// x, y 位置上必須是空的才可以添棋子
board[y][x] = WHITE;
return;
}
throw new ChessExistException("已經有棋子了!");
}
//chess 棋子:'@'/'O'
public boolean winOnY(char chess, int x, int y){
//先找到y方向第一個不是 blank的棋子
int top = y;
while(true){
if(y==0 || board[y-1][x]!=chess){
//如果y已經是棋盤的邊緣, 或者的前一個不是chess
//就不再繼續查找了
break;
}
y--;
top = y;
}
//向回統計所有chess的個數,如果是COUNT個就贏了
int count = 0;
y = top;
while(true){
if(y==MAX || board[y][x]!=chess){
//如果找到頭 或者 下一個子不是chess 就不再繼續統計了
break;
}
count++;
y++;
}
return count==COUNT;
}
//chess 棋子:'@'/'O'
public boolean winOnX(char chess, int x, int y){
//先找到x方向第一個不是 blank的棋子
int top = x;
while(true){
if(x==0 || board[y][x-1]!=chess){
//如果x已經是棋盤的邊緣, 或者的前一個不是chess
//就不再繼續查找了
break;
}
x--;
top = x;
}
//向回統計所有chess的個數,如果是COUNT個就贏了
int count = 0;
x = top;
while(true){
if(x==MAX || board[y][x]!=chess){
//如果找到頭 或者 下一個子不是chess 就不再繼續統計了
break;
}
count++;
x++;
}
return count==COUNT;
}

//chess 棋子:'@'/'O'
public boolean winOnXY(char chess, int x, int y){
//先找MAX向第一個不是 blank的棋子
int top = y;
int left = x;
while(true){
if(x==0 || y==0 || board[y-1][x-1]!=chess){
//如果x已經是棋盤的邊緣, 或者的前一個不是chess
//就不再繼續查找了
break;
}
x--;
y--;
top = y;
left=x;
}
//向回統計所有chess的個數,如果是COUNT個就贏了
int count = 0;
x = left;
y = top;
while(true){
if(x==MAX || y==MAX || board[y][x]!=chess){
//如果找到頭 或者 下一個子不是chess 就不再繼續統計了
break;
}
count++;
x++;
y++;
}
return count==COUNT;
}
//chess 棋子:'@'/'O'
public boolean winOnYX(char chess, int x, int y){
//先找到x方向第一個不是 blank的棋子
int top = y;
int left = x;
while(true){
if(x==MAX-1 || y==0 || board[y-1][x+1]!=chess){
//如果x已經是棋盤的邊緣, 或者的前一個不是chess
//就不再繼續查找了
break;
}
x++;
y--;
top = y;
left=x;
}
//向回統計所有chess的個數,如果是COUNT個就贏了
int count = 0;
x = left;
y = top;
while(true){
if(x==0 || y==MAX || board[y][x]!=chess){
//如果找到頭 或者 下一個子不是chess 就不再繼續統計了
break;
}
count++;
x--;
y++;
}
return count==COUNT;
}

public boolean whiteIsWin(int x, int y) {
//在任何一個方向上贏了,都算贏
return winOnY(WHITE, x, y) ||
winOnX(WHITE, x, y) ||
winOnXY(WHITE, x, y) ||
winOnYX(WHITE, x, y);
}
public boolean blackIsWin(int x, int y) {
return winOnY(BLACK, x, y) ||
winOnX(BLACK, x, y) ||
winOnXY(BLACK, x, y) ||
winOnYX(BLACK, x, y);
}

}

G. c語言編的五子棋源代碼

//自定義控制項,然後在工具箱拖過來用再把BackColor設置為Transparent
:ListBox
{
publicTransparentListBox()
{
this.SetStyle(ControlStyles.UserPaint,true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor,true);
}
(EventArgse)
{
this.Invalidate();
base.OnSelectedIndexChanged(e);
}
protectedoverridevoidOnPaint(PaintEventArgse)
{
if(this.Focused&&this.SelectedItem!=null)
{
RectangleitemRect=this.GetItemRectangle(this.SelectedIndex);
e.Graphics.FillRectangle(Brushes.Green,itemRect);
}
for(inti=0;i<Items.Count;i++)
{
e.Graphics.DrawString(this.GetItemText(Items[i]),this.Font,newSolidBrush(this.ForeColor),this.GetItemRectangle(i));
}
base.OnPaint(e);
}
}

H. C#網路對戰五子棋(c/s框架)

  • 一、源碼描述
    這是一款比較好玩的五子棋游戲源碼,支持網路對戰,該源碼比較適合大家學習
    交流使用,感興趣朋友們的不要錯過啊。
    二、功能介紹
    該源碼主要實現了五子棋的基本功能,並且包含了網路對戰的功能。
    三、注意事項
    1、開發環境為Visual Studio 2010,無資料庫,使用.net 2.0開發。

I. 五子棋源碼

/*
五子棋
*/

#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
#include<bios.h>
#include<conio.h>

#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
#define SPACE 0x3920

#define BILI 20
#define JZ 4
#define JS 3
#define N 19

int box[N][N];
int step_x,step_y ;
int key ;
int flag=1 ;

void draw_box();
void draw_cicle(int x,int y,int color);
void change();
void judgewho(int x,int y);
void judgekey();
int judgeresult(int x,int y);
void attentoin();

void attention()
{
char ch ;
window(1,1,80,25);
textbackground(LIGHTBLUE);
textcolor(YELLOW);
clrscr();
gotoxy(15,2);
printf("游戲操作規則:");
gotoxy(15,4);
printf("Play Rules:");
gotoxy(15,6);
printf("1、按左右上下方向鍵移動棋子");
gotoxy(15,8);
printf("1. Press Left,Right,Up,Down Key to move Piece");
gotoxy(15,10);
printf("2、按空格確定落棋子");
gotoxy(15,12);
printf("2. Press Space to place the Piece");
gotoxy(15,14);
printf("3、禁止在棋盤外按空格");
gotoxy(15,16);
printf("3. DO NOT press Space outside of the chessboard");
gotoxy(15,18);
printf("你是否接受上述的游戲規則(Y/N)");
gotoxy(15,20);
printf("Do you accept the above Playing Rules? [Y/N]:");
while(1)
{
gotoxy(60,20);
ch=getche();
if(ch=='Y'||ch=='y')
break ;
else if(ch=='N'||ch=='n')
{
window(1,1,80,25);
textbackground(BLACK);
textcolor(LIGHTGRAY);
clrscr();
exit(0);
}
gotoxy(51,12);
printf(" ");
}
}
void draw_box()
{
int x1,x2,y1,y2 ;
setbkcolor(LIGHTBLUE);
setcolor(YELLOW);
gotoxy(7,2);
printf("Left, Right, Up, Down KEY to move, Space to put, ESC-quit.");
for(x1=1,y1=1,y2=18;x1<=18;x1++)
line((x1+JZ)*BILI,(y1+JS)*BILI,(x1+JZ)*BILI,(y2+JS)*BILI);
for(x1=1,y1=1,x2=18;y1<=18;y1++)
line((x1+JZ)*BILI,(y1+JS)*BILI,(x2+JZ)*BILI,(y1+JS)*BILI);
for(x1=1;x1<=18;x1++)
for(y1=1;y1<=18;y1++)
box[x1][y1]=0 ;
}

void draw_circle(int x,int y,int color)
{
setcolor(color);
setlinestyle(SOLID_LINE,0,1);
x=(x+JZ)*BILI ;
y=(y+JS)*BILI ;
circle(x,y,8);
}

void judgekey()
{
int i ;
int j ;
switch(key)
{
case LEFT :

if(step_x-1<0)
break ;
else
{
for(i=step_x-1,j=step_y;i>=1;i--)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(i<1)break ;
step_x=i ;
judgewho(step_x,step_y);
break ;
}
case RIGHT :

if(step_x+1>18)
break ;
else
{
for(i=step_x+1,j=step_y;i<=18;i++)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(i>18)break ;
step_x=i ;
judgewho(step_x,step_y);
break ;
}
case DOWN :

if((step_y+1)>18)
break ;
else
{
for(i=step_x,j=step_y+1;j<=18;j++)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(j>18)break ;
step_y=j ;
judgewho(step_x,step_y);
break ;
}
case UP :

if((step_y-1)<0)
break ;
else
{
for(i=step_x,j=step_y-1;j>=1;j--)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(j<1)break ;
step_y=j ;
judgewho(step_x,step_y);
break ;
}
case ESC :
break ;

case SPACE :
if(step_x>=1&&step_x<=18&&step_y>=1&&step_y<=18)
{
if(box[step_x][step_y]==0)
{
box[step_x][step_y]=flag ;
if(judgeresult(step_x,step_y)==1)
{
sound(1000);
delay(1000);
nosound();
gotoxy(30,4);
if(flag==1)
{
setbkcolor(BLUE);
cleardevice();
setviewport(100,100,540,380,1);
/*定義一個圖形窗口*/
setfillstyle(1,2);
/*綠色以實填充*/
setcolor(YELLOW);
rectangle(0,0,439,279);
floodfill(50,50,14);
setcolor(12);
settextstyle(1,0,5);
/*三重筆劃字體, 水平放?5倍*/
outtextxy(20,20,"The White Win !");
setcolor(15);
settextstyle(3,0,5);
/*無襯筆劃字體, 水平放大5倍*/
outtextxy(120,120,"The White Win !");
setcolor(14);
settextstyle(2,0,8);
getch();
closegraph();
exit(0);
}
if(flag==2)
{
setbkcolor(BLUE);
cleardevice();
setviewport(100,100,540,380,1);
/*定義一個圖形窗口*/
setfillstyle(1,2);
/*綠色以實填充*/
setcolor(YELLOW);
rectangle(0,0,439,279);
floodfill(50,50,14);
setcolor(12);
settextstyle(1,0,8);
/*三重筆劃字體, 水平放大8倍*/
outtextxy(20,20,"The Red Win !");
setcolor(15);
settextstyle(3,0,5);
/*無襯筆劃字體, 水平放大5倍*/
outtextxy(120,120,"The Red Win !");
setcolor(14);
settextstyle(2,0,8);
getch();
closegraph();
exit(0);
}
}
change();
break ;
}
}
else
break ;
}
}

void change()
{
if(flag==1)
flag=2 ;
else
flag=1 ;
}

void judgewho(int x,int y)
{
if(flag==1)
draw_circle(x,y,15);
if(flag==2)
draw_circle(x,y,4);
}

int judgeresult(int x,int y)
{
int j,k,n1,n2 ;
while(1)
{
n1=0 ;
n2=0 ;
/*水平向左數*/
for(j=x,k=y;j>=1;j--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*水平向右數*/
for(j=x,k=y;j<=18;j++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}

/*垂直向上數*/
n1=0 ;
n2=0 ;
for(j=x,k=y;k>=1;k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*垂直向下數*/
for(j=x,k=y;k<=18;k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}

/*向左上方數*/
n1=0 ;
n2=0 ;
for(j=x,k=y;j>=1,k>=1;j--,k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*向右下方數*/
for(j=x,k=y;j<=18,k<=18;j++,k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}

/*向右上方數*/
n1=0 ;
n2=0 ;
for(j=x,k=y;j<=18,k>=1;j++,k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*向左下方數*/
for(j=x,k=y;j>=1,k<=18;j--,k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}
return(0);
break ;
}
}

void main()
{
int gdriver=VGA,gmode=VGAHI;
clrscr();
attention();
initgraph(&gdriver,&gmode,"c:\\tc");
/* setwritemode(XOR_PUT);*/
flag=1 ;
draw_box();
do
{
step_x=0 ;
step_y=0 ;
/*draw_circle(step_x,step_y,8); */
judgewho(step_x-1,step_y-1);
do
{
while(bioskey(1)==0);
key=bioskey(0);
judgekey();
}
while(key!=SPACE&&key!=ESC);
}
while(key!=ESC);
closegraph();
}



J. 用android studio怎麼做一個簡單的五子棋

http://tieba..com/p/1568464014 參考C的寫法 安卓語法改一下就行

熱點內容
wincc圖形編譯在哪裡 發布:2024-09-17 03:58:26 瀏覽:977
androidubuntu 發布:2024-09-17 03:50:27 瀏覽:701
識夢源碼 發布:2024-09-17 03:50:18 瀏覽:26
諾基亞密碼忘了打什麼電話 發布:2024-09-17 03:27:09 瀏覽:555
樹深度優先演算法 發布:2024-09-17 03:26:58 瀏覽:472
跳轉頁源碼 發布:2024-09-17 03:13:05 瀏覽:543
html文件上傳表單 發布:2024-09-17 03:08:02 瀏覽:785
聊天軟體編程 發布:2024-09-17 03:00:07 瀏覽:726
linuxoracle安裝路徑 發布:2024-09-17 01:57:29 瀏覽:688
兩個安卓手機照片怎麼同步 發布:2024-09-17 01:51:53 瀏覽:207