Hearts Score Keeper
This file contains 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" | |
android:background="@drawable/heart" | |
tools:context="com.shamikalashawn.heartsscorekeeper.MainActivity"> | |
<LinearLayout | |
android:id="@+id/teams" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="horizontal"> | |
<LinearLayout | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="16dp" | |
android:layout_weight="1" | |
android:orientation="vertical"> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:fontFamily="sans-serif-medium" | |
android:gravity="center_horizontal" | |
android:padding="4dp" | |
android:text="Player 1" | |
android:textColor="@android:color/black" | |
android:textSize="14sp" /> | |
<TextView | |
android:id="@+id/player_one_score" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:fontFamily="sans-serif-light" | |
android:gravity="center_horizontal" | |
android:padding="4dp" | |
android:text="0" | |
android:textColor="#000000" | |
android:textSize="56sp" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="8dp" | |
android:layout_marginLeft="24dp" | |
android:layout_marginRight="24dp" | |
android:layout_marginTop="8dp" | |
android:onClick="plusHeartOne" | |
android:text="Heart" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="8dp" | |
android:layout_marginLeft="24dp" | |
android:layout_marginRight="24dp" | |
android:layout_marginTop="8dp" | |
android:onClick="plusQueenOne" | |
android:text="Queen" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="8dp" | |
android:layout_marginLeft="24dp" | |
android:layout_marginRight="24dp" | |
android:layout_marginTop="8dp" | |
android:onClick="plusFullOne" | |
android:text="All Hearts" /> | |
</LinearLayout> | |
<View | |
android:layout_width="1dp" | |
android:layout_height="match_parent" | |
android:layout_marginTop="16dp" | |
android:background="@android:color/darker_gray" /> | |
<LinearLayout | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="16dp" | |
android:layout_weight="1" | |
android:orientation="vertical"> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:fontFamily="sans-serif-medium" | |
android:gravity="center_horizontal" | |
android:padding="4dp" | |
android:text="Player 2" | |
android:textColor="@android:color/black" | |
android:textSize="14sp" /> | |
<TextView | |
android:id="@+id/player_two_score" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:fontFamily="sans-serif-light" | |
android:gravity="center_horizontal" | |
android:padding="4dp" | |
android:text="0" | |
android:textColor="#000000" | |
android:textSize="56sp" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="8dp" | |
android:layout_marginLeft="24dp" | |
android:layout_marginRight="24dp" | |
android:layout_marginTop="8dp" | |
android:onClick="plusHeartTwo" | |
android:text="Heart" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="8dp" | |
android:layout_marginLeft="24dp" | |
android:layout_marginRight="24dp" | |
android:layout_marginTop="8dp" | |
android:onClick="plusQueenTwo" | |
android:text="Queen" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="8dp" | |
android:layout_marginLeft="24dp" | |
android:layout_marginRight="24dp" | |
android:layout_marginTop="8dp" | |
android:onClick="plusFullTwo" | |
android:text="All Hearts" /> | |
</LinearLayout> | |
</LinearLayout> | |
<TextView | |
android:id="@+id/winner" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="" | |
android:layout_below="@id/teams" | |
android:layout_centerHorizontal="true" | |
android:layout_margin="32dp" | |
android:textSize="48sp" | |
android:textColor="@android:color/black"/> | |
<Button | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignParentBottom="true" | |
android:layout_centerHorizontal="true" | |
android:layout_margin="32dp" | |
android:onClick="resetScore" | |
android:text="Reset" /> | |
</RelativeLayout> | |
This file contains 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.shamikalashawn.heartsscorekeeper; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
} | |
int scorePlayerOne = 0; | |
int scorePlayerTwo = 0; | |
/** | |
* Displays the winner if either score goes over 100. | |
*/ | |
public void displayWinner(String winningPlayer) { | |
TextView winnerView = (TextView) findViewById(R.id.winner); | |
winnerView.setText(String.valueOf(winningPlayer)); | |
} | |
/** | |
* Displays the given scorePlayerOne for Player 1. | |
*/ | |
public void displayForPlayerOne(int scorePlayerOne) { | |
TextView scorePlayerOneView = (TextView) findViewById(R.id.player_one_score); | |
scorePlayerOneView.setText(String.valueOf(scorePlayerOne)); | |
} | |
/** | |
* Adds twenty-six points to the scorePlayerTwo | |
*/ | |
public void plusFullOne(View view) { | |
scorePlayerTwo = scorePlayerTwo + 26; | |
displayForPlayerTwo(scorePlayerTwo); | |
if (scorePlayerTwo > 100){ | |
displayWinner("Player 1 Won!"); | |
} | |
} | |
/** | |
* Adds thirteen points to the scorePlayerOne | |
*/ | |
public void plusQueenOne(View view) { | |
scorePlayerOne = scorePlayerOne + 13; | |
displayForPlayerOne(scorePlayerOne); | |
if (scorePlayerOne > 100){ | |
displayWinner("Player 2 Won!"); | |
} | |
} | |
/** | |
* Adds one point to the scorePlayerOne | |
*/ | |
public void plusHeartOne(View view) { | |
scorePlayerOne = scorePlayerOne + 1; | |
displayForPlayerOne(scorePlayerOne); | |
if (scorePlayerOne > 100){ | |
displayWinner("Player 2 Won!"); | |
} | |
} | |
/** | |
* Displays the given scorePlayerTwo for Player 2. | |
*/ | |
public void displayForPlayerTwo(int scorePlayerTwo) { | |
TextView scorePlayerTwoView = (TextView) findViewById(R.id.player_two_score); | |
scorePlayerTwoView.setText(String.valueOf(scorePlayerTwo)); | |
} | |
/** | |
* Adds thirteen points to the scorePlayerTwo | |
*/ | |
public void plusQueenTwo(View view) { | |
scorePlayerTwo = scorePlayerTwo + 13; | |
displayForPlayerTwo(scorePlayerTwo); | |
if (scorePlayerTwo > 100){ | |
displayWinner("Player 1 Won!"); | |
} | |
} | |
/** | |
* Adds one point to the scorePlayerTwo | |
*/ | |
public void plusHeartTwo(View view) { | |
scorePlayerTwo = scorePlayerTwo + 1; | |
displayForPlayerTwo(scorePlayerTwo); | |
if (scorePlayerTwo > 100){ | |
displayWinner("Player 1 Won!"); | |
} | |
} | |
/** | |
* Adds twenty-six points to the scorePlayerOne | |
*/ | |
public void plusFullTwo(View view) { | |
scorePlayerOne = scorePlayerOne + 26; | |
displayForPlayerOne(scorePlayerOne); | |
if (scorePlayerOne > 100){ | |
displayWinner("Player 2 Won!"); | |
} | |
} | |
/** | |
* Resets score | |
*/ | |
public void resetScore(View view) { | |
scorePlayerOne = 0; | |
scorePlayerTwo = 0; | |
displayForPlayerOne(scorePlayerOne); | |
displayForPlayerTwo(scorePlayerTwo); | |
displayWinner(""); | |
} | |
} |
This file contains 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
<resources> | |
<!-- Base application theme. --> | |
<style name="AppTheme" parent="Theme.AppCompat.Light"> | |
<!-- Primary theme color of the app (sets background color of app bar) --> | |
<item name="colorPrimary">#f00</item> | |
<!-- Background color of buttons in the app --> | |
<item name="colorButtonNormal">#fff</item> | |
</style> | |
</resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment