老熟女激烈的高潮_日韩一级黄色录像_亚洲1区2区3区视频_精品少妇一区二区三区在线播放_国产欧美日产久久_午夜福利精品导航凹凸

重慶分公司,新征程啟航

為企業(yè)提供網(wǎng)站建設(shè)、域名注冊、服務(wù)器等服務(wù)

五子棋java簡易源代碼 五子棋java簡易源代碼是多少

java五子棋源代碼

我這有算法 不過沒做swing界面 DOS下可以直接運行 要不你拿去改改

創(chuàng)新互聯(lián)專注于翠屏網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供翠屏營銷型網(wǎng)站建設(shè),翠屏網(wǎng)站制作、翠屏網(wǎng)頁設(shè)計、翠屏網(wǎng)站官網(wǎng)定制、成都微信小程序服務(wù),打造翠屏網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供翠屏網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。

import java.io.BufferedReader;

import java.io.InputStreamReader;

/*

* 五子棋源碼

* 所用的符號標識 ○ ● ┼

* 在dos界面下運行效果最佳

* 黑白雙方交叉輸入落子點坐標 以逗號隔開如 1,1

* 輸入空 或者一方勝出 程序停止

*/

public class Chess {

// 定義棋盤大小

private static int SIZE = 15;

private String[][] board;

public static void main(String[] args) throws Exception {

Chess chess = new Chess();

// 初始化棋盤

chess.initBoard();

// 畫出棋盤

chess.paintBoard();

// 根據(jù)who的奇偶性 判斷該誰落子

int who = 0;

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

String str = null;

while ((str = br.readLine()) != null) {

// 提取輸入的 以","分開的數(shù) 分別對應(yīng)x y坐標

String[] posStr = str.split(",");

int x = Integer.parseInt(posStr[0]);

int y = Integer.parseInt(posStr[1]);

// 判斷落子點是否合法

if (!"┼".equals(chess.board[x][y])) {

System.out.println("這里不允許落子,請重下..");

continue;

}

if (who % 2 == 0) {

chess.board[x][y] = "○";

chess.paintBoard();

// 判斷是否勝出

if (chess.isWin("○")) {

System.out.println("○獲勝");

return;

}

} else {

chess.board[x][y] = "●";

chess.paintBoard();

// 判斷是否勝出

if (chess.isWin("●")) {

System.out.println("●獲勝");

return;

}

}

who++;

}

}

// 以 "┼" 初始化棋盤

public void initBoard() {

board = new String[SIZE][SIZE];

for (int i = 0; i SIZE; i++) {

for (int j = 0; j SIZE; j++) {

board[i][j] = "┼";

}

}

}

// 描繪出當前棋盤

public void paintBoard() {

// 以下代碼 這里為了使得棋盤坐標看的清楚 加入了坐標值

System.out.print(" ");

for (int i = 0; i SIZE; i++) {

if (i 10) {

System.out.print(i + " ");

} else {

System.out.print((i - 10) + " ");

}

}

System.out.println();

// 以上代碼 這里為了使得棋盤坐標看的清楚 加入了坐標值

for (int i = 0; i SIZE; i++) {

if (i 10) {

System.out.print(" " + i);

} else {

System.out.print(i);

}

for (int j = 0; j SIZE; j++) {

System.out.print(board[i][j]);

}

System.out.println();

}

}

// 判斷是否獲勝

public boolean isWin(String sign) {

int count = 0;

// 橫向掃描各行

// 有一個sign的子 計數(shù)器+1

// 碰到不是sign的子 計數(shù)器置零

// 計數(shù)器到達5時 返回true 勝出

for (int i = 0; i SIZE; i++) {

count = 0;

for (int j = 0; j SIZE; j++) {

if (board[i][j].equals(sign)) {

count++;

if (count == 5) {

return true;

}

} else {

count = 0;

}

}

}

// 縱向掃描各列

// 方法同上

for (int i = 0; i SIZE; i++) {

count = 0;

for (int j = 0; j SIZE; j++) {

if (board[j][i].equals(sign)) {

count++;

if (count == 5) {

return true;

}

} else {

count = 0;

}

}

}

// 掃描斜右下

// 在橫向掃描基礎(chǔ)上 外層套一個循環(huán) 以k為標識

// 坐標x-y的范圍在-SIZE+1到SIZE-1之間

// 當x-y的值相等時 在同一右下斜線上

for (int k = -SIZE + 1; k = SIZE - 1; k++) {

count = 0;

for (int i = 0; i SIZE; i++) {

for (int j = 0; j SIZE; j++) {

if (i - j == k) {

if (board[i][j].equals(sign)) {

count++;

if (count == 5) {

return true;

}

} else {

count = 0;

}

}

}

}

}

// 掃描斜左邊上

// 方法同上 坐標x+y的值相等時 在同一左上斜線上

for (int k = -SIZE + 1; k = SIZE - 1; k++) {

count = 0;

for (int i = 0; i SIZE; i++) {

for (int j = 0; j SIZE; j++) {

if (i + j == k) {

if (board[i][j].equals(sign)) {

count++;

if (count == 5) {

return true;

}

} else {

count = 0;

}

}

}

}

}

return false;

}

}

用簡單的java語言編寫五子棋

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

class mypanel extends Panel implements MouseListener

{

int chess[][] = new int[11][11];

boolean Is_Black_True;

mypanel()

{

Is_Black_True = true;

for(int i = 0;i 11;i++)

{

for(int j = 0;j 11;j++)

{

chess[i][j] = 0;

}

}

addMouseListener(this);

setBackground(Color.BLUE);

setBounds(0, 0, 360, 360);

setVisible(true);

}

public void mousePressed(MouseEvent e)

{

int x = e.getX();

int y = e.getY();

if(x 25 || x 330 + 25 ||y 25 || y 330+25)

{

return;

}

if(chess[x/30-1][y/30-1] != 0)

{

return;

}

if(Is_Black_True == true)

{

chess[x/30-1][y/30-1] = 1;

Is_Black_True = false;

repaint();

Justisewiner();

return;

}

if(Is_Black_True == false)

{

chess[x/30-1][y/30-1] = 2;

Is_Black_True = true;

repaint();

Justisewiner();

return;

}

}

void Drawline(Graphics g)

{

for(int i = 30;i = 330;i += 30)

{

for(int j = 30;j = 330; j+= 30)

{

g.setColor(Color.WHITE);

g.drawLine(i, j, i, 330);

}

}

for(int j = 30;j = 330;j += 30)

{

g.setColor(Color.WHITE);

g.drawLine(30, j, 330, j);

}

}

void Drawchess(Graphics g)

{

for(int i = 0;i 11;i++)

{

for(int j = 0;j 11;j++)

{

if(chess[i][j] == 1)

{

g.setColor(Color.BLACK);

g.fillOval((i + 1) * 30 - 8, (j + 1) * 30 - 8, 16, 16);

}

if(chess[i][j] == 2)

{

g.setColor(Color.WHITE);

g.fillOval((i + 1) * 30 - 8, (j + 1) * 30 - 8, 16, 16);

}

}

}

}

void Justisewiner()

{

int black_count = 0;

int white_count = 0;

int i = 0;

for(i = 0;i 11;i++)//橫向判斷

{

for(int j = 0;j 11;j++)

{

if(chess[i][j] == 1)

{

black_count++;

if(black_count == 5)

{

JOptionPane.showMessageDialog(this, "黑棋勝利");

Clear_Chess();

return;

}

}

else

{

black_count = 0;

}

if(chess[i][j] == 2)

{

white_count++;

if(white_count == 5)

{

JOptionPane.showMessageDialog(this, "白棋勝利");

Clear_Chess();

return;

}

}

else

{

white_count = 0;

}

}

}

for(i = 0;i 11;i++)//豎向判斷

{

for(int j = 0;j 11;j++)

{

if(chess[j][i] == 1)

{

black_count++;

if(black_count == 5)

{

JOptionPane.showMessageDialog(this, "黑棋勝利");

Clear_Chess();

return;

}

}

else

{

black_count = 0;

}

if(chess[j][i] == 2)

{

white_count++;

if(white_count == 5)

{

JOptionPane.showMessageDialog(this, "白棋勝利");

Clear_Chess();

return;

}

}

else

{

white_count = 0;

}

}

}

for(i = 0;i 7;i++)//左向右斜判斷

{

for(int j = 0;j 7;j++)

{

for(int k = 0;k 5;k++)

{

if(chess[i + k][j + k] == 1)

{

black_count++;

if(black_count == 5)

{

JOptionPane.showMessageDialog(this, "黑棋勝利");

Clear_Chess();

return;

}

}

else

{

black_count = 0;

}

if(chess[i + k][j + k] == 2)

{

white_count++;

if(white_count == 5)

{

JOptionPane.showMessageDialog(this, "白棋勝利");

Clear_Chess();

return;

}

}

else

{

white_count = 0;

}

}

}

}

for(i = 4;i 11;i++)//右向左斜判斷

{

for(int j = 6;j = 0;j--)

{

for(int k = 0;k 5;k++)

{

if(chess[i - k][j + k] == 1)

{

black_count++;

if(black_count == 5)

{

JOptionPane.showMessageDialog(this, "黑棋勝利");

Clear_Chess();

return;

}

}

else

{

black_count = 0;

}

if(chess[i - k][j + k] == 2)

{

white_count++;

if(white_count == 5)

{

JOptionPane.showMessageDialog(this, "白棋勝利");

Clear_Chess();

return;

}

}

else

{

white_count = 0;

}

}

}

}

}

void Clear_Chess()

{

for(int i=0;i11;i++)

{

for(int j=0;j11;j++)

{

chess[i][j]=0;

}

}

repaint();

}

public void paint(Graphics g)

{

Drawline(g);

Drawchess(g);

}

public void mouseExited(MouseEvent e){}

public void mouseEntered(MouseEvent e){}

public void mouseReleased(MouseEvent e){}

public void mouseClicked(MouseEvent e){}

}

class myframe extends Frame implements WindowListener

{

mypanel panel;

myframe()

{

setLayout(null);

panel = new mypanel();

add(panel);

panel.setBounds(0,23, 360, 360);

setTitle("單人版五子棋");

setBounds(200, 200, 360, 383);

setVisible(true);

addWindowListener(this);

}

public void windowClosing(WindowEvent e)

{

System.exit(0);

}

public void windowDeactivated(WindowEvent e){}

public void windowActivated(WindowEvent e){}

public void windowOpened(WindowEvent e){}

public void windowClosed(WindowEvent e){}

public void windowIconified(WindowEvent e){}

public void windowDeiconified(WindowEvent e){}

}

public class mywindow

{

public static void main(String argc [])

{

myframe f = new myframe();

}

}

JAVA設(shè)計的五子棋源程序

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.awt.geom.*;

import java.util.*;

class PaintPanel extends JPanel {

ArrayList Items = new ArrayList();

public PaintPanel() {

setLayout(new BorderLayout());

ButtonPanel buttonPanel = new ButtonPanel();

add(buttonPanel, BorderLayout.SOUTH);

addMouseListener(new MouseHandler());

}

public void paintComponent(Graphics g) {

int startX = 50;

int startY = 50;

boolean isMy = false;

super.paintComponent(g);

Graphics2D g2 = (Graphics2D)g;

for(int i=0; i16; i++) {

g2.draw(new Line2D.Double(startX, startY+20*i, startX+300, startY+20*i));

g2.draw(new Line2D.Double(startX+20*i, startY, startX+20*i, startY+300));

}

for(int i=0; iItems.size(); i++) {

isMy = !isMy;

if(isMy)

g2.setColor(Color.BLACK);

else

g2.setColor(Color.WHITE);

g2.fill((Ellipse2D)Items.get(i));

}

}

void myRepaint() {

repaint();

}

private class MouseHandler extends MouseAdapter {

public void mousePressed(MouseEvent event) {

int x = event.getX();

int y = event.getY();

paintItem(x, y);

repaint();

}

void paintItem(int x, int y) {

if(x 50 x 350 y 50 y 350) {

int X = x / 20;

int Y = y / 20;

int centerX = X*20 + 10;

int centerY = Y*20 + 10;

Ellipse2D ellipse = new Ellipse2D.Double();

ellipse.setFrameFromCenter(centerX, centerY, centerX+8, centerY+8);

Items.add(ellipse);

}

}

}

private class ButtonPanel extends JPanel {

public ButtonPanel() {

JButton reset = new JButton("Reset");

add(reset);

JButton quit = new JButton("Quit");

add(quit);

ResetEvent listenerR = new ResetEvent();

reset.addMouseListener(listenerR);

QuitEvent listenerQ = new QuitEvent();

quit.addMouseListener(listenerQ);

}

private class QuitEvent

extends MouseAdapter {

public void mouseClicked(MouseEvent event) {

System.exit(1);

}

}

private class ResetEvent

extends MouseAdapter {

public void mouseClicked(MouseEvent event) {

Items.clear();

myRepaint();

}

}

}

}

class GameFrame extends JFrame {

public GameFrame() {

setTitle("A Little Game");

setSize(400, 500);

setResizable(false);

PaintPanel panel = new PaintPanel();

getContentPane().add(panel);

}

} public class Game {

public static void main(String[] args) {

GameFrame frame = new GameFrame();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.show();

}

}

//有缺陷,需要更加完善

求一個簡單的JAVA五子棋代碼??! 網(wǎng)上復(fù)制的別來了!

以下是現(xiàn)寫的 實現(xiàn)了兩人對戰(zhàn) 自己復(fù)制后運行把 沒什么難度 類名 Games

import java.util.Scanner;

public class Games {

private String board[][];

private static int SIZE = 17;

private static String roles = "A玩家";

//初始化數(shù)組

public void initBoard() {

board = new String[SIZE][SIZE];

for (int i = 0; i SIZE; i++) {

for (int j = 0; j SIZE; j++) {

// if(i==0){

// String str = "";

// str += j+" ";

// board[i][j]= str;

// }else if(i!=0j==0){

// String str = "";

// str += i+" ";

// board[i][j]= str;

// }else{

board[i][j] = "╋";

// }

}

}

}

//輸出棋盤

public void printBoard() {

for (int i = 0; i SIZE; i++) {

for (int j = 0; j SIZE; j++) {

System.out.print(board[i][j]);

}

System.out.println();

}

}

//判斷所下棋子位置是否合理

public boolean isOk(int x, int y) {

boolean isRight = true;

if (x = 16 || x 1 || y = 16 | y 1) {

//System.out.println("輸入錯誤,請從新輸入");

isRight = false;

}

if (board[x][y].equals("●") || board[x][y].equals("○")) {

isRight = false;

}

return isRight;

}

//判斷誰贏了

public void whoWin(Games wz) {

// 從數(shù)組挨個查找找到某個類型的棋子就從該棋子位置向右,向下,斜向右下 各查找5連續(xù)的位置看是否為5個相同的

int xlabel;// 記錄第一次找到某個棋子的x坐標

int ylabel;// 記錄第一次找到某個棋子的y坐標

// ●○╋

// 判斷人是否贏了

for (int i = 0; i SIZE; i++) {

for (int j = 0; j SIZE; j++) {

if (board[i][j].equals("○")) {

xlabel = i;

ylabel = j;

// 橫向找 x坐標不變 y坐標以此加1連成字符串

String heng = "";

if (i + 5 SIZE j + 5 SIZE) {

for (int k = j; k j + 5; k++) {

heng += board[i][k];

}

if (heng.equals("○○○○○")) {

System.out.println(roles+"贏了!您輸了!");

System.exit(0);

}

// 向下判斷y不變 x逐增5 連成字符串

String xia = "";

for (int l = j; l i + 5; l++) {

xia += board[l][j];

// System.out.println(xia);

}

if (xia.equals("○○○○○")) {

System.out.println(roles+"贏了!您輸了!");

System.exit(0);

}

// 斜向右下判斷

String youxia = "";

for (int a = 1; a = 5; a++) {

youxia += board[xlabel++][ylabel++];

}

if (youxia.equals("○○○○○")) {

System.out.println(roles+"贏了!您輸了!");

System.exit(0);

}

}

}

}

}

// 判斷電腦是否贏了

for (int i = 0; i SIZE; i++) {

for (int j = 0; j SIZE; j++) {

if (board[i][j].equals("●")) {

xlabel = i;

ylabel = j;

// 橫向找 x坐標不變 y坐標以此加1連成字符串

String heng = "";

if (j + 5 SIZE i + 5 SIZE) {

for (int k = j; k j + 5; k++) {

heng += board[i][k];

}

if (heng.equals("●●●●●")) {

System.out.println(roles+"贏輸了!您輸了!");

System.exit(0);

}

// 向下判斷y不變 x逐增5 連成字符串

String xia = "";

for (int l = i; l i + 5; l++) {

xia += board[l][ylabel];

// System.out.println(xia);

}

if (xia.equals("●●●●●")) {

System.out.println(roles+"贏了!您輸了!");

System.exit(0);

}

// 斜向右下判斷

String youxia = "";

for (int a = 1; a = 5; a++) {

youxia += board[xlabel++][ylabel++];

}

if (youxia.equals("●●●●●")) {

System.out.println(roles+"贏了!您輸了!");

System.exit(0);

}

}

}

}

}

}

public static void main(String[] args) {

Games wz = new Games();

Scanner sc = new Scanner(System.in);

wz.initBoard();

wz.printBoard();

while (true) {

System.out.print("請"+roles+"輸入X,Y坐標,必須在0-15范圍內(nèi),xy以空格隔開,輸入16 16結(jié)束程序");

int x = sc.nextInt();

int y = sc.nextInt();

if (x == SIZE y == SIZE) {

System.out.println("程序結(jié)束");

System.exit(0);

}

if (x SIZE || x 0 || y SIZE | y 0) {

System.out.println("輸入錯誤,請從新輸入");

continue;

}

//如果roles是A玩家 就讓A玩家下棋,否則就讓B玩家下棋。

if (wz.board[x][y].equals("╋")roles.equals("A玩家")) {

wz.board[x][y] = "○";

wz.printBoard();

//判斷輸贏

wz.whoWin(wz);

}else if(wz.board[x][y].equals("╋")roles.equals("B玩家")){

wz.board[x][y] = "●";

wz.printBoard();

//判斷輸贏

wz.whoWin(wz);

} else {

System.out.println("此處已經(jīng)有棋子,從新輸入");

continue;

}

if(roles.equals("A玩家")){

roles = "B玩家";

}else if(roles.equals("B玩家")){

roles = "A玩家";

}

}

}

}


新聞標題:五子棋java簡易源代碼 五子棋java簡易源代碼是多少
分享鏈接:http://www.xueling.net.cn/article/hhsocj.html

其他資訊

在線咨詢
服務(wù)熱線
服務(wù)熱線:028-86922220
TOP
主站蜘蛛池模板: www一片黄 | 澳门成人av| 国产精品久久久午夜 | a级片免费的 | 91网视频在线观看 | 一区二区三区不人妻无码 | 亚洲一区二区三区免费视频 | 国产小视频在线观看网站 | 日韩精品无码免费毛片 | 台湾男男gay做爽爽的视频 | 无遮挡国产高潮视频免费观看 | 亚洲av中文无码乱人伦在线播放 | 中文在线免费看视频 | 女人被躁到高潮嗷嗷叫69 | 88国产精品视频一区二区三区 | 无码人妻一区二区三区免费N鬼沢 | 欧美午夜精品一区二区三区 | 亚洲日本VA中文字幕无码毛片 | 7194中文乱码一二三四芒果 | 91国产精品在线 | 久久久老司机 | 中国xxxx老师xxx在线 | 色视频免费在线观看 | 天天操天天操天天操天天 | 久久天天躁狠狠躁夜夜97 | 久久成人在线 | 亚洲国产人成自精在线尤物 | 综合激情久久综合激情 | 国产一区三区在线播放 | 国产成人亚洲综合a∨婷婷图片 | 老汉av久久午夜一区 | 亚洲最新免费视频 | 中文字幕免费日韩 | 日韩精品一区二区在线播放 | www.影院 | 国产资源在线观看视频 | www一级片| 日本三级日本三级韩国三级视 | 999久久久久久久 | 亚洲欧美日韩国产一区二区 | 国产呻吟对白刺激无套视频在线 |