Using java Syntax Highlighting
- package st.oxgame;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- public class oxgame extends Activity
- {
- /** Called when the activity is first created. */
- int c[][];
- int i, j, k=0;
- Button b[][];
- TextView textView;
- public void onCreate(Bundle icicle)
- {
- super.onCreate(icicle);
- setContentView(R.layout.main);
- b= new Button[4][4];
- c= new int[4][4];
- for (i=1; i<=3; i++)
- {
- for (j=1;j<=3;j++)
- c[i][j]=2;
- }
- textView = (TextView)findViewById(R.id.dialogue);
- b[1][3] = (Button) findViewById(R.id.one);
- b[1][2] = (Button) findViewById(R.id.two);
- b[1][1] = (Button) findViewById(R.id.three);
- b[2][3] = (Button) findViewById(R.id.four);
- b[2][2] = (Button) findViewById(R.id.five);
- b[2][1] = (Button) findViewById(R.id.six);
- b[3][3] = (Button) findViewById(R.id.seven);
- b[3][2] = (Button) findViewById(R.id.eight);
- b[3][1] = (Button) findViewById(R.id.nine);
- b[0][0] = (Button) findViewById(R.id.refresh);
- b[0][1] = (Button) findViewById(R.id.computer);
- textView.setText("Please click on any of the buttons to start the game. You are O and i am X.", TextView.BufferType.EDITABLE);
- b[1][1].setOnClickListener(new Button.OnClickListener()
- {
- public void onClick(View view)
- {
- if (b[1][1].isEnabled())
- {
- b[1][1].setEnabled(false);
- b[1][1].setText("O");
- c[1][1]=0;
- textView.setText("", TextView.BufferType.EDITABLE);
- b[0][1].setEnabled(true);
- for(i=1; i<=3; i++)
- {
- for(j=1; j<=3; j++)
- {
- if (c[i][j]==2)
- {
- b[i][j].setEnabled(false);
- }
- }
- }
- if((c[1][1]==0&&c[2][2]==0&&c[3][3]==0)||(c[1][3]==0&&c[2][2]==0&&c[3][1]==0)||(c[1][1]==0&&c[2][1]==0&&c[3][1]==0)||(c[1][2]==0&&c[2][2]==0&&c[3][2]==0)||(c[1][3]==0&&c[2][3]==0&&c[3][3]==0)||(c[1][1]==0&&c[1][2]==0&&c[1][3]==0)||(c[2][1]==0&&c[2][2]==0&&c[2][3]==0)||(c[3][1]==0&&c[3][2]==0&&c[3][3]==0))
- textView.setText("Game Over. You Won.", TextView.BufferType.EDITABLE);
- if(c[1][1]!=2&&c[1][2]!=2&&c[1][3]!=2&&c[2][1]!=2&&c[2][2]!=2&&c[2][3]!=2&&c[3][1]!=2&&c[3][2]!=2&&c[3][3]!=2)
- textView.setText("Game Over. It is a Tie.", TextView.BufferType.EDITABLE);
- }
- }
- });
- b[1][2].setOnClickListener(new Button.OnClickListener()
- {
- public void onClick(View view)
- {
- if (b[1][2].isEnabled())
- {
- b[1][2].setEnabled(false);
- b[1][2].setText("O");
- c[1][2]=0;
- textView.setText("", TextView.BufferType.EDITABLE);
- b[0][1].setEnabled(true);
- for(i=1; i<=3; i++)
- {
- for(j=1; j<=3; j++)
- {
- if (c[i][j]==2)
- {
- b[i][j].setEnabled(false);
- }
- }
- }
- if((c[1][1]==0&&c[2][2]==0&&c[3][3]==0)||(c[1][3]==0&&c[2][2]==0&&c[3][1]==0)||(c[1][1]==0&&c[2][1]==0&&c[3][1]==0)||(c[1][2]==0&&c[2][2]==0&&c[3][2]==0)||(c[1][3]==0&&c[2][3]==0&&c[3][3]==0)||(c[1][1]==0&&c[1][2]==0&&c[1][3]==0)||(c[2][1]==0&&c[2][2]==0&&c[2][3]==0)||(c[3][1]==0&&c[3][2]==0&&c[3][3]==0))
- textView.setText("Game Over. You Won.", TextView.BufferType.EDITABLE);
- if(c[1][1]!=2&&c[1][2]!=2&&c[1][3]!=2&&c[2][1]!=2&&c[2][2]!=2&&c[2][3]!=2&&c[3][1]!=2&&c[3][2]!=2&&c[3][3]!=2)
- textView.setText("Game Over. It is a Tie.", TextView.BufferType.EDITABLE);
- }
- }
- });
- b[1][3].setOnClickListener(new Button.OnClickListener()
- {
- public void onClick(View view)
- {
- if (b[1][3].isEnabled())
- {
- b[1][3].setEnabled(false);
- b[1][3].setText("O");
- c[1][3]=0;
- textView.setText("", TextView.BufferType.EDITABLE);
- b[0][1].setEnabled(true);
- for(i=1; i<=3; i++)
- {
- for(j=1; j<=3; j++)
- {
- if (c[i][j]==2)
- {
- b[i][j].setEnabled(false);
- }
- }
- }
- if((c[1][1]==0&&c[2][2]==0&&c[3][3]==0)||(c[1][3]==0&&c[2][2]==0&&c[3][1]==0)||(c[1][1]==0&&c[2][1]==0&&c[3][1]==0)||(c[1][2]==0&&c[2][2]==0&&c[3][2]==0)||(c[1][3]==0&&c[2][3]==0&&c[3][3]==0)||(c[1][1]==0&&c[1][2]==0&&c[1][3]==0)||(c[2][1]==0&&c[2][2]==0&&c[2][3]==0)||(c[3][1]==0&&c[3][2]==0&&c[3][3]==0))
- textView.setText("Game Over. You Won.", TextView.BufferType.EDITABLE);
- if(c[1][1]!=2&&c[1][2]!=2&&c[1][3]!=2&&c[2][1]!=2&&c[2][2]!=2&&c[2][3]!=2&&c[3][1]!=2&&c[3][2]!=2&&c[3][3]!=2)
- textView.setText("Game Over. It is a Tie.", TextView.BufferType.EDITABLE);
- }
- }
- });
- b[2][1].setOnClickListener(new Button.OnClickListener()
- {
- public void onClick(View view)
- {
- if (b[2][1].isEnabled())
- {
- b[2][1].setEnabled(false);
- b[2][1].setText("O");
- c[2][1]=0;
- textView.setText("", TextView.BufferType.EDITABLE);
- b[0][1].setEnabled(true);
- for(i=1; i<=3; i++)
- {
- for(j=1; j<=3; j++)
- {
- if (c[i][j]==2)
- {
- b[i][j].setEnabled(false);
- }
- }
- }
- if((c[1][1]==0&&c[2][2]==0&&c[3][3]==0)||(c[1][3]==0&&c[2][2]==0&&c[3][1]==0)||(c[1][1]==0&&c[2][1]==0&&c[3][1]==0)||(c[1][2]==0&&c[2][2]==0&&c[3][2]==0)||(c[1][3]==0&&c[2][3]==0&&c[3][3]==0)||(c[1][1]==0&&c[1][2]==0&&c[1][3]==0)||(c[2][1]==0&&c[2][2]==0&&c[2][3]==0)||(c[3][1]==0&&c[3][2]==0&&c[3][3]==0))
- textView.setText("Game Over. You Won.", TextView.BufferType.EDITABLE);
- if(c[1][1]!=2&&c[1][2]!=2&&c[1][3]!=2&&c[2][1]!=2&&c[2][2]!=2&&c[2][3]!=2&&c[3][1]!=2&&c[3][2]!=2&&c[3][3]!=2)
- textView.setText("Game Over. It is a Tie.", TextView.BufferType.EDITABLE);
- }
- }
- });
- b[2][2].setOnClickListener(new Button.OnClickListener()
- {
- public void onClick(View view)
- {
- if (b[2][2].isEnabled())
- {
- b[2][2].setEnabled(false);
- b[2][2].setText("O");
- c[2][2]=0;
- textView.setText("", TextView.BufferType.EDITABLE);
- b[0][1].setEnabled(true);
- for(i=1; i<=3; i++)
- {
- for(j=1; j<=3; j++)
- {
- if (c[i][j]==2)
- {
- b[i][j].setEnabled(false);
- }
- }
- }
- if((c[1][1]==0&&c[2][2]==0&&c[3][3]==0)||(c[1][3]==0&&c[2][2]==0&&c[3][1]==0)||(c[1][1]==0&&c[2][1]==0&&c[3][1]==0)||(c[1][2]==0&&c[2][2]==0&&c[3][2]==0)||(c[1][3]==0&&c[2][3]==0&&c[3][3]==0)||(c[1][1]==0&&c[1][2]==0&&c[1][3]==0)||(c[2][1]==0&&c[2][2]==0&&c[2][3]==0)||(c[3][1]==0&&c[3][2]==0&&c[3][3]==0))
- textView.setText("Game Over. You Won.", TextView.BufferType.EDITABLE);
- if(c[1][1]!=2&&c[1][2]!=2&&c[1][3]!=2&&c[2][1]!=2&&c[2][2]!=2&&c[2][3]!=2&&c[3][1]!=2&&c[3][2]!=2&&c[3][3]!=2)
- textView.setText("Game Over. It is a Tie.", TextView.BufferType.EDITABLE);
- }
- }
- });
- b[2][3].setOnClickListener(new Button.OnClickListener()
- {
- public void onClick(View view)
- {
- if (b[2][3].isEnabled())
- {
- b[2][3].setEnabled(false);
- b[2][3].setText("O");
- c[2][3]=0;
- textView.setText("", TextView.BufferType.EDITABLE);
- b[0][1].setEnabled(true);
- for(i=1; i<=3; i++)
- {
- for(j=1; j<=3; j++)
- {
- if (c[i][j]==2)
- {
- b[i][j].setEnabled(false);
- }
- }
- }
- if((c[1][1]==0&&c[2][2]==0&&c[3][3]==0)||(c[1][3]==0&&c[2][2]==0&&c[3][1]==0)||(c[1][1]==0&&c[2][1]==0&&c[3][1]==0)||(c[1][2]==0&&c[2][2]==0&&c[3][2]==0)||(c[1][3]==0&&c[2][3]==0&&c[3][3]==0)||(c[1][1]==0&&c[1][2]==0&&c[1][3]==0)||(c[2][1]==0&&c[2][2]==0&&c[2][3]==0)||(c[3][1]==0&&c[3][2]==0&&c[3][3]==0))
- textView.setText("Game Over. You Won.", TextView.BufferType.EDITABLE);
- if(c[1][1]!=2&&c[1][2]!=2&&c[1][3]!=2&&c[2][1]!=2&&c[2][2]!=2&&c[2][3]!=2&&c[3][1]!=2&&c[3][2]!=2&&c[3][3]!=2)
- textView.setText("Game Over. It is a Tie.", TextView.BufferType.EDITABLE);
- }
- }
- });
- b[3][1].setOnClickListener(new Button.OnClickListener()
- {
- public void onClick(View view)
- {
- if (b[3][1].isEnabled())
- {
- b[3][1].setEnabled(false);
- b[3][1].setText("O");
- c[3][1]=0;
- textView.setText("", TextView.BufferType.EDITABLE);
- b[0][1].setEnabled(true);
- for(i=1; i<=3; i++)
- {
- for(j=1; j<=3; j++)
- {
- if (c[i][j]==2)
- {
- b[i][j].setEnabled(false);
- }
- }
- }
- if((c[1][1]==0&&c[2][2]==0&&c[3][3]==0)||(c[1][3]==0&&c[2][2]==0&&c[3][1]==0)||(c[1][1]==0&&c[2][1]==0&&c[3][1]==0)||(c[1][2]==0&&c[2][2]==0&&c[3][2]==0)||(c[1][3]==0&&c[2][3]==0&&c[3][3]==0)||(c[1][1]==0&&c[1][2]==0&&c[1][3]==0)||(c[2][1]==0&&c[2][2]==0&&c[2][3]==0)||(c[3][1]==0&&c[3][2]==0&&c[3][3]==0))
- textView.setText("Game Over. You Won.", TextView.BufferType.EDITABLE);
- if(c[1][1]!=2&&c[1][2]!=2&&c[1][3]!=2&&c[2][1]!=2&&c[2][2]!=2&&c[2][3]!=2&&c[3][1]!=2&&c[3][2]!=2&&c[3][3]!=2)
- textView.setText("Game Over. It is a Tie.", TextView.BufferType.EDITABLE);
- }
- }
- });
- b[3][2].setOnClickListener(new Button.OnClickListener()
- {
- public void onClick(View view)
- {
- if (b[3][2].isEnabled())
- {
- b[3][2].setEnabled(false);
- b[3][2].setText("O");
- c[3][2]=0;
- textView.setText("", TextView.BufferType.EDITABLE);
- b[0][1].setEnabled(true);
- for(i=1; i<=3; i++)
- {
- for(j=1; j<=3; j++)
- {
- if (c[i][j]==2)
- {
- b[i][j].setEnabled(false);
- }
- }
- }
- if((c[1][1]==0&&c[2][2]==0&&c[3][3]==0)||(c[1][3]==0&&c[2][2]==0&&c[3][1]==0)||(c[1][1]==0&&c[2][1]==0&&c[3][1]==0)||(c[1][2]==0&&c[2][2]==0&&c[3][2]==0)||(c[1][3]==0&&c[2][3]==0&&c[3][3]==0)||(c[1][1]==0&&c[1][2]==0&&c[1][3]==0)||(c[2][1]==0&&c[2][2]==0&&c[2][3]==0)||(c[3][1]==0&&c[3][2]==0&&c[3][3]==0))
- textView.setText("Game Over. You Won.", TextView.BufferType.EDITABLE);
- if(c[1][1]!=2&&c[1][2]!=2&&c[1][3]!=2&&c[2][1]!=2&&c[2][2]!=2&&c[2][3]!=2&&c[3][1]!=2&&c[3][2]!=2&&c[3][3]!=2)
- textView.setText("Game Over. It is a Tie.", TextView.BufferType.EDITABLE);
- }
- }
- });
- b[3][3].setOnClickListener(new Button.OnClickListener()
- {
- public void onClick(View view)
- {
- if (b[3][3].isEnabled())
- {
- b[3][3].setEnabled(false);
- b[3][3].setText("O");
- c[3][3]=0;
- textView.setText("", TextView.BufferType.EDITABLE);
- b[0][1].setEnabled(true);
- for(i=1; i<=3; i++)
- {
- for(j=1; j<=3; j++)
- {
- if (c[i][j]==2)
- {
- b[i][j].setEnabled(false);
- }
- }
- }
- if((c[1][1]==0&&c[2][2]==0&&c[3][3]==0)||(c[1][3]==0&&c[2][2]==0&&c[3][1]==0)||(c[1][1]==0&&c[2][1]==0&&c[3][1]==0)||(c[1][2]==0&&c[2][2]==0&&c[3][2]==0)||(c[1][3]==0&&c[2][3]==0&&c[3][3]==0)||(c[1][1]==0&&c[1][2]==0&&c[1][3]==0)||(c[2][1]==0&&c[2][2]==0&&c[2][3]==0)||(c[3][1]==0&&c[3][2]==0&&c[3][3]==0))
- textView.setText("Game Over. You Won.", TextView.BufferType.EDITABLE);
- if(c[1][1]!=2&&c[1][2]!=2&&c[1][3]!=2&&c[2][1]!=2&&c[2][2]!=2&&c[2][3]!=2&&c[3][1]!=2&&c[3][2]!=2&&c[3][3]!=2)
- textView.setText("Game Over. It is a Tie.", TextView.BufferType.EDITABLE);
- }
- }
- });
- b[0][1].setOnClickListener(new Button.OnClickListener()
- {
- public void onClick(View view)
- {
- if (b[0][1].isEnabled())
- {
- if((((c[1][2]==1)&&(c[1][3]==1))||((c[2][1]==1)&&(c[3][1]==1))||((c[2][2]==1)&&(c[3][3]==1)))&&c[1][1]==2)
- {
- c[1][1]=1;
- b[1][1].setEnabled(false);
- b[1][1].setText("X");
- }
- else if((((c[1][1]==1)&&(c[1][3]==1))||((c[2][2]==1)&&(c[3][2]==1)))&&c[1][2]==2)
- {
- c[1][2]=1;
- b[1][2].setEnabled(false);
- b[1][2].setText("X");
- }
- else if((((c[1][1]==1)&&(c[1][2]==1))||((c[2][2]==1)&&(c[3][1]==1))||((c[2][3]==0)&&(c[3][3]==1)))&&c[1][3]==2)
- {
- c[1][3]=1;
- b[1][3].setEnabled(false);
- b[1][3].setText("X");
- }
- else if((((c[1][1]==1)&&(c[3][1]==1))||((c[2][2]==1)&&(c[2][3]==1)))&&c[2][1]==2)
- {
- c[2][1]=1;
- b[2][1].setEnabled(false);
- b[2][1].setText("X");
- }
- else if((((c[1][2]==1)&&(c[3][2]==1))||((c[2][1]==1)&&(c[2][3]==1))||((c[1][1]==1)&&(c[3][3]==1))||((c[1][3]==1)&&(c[3][1]==1)))&&c[2][2]==2)
- {
- c[2][2]=1;
- b[2][2].setEnabled(false);
- b[2][2].setText("X");
- }
- else if((((c[1][3]==1)&&(c[3][3]==1))||((c[2][1]==1)&&(c[2][2]==1)))&&c[2][3]==2)
- {
- c[2][3]=1;
- b[2][3].setEnabled(false);
- b[2][3].setText("X");
- }
- else if((((c[2][1]==1)&&(c[1][1]==1))||((c[2][2]==1)&&(c[1][3]==1))||((c[3][2]==0)&&(c[3][3]==1)))&&c[3][1]==2)
- {
- c[3][1]=1;
- b[3][1].setEnabled(false);
- b[3][1].setText("X");
- }
- else if((((c[1][2]==1)&&(c[2][2]==1))||((c[3][1]==1)&&(c[3][3]==1)))&&c[3][2]==2)
- {
- c[3][2]=1;
- b[3][2].setEnabled(false);
- b[3][2].setText("X");
- }
- else if((((c[1][3]==1)&&(c[2][3]==1))||((c[1][1]==1)&&(c[2][2]==1))||((c[3][1]==1)&&(c[3][2]==1)))&&c[3][3]==2)
- {
- c[3][3]=1;
- b[3][3].setEnabled(false);
- b[3][3].setText("X");
- }
- else if((((c[1][2]==0)&&(c[1][3]==0))||((c[2][1]==0)&&(c[3][1]==0))||((c[2][2]==0)&&(c[3][3]==0)))&&c[1][1]==2)
- {
- c[1][1]=1;
- b[1][1].setEnabled(false);
- b[1][1].setText("X");
- }
- else if((((c[1][1]==0)&&(c[1][3]==0))||((c[2][2]==0)&&(c[3][2]==0)))&&c[1][2]==2)
- {
- c[1][2]=1;
- b[1][2].setEnabled(false);
- b[1][2].setText("X");
- }
- else if((((c[1][1]==0)&&(c[1][2]==0))||((c[2][2]==0)&&(c[3][1]==0))||((c[2][3]==0)&&(c[3][3]==0)))&&c[1][3]==2)
- {
- c[1][3]=1;
- b[1][3].setEnabled(false);
- b[1][3].setText("X");
- }
- else if((((c[1][1]==0)&&(c[3][1]==0))||((c[2][2]==0)&&(c[2][3]==0)))&&c[2][1]==2)
- {
- c[2][1]=1;
- b[2][1].setEnabled(false);
- b[2][1].setText("X");
- }
- else if((((c[1][2]==0)&&(c[3][2]==0))||((c[2][1]==0)&&(c[2][3]==0))||((c[1][1]==0)&&(c[3][3]==0))||((c[1][3]==0)&&(c[3][1]==0)))&&c[2][2]==2)
- {
- c[2][2]=1;
- b[2][2].setEnabled(false);
- b[2][2].setText("X");
- }
- else if((((c[1][3]==0)&&(c[3][3]==0))||((c[2][1]==0)&&(c[2][2]==0)))&&c[2][3]==2)
- {
- c[2][3]=1;
- b[2][3].setEnabled(false);
- b[2][3].setText("X");
- }
- else if((((c[2][1]==0)&&(c[1][1]==0))||((c[2][2]==0)&&(c[1][3]==0))||((c[3][2]==0)&&(c[3][3]==0)))&&c[3][1]==2)
- {
- c[3][1]=1;
- b[3][1].setEnabled(false);
- b[3][1].setText("X");
- }
- else if((((c[1][2]==0)&&(c[2][2]==0))||((c[3][1]==0)&&(c[3][3]==0)))&&c[3][2]==2)
- {
- c[3][2]=1;
- b[3][2].setEnabled(false);
- b[3][2].setText("X");
- }
- else if((((c[1][3]==0)&&(c[2][3]==0))||((c[1][1]==0)&&(c[2][2]==0))||((c[3][1]==0)&&(c[3][2]==0)))&&c[3][3]==2)
- {
- c[3][3]=1;
- b[3][3].setEnabled(false);
- b[3][3].setText("X");
- }
- else
- {
- for(i=1;i<=3;i++)
- {
- if (k==0)
- {
- for(j=1;j<=3;j++)
- {
- if (k==0&&c[i][j]==2)
- {
- c[i][j]=1;
- b[i][j].setEnabled(false);
- b[i][j].setText("X");
- k=1;
- }
- }
- }
- }
- }
- if(c[1][1]!=2&&c[1][2]!=2&&c[1][3]!=2&&c[2][1]!=2&&c[2][2]!=2&&c[2][3]!=2&&c[3][1]!=2&&c[3][2]!=2&&c[3][3]!=2)
- textView.setText("Game Over. It is a Tie.", TextView.BufferType.EDITABLE);
- k=0;
- b[0][1].setEnabled(false);
- for(i=1; i<=3; i++)
- {
- for(j=1; j<=3; j++)
- {
- if (c[i][j]==2)
- {
- b[i][j].setEnabled(true);
- }
- }
- }
- if((c[1][1]==1&&c[2][2]==1&&c[3][3]==1)||(c[1][3]==1&&c[2][2]==1&&c[3][1]==1)||(c[1][1]==1&&c[2][1]==1&&c[3][1]==1)||(c[1][2]==1&&c[2][2]==1&&c[3][2]==1)||(c[1][3]==1&&c[2][3]==1&&c[3][3]==1)||(c[1][1]==1&&c[1][2]==1&&c[1][3]==1)||(c[2][1]==1&&c[2][2]==1&&c[2][3]==1)||(c[3][1]==1&&c[3][2]==1&&c[3][3]==1))
- textView.setText("Game Over. I Won.", TextView.BufferType.EDITABLE);
- }
- }
- });
- b[0][0].setOnClickListener(new Button.OnClickListener()
- {
- public void onClick(View view)
- {
- for (i=1; i<=3; i++)
- {
- for (j=1; j<=3; j++)
- {
- b[i][j].setEnabled(true);
- b[i][j].setText(" ");
- c[i][j]=2;
- }
- }
- textView.setText("Please click on any of the buttons to start the game. You are O and i am X.", TextView.BufferType.EDITABLE);
- b[0][1].setEnabled(true);
- k=0;
- }
- });
- }
- }
Parsed in 0.131 seconds, using GeSHi 1.0.8.4







