Created
April 18, 2019 12:19
-
-
Save MikeySmash/38bb825fde27381e84982605dbec4897 to your computer and use it in GitHub Desktop.
Udacity Android Developer - Soccer Counter - Java
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.soccercounter; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity { | |
/** | |
* Team A variables | |
*/ | |
int goalsTeamA = 0; | |
int throwInTeamA = 0; | |
int goalKickTeamA = 0; | |
int cornerTeamA = 0; | |
int freeKickTeamA = 0; | |
int yellowCardTeamA = 0; | |
int redCardTeamA = 0; | |
/** | |
* Team B variables | |
*/ | |
int goalsTeamB = 0; | |
int throwInTeamB = 0; | |
int goalKickTeamB = 0; | |
int cornerTeamB = 0; | |
int freeKickTeamB = 0; | |
int yellowCardTeamB = 0; | |
int redCardTeamB = 0; | |
/** | |
* Displays initial values on load | |
*/ | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
displayGoalsTeamA(goalsTeamA); | |
displayThrowInsTeamA(throwInTeamA); | |
displayGoalKicksTeamA(goalKickTeamA); | |
displayCornersTeamA(cornerTeamA); | |
displayFreeKicksTeamA(freeKickTeamA); | |
displayYellowCardsTeamA(yellowCardTeamA); | |
displayRedCardsTeamA(redCardTeamA); | |
displayGoalsTeamB(goalsTeamB); | |
displayThrowInsTeamB(throwInTeamB); | |
displayGoalKicksTeamB(goalKickTeamB); | |
displayCornersTeamB(cornerTeamB); | |
displayFreeKicksTeamB(freeKickTeamB); | |
displayYellowCardsTeamB(yellowCardTeamB); | |
displayRedCardsTeamB(redCardTeamB); | |
} | |
/** | |
* TEAM A BUTTON ACTIONS | |
* Adds 1 goal to Team A score | |
*/ | |
public void addGoalTeamA(View view) { | |
goalsTeamA = goalsTeamA + 1; | |
displayGoalsTeamA(goalsTeamA); | |
} | |
/** | |
* Adds 1 throw in to Team A | |
*/ | |
public void addThrowInTeamA(View view) { | |
throwInTeamA = throwInTeamA + 1; | |
displayThrowInsTeamA(throwInTeamA); | |
} | |
/** | |
* Adds 1 goal kick to Team A | |
*/ | |
public void addGoalKickTeamA(View view) { | |
goalKickTeamA = goalKickTeamA + 1; | |
displayGoalKicksTeamA(goalKickTeamA); | |
} | |
/** | |
* Adds 1 corner to Team A | |
*/ | |
public void addCornerTeamA(View view) { | |
cornerTeamA = cornerTeamA + 1; | |
displayCornersTeamA(cornerTeamA); | |
} | |
/** | |
* Adds 1 free kick to Team A | |
*/ | |
public void addFreeKickTeamA(View view) { | |
freeKickTeamA = freeKickTeamA + 1; | |
displayFreeKicksTeamA(freeKickTeamA); | |
} | |
/** | |
* Adds 1 yellow card to Team A | |
*/ | |
public void addYellowCardTeamA(View view) { | |
yellowCardTeamA = yellowCardTeamA + 1; | |
displayYellowCardsTeamA(yellowCardTeamA); | |
} | |
/** | |
* Adds 1 red card to Team A | |
*/ | |
public void addRedCardTeamA(View view) { | |
redCardTeamA = redCardTeamA + 1; | |
displayRedCardsTeamA(redCardTeamA); | |
} | |
/** | |
* TEAM B BUTTON ACTIONS | |
* Adds 1 goal to Team B score | |
*/ | |
public void addGoalTeamB(View view) { | |
goalsTeamB = goalsTeamB + 1; | |
displayGoalsTeamB(goalsTeamB); | |
} | |
/** | |
* Adds 1 throw in to Team B | |
*/ | |
public void addThrowInTeamB(View view) { | |
throwInTeamB = throwInTeamB + 1; | |
displayThrowInsTeamB(throwInTeamB); | |
} | |
/** | |
* Adds 1 goal kick to Team B | |
*/ | |
public void addGoalKickTeamB(View view) { | |
goalKickTeamB = goalKickTeamB + 1; | |
displayGoalKicksTeamB(goalKickTeamB); | |
} | |
/** | |
* Adds 1 corner to Team B | |
*/ | |
public void addCornerTeamB(View view) { | |
cornerTeamB = cornerTeamB + 1; | |
displayCornersTeamB(cornerTeamB); | |
} | |
/** | |
* Adds 1 free kick to Team B | |
*/ | |
public void addFreeKickTeamB(View view) { | |
freeKickTeamB = freeKickTeamB + 1; | |
displayFreeKicksTeamB(freeKickTeamB); | |
} | |
/** | |
* Adds 1 yellow card to Team B | |
*/ | |
public void addYellowCardTeamB(View view) { | |
yellowCardTeamB = yellowCardTeamB + 1; | |
displayYellowCardsTeamB(yellowCardTeamB); | |
} | |
/** | |
* Adds 1 red card to Team B | |
*/ | |
public void addRedCardTeamB(View view) { | |
redCardTeamB = redCardTeamB + 1; | |
displayRedCardsTeamB(redCardTeamB); | |
} | |
/** | |
* TEAM A DISPLAYS | |
* Displays the goals for Team A. | |
*/ | |
public void displayGoalsTeamA(int goals) { | |
TextView scoreView = (TextView) findViewById(R.id.team_a_goals); | |
scoreView.setText(String.valueOf(goals)); | |
} | |
/** | |
* Displays the throw ins for Team A. | |
*/ | |
public void displayThrowInsTeamA(int throwIns) { | |
TextView scoreView = (TextView) findViewById(R.id.team_a_throwIns); | |
scoreView.setText(String.valueOf(throwIns)); | |
} | |
/** | |
* Displays the goal kicks for Team A. | |
*/ | |
public void displayGoalKicksTeamA(int goalKicks) { | |
TextView scoreView = (TextView) findViewById(R.id.team_a_goalKicks); | |
scoreView.setText(String.valueOf(goalKicks)); | |
} | |
/** | |
* Displays the corners for Team A. | |
*/ | |
public void displayCornersTeamA(int corners) { | |
TextView scoreView = (TextView) findViewById(R.id.team_a_corners); | |
scoreView.setText(String.valueOf(corners)); | |
} | |
/** | |
* Displays the free kicks for Team A. | |
*/ | |
public void displayFreeKicksTeamA(int freeKicks) { | |
TextView scoreView = (TextView) findViewById(R.id.team_a_freeKicks); | |
scoreView.setText(String.valueOf(freeKicks)); | |
} | |
/** | |
* Displays the yellow cards for Team A. | |
*/ | |
public void displayYellowCardsTeamA(int yellowCards) { | |
TextView scoreView = (TextView) findViewById(R.id.team_a_yellowCards); | |
scoreView.setText(String.valueOf(yellowCards)); | |
} | |
/** | |
* Displays the red cards for Team A. | |
*/ | |
public void displayRedCardsTeamA(int redCards) { | |
TextView scoreView = (TextView) findViewById(R.id.team_a_redCards); | |
scoreView.setText(String.valueOf(redCards)); | |
} | |
/** | |
* Team B DISPLAYS | |
* Displays the goals for Team B. | |
*/ | |
public void displayGoalsTeamB(int goals) { | |
TextView scoreView = (TextView) findViewById(R.id.team_b_goals); | |
scoreView.setText(String.valueOf(goals)); | |
} | |
/** | |
* Displays the throw ins for Team B. | |
*/ | |
public void displayThrowInsTeamB(int throwIns) { | |
TextView scoreView = (TextView) findViewById(R.id.team_b_throwIns); | |
scoreView.setText(String.valueOf(throwIns)); | |
} | |
/** | |
* Displays the goal kicks for Team B. | |
*/ | |
public void displayGoalKicksTeamB(int goalKicks) { | |
TextView scoreView = (TextView) findViewById(R.id.team_b_goalKicks); | |
scoreView.setText(String.valueOf(goalKicks)); | |
} | |
/** | |
* Displays the corners for Team B. | |
*/ | |
public void displayCornersTeamB(int corners) { | |
TextView scoreView = (TextView) findViewById(R.id.team_b_corners); | |
scoreView.setText(String.valueOf(corners)); | |
} | |
/** | |
* Displays the free kicks for Team B. | |
*/ | |
public void displayFreeKicksTeamB(int freeKicks) { | |
TextView scoreView = (TextView) findViewById(R.id.team_b_freeKicks); | |
scoreView.setText(String.valueOf(freeKicks)); | |
} | |
/** | |
* Displays the yellow cards for Team B. | |
*/ | |
public void displayYellowCardsTeamB(int yellowCards) { | |
TextView scoreView = (TextView) findViewById(R.id.team_b_yellowCards); | |
scoreView.setText(String.valueOf(yellowCards)); | |
} | |
/** | |
* Displays the red cards for Team B. | |
*/ | |
public void displayRedCardsTeamB(int redCards) { | |
TextView scoreView = (TextView) findViewById(R.id.team_b_redCards); | |
scoreView.setText(String.valueOf(redCards)); | |
} | |
/** | |
* Resets all values. | |
*/ | |
public void resetScores(View view) { | |
goalsTeamA = 0; | |
throwInTeamA = 0; | |
goalKickTeamA = 0; | |
cornerTeamA = 0; | |
freeKickTeamA = 0; | |
yellowCardTeamA = 0; | |
redCardTeamA = 0; | |
goalsTeamB = 0; | |
throwInTeamB = 0; | |
goalKickTeamB = 0; | |
cornerTeamB = 0; | |
freeKickTeamB = 0; | |
yellowCardTeamB = 0; | |
redCardTeamB = 0; | |
displayGoalsTeamA(goalsTeamA); | |
displayThrowInsTeamA(throwInTeamA); | |
displayGoalKicksTeamA(goalKickTeamA); | |
displayCornersTeamA(cornerTeamA); | |
displayFreeKicksTeamA(freeKickTeamA); | |
displayYellowCardsTeamA(yellowCardTeamA); | |
displayRedCardsTeamA(redCardTeamA); | |
displayGoalsTeamB(goalsTeamB); | |
displayThrowInsTeamB(throwInTeamB); | |
displayGoalKicksTeamB(goalKickTeamB); | |
displayCornersTeamB(cornerTeamB); | |
displayFreeKicksTeamB(freeKickTeamB); | |
displayYellowCardsTeamB(yellowCardTeamB); | |
displayRedCardsTeamB(redCardTeamB); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment