项目实例--大炮小兵游戏源码解析

  游戏说明:大炮2个棋子,小兵18个棋子,大炮隔格可以吃掉小兵,小兵只好一步一步围死大炮

\点击此处下载源码
\

  package com.wenbo.game.cbp;
  import android.app.Activity;
  import android.app.AlertDialog;
  import android.content.DialogInterface;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.Window;
  import android.view.WindowManager;
  public class cannonBombpawn extends Activity {
  ChessView cv;
  final int MENU_START=Menu.FIRST;
  final int MENU_BIN=Menu.FIRST+1;
  final int MENU_PAO=Menu.FIRST+2;
  final int MENU_HELP=Menu.FIRST+3;
  final int MENU_QUIT=Menu.FIRST+4;
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  //设置全屏
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
  setContentView(R.layout.main);
  cv = (ChessView) findViewById(R.id.myview);
  }
  public boolean onCreateOptionsMenu(Menu menu) {
  menu.add(0,MENU_START, 0, "开始游戏");
  menu.add(0,MENU_BIN, 0, "选择小兵");
  menu.add(0,MENU_PAO, 0, "选择大炮");
  menu.add(0,MENU_HELP, 0, "游戏帮助");
  menu.add(0,MENU_QUIT, 0, "退出");
  return true;
  }
  /* (non-Javadoc)
  * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
  */
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
  super.onOptionsItemSelected(item);
  switch(item.getItemId()){
  case MENU_START:
  cv.init();
  break;
  case MENU_HELP:
  Intent in = new Intent();
  in.setClass(cannonBombpawn.this, AboutActivy.class);
  startActivity(in);
  break;
  case MENU_QUIT:
  openDialog();
  break;
  case MENU_BIN:
  cv.choiceBin();
  break;
  case MENU_PAO:
  cv.choicePao();
  break;
  }
  return true;
  }
  /**
  * 用户点击退出对话框
  *@author chenbo
  *@date 2010-12-17
  */
  private void openDialog(
  AlertDialog.Builder bl = new AlertDialog.Builder(this);
  bl.setTitle("退出游戏");
  bl.setMessage("确定要退出游戏?");
  bl.setPositiveButton("确定", new DialogInterface.OnClickListener() {
  public void onClick(DialogInterface dialog, int which) {
  finish();
  }
  });
  bl.setNegativeButton("取消", new DialogInterface.OnClickListener() {
  @Override
  public void onClick(DialogInterface dialog, int which) {
  }
  });
  bl.show();
  }
  }

项目实例--大炮小兵游戏源码解析


转载:http://www.adobex.com/android/source/details/00000166.htm

你可能感兴趣的:(项目实例--大炮小兵游戏源码解析)