您好,欢迎访问三七文档
当前位置:首页 > IT计算机/网络 > 其它相关文档 > 手机编程培训 Android斗地主[牌桌实现源码]
最近一直在研究关于游戏编程,人在深圳,工作不好找啊!发一个斗地主游戏的牌桌实现。为了节约内存资源,每张扑克牌都是剪切形成的,当然这也是当前编程的主流方法。1、主Activity2、牌桌页面3、相关实体类扑克牌类:玩家类:PS:斗地主还是可以做成很复杂的。相关图片[java]viewplaincopyprint?1.span style=font-size:18px;color:#3333ff;package com.bison; 2. 3.import android.app.Activity; 4.import android.content.pm.ActivityInfo; 5.import android.os.Bundle; 6.import android.view.Window; 7.import android.view.WindowManager; 8. 9./**10. * 求某公司包养11. * 12. * @author Bison13. * 14. */ 15.publicclass PukeActivity extends Activity { 16. /** Called when the activity is first created. */ 17. @Override 18. publicvoid onCreate(Bundle savedInstanceState) { 19. super.onCreate(savedInstanceState); 20. // 这个事隐藏标题栏,不解释 21. requestWindowFeature(Window.FEATURE_NO_TITLE); 22. // 隐藏状态栏,你懂的 23. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 24. WindowManager.LayoutParams.FLAG_FULLSCREEN); 25. /*26. * 开始有考虑使屏幕上扑克的排列随屏幕的分辨率变动结果貌似不好做,注释掉了Display display =27. * getWindowManager().getDefaultDisplay(); int screenWidth =28. * display.getWidth(); int screenHeight = display.getHeight();29. */ 30. 31. // 使用代码锁定横屏 32. setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 33. // setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);这个是竖屏 34. setContentView(new GameView(this)); 35. } 36.}/span [java]viewplaincopyprint?1.span style=color:#3333ff;package com.bison; 2. 3.import android.content.Context; 4.import android.graphics.Bitmap; 5.import android.graphics.BitmapFactory; 6.import android.graphics.Canvas; 7.import android.graphics.Rect; 8.import android.view.MotionEvent; 9.import android.view.SurfaceHolder; 10.import android.view.SurfaceView; 11. 12.import com.bison.utils.Person; 13. 14./**15. * 牌桌,会被老婆骂,最好不要上去,你懂的16. * 17. * 扑克图片来源,和牌桌背景在文章的下面。扑克背面图等我没上传,玩家自行百度18. * 19. * @author Bison20. * 21. */ 22.publicclass GameView extends SurfaceView implements SurfaceHolder.Callback { 23. private FlushThread thread = null;// 刷帧线程 24. private Bitmap sourceBitmap = null;// 扑克图片来源 25. private Bitmap backgroundDesk = null;// 牌桌背景 26. private Bitmap backgroundPuke = null;// 扑克背面 27. 28. privatefinal Person person; 29. privateint pukeWidth = 0;// 扑克的宽 30. privateint pukeHeight = 0;// 扑克的高 31. privateint deskWidth = 0;// 牌桌的宽 32. privateint deskHeight = 0;// 牌桌的高 33. privateint left = 0;// 我自己首张牌左距离 34. 35. public GameView(Context context) { 36. super(context); 37. getHolder().addCallback(this); 38. this.thread = new FlushThread(getHolder(), this);// 实例化线程 39. initBitmap();// 实例化图片 40. this.person = new Person();// 实例化Person类 41. this.left = deskWidth / 2- (16 * 25 + pukeWidth) / 2;// 左距开始时赋值 42. } 43. 44. privatevoid initBitmap() {// 初始化图片 45. sourceBitmap = BitmapFactory.decodeResource(getResources(), 46. R.drawable.smallcard); 47. pukeWidth = sourceBitmap.getWidth() / 14;// 每张扑克的宽高 48. pukeHeight = sourceBitmap.getHeight() / 4; 49. 50. backgroundDesk = BitmapFactory.decodeResource(getResources(), 51. R.drawable.gameback2); 52. 53. deskWidth = backgroundDesk.getWidth();// 牌桌的宽高 54. deskHeight = backgroundDesk.getHeight(); 55. 56. backgroundPuke = BitmapFactory.decodeResource(getResources(), 57. R.drawable.cardback); 58. } 59. 60. @Override 61. protectedvoid onDraw(Canvas canvas) { 62. // 绘制牌桌 63. canvas.drawBitmap(backgroundDesk, 0, 0, null); 64. personPaint(canvas, pukeWidth, pukeHeight); 65. deskthreePukes(canvas, pukeWidth, pukeHeight); 66. } 67. 68. /** 绘制每个玩家手里的牌 */ 69. publicvoid personPaint(Canvas c, int pukeWidth, int pukeHeight) { 70. Rect src = new Rect(); 71. Rect dst = new Rect(); 72. 73. // 遍历数组 74. for (int i = 0; i 3; i++) { 75. for (int j = 0; j 17; j++) { 76. if (i == 0) {// 左手边玩家,不用绘出正面 77. // src = person.cardRect(person.person1[j], pukeWidth, 78. // pukeHeight); 79. // dst.set(10, j * 20, 10 + pukeWidth, j * 20 + pukeHeight); 80. c.drawBitmap(backgroundPuke, 35, 85, null); 81. } 82. if (i == 1) {// 自己 83. src = person.cardRect(person.person2[j], pukeWidth, 84. pukeHeight); 85. dst.set(left + j * 25, this.deskHeight -20- pukeHeight, 86. left + j * 25 + pukeWidth, deskHeight -20); 87. c.drawBitmap(sourceBitmap, src, dst, null); 88. } 89. if (i == 2) {// 右手边玩家,同样不用绘出正面 90. // src = person.cardRect(person.person3[j], pukeWidth, 91. // puk
本文标题:手机编程培训 Android斗地主[牌桌实现源码]
链接地址:https://www.777doc.com/doc-7211250 .html