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

📄 controller.html

📁 这是一个用JAVA编程的俄罗斯方块程序
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc (build 1.5.0_01) on Tue Jan 29 17:09:35 CST 2008 -->
<TITLE>
Controller
</TITLE>

<META NAME="keywords" CONTENT="cn.itcast.tetris.controller.Controller class">

<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../stylesheet.css" TITLE="Style">

<SCRIPT type="text/javascript">
function windowTitle()
{
    parent.document.title="Controller";
}
</SCRIPT>
<NOSCRIPT>
</NOSCRIPT>

</HEAD>

<BODY BGCOLOR="white" onload="windowTitle();">


<!-- ========= START OF TOP NAVBAR ======= -->
<A NAME="navbar_top"><!-- --></A>
<A HREF="#skip-navbar_top" title="Skip navigation links"></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_top_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
  <TR ALIGN="center" VALIGN="top">
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="class-use/Controller.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
  </TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>

<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;PREV CLASS&nbsp;
&nbsp;NEXT CLASS</FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
  <A HREF="../../../../index.html?cn/itcast/tetris/controller/Controller.html" target="_top"><B>FRAMES</B></A>  &nbsp;
&nbsp;<A HREF="Controller.html" target="_top"><B>NO FRAMES</B></A>  &nbsp;
&nbsp;<SCRIPT type="text/javascript">
  <!--
  if(window==top) {
    document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>');
  }
  //-->
</SCRIPT>
<NOSCRIPT>
  <A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>


</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_top"></A>
<!-- ========= END OF TOP NAVBAR ========= -->

<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
<FONT SIZE="-1">
cn.itcast.tetris.controller</FONT>
<BR>
Class Controller</H2>
<PRE>
java.lang.Object
  <IMG SRC="../../../../resources/inherit.gif" ALT="extended by ">java.awt.event.KeyAdapter
      <IMG SRC="../../../../resources/inherit.gif" ALT="extended by "><B>cn.itcast.tetris.controller.Controller</B>
</PRE>
<DL>
<DT><B>All Implemented Interfaces:</B> <DD><A HREF="../../../../cn/itcast/tetris/listener/GroundListener.html" title="interface in cn.itcast.tetris.listener">GroundListener</A>, <A HREF="../../../../cn/itcast/tetris/listener/ShapeListener.html" title="interface in cn.itcast.tetris.listener">ShapeListener</A>, java.awt.event.KeyListener, java.util.EventListener</DD>
</DL>
<HR>
<DL>
<DT><PRE>public class <B>Controller</B><DT>extends java.awt.event.KeyAdapter<DT>implements <A HREF="../../../../cn/itcast/tetris/listener/ShapeListener.html" title="interface in cn.itcast.tetris.listener">ShapeListener</A>, <A HREF="../../../../cn/itcast/tetris/listener/GroundListener.html" title="interface in cn.itcast.tetris.listener">GroundListener</A></DL>
</PRE>

<P>
控制器<BR> 控制Ground, Snake, Food<BR> 负责游戏的逻辑<BR> 处理按键事件<BR> <BR>
<P>

<P>
<DL>
<DT><B>Version:</B></DT>
  <DD>1.0, 01/01/08</DD>
<DT><B>Author:</B></DT>
  <DD>汤阳光</DD>
</DL>
<HR>

<P>

<!-- ======== CONSTRUCTOR SUMMARY ======== -->

<A NAME="constructor_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Constructor Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><B><A HREF="../../../../cn/itcast/tetris/controller/Controller.html#Controller(cn.itcast.tetris.entities.ShapeFactory, cn.itcast.tetris.entities.Ground, cn.itcast.tetris.view.GamePanel)">Controller</A></B>(<A HREF="../../../../cn/itcast/tetris/entities/ShapeFactory.html" title="class in cn.itcast.tetris.entities">ShapeFactory</A>&nbsp;shapeFactory,
           <A HREF="../../../../cn/itcast/tetris/entities/Ground.html" title="class in cn.itcast.tetris.entities">Ground</A>&nbsp;ground,
           <A HREF="../../../../cn/itcast/tetris/view/GamePanel.html" title="class in cn.itcast.tetris.view">GamePanel</A>&nbsp;gamePanel)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><B><A HREF="../../../../cn/itcast/tetris/controller/Controller.html#Controller(cn.itcast.tetris.entities.ShapeFactory, cn.itcast.tetris.entities.Ground, cn.itcast.tetris.view.GamePanel, javax.swing.JLabel)">Controller</A></B>(<A HREF="../../../../cn/itcast/tetris/entities/ShapeFactory.html" title="class in cn.itcast.tetris.entities">ShapeFactory</A>&nbsp;shapeFactory,
           <A HREF="../../../../cn/itcast/tetris/entities/Ground.html" title="class in cn.itcast.tetris.entities">Ground</A>&nbsp;ground,
           <A HREF="../../../../cn/itcast/tetris/view/GamePanel.html" title="class in cn.itcast.tetris.view">GamePanel</A>&nbsp;gamePanel,
           javax.swing.JLabel&nbsp;gameInfoLabel)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;多接受一个 JTextComponent, 可以给在这个组件上显示提示信息</TD>
</TR>
</TABLE>
&nbsp;
<!-- ========== METHOD SUMMARY =========== -->

<A NAME="method_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Method Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../cn/itcast/tetris/controller/Controller.html#addGameListener(cn.itcast.tetris.listener.GameListener)">addGameListener</A></B>(<A HREF="../../../../cn/itcast/tetris/listener/GameListener.html" title="interface in cn.itcast.tetris.listener">GameListener</A>&nbsp;l)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;添加监听器, 可添加多个</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../cn/itcast/tetris/controller/Controller.html#beforeDeleteFullLine(cn.itcast.tetris.entities.Ground, int)">beforeDeleteFullLine</A></B>(<A HREF="../../../../cn/itcast/tetris/entities/Ground.html" title="class in cn.itcast.tetris.entities">Ground</A>&nbsp;ground,
                     int&nbsp;lineNum)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;处理Ground 触发的 beforeDeleteFullLine 事件将会改变满行的颜色并暂停一段时间</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../cn/itcast/tetris/controller/Controller.html#continueGame()">continueGame</A></B>()</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;继续游戏</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../cn/itcast/tetris/controller/Controller.html#fullLineDeleted(cn.itcast.tetris.entities.Ground, int)">fullLineDeleted</A></B>(<A HREF="../../../../cn/itcast/tetris/entities/Ground.html" title="class in cn.itcast.tetris.entities">Ground</A>&nbsp;ground,
                int&nbsp;deletedLineCount)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;处理Ground 触发的 fullLineDeleted 事件, 这个方法什么也没做, 只是打印了一句话</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;javax.swing.JLabel</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../cn/itcast/tetris/controller/Controller.html#getGameInfoLabel()">getGameInfoLabel</A></B>()</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;得到显示提示信息的组件</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../../../../cn/itcast/tetris/view/GamePanel.html" title="class in cn.itcast.tetris.view">GamePanel</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../cn/itcast/tetris/controller/Controller.html#getGamePanel()">getGamePanel</A></B>()</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../../../../cn/itcast/tetris/entities/Ground.html" title="class in cn.itcast.tetris.entities">Ground</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../cn/itcast/tetris/controller/Controller.html#getGround()">getGround</A></B>()</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../cn/itcast/tetris/controller/Controller.html#getNewInfo()">getNewInfo</A></B>()</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;获得游戏的最新提示信息</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../../../../cn/itcast/tetris/entities/ShapeFactory.html" title="class in cn.itcast.tetris.entities">ShapeFactory</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../cn/itcast/tetris/controller/Controller.html#getShapeFactory()">getShapeFactory</A></B>()</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../cn/itcast/tetris/controller/Controller.html#groundIsFull(cn.itcast.tetris.entities.Ground)">groundIsFull</A></B>(<A HREF="../../../../cn/itcast/tetris/entities/Ground.html" title="class in cn.itcast.tetris.entities">Ground</A>&nbsp;ground)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;处理Ground 的 groundIsFull() 事件, 将触发游戏结束事件</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;boolean</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../cn/itcast/tetris/controller/Controller.html#isPausingGame()">isPausingGame</A></B>()</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;游戏是否是在暂停状态</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;boolean</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../cn/itcast/tetris/controller/Controller.html#isPlaying()">isPlaying</A></B>()</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;是否正在游戏中</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;boolean</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../cn/itcast/tetris/controller/Controller.html#isShapeMoveDownable(cn.itcast.tetris.entities.Shape)">isShapeMoveDownable</A></B>(<A HREF="../../../../cn/itcast/tetris/entities/Shape.html" title="class in cn.itcast.tetris.entities">Shape</A>&nbsp;s)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;询问一下图形是否可以下落,如果不能下落了,就会让图形变成障碍物<BR> 这个方法是同步的</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../cn/itcast/tetris/controller/Controller.html#keyPressed(java.awt.event.KeyEvent)">keyPressed</A></B>(java.awt.event.KeyEvent&nbsp;e)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;处理键盘按键 <BR> LEFT: 向左移动<BR> RIGHT:向右移动<BR> DOWN: 向下移动<BR> UP: 变形<BR> PAGE UP: 加快速度<BR> PAGE DOWN: 减慢速度<BR> Y: 重新开始游戏<BR> ENTER: 暂停/继续</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../cn/itcast/tetris/controller/Controller.html#newGame()">newGame</A></B>()</CODE>

<BR>

⌨️ 快捷键说明

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