⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 humanplayer.java

📁 ParallelConnectFour是一个java小游戏
💻 JAVA
字号:
package edu.rit.cs.mlr5773.connectfour;import java.awt.event.*;import java.awt.*;/** * A Human Player.  Chooses a move by watching the board panel for * mouse clicks.  If the user chooses an invalid move, the system beeps * and waits for another move. * * @author Mark Roth */public class HumanPlayer extends Player implements MouseListener {  /** The board panel to watch for mouse clicks on */  private BoardPanel panel;  /**   * Creates a new Human Player   */  public HumanPlayer( ConnectFourGame game, int player, BoardPanel panel ) {    super( game, player );    this.panel = panel;  }  /**   * Ignore this Mouse Clicked event   */  public void mouseClicked( MouseEvent e ) {  }  /**   * Ignore this Mouse Entered event   */  public void mouseEntered( MouseEvent e ) {  }  /**   * Ignore this MouseExited Event   */  public void mouseExited( MouseEvent e ) {  }  /**   * When the user presses either mouse button, consider it a move   * in the column of the mouse cursor.  Assumes each column is 50   * pixels wide.  Removes self as a listener to the panel so that   * another player can grab the mouse as its own.   */  public void mousePressed( MouseEvent e ) {    Point p = e.getPoint();    Point move = new Point( p.x / 50, 5-(p.y/50) );    if( game.isValidMove( move.x ) ) {      panel.removeMouseListener( this );      game.move( move.x );    }    else {      Toolkit.getDefaultToolkit().beep();    }  }  /**   * Ignore this MouseReleased Event.   */  public void mouseReleased( MouseEvent e ) {  }  /**   * Process request by game to make a move.  Attach as a listener to the   * panel.   */  public void move() {    panel.addMouseListener( this );  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -