android平台俄罗斯方块游戏完整代码
2012-12-02 14:31:58 来源:WEB开发网核心提示:public class WelcomeActivity extends Activity implements OnTouchListener,OnGestureListener{GestureDetector m_GestureDetector ; // 手势 public WelcomeActivity() {
public class WelcomeActivity extends Activity implements OnTouchListener,OnGestureListener{
GestureDetector m_GestureDetector ; // 手势
public WelcomeActivity()
{
m_GestureDetector = new GestureDetector((OnGestureListener) this);
}
TextView mTextView = null;
MenuView m_MenuView = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); // 设置无标题,全面模式
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
m_MenuView = new MenuView(this);
setContentView(m_MenuView);
MusicPlay.inItMenuMusicPlay(this);
MusicPlay.menuMusic();
MusicPlay.startMenuMusic();
m_MenuView.setOnTouchListener((OnTouchListener) this);
m_MenuView.setClickable(true);
m_GestureDetector.setIsLongpressEnabled(true);
}
public boolean onKeyDown(int key,KeyEvent keyevent) //对按键的响应
{
if(key == KeyEvent.KEYCODE_BACK && keyevent.getRepeatCount() == 0) //返回键 提示对话框
{
dialog();
return true;
}
return true;//super.onKeyDown(key, keyevent);
}
protected void dialog() // 对话框函数
{
AlertDialog.Builder builder = new Builder(WelcomeActivity.this);
builder.setMessage("是否需要帮助!!!");
builder.setTitle("提示");
builder.setPositiveButton("取消",
new android.content.DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
MusicPlay.releaseMenuMusic();
dialog.dismiss();
android.os.Process.killProcess(android.os.Process.myPid());
}
});
builder.setNegativeButton("确定",
new android.content.DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(WelcomeActivity.this,helpActivity.class);
startActivity(intent);
}
});
builder.create().show();
}
public boolean onTouch(View v, MotionEvent event)
{
return m_GestureDetector.onTouchEvent(event);
}
public void onResume()
{
super.onResume();
MusicPlay.startMenuMusic();
}
public void onDestroy()
{
super.onDestroy();
MusicPlay.releaseMenuMusic();
WelcomeActivity.this.finish();
}
public boolean onDown(MotionEvent event) {
// TODO Auto-generated method stub
int x = (int)event.getX();
int y = (int)event.getY();
if(m_MenuView.m_ImageButton_Play.IsClick(x, y))
{
Intent intent = new Intent(WelcomeActivity.this,GameActivity.class);
startActivity(intent);
MusicPlay.pauseMenuMusic();
}
return true;
}
public boolean onFling(MotionEvent arg0, MotionEvent arg1, float arg2,
float arg3) {
// TODO Auto-generated method stub
return false;
}
public void onLongPress(MotionEvent arg0) {
// TODO Auto-generated method stub
}
public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
float arg3) {
// TODO Auto-generated method stub
return false;
}
public void onShowPress(MotionEvent arg0) {
// TODO Auto-generated method stub
}
public boolean onSingleTapUp(MotionEvent arg0) {
// TODO Auto-generated method stub
return false;
}
}
public WelcomeActivity()
{
m_GestureDetector = new GestureDetector((OnGestureListener) this);
}
TextView mTextView = null;
MenuView m_MenuView = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); // 设置无标题,全面模式
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
m_MenuView = new MenuView(this);
setContentView(m_MenuView);
MusicPlay.inItMenuMusicPlay(this);
MusicPlay.menuMusic();
MusicPlay.startMenuMusic();
m_MenuView.setOnTouchListener((OnTouchListener) this);
m_MenuView.setClickable(true);
m_GestureDetector.setIsLongpressEnabled(true);
}
public boolean onKeyDown(int key,KeyEvent keyevent) //对按键的响应
{
if(key == KeyEvent.KEYCODE_BACK && keyevent.getRepeatCount() == 0) //返回键 提示对话框
{
dialog();
return true;
}
return true;//super.onKeyDown(key, keyevent);
}
protected void dialog() // 对话框函数
{
AlertDialog.Builder builder = new Builder(WelcomeActivity.this);
builder.setMessage("是否需要帮助!!!");
builder.setTitle("提示");
builder.setPositiveButton("取消",
new android.content.DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
MusicPlay.releaseMenuMusic();
dialog.dismiss();
android.os.Process.killProcess(android.os.Process.myPid());
}
});
builder.setNegativeButton("确定",
new android.content.DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(WelcomeActivity.this,helpActivity.class);
startActivity(intent);
}
});
builder.create().show();
}
public boolean onTouch(View v, MotionEvent event)
{
return m_GestureDetector.onTouchEvent(event);
}
public void onResume()
{
super.onResume();
MusicPlay.startMenuMusic();
}
public void onDestroy()
{
super.onDestroy();
MusicPlay.releaseMenuMusic();
WelcomeActivity.this.finish();
}
public boolean onDown(MotionEvent event) {
// TODO Auto-generated method stub
int x = (int)event.getX();
int y = (int)event.getY();
if(m_MenuView.m_ImageButton_Play.IsClick(x, y))
{
Intent intent = new Intent(WelcomeActivity.this,GameActivity.class);
startActivity(intent);
MusicPlay.pauseMenuMusic();
}
return true;
}
public boolean onFling(MotionEvent arg0, MotionEvent arg1, float arg2,
float arg3) {
// TODO Auto-generated method stub
return false;
}
public void onLongPress(MotionEvent arg0) {
// TODO Auto-generated method stub
}
public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
float arg3) {
// TODO Auto-generated method stub
return false;
}
public void onShowPress(MotionEvent arg0) {
// TODO Auto-generated method stub
}
public boolean onSingleTapUp(MotionEvent arg0) {
// TODO Auto-generated method stub
return false;
}
}
更多精彩
赞助商链接