Skip to content

Commit

Permalink
Merge pull request #1 from Jookie262/version-2
Browse files Browse the repository at this point in the history
Version 2
  • Loading branch information
Jookie262 authored Jun 11, 2023
2 parents 9484aaf + ed9e46e commit 186d461
Show file tree
Hide file tree
Showing 29 changed files with 844 additions and 134 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<h4 align=center>
<img src="screenshot/banner.png" width=450">
<br>
<b> A Task Performance in Mobile App that aims to develop a simple mobile game like memory game. </b>
<img src="https://img.shields.io/badge/Subject-Mobile%20App-yellowgreen?style=for-the-badge" alt="subject badge"/>
<img src="https://img.shields.io/badge/Version-2.0-green?style=for-the-badge" alt="version badge"/>
<br><br>
<b> A Task Performance in Mobile App that aims to develop a simple mobile game like memory game. </b>
</h4>

## **Description** 🔥
Expand All @@ -10,9 +13,6 @@ last pair has been picked up.

## **Scoring** 💯
The scoring system in the game is straightforward: correctly guessing a pair awards an additional 10 points, while an incorrect guess results in a deduction of 5 points.
| Correct | Wrong |
| :---: | :---: |
| + 10 points | -5 points |

## **Screen Shots** 📷
<p float="center">
Expand All @@ -25,7 +25,7 @@ The scoring system in the game is straightforward: correctly guessing a pair awa
</p>

## **Video** 🎥
https://github.com/Jookie262/animal-match-up/assets/62915062/844c26a8-14ed-4787-804c-a985e8c1e07d
https://github.com/Jookie262/animal-match-up/assets/62915062/15ffa033-a637-4384-9df6-44708e31dd5c

## **Special Thanks** 💖
I would like to express my sincere appreciation to Wajahat Karim (author of [EasyFlipView](https://github.com/wajahatkarim3/EasyFlipView)) for providing me with the incredible EasyFlipView library. It has been instrumental in making my simple project a success and adding an engaging flipping animation to my application.
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
android:supportsRtl="true"
android:theme="@style/Theme.AnimalMatchUp"
tools:targetApi="31">
<activity
android:name=".HighScoreScreen"
android:exported="false" />
<activity
android:name=".PlayScreen"
android:exported="false" />
Expand Down
79 changes: 79 additions & 0 deletions app/src/main/java/com/example/animalmatchup/HighScoreScreen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.example.animalmatchup;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

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

import com.example.animalmatchup.adapter.scoreadapter.ScoreAdapter;
import com.example.animalmatchup.game.InfoBox;
import com.example.animalmatchup.game.PopulateScore;
import com.example.animalmatchup.model.ScoreModel;

import java.util.ArrayList;

public class HighScoreScreen extends AppCompatActivity {
ImageView backBtn, infoBtn;
TextView highest_score_txt, highest_score_name_txt;
RecyclerView score_view;
InfoBox infoBox;
PopulateScore populateScore;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_high_score_screen);
init();
clickBackInfo();
scoreRecyclerView();
changeHighestScore();
}

public void init(){
backBtn = findViewById(R.id.back_btn);
infoBtn = findViewById(R.id.info_btn);
infoBox = new InfoBox();
highest_score_txt = findViewById(R.id.highest_score_txt);
highest_score_name_txt = findViewById(R.id.highest_score_name_txt);
score_view = findViewById(R.id.score_view);
populateScore = new PopulateScore(getApplicationContext());
}

public void clickBackInfo(){
backBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});

infoBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
infoBox.infoBox(HighScoreScreen.this);
}
});
}

public void changeHighestScore(){
ArrayList<ScoreModel> highestScores = populateScore.getHighestScore();
if (!highestScores.isEmpty()) {
ScoreModel highestScore = highestScores.get(0);
String highestScoreValue = String.valueOf(highestScore.getScore());
String highestScoreName = highestScore.getName();
highest_score_txt.setText(highestScoreValue);
highest_score_name_txt.setText(highestScoreName);
}
}

public void scoreRecyclerView(){
PopulateScore populateScore = new PopulateScore(getApplicationContext());
ScoreAdapter scoreAdapter = new ScoreAdapter(populateScore.populateScore());
score_view.setLayoutManager(new GridLayoutManager(this, 1));
score_view.setAdapter(scoreAdapter);
}
}
15 changes: 14 additions & 1 deletion app/src/main/java/com/example/animalmatchup/WelcomeScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;

import com.example.animalmatchup.game.InfoBox;

public class WelcomeScreen extends AppCompatActivity {
ImageButton playButton;
ImageButton playButton, highScoreButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome_screen);
playButton = findViewById(R.id.play_button);
highScoreButton = findViewById(R.id.high_score_button);

playButton.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -23,5 +28,13 @@ public void onClick(View v) {
startActivity(i);
}
});

highScoreButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(WelcomeScreen.this, HighScoreScreen.class);
startActivity(i);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package com.example.animalmatchup.adapter;
package com.example.animalmatchup.adapter.gameadapter;

import android.content.Context;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.animalmatchup.R;
import com.example.animalmatchup.WelcomeScreen;
import com.example.animalmatchup.game.InfoBox;
import com.example.animalmatchup.game.ScoreAnimation;
import com.example.animalmatchup.model.CardModel;
import com.example.animalmatchup.model.GameModel;
import com.example.animalmatchup.play.CongratsScreen;
Expand All @@ -25,21 +29,24 @@ public class CardAdapter extends RecyclerView.Adapter<CardHolder> {
private ArrayList<String> names;
GameModel gameModel;
Context context;
TextView gameScore;
TextView gameScore, animScore;
int totalCard;
String fragment_round_num;
FragmentManager fragment;
ScoreAnimation scoreAnimation;

public CardAdapter(ArrayList<CardModel> mData, Context context, GameModel gameModel, TextView gameScore, int totalCard, FragmentManager fragment, String fragment_round_num){
public CardAdapter(ArrayList<CardModel> mData, Context context, GameModel gameModel, TextView gameScore, TextView animScore, int totalCard, FragmentManager fragment, String fragment_round_num){
this.mData = mData;
this.context = context;
this.gameModel = gameModel;
this.gameScore = gameScore;
this.animScore = animScore;
this.totalCard = totalCard;
this.fragment_round_num = fragment_round_num;
this.fragment = fragment;
flipCards = new ArrayList<>();
names = new ArrayList<>();
scoreAnimation = new ScoreAnimation();
}

@NonNull
Expand All @@ -53,17 +60,17 @@ public CardHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
public void onBindViewHolder(@NonNull CardHolder holder, int position) {
CardModel model = mData.get(position);
holder.getBackImage().setImageResource(model.getBack_img());
holder.getFrontImage().setImageResource(model.getImg());
holder.getFrontImage().setImageResource(model.getFront_img());
Handler handler = new Handler();
gameLogic(holder.getEasyFlipView(), handler, model);
gameLogic(holder.getEasyFlipView(), handler, model, scoreAnimation);
}

@Override
public int getItemCount() {
return mData.size();
}

public void gameLogic(EasyFlipView flipView, Handler handler, CardModel model){
public void gameLogic(EasyFlipView flipView, Handler handler, CardModel model, ScoreAnimation scoreAnimation){
flipView.setOnFlipListener(new EasyFlipView.OnFlipAnimationListener() {
@Override
public void onViewFlipCompleted(EasyFlipView easyFlipView, EasyFlipView.FlipState newCurrentSide) {
Expand All @@ -78,6 +85,7 @@ public void onViewFlipCompleted(EasyFlipView easyFlipView, EasyFlipView.FlipStat
if (flipCards.size() == 2) {
if(names.get(0).equals(names.get(1))){
totalCard--;
scoreAnimation.animationScore(animScore, "+10");
gameModel.setScore(+10);

handler.postDelayed(new Runnable() {
Expand All @@ -91,6 +99,7 @@ public void run() {
}
}, 200);
} else {
scoreAnimation.animationScore(animScore, "-5");
gameModel.setScore(-5);
handler.postDelayed(new Runnable() {
@Override
Expand All @@ -104,7 +113,8 @@ public void run() {
}, 200);
}
}
gameScore.setText(String.valueOf(gameModel.getScore()));
scoreAnimation.delaySetText(gameScore, String.valueOf(gameModel.getScore()));
//gameScore.setText(String.valueOf(gameModel.getScore()));

if(totalCard == 0){
handler.postDelayed(new Runnable() {
Expand All @@ -113,10 +123,12 @@ public void run() {
if(fragment_round_num.equals("Round 1")){
fragment.beginTransaction().replace(R.id.fragment_container, new CongratsScreen(gameModel, "Round 1")).commit();
} else if(fragment_round_num.equals("Round 2")){
InfoBox infoBox = new InfoBox();
infoBox.addNameScore(context, String.valueOf(gameModel.getScore()));
fragment.beginTransaction().replace(R.id.fragment_container, new CongratsScreen(gameModel, "Round 2")).commit();
}
}
}, 300);
}, 800);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.animalmatchup.adapter;
package com.example.animalmatchup.adapter.gameadapter;

import android.view.View;
import android.widget.ImageView;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.example.animalmatchup.adapter.scoreadapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.animalmatchup.R;
import com.example.animalmatchup.adapter.gameadapter.CardHolder;
import com.example.animalmatchup.model.ScoreModel;

import java.util.ArrayList;

public class ScoreAdapter extends RecyclerView.Adapter<ScoreHolder> {
private ArrayList<ScoreModel> scoreModels;

public ScoreAdapter(ArrayList<ScoreModel> scoreModels){
this.scoreModels = scoreModels;
}

@NonNull
@Override
public ScoreHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.score_card, parent, false);
return new ScoreHolder(view);
}

@Override
public void onBindViewHolder(@NonNull ScoreHolder holder, int position) {
ScoreModel scoreModel = scoreModels.get(position);
holder.getName().setText(scoreModel.getName());
holder.getScore().setText(String.valueOf(scoreModel.getScore()));
holder.getRank().setText(String.valueOf(position + 2));
}

@Override
public int getItemCount() {
return scoreModels.size();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.example.animalmatchup.adapter.scoreadapter;

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

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.animalmatchup.R;

public class ScoreHolder extends RecyclerView.ViewHolder {
private TextView rank, name, score;

public ScoreHolder(@NonNull View itemView) {
super(itemView);
rank = itemView.findViewById(R.id.rank_txt);
name = itemView.findViewById(R.id.name_txt);
score = itemView.findViewById(R.id.score_txt);
}

public TextView getRank() {
return rank;
}


public TextView getName() {
return name;
}

public TextView getScore() {
return score;
}

}
Loading

0 comments on commit 186d461

Please sign in to comment.