Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.ac949.androidmobilegame.Classes;
- import android.app.Fragment;
- import android.os.Bundle;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.ImageButton;
- import com.example.ac949.androidmobilegame.R;
- public class GameScreen extends Fragment {
- private int turn = 0;
- private static int[] images = {R.drawable.blue, R.drawable.red};
- private static int[] squares = {
- R.id.sq_1,R.id.sq_2,R.id.sq_3,
- R.id.sq_4,R.id.sq_5,R.id.sq_6,
- R.id.sq_7,R.id.sq_8,R.id.sq_9
- };
- private GameBoard board;
- View view;
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup containter,
- Bundle saveInstanceState) {
- view = inflater.inflate(R.layout.activity_game_screen, containter, false);
- setupBtnClicks();
- return (view);
- }
- private void setupBtnClicks() {
- for (int i = 0; i < GameBoard.MAX; i++) {
- view.findViewById(squares[i]).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- ImageButton iBtn = (ImageButton) view;
- iBtn.setImageResource(images[turn]);
- turn = (turn + 1) % 2;
- for (int i = 0; i < GameBoard.MAX; i++) {
- if (squares[i] == iBtn.getId()) {
- board.updateBoard(i);
- iBtn.setOnClickListener(null);
- }
- }
- if (board.checkWin()) {
- //EndGame();
- }
- }
- });
- }
- }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- board = new GameBoard();
- }
- //public void EndGame(){
- //Intent intent = new Intent(MainActivity.this,EndGame.class);
- //intent.putExtra(MainActivity.NAME_EXTRA, name);
- //startActivity(intent);
- //}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement