package com.example.basketballgame;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import java.text.MessageFormat;

public class MainActivity extends AppCompatActivity {
    int team_A_score = 0;
    int team_B_score = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }



    private void displayScoreForTeamA(int score_A){
        TextView scoreView = (TextView) findViewById(R.id.score_view_TeamA);
        scoreView.setText(String.valueOf(score_A));
    }
    public void threePoints_A(View view){
        team_A_score +=3;
        displayScoreForTeamA(team_A_score);
    }

    public void twoPoints_A(View view){
        team_A_score +=2;
        displayScoreForTeamA(team_A_score);
    }
    public void freeThrow_A(View view){
        team_A_score +=1;
        displayScoreForTeamA(team_A_score);
    }
    public void minus_score_A(View view){
        team_A_score -= 1;
        displayScoreForTeamA(team_A_score);
    }

    // for team B//

    private void displayScoreForTeamB(int score_B){
        TextView scoreView = (TextView) findViewById(R.id.score_view_TeamB);
        scoreView.setText(String.valueOf(score_B));
    }
    public void threePoints_B(View view){
        team_B_score +=3;
        displayScoreForTeamB(team_B_score);
    }

    public void twoPoints_B(View view){
        team_B_score +=2;
        displayScoreForTeamB(team_B_score);
    }
    public void freeThrow_B(View view){
        team_B_score +=1;
        displayScoreForTeamB(team_B_score);
    }
    public void minus_score_B(View view){
        team_B_score -= 1;
        displayScoreForTeamB(team_B_score);
    }

    // reset button
    public void reset(View view){
        team_A_score = 0;
        team_B_score = 0;
        displayScoreForTeamA(team_A_score);
        displayScoreForTeamB(team_B_score);
        String message = "result will be declared here.";
        resetresult(message);

    }
    private void resetresult(String message) {
        TextView reset = (TextView) findViewById(R.id.result_display);
        reset.setText(message);
    }




    // result button


    public void result(View view){

        TextView finalscore = (TextView) findViewById(R.id.result_display);
        int diff;
        if (team_A_score == 0 && team_B_score ==0){
            finalscore.setText("match yet to be started");
        }
        else if(team_B_score > team_A_score){
            diff = team_B_score - team_A_score;
            finalscore.setText(MessageFormat.format("Team B has won with {0} points", diff));
        }
        else{
            diff = team_A_score - team_B_score;
            finalscore.setText(MessageFormat.format("Team A has won with {0} points", diff));
        }
    }

}