Created
February 6, 2018 21:56
-
-
Save Leonard02/8234a83b668d7448cc494d2487515f1b to your computer and use it in GitHub Desktop.
FOOTBALL APP by Leonard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.android.football; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.widget.TextView; | |
import android.view.View; | |
import android.widget.Toast; | |
import com.example.android.football.R; | |
public class MainActivity extends AppCompatActivity { | |
int scoreTeamA=0; | |
int scoreTeamB=0; | |
int scoreTeamAfouls=0; | |
int scoreTeamBfouls=0; | |
int scoreTeamApenalties=0; | |
int scoreTeamBpenalties=0; | |
int scoreTeamAcorners=0; | |
int scoreTeamBcorners=0; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
displayForTeamA(0); | |
displayForTeamB(0); | |
displayForTeamAFouls(0); | |
displayForTeamBFouls(0); | |
displayForTeamAPenalties(0); | |
displayForTeamBPenalties(0); | |
displayForTeamACorners(0); | |
displayForTeamBCorners(0); | |
} | |
public void goal(View view){ | |
scoreTeamA=scoreTeamA+1; | |
displayForTeamA(scoreTeamA); | |
} | |
public void fouls(View view){ | |
scoreTeamAfouls=scoreTeamAfouls+1; | |
displayForTeamAFouls(scoreTeamAfouls); | |
} | |
public void penalties(View view){ | |
scoreTeamApenalties=scoreTeamApenalties+1; | |
displayForTeamAPenalties(scoreTeamApenalties); | |
} | |
public void corners(View view){ | |
scoreTeamAcorners=scoreTeamAcorners+1; | |
displayForTeamACorners(scoreTeamAcorners); | |
} | |
public void goalb(View view){ | |
scoreTeamB=scoreTeamB+1; | |
displayForTeamB(scoreTeamB); | |
} | |
public void foulsb(View view){ | |
scoreTeamBfouls=scoreTeamBfouls+1; | |
displayForTeamBFouls(scoreTeamBfouls); | |
} | |
public void penaltiesb(View view){ | |
scoreTeamBpenalties=scoreTeamBpenalties+1; | |
displayForTeamBPenalties(scoreTeamBpenalties); | |
} | |
public void cornersb(View view){ | |
scoreTeamBcorners=scoreTeamBcorners+1; | |
displayForTeamBCorners(scoreTeamBcorners); | |
} | |
public void winner(View view){ | |
if (scoreTeamA>scoreTeamB){ | |
Toast.makeText(this, "TEAM A IS THE WINNER!!", Toast.LENGTH_SHORT).show(); | |
} | |
else if (scoreTeamB>scoreTeamA){ | |
Toast.makeText(this, "TEAM B IS THE WINNER!!", Toast.LENGTH_SHORT).show(); | |
} | |
else | |
{ | |
Toast.makeText(this, "THE GAME IS DRAW!!", Toast.LENGTH_SHORT).show(); | |
} | |
} | |
public void reset(View view){ | |
scoreTeamA=0; | |
scoreTeamB=0; | |
scoreTeamAfouls=0; | |
scoreTeamBfouls=0; | |
scoreTeamApenalties=0; | |
scoreTeamBpenalties=0; | |
scoreTeamAcorners=0; | |
scoreTeamBcorners=0; | |
displayForTeamA(scoreTeamA); | |
displayForTeamB(scoreTeamB); | |
displayForTeamAFouls(scoreTeamAfouls); | |
displayForTeamBFouls(scoreTeamBfouls); | |
displayForTeamAPenalties(scoreTeamApenalties); | |
displayForTeamBPenalties(scoreTeamBpenalties); | |
displayForTeamACorners(scoreTeamAcorners); | |
displayForTeamBCorners(scoreTeamBcorners); | |
Toast.makeText(this, "All Reseted!!", Toast.LENGTH_SHORT).show(); | |
} | |
public void displayForTeamA(int score) { | |
TextView scoreView = (TextView) findViewById(R.id.team_a_score); | |
scoreView.setText(String.valueOf(score)); | |
} | |
public void displayForTeamB(int score) { | |
TextView scoreView = (TextView) findViewById(R.id.team_b_score); | |
scoreView.setText(String.valueOf(score)); | |
} | |
public void displayForTeamAFouls(int score) { | |
TextView scoreView = (TextView) findViewById(R.id.fouls_team_a_score); | |
scoreView.setText(String.valueOf(score)); | |
} | |
public void displayForTeamBFouls(int score) { | |
TextView scoreView = (TextView) findViewById(R.id.fouls_team_b_score); | |
scoreView.setText(String.valueOf(score)); | |
} | |
public void displayForTeamAPenalties(int score) { | |
TextView scoreView = (TextView) findViewById(R.id.penalties_team_a_score); | |
scoreView.setText(String.valueOf(score)); | |
} | |
public void displayForTeamBPenalties(int score) { | |
TextView scoreView = (TextView) findViewById(R.id.penalties_team_b_score); | |
scoreView.setText(String.valueOf(score)); | |
} | |
public void displayForTeamACorners(int score) { | |
TextView scoreView = (TextView) findViewById(R.id.corners_team_a_score); | |
scoreView.setText(String.valueOf(score)); | |
} | |
public void displayForTeamBCorners(int score) { | |
TextView scoreView = (TextView) findViewById(R.id.corners_team_b_score); | |
scoreView.setText(String.valueOf(score)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context="com.example.android.football.MainActivity"> | |
<ImageView | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:layout_alignParentLeft="true" | |
android:layout_alignParentStart="true" | |
android:layout_alignParentTop="true" | |
android:scaleType="centerCrop" | |
android:background="@drawable/football" /> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<LinearLayout | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:layout_weight="1" | |
android:orientation="vertical"> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:fontFamily="sans-serif" | |
android:gravity="center_horizontal" | |
android:paddingTop="16dp" | |
android:paddingBottom="16dp" | |
android:paddingRight="24dp" | |
android:paddingLeft="24dp" | |
android:text="Team A" | |
android:textAllCaps="true" | |
android:textColor="@android:color/white" | |
android:textSize="20sp" /> | |
<TextView | |
android:id="@+id/team_a_score" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:fontFamily="sans-serif" | |
android:gravity="center_horizontal" | |
android:text="0" | |
android:textColor="@android:color/white" | |
android:textSize="40sp" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_margin="5dp" | |
android:paddingRight="10dp" | |
android:paddingLeft="10dp" | |
android:onClick="goal" | |
android:text="GOAL" /> | |
<TextView | |
android:id="@+id/fouls_team_a_score" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:fontFamily="sans-serif" | |
android:gravity="center_horizontal" | |
android:text="0" | |
android:textColor="@android:color/white" | |
android:textSize="20sp" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_margin="5dp" | |
android:paddingRight="10dp" | |
android:paddingLeft="10dp" | |
android:onClick="fouls" | |
android:text="FOULS" /> | |
<TextView | |
android:id="@+id/penalties_team_a_score" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:fontFamily="sans-serif" | |
android:gravity="center_horizontal" | |
android:text="0" | |
android:textColor="@android:color/white" | |
android:textSize="20sp" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_margin="5dp" | |
android:paddingRight="10dp" | |
android:paddingLeft="10dp" | |
android:onClick="penalties" | |
android:text="PENALTIES" /> | |
<TextView | |
android:id="@+id/corners_team_a_score" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:fontFamily="sans-serif" | |
android:gravity="center_horizontal" | |
android:text="0" | |
android:textColor="@android:color/white" | |
android:textSize="20sp" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_margin="5dp" | |
android:paddingRight="10dp" | |
android:paddingLeft="10dp" | |
android:onClick="corners" | |
android:text="Corners" /> | |
</LinearLayout> | |
<View | |
android:layout_width="1dp" | |
android:layout_height="match_parent" | |
android:layout_marginTop="16dp" | |
android:background="@android:color/white" /> | |
<LinearLayout | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:layout_weight="1" | |
android:orientation="vertical"> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:fontFamily="sans-serif" | |
android:gravity="center_horizontal" | |
android:paddingTop="16dp" | |
android:paddingBottom="16dp" | |
android:paddingRight="24dp" | |
android:paddingLeft="24dp" | |
android:text="Team B" | |
android:textAllCaps="true" | |
android:textColor="@android:color/white" | |
android:textSize="20sp" /> | |
<TextView | |
android:id="@+id/team_b_score" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:fontFamily="sans-serif" | |
android:gravity="center_horizontal" | |
android:text="0" | |
android:textColor="@android:color/white" | |
android:textSize="40sp" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_margin="5dp" | |
android:paddingRight="10dp" | |
android:paddingLeft="10dp" | |
android:onClick="goalb" | |
android:text="GOAL" /> | |
<TextView | |
android:id="@+id/fouls_team_b_score" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:fontFamily="sans-serif" | |
android:gravity="center_horizontal" | |
android:text="0" | |
android:textColor="@android:color/white" | |
android:textSize="20sp" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_margin="5dp" | |
android:paddingRight="10dp" | |
android:paddingLeft="10dp" | |
android:onClick="foulsb" | |
android:text="FOULS" /> | |
<TextView | |
android:id="@+id/penalties_team_b_score" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:fontFamily="sans-serif" | |
android:gravity="center_horizontal" | |
android:text="0" | |
android:textColor="@android:color/white" | |
android:textSize="20sp" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_margin="5dp" | |
android:paddingRight="10dp" | |
android:paddingLeft="10dp" | |
android:onClick="penaltiesb" | |
android:text="Penalties" /> | |
<TextView | |
android:id="@+id/corners_team_b_score" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:fontFamily="sans-serif" | |
android:gravity="center_horizontal" | |
android:text="0" | |
android:textColor="@android:color/white" | |
android:textSize="20sp" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_margin="5dp" | |
android:paddingRight="10dp" | |
android:paddingLeft="10dp" | |
android:onClick="cornersb" | |
android:text="Corners" /> | |
</LinearLayout> | |
</LinearLayout> | |
<Button | |
android:id="@+id/reset_button" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignParentBottom="true" | |
android:layout_centerInParent="true" | |
android:paddingBottom="32dp" | |
android:onClick="reset" | |
android:padding="16dp" | |
android:text="RESET" /> | |
<Button | |
android:id="@+id/winner_button" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignParentBottom="true" | |
android:onClick="winner" | |
android:paddingBottom="32dp" | |
android:padding="16dp" | |
android:text="Winner is ?" /> | |
</RelativeLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment