package com.androidstudio.secondtest; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.graphics.Color; // // Player 1: Wert = 1 // Player 2: Wert = 5 // public class Activity_Multi extends AppCompatActivity { int player = 1; int M1 = 0; int M2 = 0; int M3 = 0; int M4 = 0; int M5 = 0; int M6 = 0; int M7 = 0; int M8 = 0; int M9 = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity__multi); findViewById(R.id.M1).setBackgroundColor(Color.GRAY); findViewById(R.id.M2).setBackgroundColor(Color.GRAY); findViewById(R.id.M3).setBackgroundColor(Color.GRAY); findViewById(R.id.M4).setBackgroundColor(Color.GRAY); findViewById(R.id.M5).setBackgroundColor(Color.GRAY); findViewById(R.id.M6).setBackgroundColor(Color.GRAY); findViewById(R.id.M7).setBackgroundColor(Color.GRAY); findViewById(R.id.M8).setBackgroundColor(Color.GRAY); findViewById(R.id.M9).setBackgroundColor(Color.GRAY); } Button Button1 = (Button) findViewById(R.id.M1); Button Button2 = (Button) findViewById(R.id.M2); Button Button3 = (Button) findViewById(R.id.M3); Button Button4 = (Button) findViewById(R.id.M4); Button Button5 = (Button) findViewById(R.id.M5); Button Button6 = (Button) findViewById(R.id.M6); Button Button7 = (Button) findViewById(R.id.M7); Button Button8 = (Button) findViewById(R.id.M8); Button Button9 = (Button) findViewById(R.id.M9); public void Button_Multi_Accept(View v){ View layout_multi = findViewById(R.id.LAYOUT_MULTI_INTRO); layout_multi.setVisibility(View.GONE); } public void M1(View v) { if (player == 1 && M1 == 0) { Button1.setText("X"); player++; M1 = 1; } else if(player == 2 && M1 == 0){ Button1.setText("O"); player--; M1 = 5; }; testing(); } public void M2(View v){ if (player == 1 && M2 == 0) { Button p1_button = (Button) findViewById(R.id.M2); p1_button.setText("X"); player++; M2 = 1; } else if(player == 2 && M2 == 0){ Button p1_button = (Button) findViewById(R.id.M2); p1_button.setText("O"); player--; M2 = 5; }; testing(); } public void M3(View v){ if (player == 1 && M3 == 0) { Button p1_button = (Button) findViewById(R.id.M3); p1_button.setText("X"); player++; M3 = 1; } else if(player == 2 && M3 == 0){ Button p1_button = (Button) findViewById(R.id.M3); p1_button.setText("O"); player--; M3 = 5; }; testing(); } public void M4(View v){ if (player == 1 && M4 == 0) { Button p1_button = (Button) findViewById(R.id.M4); p1_button.setText("X"); player++; M4 = 1; } else if(player == 2 && M4 == 0){ Button p1_button = (Button) findViewById(R.id.M4); p1_button.setText("O"); player--; M4 = 5; }; testing(); } public void M5(View v){ if (player == 1 && M5 == 0) { Button p1_button = (Button) findViewById(R.id.M5); p1_button.setText("X"); player++; M5 = 1; } else if(player == 2 && M5 == 0){ Button p1_button = (Button) findViewById(R.id.M5); p1_button.setText("O"); player--; M5 = 5; }; testing(); } public void M6(View v){ if (player == 1 && M6 == 0) { Button p1_button = (Button) findViewById(R.id.M6); p1_button.setText("X"); player++; M6 = 1; } else if(player == 2 && M6 == 0){ Button p1_button = (Button) findViewById(R.id.M6); p1_button.setText("O"); player--; M6 = 5; }; testing(); } public void M7(View v){ if (player == 1 && M7 == 0) { Button p1_button = (Button) findViewById(R.id.M7); p1_button.setText("X"); player++; M7 = 1; } else if(player == 2 && M7 == 0){ Button p1_button = (Button) findViewById(R.id.M7); p1_button.setText("O"); player--; M7 = 5; }; testing(); } public void M8(View v){ if (player == 1 && M8 == 0) { Button p1_button = (Button) findViewById(R.id.M8); p1_button.setText("X"); player++; M8 = 1; } else if(player == 2 && M8 == 0){ Button p1_button = (Button) findViewById(R.id.M8); p1_button.setText("O"); player--; M8 = 5; }; testing(); } public void M9(View v){ if (player == 1 && M9 == 0) { Button p1_button = (Button) findViewById(R.id.M9); p1_button.setText("X"); player++; M9 = 1; } else if(player == 2 && M9 == 0){ Button p1_button = (Button) findViewById(R.id.M9); p1_button.setText("O"); player--; M9 = 5; }; testing(); } // Lösung public void testing(){ // GRID FULL? if(M1 != 0 && M2 != 0 && M3 != 0 && M4 != 0 && M5 != 0 && M6 != 0 && M7 != 0 && M8 != 0 && M9 != 0){ findViewById(R.id.M1).setBackgroundColor(Color.RED); findViewById(R.id.M2).setBackgroundColor(Color.RED); findViewById(R.id.M3).setBackgroundColor(Color.RED); findViewById(R.id.M4).setBackgroundColor(Color.RED); findViewById(R.id.M5).setBackgroundColor(Color.RED); findViewById(R.id.M6).setBackgroundColor(Color.RED); findViewById(R.id.M7).setBackgroundColor(Color.RED); findViewById(R.id.M8).setBackgroundColor(Color.RED); findViewById(R.id.M9).setBackgroundColor(Color.RED); View layout_multi = findViewById(R.id.BUTTON_RETRY); layout_multi.setVisibility(View.VISIBLE); //TURN BUTTONS RED //BUTTON RETRY } } //RETRY public void RETRY(View v){ View layout_multi = findViewById(R.id.BUTTON_RETRY); layout_multi.setVisibility(View.GONE); findViewById(R.id.M1).setBackgroundColor(Color.GRAY); findViewById(R.id.M2).setBackgroundColor(Color.GRAY); findViewById(R.id.M3).setBackgroundColor(Color.GRAY); findViewById(R.id.M4).setBackgroundColor(Color.GRAY); findViewById(R.id.M5).setBackgroundColor(Color.GRAY); findViewById(R.id.M6).setBackgroundColor(Color.GRAY); findViewById(R.id.M7).setBackgroundColor(Color.GRAY); findViewById(R.id.M8).setBackgroundColor(Color.GRAY); findViewById(R.id.M9).setBackgroundColor(Color.GRAY); player = 1; M1 = 0; M2 = 0; M3 = 0; M4 = 0; M5 = 0; M6 = 0; M7 = 0; M8 = 0; M9 = 0; Button1.setText(""); Button2.setText(""); Button3.setText(""); Button4.setText(""); Button5.setText(""); Button6.setText(""); Button7.setText(""); Button8.setText(""); Button9.setText(""); } }