Sie sind auf Seite 1von 4

Activity_Main.

xml android:textSize="72dp" />


</LinearLayout>
<LinearLayout
<LinearLayout
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/
android:layout_height="match_parent"
apk/res/android"
android:layout_weight="1"
android:weightSum="3" >
xmlns:tools="http://schemas.android.com/to
Button
ols"
android:id="@+id/b4"
android:layout_width="match_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="match_parent"
android:background="#0D0E0D"
android:layout_weight="1"
android:orientation="vertical"
android:textSize="72dp" />
android:paddingBottom="0dp"
<Button
android:paddingLeft="0dp"
android:id="@+id/b5"
android:paddingRight="0dp"
android:layout_width="match_parent"
android:paddingTop="0dp"
android:layout_height="match_parent"
android:weightSum="3"
android:layout_weight="1"
android:textSize="72dp" />
tools:context="${relativePackage}.${activi
<Button
tyClass}" >
android:id="@+id/b6"
<TextView
android:layout_width="match_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:textSize="72dp" />
android:text="TicTacToe"
</LinearLayout>
android:textColor="#F4F8F4"
<LinearLayout
android:textSize="30dp"
android:layout_width="match_parent"
android:textStyle="bold"
android:layout_height="match_parent"
android:typeface="serif" />
android:layout_weight="1"
<TextView
android:weightSum="3" >
android:layout_width="match_parent"
<Button
android:layout_height="wrap_content"
android:id="@+id/b7"
android:gravity="center"
android:layout_width="match_parent"
android:text="by: Bandarlipe and
android:layout_height="match_parent"
Salvador"
android:layout_weight="1"
android:textColor="#F4F8F4"
android:textSize="72dp" />
android:textSize="10dp"
<Button
android:textStyle="bold"
android:id="@+id/b8"
android:typeface="serif" />
android:layout_width="match_parent"
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="match_parent"
android:textSize="72dp" />
android:layout_weight="1"
<Button
android:weightSum="3" >
android:id="@+id/b9"
<Button
android:layout_width="match_parent"
android:id="@+id/b1"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="match_parent"
android:textSize="72dp" />
android:layout_weight="1"
</LinearLayout>
android:textSize="72dp" />
<LinearLayout
<Button
android:layout_width="match_parent"
android:id="@+id/b2"
android:layout_height="wrap_content" >
android:layout_width="match_parent"
<Button
android:layout_height="match_parent"
android:id="@+id/b10"
android:layout_weight="1"
android:layout_width="match_parent"
android:textSize="72dp" />
android:layout_height="wrap_content"
<Button
android:id="@+id/b3"
android:gravity="center_vertical|center_ho
android:layout_width="match_parent"
rizontal"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="R E S
E T" b1.setOnClickListener(new
android:textColor="#F4F8F4" View.OnClickListener() {
android:textStyle="bold" /> @Override
</LinearLayout> public void onClick(View
</LinearLayout> arg0) {

if(b1.getText().toString().equals(""
)) {
if (turn == 1){
MainActivity.java
turn = 2;
b1.setText("X");
package com.bandarlipe.tictactoe; }else if (turn == 2) {
turn = 1;
import android.app.Activity; b1.setText("O");
import android.content.Intent; }}
import android.os.Bundle; endGame();
import android.view.Menu; }});
import android.view.MenuItem; b2.setOnClickListener(new
import android.view.View; View.OnClickListener() {
import android.widget.Button; @Override
import android.widget.Toast; public void onClick(View
arg0) {
public class MainActivity extends Activity
{ if(b2.getText().toString().equals(""
)) {
Button b1, b2, b3, b4, b5, b6, b7, if (turn == 1){
b8, b9, b10; turn = 2;
b2.setText("X");
int turn; }else if (turn == 2) {
turn = 1;
@Override b2.setText("O");
protected void onCreate(Bundle }}
savedInstanceState) { endGame();
}});
super.onCreate(savedInstanceState); b3.setOnClickListener(new
View.OnClickListener() {
setContentView(R.layout.activity_main); @Override
public void onClick(View
b1 = (Button) arg0) {
findViewById(R.id.b1);
b2 = (Button) if(b3.getText().toString().equals(""
findViewById(R.id.b2); )) {
b3 = (Button) if (turn == 1){
findViewById(R.id.b3); turn = 2;
b4 = (Button) b3.setText("X");
findViewById(R.id.b4); }else if (turn == 2) {
b5 = (Button) turn = 1;
findViewById(R.id.b5); b3.setText("O");
b6 = (Button) }}
findViewById(R.id.b6); endGame();
b7 = (Button)
findViewById(R.id.b7); }});
b8 = (Button) b4.setOnClickListener(new
findViewById(R.id.b8); View.OnClickListener() {
b9 = (Button) @Override
findViewById(R.id.b9); public void onClick(View
b10 = (Button) arg0) {
findViewById(R.id.b10);
if(b4.getText().toString().equals(""
turn = 1; )) {
if (turn == 1){ }}
turn = 2; endGame();
b4.setText("X");
}else if (turn == 2) { }});
turn = 1; b8.setOnClickListener(new
b4.setText("O"); View.OnClickListener() {
}} @Override
endGame(); public void onClick(View
arg0) {
}});
if(b8.getText().toString().equals(""
b5.setOnClickListener(new )) {
View.OnClickListener() { if (turn == 1){
@Override turn = 2;
public void onClick(View b8.setText("X");
arg0) { }else if (turn == 2) {
turn = 1;
if(b5.getText().toString().equals("" b8.setText("O");
)) { }}
if (turn == 1){ endGame();
turn = 2;
b5.setText("X"); }});
}else if (turn == 2) { b9.setOnClickListener(new
turn = 1; View.OnClickListener() {
b5.setText("O"); @Override
}} public void onClick(View
endGame(); arg0) {

}}); if(b9.getText().toString().equals(""
b6.setOnClickListener(new )) {
View.OnClickListener() { if (turn == 1){
@Override turn = 2;
public void onClick(View b9.setText("X");
arg0) { }else if (turn == 2) {
turn = 1;
if(b6.getText().toString().equals("" b9.setText("O");
)) { }}
if (turn == 1){ endGame();
turn = 2;
b6.setText("X"); }});
}else if (turn == 2) { b10 =
turn = 1; (Button)findViewById(R.id.b10);
b6.setText("O"); b10.setOnClickListener(new
}} View.OnClickListener() {
endGame(); @Override
public void onClick(View
}}); arg0) {
b7.setOnClickListener(new Intent restartIntent =
View.OnClickListener() { getBaseContext().getPackageManager()
@Override .getLaunchIntentForPackage(getBaseCo
public void onClick(View ntext().getPackageName());
arg0) { startActivity(restartIntent);
}});}
if(b7.getText().toString().equals("" public void endGame(){
)) { String a, b, c, d, e, f, g, h, i;
if (turn == 1){ boolean end = false;
turn = 2;
b7.setText("X"); a = b1.getText().toString();
}else if (turn == 2) { b = b2.getText().toString();
turn = 1; c = b3.getText().toString();
b7.setText("O"); d = b4.getText().toString();
e = b5.getText().toString(); if (a.equals("O") && b.equals("O")
f = b6.getText().toString(); && c.equals("O")){
g = b7.getText().toString();
h = b8.getText().toString(); Toast.makeText(MainActivity.this,
i = b9.getText().toString(); "Winner Player O!",
Toast.LENGTH_LONG).show();
if (a.equals("X") && b.equals("X") end = true;
&& c.equals("X")){ }
Toast.makeText(MainActivity.t if (a.equals("O") && e.equals("O")
his, "Winner Player X!", && i.equals("O")){
Toast.LENGTH_LONG).show();
end = true; Toast.makeText(MainActivity.this,
} "Winner Player O!",
if (a.equals("X") && e.equals("X") Toast.LENGTH_LONG).show();
&& i.equals("X")){ end = true;
}
Toast.makeText(MainActivity.this, if (a.equals("O") && d.equals("O")
"Winner Player X!", && g.equals("O")){
Toast.LENGTH_LONG).show();
end = true; Toast.makeText(MainActivity.this,
} "Winner Player O!",
if (a.equals("X") && d.equals("X") Toast.LENGTH_LONG).show();
&& g.equals("X")){ end = true;}
if (b.equals("O") && e.equals("O")
Toast.makeText(MainActivity.this, && h.equals("O")){
"Winner Player X!",
Toast.LENGTH_LONG).show(); Toast.makeText(MainActivity.this,
end = true; "Winner Player O!",
} Toast.LENGTH_LONG).show();
if (b.equals("X") && e.equals("X") end = true;}
&& h.equals("X")){ if (c.equals("O") && f.equals("O")
&& i.equals("O")){
Toast.makeText(MainActivity.this,
"Winner Player X!", Toast.makeText(MainActivity.this,
Toast.LENGTH_LONG).show(); "Winner Player O!",
end = true; Toast.LENGTH_LONG).show();
} end = true;}
if (c.equals("X") && f.equals("X") if (d.equals("O") && e.equals("O")
&& i.equals("X")){ && f.equals("O")){

Toast.makeText(MainActivity.this, Toast.makeText(MainActivity.this,
"Winner Player X!", "Winner Player O!",
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
end = true; end = true;}
} if (g.equals("O") && h.equals("O")
if (d.equals("X") && e.equals("X") && i.equals("O")){
&& f.equals("X")){
Toast.makeText(MainActivity.this,
Toast.makeText(MainActivity.this, "Winner Player O!",
"Winner Player X!", Toast.LENGTH_LONG).show();
Toast.LENGTH_LONG).show(); end = true;}
end = true; if (end){
} b1.setEnabled(false);
if (g.equals("X") && h.equals("X") b2.setEnabled(false);
&& i.equals("X")){ b3.setEnabled(false);
b4.setEnabled(false);
Toast.makeText(MainActivity.this, b5.setEnabled(false);
"Winner Player X!", b6.setEnabled(false);
Toast.LENGTH_LONG).show(); b7.setEnabled(false);
end = true; b8.setEnabled(false);
} b9.setEnabled(false);}}}

Das könnte Ihnen auch gefallen