DVD-SUN--connectfour.zip

  • PUDN用户
    了解作者
  • Java
    开发工具
  • 9.9MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 4
    下载次数
  • 2015-06-01 04:02
    上传日期
屏风式四子棋(Connect Four),简称四子棋 双方必须轮流把一枚己棋投入开口,让棋子因地心引力落下在底部或其他棋子上。 当己方四枚棋子以纵、横、斜方向连成一线时获胜。 棋盘满棋时,无任何连成四子,则平手。
DVD-SUN--connectfour.zip
  • New folder connectfourtext
  • Flag_of_Ontario.svg.png
    3.3KB
  • fabrique-au-quebec-md.png
    24.7KB
  • quebec-vs-ontario.jpg
    21.3KB
  • BANANA.gif
    24.3KB
  • de^vrd2.gif
    1.3KB
  • USSSR.jpg
    25.9KB
  • ready_files.ini
    289B
  • strawberry1.gif
    1.7KB
  • banana2.GIF
    1.3KB
  • ConnectFour.java
    18.3KB
  • ussr_vs__nazi_germany_by_therazgar-d6n6m8g.png
    66.6KB
  • 20140503164405_ewvuK.thumb.700_0.jpeg
    97.1KB
  • T1AYfxXfRtXXXXXXXX_!!0-item_pic.jpg_210x210.jpg
    14.2KB
  • ConnectFour.class
    10.7KB
  • strawberry.gif
    185.2KB
  • News_Image_United-StatesVsCanada.png
    190.2KB
  • 3~1.wav
    9.7MB
  • Flag_of_Ontario.svg (1).png
    23.8KB
  • timg.jpg
    8.9KB
内容介绍
import java.awt.event.*; import java.awt.*; import javax.swing.*; import java.io.*; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.SourceDataLine; import javax.sound.sampled.DataLine; import javax.sound.sampled.FloatControl; /* The "ConnectFour" class. * Author: * Date: * Purpose: */ public class ConnectFour extends Frame { final int BANANA = -1; final int STRAWBERRY = 1; final int EMPTY = 0; final int SQUARE_SIZE = 60; final int TOP_OFFSET = 42; final int BORDER_SIZE = 4; MenuItem newOption, exitOption, helpOption, iconOption; int[] [] board; int currentPlayer; int currentColumn; Image firstImage, secondImage; Timer timer; String player1win = "CANADA WIN!!!\nA Mari usque ad Mare."; //winner1 String player2win = "USA WIN!!!\nE Pluribus Unum"; //winner2 // For drawing images offScreen (prevents Flicker) // These variables keep track of an off screen image object and // its corresponding graphics object Image offScreenImage; Graphics offScreenBuffer; boolean gameOver; public ConnectFour () { board = new int [8] [9]; setSize (7 * SQUARE_SIZE + 2 * BORDER_SIZE + 1, (6 + 1) * SQUARE_SIZE + TOP_OFFSET + BORDER_SIZE + 1); setLocation (100, 10); setTitle ("Connect Four: CANADA VS USA"); setBackground (new Color (100, 100, 100)); // Set up the Menu // Set up the Game MenuItems newOption = new MenuItem ("New"); exitOption = new MenuItem ("Exit"); helpOption = new MenuItem ("Help"); iconOption = new MenuItem ("Icon"); // Set up the Game Menu Menu gameMenu = new Menu ("Game"); Menu iconMenu = new Menu ("Icon"); Menu poiMenu = new Menu ("Help"); // Add each MenuItem to the Game Menu (with a separator) gameMenu.add (newOption); gameMenu.addSeparator (); gameMenu.add (exitOption); iconMenu.add (iconOption); poiMenu.add (helpOption); MenuBar mainMenu = new MenuBar (); mainMenu.add (gameMenu); mainMenu.add (iconMenu); mainMenu.add (poiMenu); // Set the menu bar for this frame to mainMenu setMenuBar (mainMenu); // Use a media tracker to make sure all of the images are // loaded before we continue with the program MediaTracker tracker = new MediaTracker (this); firstImage = Toolkit.getDefaultToolkit ().getImage ("banana.gif"); tracker.addImage (firstImage, 0); secondImage = Toolkit.getDefaultToolkit ().getImage ("strawberry.gif"); tracker.addImage (secondImage, 1); // Wait until all of the images are loaded try { tracker.waitForAll (); } catch (InterruptedException e) { } // Set up the icon image (Tracker not needed for the icon image) Image iconImage = Toolkit.getDefaultToolkit ().getImage ("News_Image_United-StatesVsCanada.png"); setIconImage (iconImage); // Start a new game and then make the window visible newGame (); setVisible (true); } // Constructor public void newGame () { currentPlayer = BANANA; clearBoard (board); gameOver = false; currentColumn = 3; repaint (); } public void clearBoard (int[] [] board) { for (int x = 0 ; x < board.length ; x++) for (int y = 0 ; y < board [x].length ; y++) board [x] [y] = 0; } public int findNextRow (int[] [] board, int column) { int height = 0; for (int i = 1 ; i < 7 ; i++) { if (board [i] [column] == 1 || board [i] [column] == -1) height++; } if (height == 6) return (-1); else return (6 - height); } public int checkForWinner (int[] [] board, int lastRow, int lastColumn) { int rowrow = lastRow; int column = lastColumn; //row int countDown = 0; while (lastRow >= 1) { if (board [lastRow] [lastColumn] == board [lastRow + 1] [lastColumn]) { countDown += 1; lastRow += 1; } else break; } lastRow = rowrow; int returning = 0; if (returning == 0) { for (int i = lastColumn - 3 ; i <= lastColumn + 3 ; i++) { if (i - 3 >= 0 && i <= 8 && returning == 0) { if (board [lastRow] [i] == -1 && board [lastRow] [i - 1] == -1 && board [lastRow] [i - 2] == -1 && board [lastRow] [i - 3] == -1) returning = -1; else if (board [lastRow] [i] == 1 && board [lastRow] [i - 1] == 1 && board [lastRow] [i - 2] == 1 && board [lastRow] [i - 3] == 1) returning = 1; } else if (i + 3 <= 8 && i >= 0 && returning == 0) { if (board [lastRow] [i] == -1 && board [lastRow] [i + 1] == -1 && board [lastRow] [i + 2] == -1 && board [lastRow] [i + 3] == -1) returning = -1; else if (board [lastRow] [i] == 1 && board [lastRow] [i + 1] == 1 && board [lastRow] [i + 2] == 1 && board [lastRow] [i + 3] == 1) returning = 1; } } } //right /*int countRight = 0; while (lastColumn < 8) { if (board [lastRow] [lastColumn] == board [lastRow] [lastColumn + 1]) { countRight += 1; lastColumn += 1; } else break; } lastColumn = column; //column int countLeft = 0; while (lastColumn > 0) { if (board [lastRow] [lastColumn] == board [lastRow] [lastColumn - 1]) { countLeft += 1; lastColumn -= 1; } else break; }*/ // to up left lastRow = rowrow; lastColumn = column; int countUpleft = 0; while (lastRow > 0 && lastColumn > 0) { if (board [lastRow] [lastColumn] == board [lastRow - 1] [lastColumn - 1]) { countUpleft++; lastColumn--; lastRow--; } else break; } //tp down right lastRow = rowrow; lastColumn = column; int countDownright = 0; while (lastRow < 8 && lastColumn < 9) { if (board [lastRow] [lastColumn] == board [lastRow + 1] [lastColumn + 1]) { countDownright++; lastColumn++; lastRow++; } else break; } // to up left lastRow = rowrow; lastColumn = column; int countUpright = 0; while (lastRow > 0 && lastColumn <= 7) { if (board [lastRow] [lastColumn] == board [lastRow - 1] [lastColumn + 1]) { countUpright++; lastColumn++; lastRow--; } else break; } //tp down right lastRow = rowrow; lastColumn = column; int countDownleft = 0; while (lastRow < 8 && lastColumn > 0) { if (board [lastRow] [lastColumn] == board [lastRow + 1] [lastColumn - 1]) { countDownleft++; lastColumn--; lastRow++; } else break; } if (countDown >= 3) return board [lastRow] [lastColumn]; else if (countUpleft + countDownright >= 3) return board [lastRow] [lastColumn]; else if (countUpright + countDownleft >= 3) return board [lastRow] [lastColumn]; else return returning; } public boolean mouseDown (Event event, int x, int y) { if (gameOver) { JOptionPane.showMessageDialog (this, "Please Select Game...New to start a new game", "Game Over", JOptionPane.WARNING_MESSAGE); return true; } int column = (x - BORDER_SIZE) / SQUARE_SIZE + 1; int row = findNextRow (board, column); if (row <= 0) { JOptionPane.showMessageDialog (this, "Please Select another Column", "Column is Full", JOptionPane.WARNING_MESSAGE); return true; } animatePiece (currentPlayer, column, row); board [row] [column] = currentPlayer; int winner = checkForWinner (board, row, column); if (winner == BANANA) { gameOver = true; repaint (0); JOptionPane.showMessageDialog (this, player1win, "GAME OVER", JOptionPane.INFORMATION_MESSAGE); } else if (winner == STRAWBERRY) { gameOver = true; repaint (0); JOptionPane.showMessageDialog (this, player2win, "GAME OVER", JOptionPane.INFORMATION_MESSAGE); } else // Switch to the other player
评论
    相关推荐
    • Connect6GUI.rar
      子棋人机博弈程序,可实现人人,机机,人机对战,有较强棋力。
    • 子棋.rar
      实现局面空位估值算法的六子棋程序,具有较好的AI性能,但仍需提高!
    • connect6.rar
      子棋作为五子棋改进的产物,问世很迟,推广的前景很广,我们旨在制作一个具有友好界面和完整功能的六子棋人机对弈的游戏软件,供六子棋爱好者进行人机对弈或者人人对弈。
    • dgtchess:用于电子 DGT 棋盘的事件驱动 JavaScript 连接器
      国际象棋 用于电子国际象棋棋盘的 JavaScript 连接器,可在浏览器和 node.js 中运行。 浏览器使用情况 客户端版本依赖于浏览器的 ,目前只有 Google Chrome 80 及更高版本支持,需要通过chrome://flags的#enable-...
    • 四子棋【人人/人机对战】
      四子棋 数据结构 C++ 人人对战 人机对战
    • JAVA实现分布式三子棋(文档化注释,可联网)
      程序说明: 当第一次开启一盘新棋局时,由玩家1先下,此盘结束后,下一盘开始,由输的一方先下,若平局,则下一盘开始由对方先下.当双方不再继续对战,即其中有一方退出或者双方退出后,重新开启的棋局依然由玩家1先下.
    • e-chess:带有AI Minimax算法的电子项目
      Docker安装和映像拉取 Debian: 安装Docker: : 在Docker Hub上创建帐户: : 运行以下命令: xhost + 登录到您的Docker帐户: sudo docker login (*)为e-chess sudo docker pull coderon98/e-chess:beta :...
    • connectfour-fxos:ConnectFour克隆
      这是在实施了屏风式四子棋克隆使用 (更精确地说,它使用实施FLUX架构)。 它使用和进行实时通信,并使用进行REST API(可以在找到代码)。 要求 nodejs / npm Redis 安装说明 安装bower ang gulp globaly npm ...
    • 子棋 ZSC幸存版
      子棋人机游戏。算法还可以,深度7,棋力还可以,搜索比较弱,速度比较慢,可供参考学习。可用visual studio直接打开
    • snowglobe-src-viewer-2.0.0-r0.tar.gz
      国外的开源游戏引擎,能够承载上千人,属于社交类的游戏