package com.lrosier.tictactoe; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; // *********** you will need to add these two imports // in order to use Buttons, etc. and refer to them import android.widget.*; import android.view.*; // ***** Only copy what you need from this outline // ***** don't change your class name, etc. public class TicTacToeActivity extends ActionBarActivity { // ***** put your instance variables here // ***** declare variables to reference any UI objects // ***** that you need to access Button [][] board = new Button[3][3]; char whosTurn; boolean gameOver = false; // ***** declare variables to reference any UI objects that you need to change @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tic_tac_toe); // ****** get the reference variables initialized setTitle("Tic Tac Toe"); whosTurn = 'X'; board[0][0] = (Button) findViewById(R.id.button00); board[0][1] = (Button) findViewById(R.id.button01); // add more of these } public void clearBoard() { // use two loops to set the Button objects to " " // call the Button object's setText method to set the text on the Button // you can call the Button object's getText().toString() method to get the text } public void newGameClick(View v) { // call clearBoard() and do any other initialization } public void buttonClick(View v) { if (gameOver) return; for (int r=0; r<3; r++) { for (int c=0; c<3; c++) { if (v == board[r][c]) { String text = board[r][c].getText().toString(); if (text.equals(" ")) { if (whosTurn=='X') { board[r][c].setText("X"); if (!isWinner(whosTurn).equals("")) { // update the message gameOver = true; } whosTurn = 'O'; } else { board[r][c].setText("O"); if (!isWinner(whosTurn).equals("")) { // update the message gameOver = true; } whosTurn = 'X'; } } return; } } } } public String isWinner(char player) { // return a message if player is a winner or there is a Cat's game return ""; } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.tic_tac_toe, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } // *********************************************************************************************