Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added GuessME game android #1156

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions App Development/GuessMe/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 🎲 Guessing Game App
This is a number guessing game where you have to guess the correct number and everytime you guess you'll be charged with an attempt.<br>A person with minimum number of attempts wins the game.

# 🎮 How to Play ?
* You have to guess any random number between 1-100 at first if the number you chose is lower than the correct number then a message will pop up (Higher Number Please) and if you chose a number higher than the correct number than it will show (Lower Number Please).

* If you try to choose a number less than 0 or greater than 100 then a pop-up (toast) will be popped up asking you to enter a valid number.

* Once you guessed the correct number, a Congratulation message will be shown and the number of tries will be mentioned.

* You can either quit the game or you can replay.

# 📱 Screenshots
<table>
<tr>
<td> <img src="https://github.com/adnan-sam/Guessing-Game-App/blob/master/screenshots/new_img1.jpg" width="300" height="580">
<td> <img src="https://github.com/adnan-sam/Guessing-Game-App/blob/master/screenshots/new_img2.jpg" width="300" height="580">
<td> <img src="https://github.com/adnan-sam/Guessing-Game-App/blob/master/screenshots/new_img3.jpg" width="300" height="580">
</tr>
</table>

# 👨🏽‍💻 Tech Stack
<b>Front-End Design:</b> Figma
<br><br>
<b>Mark-up Language:</b> XML
<br><br>
<b>Back-End:</b> Java
38 changes: 38 additions & 0 deletions App Development/GuessMe/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
plugins {
id 'com.android.application'
}

android {
compileSdk 32

defaultConfig {
applicationId "com.example.guessinggame"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
21 changes: 21 additions & 0 deletions App Development/GuessMe/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example.guessinggame;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.example.guessinggame", appContext.getPackageName());
}
}
32 changes: 32 additions & 0 deletions App Development/GuessMe/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.guessinggame">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="Guess Me"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.GuessingGame">
<activity
android:name=".MainActivity"
android:exported="false" />

<activity
android:name=".splashscreen"
android:exported="true">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
</application>

</manifest>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package com.example.guessinggame;

import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Random;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
public static final int MAX_NUM=100;
public static final Random RANDOM =new Random();
private TextView head;
private TextView msgtv;
private TextView numtry;
private EditText numinput;
private Button submit;
private Button playagain;
private Button exit;
private int numtofind,tries;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
head=(TextView)findViewById(R.id.textView2);
msgtv=(TextView) findViewById(R.id.textView3);
numtry=(TextView) findViewById(R.id.textView5);
numinput=(EditText) findViewById(R.id.editTextNumber);
playagain=(Button) findViewById(R.id.button2);
playagain.setOnClickListener(this);
exit=(Button) findViewById(R.id.button3);
exit.setOnClickListener(this);
submit = (Button) findViewById(R.id.button);
submit.setOnClickListener(this);
newgame();
}
@Override
public void onClick(View view){
try {
if(view == submit)
{
submit();
}
} catch (NumberFormatException e) {
Toast.makeText(getApplicationContext(), "Enter a valid number", Toast.LENGTH_SHORT).show();
// numinput.setText("");
}
if(view == playagain)
{
Intent intent=new Intent();
intent.setClass(this, this.getClass());
this.startActivity(intent);
this.finish();
}
else if(view == exit)
{
finish();
}
}
private void submit()
{
int n=Integer.parseInt(numinput.getText().toString());
if(n<1 || n>100)
{
msgtv.setText("Please Enter a number between 1-100");
numinput.setText("");
numtry.setText("Number of tries = "+tries);
}
else if(n == numtofind)
{
msgtv.setTextColor(0xFF00FF00);
head.setText("Want to play once again?\nIf Yes then click on Play again else you can Exit");
msgtv.setText("Congratulations !\nYou found the correct number "+numtofind+" in "+tries+" tries.");
numinput.setText("");
submit.setText("EXIT");
numtry.setVisibility(View.INVISIBLE);
submit.setVisibility(View.INVISIBLE);
playagain.setVisibility(View.VISIBLE);
exit.setVisibility(View.VISIBLE);

// Intent i = getBaseContext().getPackageManager()
// .getLaunchIntentForPackage(getBaseContext().getPackageName());
// i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
// startActivity(i);
}
else if(n<numtofind)
{
msgtv.setText("Please guess a Higher number");
tries++;
numtry.setText("Number of tries = "+tries);
numinput.setText("");
}
else
{
msgtv.setText("Please guess a Lower number");
tries++;
numinput.setText("");
numtry.setText("Number of tries = "+tries);
}
}

private void newgame()
{
numtofind=RANDOM.nextInt(MAX_NUM)+1;
head.setText("GUESS A NUMBER BETWEEN 1-100");
numinput.setText("");
// msgtv.setTextColor(0xFF000000);
tries=0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.example.guessinggame;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ImageView;
import android.widget.TextView;
import android.window.SplashScreen;

public class splashscreen extends AppCompatActivity {

private TextView txt1;
private TextView txt2;
private ImageView img1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splashscreen);
txt1 = (TextView) findViewById(R.id.textView);
txt2 = (TextView) findViewById(R.id.textView4);
img1 = (ImageView) findViewById(R.id.imageView);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent=new Intent(splashscreen.this,MainActivity.class);
startActivity(intent);
finish();
}
},1700);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="90"
android:startColor="#006778"
android:endColor="#95D1CC"/>
</shape>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#890F0D" />
</shape>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="90"
android:startColor="#75DF5D"
android:endColor="#D3CEE3"/>
</shape>
5 changes: 5 additions & 0 deletions App Development/GuessMe/app/src/main/res/drawable/curved.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="40dp"/>
<solid android:color="@color/purple_500"></solid>
</shape>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<group android:scaleX="0.30560553"
android:scaleY="0.30560553"
android:translateX="38.414116"
android:translateY="29.16">
<group android:translateY="133.10156">
<path android:pathData="M98,-1.90625Q98.140625,-0,96.09375,-0Q94.796875,-0,88.609375,-1.6875Q82.4375,-3.390625,81,-4Q66.421875,2,53.03125,2Q31.484375,2,17.671875,-12.515625Q4,-26.828125,4,-48.6875Q4,-71.03125,17.28125,-85.765625Q30.984375,-101,52.875,-101Q63.5,-101,72.875,-96.921875Q83.015625,-92.4375,88.8125,-84.296875Q90,-82.609375,90,-81.90625Q90,-79.65625,83.671875,-71.828125Q77.34375,-64,75.5,-64Q75.078125,-64,72.265625,-66.859375Q68.828125,-70.265625,65.25,-72.140625Q59.921875,-75,53.453125,-75Q42.9375,-75,36.75,-67.125Q31,-59.875,31,-49.046875Q31,-37.578125,37.046875,-30.890625Q43.296875,-24,54.75,-24Q62,-24,70,-27.5625Q69.8125,-29.859375,68.84375,-39.296875Q68,-46.546875,68,-51.015625Q68,-52.34375,68.921875,-52.625Q69.28125,-52.765625,70.0625,-52.765625Q72.125,-52.765625,76.28125,-52.375Q80.4375,-52,82.578125,-52Q84.84375,-52,89.390625,-52.3125Q93.953125,-52.625,96.21875,-52.625Q98,-52.625,98,-50.3125Q98,-46.921875,97.5,-40.078125Q97,-33.25,97,-29.875Q97,-20.78125,97.953125,-2.671875L98,-1.90625Z"
android:fillColor="#FFFFFF"/>
</group>
</group>
</vector>
5 changes: 5 additions & 0 deletions App Development/GuessMe/app/src/main/res/drawable/oval_bg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/black"/>
</shape>
Loading