Advertisement
Guest User

code for will

a guest
Apr 23rd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. package com.example.ac949.androidmobilegame.Classes;
  2.  
  3. import android.app.Fragment;
  4. import android.os.Bundle;
  5. import android.view.LayoutInflater;
  6. import android.view.View;
  7. import android.view.ViewGroup;
  8. import android.widget.ImageButton;
  9.  
  10.  
  11. import com.example.ac949.androidmobilegame.R;
  12.  
  13. public class GameScreen extends Fragment {
  14.  
  15. private int turn = 0;
  16. private static int[] images = {R.drawable.blue, R.drawable.red};
  17.  
  18. private static int[] squares = {
  19. R.id.sq_1,R.id.sq_2,R.id.sq_3,
  20. R.id.sq_4,R.id.sq_5,R.id.sq_6,
  21. R.id.sq_7,R.id.sq_8,R.id.sq_9
  22. };
  23.  
  24. private GameBoard board;
  25. View view;
  26.  
  27.  
  28. @Override
  29. public View onCreateView(LayoutInflater inflater, ViewGroup containter,
  30. Bundle saveInstanceState) {
  31.  
  32. view = inflater.inflate(R.layout.activity_game_screen, containter, false);
  33. setupBtnClicks();
  34. return (view);
  35. }
  36.  
  37.  
  38. private void setupBtnClicks() {
  39. for (int i = 0; i < GameBoard.MAX; i++) {
  40. view.findViewById(squares[i]).setOnClickListener(new View.OnClickListener() {
  41. @Override
  42. public void onClick(View view) {
  43. ImageButton iBtn = (ImageButton) view;
  44. iBtn.setImageResource(images[turn]);
  45. turn = (turn + 1) % 2;
  46.  
  47. for (int i = 0; i < GameBoard.MAX; i++) {
  48. if (squares[i] == iBtn.getId()) {
  49. board.updateBoard(i);
  50. iBtn.setOnClickListener(null);
  51. }
  52. }
  53. if (board.checkWin()) {
  54. //EndGame();
  55. }
  56. }
  57. });
  58. }
  59. }
  60.  
  61.  
  62. @Override
  63. public void onCreate(Bundle savedInstanceState) {
  64. super.onCreate(savedInstanceState);
  65. board = new GameBoard();
  66. }
  67.  
  68. //public void EndGame(){
  69. //Intent intent = new Intent(MainActivity.this,EndGame.class);
  70. //intent.putExtra(MainActivity.NAME_EXTRA, name);
  71. //startActivity(intent);
  72. //}
  73.  
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement