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

📄 chuangti.java~581~

📁 一个使用JB9编写的网络俄罗斯方块,大家可以下载如有不足还请原谅,有是可以给我EMAIL
💻 JAVA~581~
📖 第 1 页 / 共 3 页
字号:
package one_piece;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.awt.KeyboardFocusManager;
import java.net.*;
import java.io.*;
import javax.swing.border.*;
import javax.swing.event.*;
import Server.*;
import Client.*;
import java.util.StringTokenizer;
import 数据库.*;


public class CHUANGTI extends JFrame implements Runnable,NetRead {//窗体主类,游戏的引擎。
  JPanel contentPane;//用JPanel声名一个变量
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  JButton jButton3 = new JButton();
  JButton jButton4 = new JButton();
  public static final int NOCONNECT = 0, SERVER = 1, CLIENT = 2;//其中的NOCONNECT = 0表示单机游戏.
  public int m_nNetStatus = NOCONNECT;
  public Server m_server;
  public Client m_client;
  Panel Mine = new Panel();
  Panel Rival = new Panel();
  YuLan yulan = new YuLan();
  KeyboardFocusManager KeyFocus ;
  XYLayout xYLayout1 = new XYLayout();
    CHUANGTI m_CHUANGTI;

    private java.applet.AudioClip audioClip;//播放按键声音对象
    java.net.URL url;//存放背景音效

  ImageIcon kuai;
  //控制自己游戏区域的数组
  public static   int[][] mine = new int[10][24];
  //控制对手游戏区域的数组
  public static   int[][] ravil = new int[10][24];
  //生成新的方块
  Kuai  m_prePiece[] = new Kuai[4];
  //储存用的方块
  Kuai  m_curPiece[] = new Kuai[4];
  //用来存储游戏中的方块图片
  ImageIcon[]  tukuai= new ImageIcon[10];
  //存储游戏速度
  public  static  int thespeed = 7;
  //存储玩家分数
  public  static int  Score=0;
   int m_nPieceValue;
  public String str;
  //游戏是否在进行
  boolean IsGameInPlay;
  //是否要产生新方块
  boolean IsNeedNewPiece;
  //游戏是否暂停
  boolean Paused=false;
  //延迟时间
  int DelayMap[]={600,600,550,550,500,400,300,250,200,150,100};
  //线程
  //Thread  theThread = null;
  Thread  theThread;
  JDialog dd;
  //改变thespeed用的形参
  int value;
  //转换value用的
  String  valuestr;
  JSlider jSlider1 = new JSlider();
  JLabel jLabel1 = new JLabel(new ImageIcon("Mine2.gif"));//自己的游戏窗体背景的图片
   JLabel jLabel2 = new JLabel(new ImageIcon("zpbeijing4.gif"));//整体游戏的背景.
   public static int NOSQUARE=0;//连机时初始的
  JScrollPane jScrollPane1 = new JScrollPane();
  JTextField jTextField1 = new JTextField();
  ServerSocket server;
  Socket client;
  InputStream in;
  OutputStream out;
  Thread   Server = new  Thread(this);
  Thread Clinet = new  Thread(this);
  JButton jButton6 = new JButton();
  JLabel jLabel3 = new JLabel(new ImageIcon ("yulan.gif"));//预览匡的图片.
  Border border1;
  Border border2;
  Border border3;
  Border border4;
  JTextArea jTextArea1 = new JTextArea();
  Border border5;
  JLabel jLabel4 = new JLabel();
  JButton jButton5 = new JButton();
  Border border6;
  Border border7;
  Border border8;
  Border border9;
  JButton jButton7 = new JButton();
  Border border10;
  JButton jButton8 = new JButton();
  JButton jButton9 = new JButton();
  Border border11;
  JButton jButton10 = new JButton();
  Border border12;
  JButton jButton11 = new JButton();
  Border border13;
  Border border14;


  public CHUANGTI() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
      jbInit();
      myinit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
   private void jbInit() throws Exception  {
    contentPane = (JPanel) this.getContentPane();
    border1 = new MatteBorder(null);
    border2 = new MatteBorder(null);
    border3 = new MatteBorder(null);
    border4 = new MatteBorder(null);
    border5 = BorderFactory.createMatteBorder(6,6,6,6,Color.black);
    border6 = BorderFactory.createMatteBorder(6,6,6,6,SystemColor.windowBorder);
    border7 = BorderFactory.createMatteBorder(6,6,6,6,SystemColor.windowBorder);
    border8 = BorderFactory.createMatteBorder(6,6,6,6,SystemColor.controlText);
    border9 = BorderFactory.createMatteBorder(6,6,6,6,SystemColor.windowBorder);
    border10 = new MatteBorder(null);
    border11 = BorderFactory.createMatteBorder(6,6,6,6,SystemColor.windowBorder);
    border12 = BorderFactory.createMatteBorder(6,6,6,6,SystemColor.controlText);
    border13 = BorderFactory.createMatteBorder(6,6,6,6,SystemColor.controlText);
    border14 = BorderFactory.createMatteBorder(6,6,6,6,SystemColor.controlText);
    contentPane.setLayout(xYLayout1);
    this.setSize(new Dimension(1024, 768));
    this.setTitle("ONE PIECE");
    jButton1.setBackground(Color.red);
    jButton1.setFont(new java.awt.Font("Dialog", 0, 15));
    jButton1.setBorder(border1);
    jButton1.setDebugGraphicsOptions(0);
    jButton1.setBorderPainted(true);
    jButton1.setContentAreaFilled(true);
    jButton1.setDisabledIcon(null);
    jButton1.setDisabledSelectedIcon(null);
    jButton1.setIcon(new ImageIcon("image/kaishi.gif"));
    jButton1.setText("开始");
    jButton1.addMouseListener(new CHUANGTI_jButton1_mouseAdapter(this));
    jButton1.addActionListener(new CHUANGTI_jButton1_actionAdapter(this));
    jButton2.setBackground(Color.red);
    jButton2.setFont(new java.awt.Font("Dialog", 0, 15));
    jButton2.setBorder(border2);
    jButton2.setIcon(new ImageIcon("image/tuichu.gif"));
    jButton2.setMargin(new Insets(2, 14, 2, 14));
    jButton2.setText("退出");
    jButton2.addActionListener(new CHUANGTI_jButton2_actionAdapter(this));
    Mine.addKeyListener(new CHUANGTI_Mine_keyAdapter(this));
    jButton3.setBackground(Color.red);
    jButton3.setFont(new java.awt.Font("Dialog", 0, 15));
    jButton3.setBorder(border4);
    jButton3.setIcon(new ImageIcon("image/jieshu.gif"));
    jButton3.setText("结束");
    jButton3.addActionListener(new CHUANGTI_jButton3_actionAdapter(this));
    jButton4.setBackground(Color.red);
    jButton4.setFont(new java.awt.Font("Dialog", 0, 15));
    jButton4.setAlignmentY((float) 0.5);
    jButton4.setBorder(border3);
    jButton4.setIcon(new ImageIcon("image/zanting.gif"));
    jButton4.setText("暂停");
    jButton4.addActionListener(new CHUANGTI_jButton4_actionAdapter(this));
    jSlider1.setMaximum(11);
    jSlider1.setMinimum(1);
    jSlider1.setMinorTickSpacing(1);
    jSlider1.setBackground(Color.blue);
    jSlider1.setBorder(border8);
    jSlider1.setToolTipText("1");
    jSlider1.addAncestorListener(new CHUANGTI_jSlider1_ancestorAdapter(this));
    jSlider1.addMouseListener(new CHUANGTI_jSlider1_mouseAdapter(this));
    jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    jScrollPane1.setBorder(border5);
    jTextField1.setBackground(Color.blue);
    jTextField1.setBorder(border7);
    jTextField1.addActionListener(new CHUANGTI_jTextField1_actionAdapter(this));
    jButton6.setBackground(Color.blue);
    jButton6.setFont(new java.awt.Font("Dialog", 0, 13));
    jButton6.setForeground(Color.red);
    jButton6.setBorder(border6);
    jButton6.setText("发送");
    jButton6.addActionListener(new CHUANGTI_jButton6_actionAdapter(this));
    jTextArea1.setBackground(Color.blue);
    jTextArea1.setText("");
    jTextArea1.addAncestorListener(new CHUANGTI_jTextArea1_ancestorAdapter(this));
    jLabel4.setIcon(new ImageIcon("image/Mine.gif"));
    jButton5.setBackground(Color.blue);
    jButton5.setFont(new java.awt.Font("Dialog", 0, 13));
    jButton5.setForeground(Color.red);
    jButton5.setBorder(border9);
    jButton5.setText("OK");
    jButton5.addActionListener(new CHUANGTI_jButton5_actionAdapter(this));
    jButton7.setFont(new java.awt.Font("Dialog", 0, 13));
    jButton7.setForeground(Color.red);
    jButton7.setBorder(border10);
    jButton7.setMinimumSize(new Dimension(113, 85));
    jButton7.setToolTipText("");
    jButton7.setVerifyInputWhenFocusTarget(true);
    jButton7.setActionCommand("jButton7");
    jButton7.setIcon(new ImageIcon("image/shezhi.gif"));
    jButton7.setText("设置");
    jButton7.addActionListener(new CHUANGTI_jButton7_actionAdapter(this));
    jButton8.setBackground(Color.blue);
    jButton8.setBorder(border14);
    jButton8.setIcon(new ImageIcon("image/bangzhu.gif"));
    jButton8.setText("榜");
    jButton8.addActionListener(new CHUANGTI_jButton8_actionAdapter(this));
    jButton9.setBackground(Color.blue);
    jButton9.setFont(new java.awt.Font("Dialog", 0, 13));
    jButton9.setBorder(border11);
    jButton9.setText("等待连接");
    jButton9.addActionListener(new CHUANGTI_jButton9_actionAdapter(this));
    jButton10.setBackground(Color.blue);
    jButton10.setFont(new java.awt.Font("Dialog", 0, 13));
    jButton10.setBorder(border12);
    jButton10.setText("音乐");
    jButton10.addActionListener(new CHUANGTI_jButton10_actionAdapter(this));
    jButton11.setBackground(Color.blue);
    jButton11.setFont(new java.awt.Font("Dialog", 0, 13));
    jButton11.setBorder(border13);
    jButton11.setText("帮助");
    jButton11.addActionListener(new CHUANGTI_jButton11_actionAdapter(this));
    contentPane.add(Mine,   new XYConstraints(12, Mine.sqlenth*12+10, -1, -1));
    contentPane.add(Rival,   new XYConstraints(Mine.sqlenth*26,  Mine.sqlenth*12+10, -1, -1));
    Rival.add(jLabel4, new XYConstraints(0, 0, -1, -1));
    contentPane.add(yulan ,new XYConstraints(Mine.sqlenth*19+3, Mine.sqlenth*11+13, -1, -1));
    Mine.add(jLabel1,  new XYConstraints(0, 0, -1, -1));
    yulan.add(jLabel3, new XYConstraints(0, 0, -1, -1));
    contentPane.add(jButton6,   new XYConstraints(953, 475, 68, 28));
    contentPane.add(jTextField1,  new XYConstraints(742, 476, 205, 26));
    contentPane.add(jSlider1,      new XYConstraints(762, 394, 170, 54));
    contentPane.add(jScrollPane1,    new XYConstraints(739, 241, 268, 85));
    contentPane.add(jButton1,  new XYConstraints(636, 44, 108, 43));
    contentPane.add(jButton4,  new XYConstraints(906, 39, 106, 35));
    contentPane.add(jButton3, new XYConstraints(907, 149, 100, 38));
    contentPane.add(jButton2, new XYConstraints(634, 152, 106, 36));
    contentPane.add(jLabel2,  new XYConstraints(0, 0, -1, -1));
    contentPane.add(jButton5, new XYConstraints(945, 407, 65, 33));
    contentPane.add(jButton7,          new XYConstraints(796, 79, 55, 86));
    contentPane.add(jButton9, new XYConstraints(781, 180, 97, 41));
    contentPane.add(jButton8,   new XYConstraints(969, 581, 54, 48));
    contentPane.add(jButton10, new XYConstraints(782, 540, 129, 51));
    contentPane.add(jButton11, new XYConstraints(825, 644, 118, 50));
    jScrollPane1.getViewport().add(jTextArea1, null);
    tukuai[0] = new ImageIcon("image/touming.gif");
    tukuai[1] = new ImageIcon("image/tu1.gif");
    tukuai[2] = new ImageIcon("image/tu2.gif");
    tukuai[3] = new ImageIcon("image/tu3.gif");
    tukuai[4] = new ImageIcon("image/tu4.gif");
    tukuai[5] = new ImageIcon("image/tu5.gif");
    tukuai[6] = new ImageIcon("image/tu6.gif");
    tukuai[7] = new ImageIcon("image/tu6.gif");
    tukuai[8] = new ImageIcon("image/tu7.gif");
    tukuai[9] = new ImageIcon("image/tu8.gif");


  }
  void this_windowClosing(WindowEvent e) {
   if(m_nNetStatus==SERVER)m_server.close();

    if(m_nNetStatus==CLIENT)m_client.close();
    System.exit(0);
  }
///////////////////////////
  public void readStr(String str) {//对读过来的东西进行判断和处理.

          String  newstr;

          newstr=str;
  try{
      if(newstr.startsWith("talk:"))
      {
      this.str = str.substring( 5, str.length());//其中的5表示标识0
       jTextArea1.setText(this.str);//在TextArea1上显示聊天的信息.
     //以上是聊天显示信西
      }
      if(newstr.startsWith("start"))//游戏的开始事件
      {
        this.start();
      }
      if (str.equals("Pause")) {//游戏的暂停事件.
      this.pause();
    }
    if (str.equals("Stop")) {//游戏的结束事件.
     this.stop();
    }
     //以上是游戏开始
     //以下是游戏中对手部分的读取
     if (str.startsWith("mine:")) {
         int[] nRivalField = new int[200];
         str = str.substring(5, str.length());
         StringTokenizer st = new StringTokenizer(str, "|");
         int i = 0;
         try {
           while (st.hasMoreTokens()) {
             nRivalField[i] = Integer.parseInt(st.nextToken());
             i++;
           }
         }
         catch (Exception e) {}
         try{
         i = 0;
         for (int col = 0; col < 10; col++)
           for (int row = 0; row < 20; row++) {//通过两个循环将一维数组转换为二维数组.
             if (ravil[col][row] != nRivalField[i])
               ravil[col][row] = nRivalField[i];
             Rival.SetIcon(col, row, tukuai[ravil[col][row]]);//输出对手的游戏方块
             i++;
           }
           }
             catch(Exception e){ }
             }
           }
     catch(Exception e){}
  }
public void showMessage(String str)
  {
  }
  private void myinit()
  {
    try{
       kuai = new ImageIcon(new java.net.URL("file:///E:/Picture/money1.gif"));

   } catch(Exception e){}
  }
  private void newPrePiece()//产生新方块
{
    for(int i=0;i<4;i++)
      for(int j= 0 ;j<4;j++)
      yulan.SetIcon(i,j,tukuai[0]);//通过双循环每次刷新预栏区域的方块
     int middle=Mine.Comln/2;  //5
     int top=Mine.Row; //20
     int i;
   switch((int)(Math.random()*7))
     {//Math.ramdom 产生0--1的数
     case 0:
      //XXXX  red;
         m_nPieceValue=10;
        /*
         X X X X
        */
         m_prePiece[0]=new Kuai(middle-1,top-1,1);
         m_prePiece[1]=new Kuai(middle-2,top-1,1);
         m_prePiece[2]=new Kuai(middle,top-1,1);
         m_prePiece[3]=new Kuai(middle+1,top-1,1);
         for(i = 0;i<4;i++)
        {
     yulan.SetIcon(m_prePiece[i].m_nColumn-3,m_prePiece[i].m_nRow-18,tukuai[m_prePiece[i].m_ntupian]);

       }
         break;
        case 1:
        // X orange;
             //XX
        m_nPieceValue=20;
        /***
            X
        X X X
        */
          m_prePiece[0]=new  Kuai(middle-1,top-1,1);
          m_prePiece[1]=new  Kuai(middle-2,top-1,1);
          m_prePiece[2]=new  Kuai(middle,top-1,1);
          m_prePiece[3]=new Kuai(middle,top-2,1);
          for(i = 0;i<4;i++)

⌨️ 快捷键说明

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