欢迎来到三一文库! | 帮助中心 三一文库31doc.com 一个上传文档投稿赚钱的网站
三一文库
全部分类
  • 研究报告>
  • 工作总结>
  • 合同范本>
  • 心得体会>
  • 工作报告>
  • 党团相关>
  • 幼儿/小学教育>
  • 高等教育>
  • 经济/贸易/财会>
  • 建筑/环境>
  • 金融/证券>
  • 医学/心理学>
  • ImageVerifierCode 换一换
    首页 三一文库 > 资源分类 > DOC文档下载  

    程序源代码模板 (2).doc

    • 资源ID:11045962       资源大小:139.50KB        全文页数:40页
    • 资源格式: DOC        下载积分:6
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录   微博登录  
    二维码
    微信扫一扫登录
    下载资源需要6
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    程序源代码模板 (2).doc

    页面布局模块程序代码MainActivity.javapackage com.my.llkangame;/第一个页面import android.app.ListActivity;import android.app.ProgressDialog;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.ViewGroup;import android.widget.ImageView;import android.widget.ListView;import android.widget.TextView;import com.plter.lib.android.java.controls.ArrayAdapter;import com.plter.linkgame.R;public class MainActivity extends ListActivity private ArrayAdapter<GameListCellData> adapter;/定义适配器private ProgressDialog dialog=null;/dialog/savedInstanceStateprotected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);setContentView(R.layout.main_activity);/main_activity.xml/设置适配器adapter=new ArrayAdapter<MainActivity.GameListCellData>(this,R.layout.game_list_cell) Overridepublic void initListCell(int position, View listCell, ViewGroup parent) ImageView iconIv = (ImageView) listCell.findViewById(R.id.iconIv);TextView labelTv=(TextView) listCell.findViewById(R.id.labelTv);GameListCellData data = getItem(position);iconIv.setImageResource(data.iconResId);labelTv.setText(data.label);setListAdapter(adapter);/适配器集合adapter.add(new GameListCellData("水果连连看", R.drawable.sg_icon, "sg_config.json");adapter.add(new GameListCellData("蔬菜连连看", R.drawable.sc_icon, "sc_config.json");adapter.add(new GameListCellData("动物连连看", R.drawable.dw_icon, "dw_config.json");adapter.add(new GameListCellData("爱心连连看", R.drawable.love_icon, "love_config.json");adapter.add(new GameListCellData("宝石连连看", R.drawable.coin_icon, "coin_config.json");Overrideprotected void onPause() if (dialog!=null) dialog.dismiss();dialog=null;super.onPause();Overrideprotected void onListItemClick(ListView l, View v, int position, long id) dialog=ProgressDialog.show(this, "请稍候", "正在加载游戏资源");GameListCellData data = adapter.getItem(position);Intent i = new Intent(this, LinkGameActivity.class);i.putExtra("configFile", data.gameConfigFile);startActivity(i);super.onListItemClick(l, v, position, id);public static class GameListCellDatapublic String label=null;public int iconResId=0;public String gameConfigFile=null;public GameListCellData(String label,int iconResId,String gameConfigFile) this.label=label;this.iconResId=iconResId;this.gameConfigFile=gameConfigFile;LinkGameActivity.javapackage com.my.llkangame;import android.app.Activity;import android.os.Bundle;import android.text.TextUtils;import android.view.Display;import android.widget.Button;import android.widget.TextView;import com.my.cord.Config;import com.my.cord.GameViewhhxx;import com.my.reader.InnerGameReader;import com.plter.linkgame.R;/游戏开始界面宽高、布局等且开始游戏public class LinkGameActivity extends Activity private GameViewhhxx gameView;/* Called when the activity is first created. */ SuppressWarnings("deprecation")public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); String configFile = getIntent().getStringExtra("configFile"); if (TextUtils.isEmpty(configFile) finish();return; /获得屏幕宽高 Display display = getWindowManager().getDefaultDisplay(); Config.setScreenWidth(display.getWidth(); Config.setScreenHeight(display.getHeight(); /设置内容布局 setContentView(R.layout.link_game_activity); gameView=(GameViewhhxx) findViewById(R.id.gameView); gameView.setTimeTv(TextView) findViewById(R.id.timeTv); gameView.setLevelTv(TextView) findViewById(R.id.levelTv); gameView.setBreakCardsBtn(Button) findViewById(R.id.breakCardsBtn); gameView.setNoteBtn(Button) findViewById(R.id.noteBtn); gameView.setPauseBtn(Button) findViewById(R.id.pauseBtn); /根据游戏资源包初始化游戏 gameView.initWithGamePkg(InnerGameReader.readGame(this, configFile); /开始启动游戏 gameView.showStartGameAlert(); protected void onPause() gameView.pause(); super.onPause(); protected void onResume() gameView.resume(); super.onResume(); LinesContainer.javapackage com.my.cord;import java.util.List;import android.content.Context;import android.graphics.Canvas;import android.graphics.Paint;import android.graphics.Paint.Style;import android.graphics.Path;import android.graphics.PointF;import android.view.View;import android.view.animation.AlphaAnimation;import android.view.animation.Animation;import android.view.animation.Animation.AnimationListener;/* * 设置对图片进行连接的线的宽度和颜色 */public class LinesContainer extends View implements AnimationListenerprivate List<PointF> points=null;private final Paint paint=new Paint();private final Path path = new Path();private final AlphaAnimation aa = new AlphaAnimation(1, 0);public LinesContainer(Context context) super(context);paint.setStyle(Style.STROKE);paint.setStrokeWidth(5);paint.setColor(0xFFFF0000);aa.setDuration(500);aa.setAnimationListener(this);setVisibility(View.GONE);public void showLines(List<PointF> points)if (points.size()<2) throw new RuntimeException("点的个数不能小于2");elsesetVisibility(View.VISIBLE);this.points=points;invalidate();startAnimation(aa);protected void onDraw(Canvas canvas) if (points=null|points.size()<2) return;path.reset();PointF p=points.get(0);path.moveTo(p.x, p.y);for (int i = 1; i < points.size(); i+) p=points.get(i);path.lineTo(p.x, p.y);canvas.drawPath(path, paint);super.onDraw(canvas);public void onAnimationStart(Animation animation) public void onAnimationEnd(Animation animation) setVisibility(View.GONE);public void onAnimationRepeat(Animation animation) Config.javapackage com.my.cord;public class Config private static float cardWidth=0;private static float cardHeight=0;private static float screenWidth=0;private static float screenHeight=0;private static float cardsOffsetX=0;private static float cardsOffsetY=0;/* * 游戏区域的宽度 */private static float gameCardsAreaWidth=0;/* * 游戏区域的高度 */private static float gameCardsAreaHeight=0;/* * 卡片的上边距 */public static final float GAME_CARDS_AREA_TOP=80;/* * 卡片的下边距 */public static final float GAME_CARDS_AREA_BOTTOM=80;/* * 卡片区域左边距 */public static final float GAME_CARDS_AREA_LEFT=0;/* * 卡片区域右边距 */public static final float GAME_CARDS_AREA_RIGHT=0;/* * return the screenWidth */public static float getScreenWidth() return screenWidth;/* * param screenWidth the screenWidth to set */public static void setScreenWidth(float screenWidth) Config.screenWidth = screenWidth;Config.setGameCardsAreaWidth(Config.getScreenWidth()-Config.GAME_CARDS_AREA_LEFT-Config.GAME_CARDS_AREA_RIGHT);computeCardWidthAndHeight();/* * return the screenHeight */public static float getScreenHeight() return screenHeight;/* * param screenHeight the screenHeight to set */public static void setScreenHeight(float screenHeight) Config.screenHeight = screenHeight;Config.setGameCardsAreaHeight(Config.getScreenHeight()-Config.GAME_CARDS_AREA_BOTTOM-Config.GAME_CARDS_AREA_TOP);computeCardWidthAndHeight();private static void computeCardWidthAndHeight()float cardWidth=Config.getGameCardsAreaWidth()/Level.MAX_H_CARDS_COUNT;float cardHeight=Config.getGameCardsAreaHeight()/Level.MAX_V_CARDS_COUNT;float min = Math.min(cardWidth, cardHeight);Config.setCardWidth(min);/卡片最小宽Config.setCardHeight(min);/卡片最小高/* * return the cardWidth */public static float getCardWidth() return cardWidth;/* * param cardWidth the cardWidth to set */private static void setCardWidth(float cardWidth) Config.cardWidth = cardWidth;/* * return the cardHeight */public static float getCardHeight() return cardHeight;/* * param cardHeight the cardHeight to set */private static void setCardHeight(float cardHeight) Config.cardHeight = cardHeight;/* * return the cardsOffsetX */public static float getCardsOffsetX() return cardsOffsetX;/* * param cardsOffsetX the cardsOffsetX to set */public static void setCardsOffsetX(float cardsOffsetX) Config.cardsOffsetX = cardsOffsetX;/* * return the cardsOffsetY */public static float getCardsOffsetY() return cardsOffsetY;/* * param cardsOffsetY the cardsOffsetY to set */public static void setCardsOffsetY(float cardsOffsetY) Config.cardsOffsetY = cardsOffsetY;/* * return the gameCardsAreaWidth */public static float getGameCardsAreaWidth() return gameCardsAreaWidth;/* * param gameCardsAreaWidth the gameCardsAreaWidth to set */private static void setGameCardsAreaWidth(float gameCardsAreaWidth) Config.gameCardsAreaWidth = gameCardsAreaWidth;/* * return the gameCardsAreaHeight */public static float getGameCardsAreaHeight() return gameCardsAreaHeight;/* * param gameCardsAreaHeight the gameCardsAreaHeight to set */private static void setGameCardsAreaHeight(float gameCardsAreaHeight) Config.gameCardsAreaHeight = gameCardsAreaHeight;Picture.javapackage com.my.reader;import android.graphics.Bitmap;/* * Bitmap 面板 * */public class Picture public Picture(Bitmap bitmap) this.bitmap=bitmap;id=_getId();public Bitmap getBitmap() return bitmap;private int id=0;public int getId() return id;private Bitmap bitmap=null;private static int _id=0;private static int _getId()_id+;return _id;算法分析模块程序代码Cardmm.javapackage com.my.cord;/*重排:先遍历当前页面还有的图片,调用随机算法调换页面中图片的位置 * 先选中一张图片,获取此图片在垂直和水平方向上的的位置,判断是否被选中,判断当前已选中的图片个数 *若选中图片个数小于2张,再选择一张图片,重复上一个动作,若选中图片个数达到2张,判断是否满足消除条件 *若满足,则消除,若不满足,则不发生任何变化。 */import android.content.Context;import android.graphics.Canvas;import android.graphics.Paint;import android.graphics.Paint.Style;import android.graphics.PointF;import android.view.View;import android.view.animation.Animation;import android.view.animation.Animation.AnimationListener;import android.widget.FrameLayout;import android.widget.ImageView;import android.widget.RelativeLayout;import com.my.reader.Picture;public class Cardmm extends FrameLayout private Picture picture=null;private boolean checked=false;private int indexI=0;private int indexJ=0;private final PointF center=new PointF();private final float lineWidth=3;private final float halfWidth=lineWidth/2;private RelativeLayout.LayoutParams lp;private ImageView imageView=null;private View checkedRect=null;private View noteRect=null;private final CardNoteAnim cna = new CardNoteAnim();public Cardmm(Context context,Picture pic) super(context);picture=pic;imageView=new ImageView(getContext();/图像集合imageView.setImageBitmap(getPicture().getBitmap();addView(imageView, -1, -1);noteRect=createRectLine(0xFF00FF00);addView(noteRect, -1, -1);noteRect.setVisibility(View.INVISIBLE);checkedRect=createRectLine(0xFFFF0000);addView(checkedRect, -1, -1);setChecked(false);/config note animationcna.setDuration(3000);cna.setAnimationListener(cardNoteAnimListener);public void setX(float x) lp=getLayoutParams();lp.leftMargin=(int) x;setLayoutParams(lp);resetCenter();public void setY(float y) lp=getLayoutParams();lp.topMargin=(int) y;setLayoutParams(lp);resetCenter();public void setXY(float x,float y)lp=getLayoutParams();lp.topMargin=(int) y;lp.leftMargin=(int) x;setLayoutParams(lp);resetCenter();/* * 根据index i j重置图片的位置 * 重排图片 */public void resetPositionByIndexIJ()setX(GameUtilmm.getXByIndexi(getIndexI();/定位获取x方向setY(GameUtilmm.getYByIndexJ(getIndexJ();/定位获取y方向/* * 返回图片 */public Picture getPicture() return picture;/* * 判断是否选中 */public boolean isChecked() return checked;/* * 根据是否选中图片进行消除操作 */public void setChecked(boolean checked) this.checked = checked;if (checked) checkedRect.setVisibility(View.VISIBLE);stopNoteAnim();/停止提示动画elsecheckedRect.setVisibility(View.INVISIBLE);/* * return the indexI */public int getIndexI() return indexI;/* * param indexI the indexI to set */public void setIndexI(int indexI) this.indexI = indexI;/* * return the indexJ */public int getIndexJ() return indexJ;/* * param indexJ the indexJ to set */public void setIndexJ(int indexJ) this.indexJ = indexJ;public float getCenterX() return getCenter().x;public float getCenterY() return getCenter().y;public float getX()return getLayoutParams().leftMargin;public float getY()return getLayoutParams().topMargin;public RelativeLayout.LayoutParams getLayoutParams() return (android.widget.RelativeLayout.LayoutParams) super.getLayoutParams();private void resetCenter()getCenter().x=getX()+Config.getCardWidth()/2;getCenter().y=getY()+Config.getCardHeight()/2;/* * return the center */public PointF getCenter() return center;/* * 开始提示动画 */public void startNoteAnim()noteRect.setVisibility(View.VISIBLE);noteRect.startAnimation(cna);/* * 停止提示动画 */public void stopNoteAnim()if (noteRect.getVisibility()!=View.VISIBLE) noteRect.setAnimation(null);noteRect.setVisibility(View.INVISIBLE);private View createRectLine(int color)final Paint frontShapePaint=new Paint();frontShapePaint.setColor(color);frontShapePaint.setStyle(Style.STROKE);frontShapePaint.setStrokeWidth(lineWidth);/行宽return new View(getContext()protected void onDraw(Canvas canvas) canvas.drawRect(halfWidth, halfWidth, Config.getCardWidth()-lineWidth, Config.getCardHeight()-lineWidth, frontShapePaint);super.onDraw(canvas);private final AnimationListener cardNoteAnimListener=new AnimationListener() public void onAnimationStart(Animation animation) / TODO Auto-generated method stubpublic void onAnimationRepeat(Anim

    注意事项

    本文(程序源代码模板 (2).doc)为本站会员(rrsccc)主动上传,三一文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一文库(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    经营许可证编号:宁ICP备18001539号-1

    三一文库
    收起
    展开