ImageVerifierCode 换一换
格式:DOCX , 页数:37 ,大小:257.58KB ,
资源ID:4380425      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/4380425.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(android平台俄罗斯方块游戏完整代码.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

android平台俄罗斯方块游戏完整代码.docx

1、android平台俄罗斯方块游戏完整代码整个游戏我分为10个java文件:先是俄罗斯方块的形状存储statefang.java,代码如下: package com.example.eluosifangkuai;public class statefang /方块的逻辑类 public static int state = new i整个游戏我分为10个java文件:先是俄罗斯方块的形状存储statefang.java,代码如下:package com.example.eluosifangkuai;public class statefang /方块的逻辑类public static int s

2、tate = new int / I 0, 0, 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, 1, 0 , 0, 1, 0, 0 , / T19 0, 0, 0, 0 , 1, 0, 0, 0 , 1, 1, 0, 0 , 1, 0, 0, 0 , / T20 0, 0, 0, 0 , 0, 0, 0, 0 , 0, 1

6、, 1, 0 , 1, 1, 0, 0 , / S21 0, 0, 0, 0 , 0, 1, 0, 0 , 0, 1, 1, 0 , 0, 0, 1, 0 , / S22 0, 0, 0, 0 , 0, 0, 0, 0 , 0, 1, 1, 0 , 1, 1, 0, 0 , / S23 0, 0, 0, 0 , 0, 1, 0, 0 , 0, 1, 1, 0 , 0, 0, 1, 0 , / Z24 0, 0, 0, 0 , 0, 0, 0, 0 , 1, 1, 0, 0 , 0, 1, 1, 0 , / Z25 0, 0, 0, 0 , 0, 0, 1, 0 , 0, 1, 1, 0 , 0

7、, 1, 0, 0 , / Z26 0, 0, 0, 0 , 0, 0, 0, 0 , 1, 1, 0, 0 , 0, 1, 1, 0 , / Z27 0, 0, 0, 0 , 0, 0, 1, 0 , 0, 1, 1, 0 , 0, 1, 0, 0 / 28;我们当然还要编写音乐播放类,资源播放类了等等。我把所有的图片资源编写在一个类里面,叫做GameResources.java,具体代码如下:package com.example.eluosifangkuai;import android.content.Context;import android.content.res.Resourc

8、es;import android.graphics.Bitmap;import android.graphics.Canvas;import android.graphics.Bitmap.Config;import android.graphics.Paint;import android.graphics.drawable.Drawable;public class GameResources Resources m_Resources; / 资源类Canvas m_Canvas; / 画布Bitmap m_Bitmaphc = null; / 缓冲位图Bitmap m_Bitmap01

9、 = null; / 图像位图Bitmap m_Bitmaps = new Bitmap8; /精灵位图Bitmap score; / 分数位图Bitmap Play; / 开始位图Bitmap Level;public GameResources(Context context) / 初始化 装载位图m_Resources = context.getResources();for(int i=0;i7;i+)m_Bitmapsi = createImage(m_Resources.getDrawable(R.drawable.cube_960_011+i),18,18);m_Bitmap01

10、 = createImage(m_Resources.getDrawable(R.drawable.bgcatcher),320,480);m_Bitmaps7 = createImage(m_Resources.getDrawable(R.drawable.main11),320,402);score = createImage(m_Resources.getDrawable(R.drawable.score),87,150);Play = createImage(m_Resources.getDrawable(R.drawable.b7),320,480);Level = createIm

11、age(m_Resources.getDrawable(R.drawable.levelup),139,88);m_Bitmaphc = Bitmap.createBitmap(320,480, Config.ARGB_8888);m_Canvas = new Canvas(m_Bitmaphc);bitmapB();public void bitmapB()Paint m_Paint = new Paint();m_Paint.setAntiAlias(true);m_Paint.setAlpha(220);m_Canvas.drawBitmap(m_Bitmap01, 0,0,null);

12、public static Bitmap createImage(Drawable tile, int w, int h) / 双缓冲 加载位图资源Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);Canvas canvas = new Canvas(bitmap);tile.setBounds(0, 0, w, h);tile.draw(canvas);return bitmap;音乐播放类,MusicPlay.java 具体代码如下:package com.example.eluosifangkuai;im

13、port java.util.HashMap;import java.util.Map;import android.content.Context;import android.media.AudioManager;import android.media.MediaPlayer;import android.media.SoundPool;public class MusicPlay public static MediaPlayer m_MediaPlay ; / 背景播放器public static MediaPlayer m_MenuPlay ;public static Sound

14、Pool soundPool;/声明 音效播放器public MediaPlayer m_FastDown ;private static boolean musicSwitch = true;/音乐开关private static boolean soundSwitch = true;/音效开关private static Map soundMap; /音效资源id与加载过后的音源id的映射关系表private static Context context;public static void inItMusicPlay(Context c) context = c;public stati

15、c void inItMenuMusicPlay(Context c) context = c;/初始化背景播放器public static void BgMediaplayer() m_MediaPlay = MediaPlayer.create(context, R.raw.gamebg); m_MediaPlay.setLooping(true);public static void menuMusic()m_MenuPlay = MediaPlayer.create(context, R.raw.menubg);m_MenuPlay.setLooping(true); public s

16、tatic void pauseMusic() if(m_MediaPlay.isPlaying() m_MediaPlay.pause(); public static void pauseMenuMusic() if(m_MenuPlay.isPlaying() m_MenuPlay.pause(); public static void startMusic()if(musicSwitch) m_MediaPlay.start(); public static void startMenuMusic()if(musicSwitch) m_MenuPlay.start(); public

17、static void releaseMusic()if(m_MediaPlay != null) m_MediaPlay.release(); public static void releaseMenuMusic()if(m_MenuPlay != null) m_MenuPlay.release();/设置音乐开关 public static void setMusicSwitch(boolean musicSwitch)MusicPlay.musicSwitch = musicSwitch;if(MusicPlay.musicSwitch) m_MediaPlay.start();el

18、se m_MediaPlay.stop();public static void inItSound()soundPool = new SoundPool(8,AudioManager.STREAM_MUSIC,0);soundMap = new HashMap();/将音效资源加入 soundPool,并做成soundMap 映射soundMap.put(R.raw.action,soundPool.load(context, R.raw.action, 1);soundMap.put(R.raw.fastdown,soundPool.load(context, R.raw.fastdown

19、, 1);soundMap.put(R.raw.rotation,soundPool.load(context, R.raw.rotation, 1);soundMap.put(R.raw.down,soundPool.load(context, R.raw.down, 1);soundMap.put(R.raw.delete1,soundPool.load(context, R.raw.delete1, 1);soundMap.put(R.raw.delete2,soundPool.load(context, R.raw.delete2, 1);soundMap.put(R.raw.dele

20、te3,soundPool.load(context, R.raw.delete3, 1);soundMap.put(R.raw.delete4,soundPool.load(context, R.raw.delete4, 1); public static int playSound(int resId,int loop) if(!soundSwitch) return 0;Integer soundId = soundMap.get(resId); if(soundId != null) return soundPool.play(soundId, 1, 1, 1, loop, 1); e

21、lse return 0; public static void releaseSound() if(soundPool != null)soundPool.release(); 另外我还编写了一个图片按钮类,名为ImageButton.java 具体代码如下:package com.example.eluosifangkuai;import java.io.InputStream;import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import

22、android.graphics.Canvas;import android.graphics.Paint;public class ImageButton / 按钮图片 private Bitmap mBitButton = null; /图片绘制的XY坐标 private int mPosX =0; private int mPosY =0; /图片绘制的宽高 private int mWidth =0; private int mHeight =0; public ImageButton(Context context, int frameBitmapID, int x, int y)

23、mBitButton = ReadBitMap(context,frameBitmapID);mPosX = x;mPosY = y;mWidth = mBitButton.getWidth();mHeight = mBitButton.getHeight(); /绘制图片按钮 public void DrawImageButton(Canvas canvas, Paint paint) canvas.drawBitmap(mBitButton, mPosX, mPosY, paint); / 判断是否点中图片按钮 public boolean IsClick(int x, int y) bo

24、olean isClick = false;if (x = mPosX & x = mPosY & y = mPosY + mHeight) isClick = true;return isClick; / 读取图片资源 public Bitmap ReadBitMap(Context context, int resId) BitmapFactory.Options opt = new BitmapFactory.Options();opt.inPreferredConfig = Bitmap.Config.RGB_565;opt.inPurgeable = true;opt.inInput

25、Shareable = true;/ 获取资源图片InputStream is = context.getResources().openRawResource(resId);return BitmapFactory.decodeStream(is, null, opt); 下面是显示开始图片按钮MenuView.java,代码如下:package com.example.eluosifangkuai;import android.content.Context;import android.graphics.Canvas;import android.view.View;public cla

26、ss MenuView extends View ImageButton m_ImageButton_Play; / 开始播放按钮 ImageButton m_ImageButton_Play_a; ImageButton m_bg; / 背景图片public MenuView(Context context) / 初始化工作super(context);m_bg = new ImageButton(context,R.drawable.b7,0,0);m_ImageButton_Play = new ImageButton(context,R.drawable.play,62,136);m_

27、ImageButton_Play_a = new ImageButton(context,R.drawable.play1,62,136); public void onDraw(Canvas canvas) / 画布中显示位图 m_bg.DrawImageButton(canvas, null); m_ImageButton_Play.DrawImageButton(canvas, null); 还有一个启动活动类,MainActivity.java 代码为:package com.example.eluosifangkuai;import android.os.Bundle;import

28、android.os.Handler;import android.app.Activity;import android.content.Intent;import android.util.Log;import android.view.Window;import android.view.WindowManager;public class MainActivity extends Activity private static final int GOTO_MAIN_ACTIVITY = 0; / 发送消息参数 private Handler mHandler = new Handler() / 消息推送类 publ

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1