Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.45 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:background="@drawable/easymap"
  6. android:orientation="vertical" >
  7.  
  8. <TextView
  9. android:id="@+id/whitePlayer"
  10. android:layout_width="32dp"
  11. android:layout_height="32dp"
  12. android:background="@drawable/white"
  13. android:visibility="gone" />
  14.  
  15. <TextView
  16. android:id="@+id/blackPlayer"
  17. android:layout_width="32dp"
  18. android:layout_height="32dp"
  19. android:background="@drawable/black"
  20. android:visibility="gone" />
  21.  
  22. <Button
  23. android:id="@+id/btRoll"
  24. android:layout_width="160dp"
  25. android:layout_height="50dp"
  26. android:layout_alignParentLeft="true"
  27. android:layout_alignTop="@+id/cubePic"
  28. android:background="@drawable/buttonshape"
  29. android:text="Roll"
  30. android:textColor="#FFFFFF" />
  31.  
  32. <TextView
  33. android:id="@+id/cubePic"
  34. android:layout_width="100dp"
  35. android:layout_height="100dp"
  36. android:layout_alignParentBottom="true"
  37. android:layout_alignParentRight="true"
  38. android:layout_marginBottom="42dp"
  39. android:layout_marginRight="22dp"
  40. android:background="@drawable/cube" />
  41.  
  42. <TextView
  43. android:id="@+id/tvTurn"
  44. android:layout_width="wrap_content"
  45. android:layout_height="wrap_content"
  46. android:layout_alignBottom="@+id/cubePic"
  47. android:layout_alignRight="@+id/btRoll"
  48. android:text="Your turn!"
  49. android:textColor="@color/green"
  50. android:textSize="32dp"
  51. android:textStyle="italic" />
  52.  
  53. </RelativeLayout>
  54.  
  55. The java class:
  56.  
  57. package com.example.snakesnladders;
  58.  
  59. import android.app.Activity;
  60. import android.content.Context;
  61. import android.graphics.Bitmap;
  62. import android.graphics.BitmapFactory;
  63. import android.graphics.Canvas;
  64. import android.os.Bundle;
  65. import android.util.Log;
  66. import android.view.SurfaceHolder;
  67. import android.view.SurfaceView;
  68. import android.view.View;
  69. import android.view.View.OnClickListener;
  70. import android.widget.Button;
  71. import android.widget.TextView;
  72.  
  73. public class GFX_Game extends Activity implements OnClickListener {
  74. TextView whitePlayer, blackPlayer;
  75. Button roll;
  76. TextView cube, map1, map2, map3, label;
  77. boolean yourTurn = true;
  78. MyBringBack ourView;
  79.  
  80. @Override
  81. protected void onCreate(Bundle savedInstanceState) {
  82. super.onCreate(savedInstanceState);
  83. ourView = new MyBringBack(this);
  84. setContentView(ourView);
  85. init();
  86. }
  87.  
  88. private void init() {
  89. cube = (TextView) findViewById(R.id.cubePic);
  90. roll = (Button) findViewById(R.id.btRoll);
  91. label = (TextView) findViewById(R.id.tvTurn);
  92. roll.setOnClickListener(this);
  93. }
  94.  
  95. @Override
  96. protected void onDestroy() {
  97. super.onDestroy();
  98. }
  99.  
  100. @Override
  101. public void onClick(View view) {
  102. int rand = (int) (Math.random() * 6) + 1;
  103.  
  104. }
  105.  
  106. class MyBringBack extends SurfaceView implements Runnable {
  107.  
  108. SurfaceHolder ourHolder;
  109. Thread ourThread = null;
  110. Bitmap backGround, playerB, playerW;
  111. boolean isRunning = true;
  112.  
  113. public MyBringBack(Context context) {
  114. super(context);
  115. playerW = BitmapFactory.decodeResource(getResources(),
  116. R.id.whitePlayer);
  117. ourHolder = getHolder();
  118. ourThread = new Thread(this);
  119. ourThread.start();
  120.  
  121. }
  122.  
  123. @Override
  124. public void run() {
  125.  
  126. while (isRunning) {
  127. if (!ourHolder.getSurface().isValid())
  128. continue;
  129. Canvas canvas = ourHolder.lockCanvas();
  130. canvas.drawBitmap(playerW, 0, 0, null);
  131. ourHolder.unlockCanvasAndPost(canvas);
  132. }
  133.  
  134. }
  135.  
  136. }
  137.  
  138. }
  139.  
  140. class MyBringBack extends View {
  141. Bitmap playerW;
  142.  
  143. public MyBringBack(Context context) {
  144. super(context);
  145. playerW = BitmapFactory.decodeResource(getResources(),
  146. R.id.whitePlayer);
  147.  
  148. }
  149.  
  150. @Override
  151. protected void onDraw(Canvas canvas) {
  152. // TODO Auto-generated method stub
  153. super.onDraw(canvas);
  154. canvas.drawBitmap(playerW,0,0,null);
  155. }
  156.  
  157. }
  158.  
  159. public final class MyRelativeLayout extends RelativeLayout {
  160. Bitmap playerW;
  161.  
  162. public MyRelativeLayout(Context context) {
  163. super(context);
  164. init(context);
  165. }
  166.  
  167. public MyRelativeLayout(Context context, AttributeSet attrs) {
  168. super(context, attrs);
  169. init(context);
  170. }
  171.  
  172. public MyRelativeLayout(Context context, AttributeSet attrs, int style) {
  173. super(context, atts, style);
  174. init(context);
  175. }
  176.  
  177. private void init(final Context context) {
  178. playerW = BitmapFactory.decodeResource(context.getResources(),
  179. R.id.whitePlayer);
  180. }
  181.  
  182. @Override
  183. protected void onDraw(Canvas canvas) {
  184. super.onDraw(canvas);
  185. canvas.drawBitmap(playerW,0,0,null);
  186. }
  187. }
  188.  
  189. <?xml version="1.0" encoding="utf-8"?>
  190. <your.package.name.package.MyRelativeLayout
  191. xmlns:android="http://schemas.android.com/apk/res/android"
  192. android:layout_width="match_parent"
  193. android:layout_height="match_parent">
  194.  
  195. ...
  196. all the stuff here
  197.  
  198. <your.package.name.package.MyRelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement