Skip to content

Commit 2934322

Browse files
committed
Added structured JAVA based mini games
1 parent df05ada commit 2934322

6 files changed

Lines changed: 342 additions & 0 deletions

File tree

games/QuizGame/Main.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package QuizGame;
2+
3+
import java.util.Scanner;
4+
5+
public class Main {
6+
public static void main(String[] args) {
7+
// QUIZ GAME
8+
String[] questions = {"I. Which language is good for ML?",
9+
"II. How many finger do humans have?",
10+
"III. Most importent part of human?",
11+
"IV. How Many months are in one month?",
12+
"VI. How many years in one month?"};
13+
14+
String[][] options = {{"1. java" , "2. python"},
15+
{"1. 10" , "2. 20"},
16+
{"1. Brain" , "2. heart"},
17+
{"1. 30" , "2. 0"},
18+
{"1 . 0" , "2. 12"}};
19+
20+
int[] answers = {2 , 1 , 1 , 2 , 1};
21+
22+
int score = 0;
23+
int guess = 0;
24+
25+
Scanner scanner = new Scanner(System.in);
26+
27+
System.out.println("---------------------");
28+
System.out.println("Welcome to Quiz Game!");
29+
System.out.println("---------------------");
30+
31+
for(int i = 0 ; i < questions.length ; i ++){
32+
System.out.println(questions[i]);
33+
for(String option : options[i]){
34+
System.out.println(option);
35+
}
36+
37+
System.out.print("Enter your Guess: ");
38+
guess = scanner.nextInt();
39+
40+
if(guess == answers[i]){
41+
System.out.println("----------");
42+
System.out.println(" CORRECT! ");
43+
System.out.println("----------");
44+
score += 1;
45+
}
46+
47+
else{
48+
System.out.println("--------");
49+
System.out.println(" WRONG! ");
50+
System.out.println("--------");
51+
}
52+
53+
}
54+
System.out.println("You final score is: " + score + " out of " + questions.length);
55+
56+
scanner.close();
57+
}
58+
}

games/QuizGame/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# 🧠 Quiz Game (Java)
2+
3+
A console-based quiz application that presents multiple-choice questions and tracks user score.
4+
5+
## 📌 Features
6+
7+
- Multiple-choice questions
8+
- Score tracking
9+
- Input validation
10+
- Structured question flow
11+
12+
## 🛠 Concepts Used
13+
14+
- Arrays
15+
- Loops
16+
- Conditional statements
17+
- Scanner input handling
18+
- Basic state management
19+
20+
## ▶ How to Run
21+
22+
Compile:
23+
javac Main.java
24+
25+
Run:
26+
java Main
27+
28+
## 🎯 Objective
29+
30+
This project demonstrates interactive application design and structured logic implementation using Java.

games/RockPaperScissors/Main.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package RockPaperScissors;
2+
3+
import java.util.Random;
4+
import java.util.Scanner;
5+
6+
public class Main {
7+
8+
public static void main(String[] args) {
9+
10+
// ROCK PAPER SCISSORS
11+
12+
Scanner scanner = new Scanner(System.in);
13+
Random random = new Random();
14+
15+
String[] choices = {"stonge" , "paper" , "scissors"};
16+
17+
String playerChoice;
18+
String computerChoice;
19+
String playAgain = "yes";
20+
21+
do{
22+
System.out.print("Enter your move (rock , paper , scissors): ");
23+
playerChoice = scanner.nextLine().toLowerCase();
24+
25+
if(!playerChoice.equals("rock") &&
26+
!playerChoice.equals("paper") &&
27+
!playerChoice.equals("scissors")){
28+
29+
System.out.println("Invalid Choice");
30+
continue;
31+
}
32+
33+
computerChoice = choices[random.nextInt(3)];
34+
System.out.println("Computer choice: " + computerChoice);
35+
36+
if(playerChoice == computerChoice){
37+
System.out.println("------");
38+
System.out.println(" Tie! ");
39+
System.out.println("------");
40+
}
41+
else if (
42+
(playerChoice.equals("rock") && computerChoice.equals("scissors")) ||
43+
(playerChoice.equals("paper") && computerChoice.equals("stone")) ||
44+
(playerChoice.equals("scissors") && computerChoice.equals("paper"))
45+
) {
46+
System.out.println("----------");
47+
System.out.println(" You win! ");
48+
System.out.println("----------");
49+
}
50+
51+
else{
52+
System.out.println("-------------");
53+
System.out.println("Computer win!");
54+
System.out.println("-------------");
55+
}
56+
57+
System.out.println("Wanna play again? (yes/no): ");
58+
playAgain = scanner.nextLine().toLowerCase();
59+
}
60+
61+
while(playAgain.equals("yes"));
62+
63+
System.out.println("---------");
64+
System.out.println("Good Bye!");
65+
System.out.println("---------");
66+
scanner.close();
67+
}
68+
}

games/RockPaperScissors/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# 🎮 Rock Paper Scissors (Java)
2+
3+
A console-based implementation of the classic Rock Paper Scissors game built using core Java fundamentals.
4+
5+
## 📌 Features
6+
7+
- User vs Computer gameplay
8+
- Randomized computer choice
9+
- Input validation
10+
- Game loop structure
11+
- Clear win/lose/draw logic
12+
13+
## 🛠 Concepts Used
14+
15+
- Conditional statements (if-else / switch)
16+
- Loops
17+
- Random class
18+
- Scanner for user input
19+
- Basic game logic implementation
20+
21+
## ▶ How to Run
22+
23+
Compile:
24+
javac Main.java
25+
26+
Run:
27+
java Main
28+
29+
## 🎯 Objective
30+
31+
This project demonstrates structured control flow and interactive console-based program design using Java.

games/SlotMachine/Main.java

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
package SlotMachine;
2+
3+
import java.util.Random;
4+
import java.util.Scanner;
5+
6+
public class Main {
7+
public static void main(String[] args) {
8+
9+
// SLOT MACHINE
10+
11+
Scanner scanner = new Scanner(System.in);
12+
13+
int balance = 100;
14+
int bet;
15+
int payout;
16+
String[] row;
17+
String playAgain;
18+
19+
System.out.println("----------------------------");
20+
System.out.println("Welcome to Slot Arena");
21+
System.out.println("Symbols: 🍒 🍉 🍋 🔔 ⭐ ");
22+
System.out.println("----------------------------");
23+
24+
while(balance >= 0){
25+
System.out.println("Current Balance: $" + balance);
26+
27+
System.out.print("Place your bet amount: ");
28+
bet = scanner.nextInt();
29+
scanner.nextLine();
30+
31+
if(bet > balance){
32+
System.out.println("INSUFFICIENT FUNDS");
33+
continue;
34+
}
35+
36+
else if (bet <= 0){
37+
System.out.println("Bet must be greater than 0");
38+
continue;
39+
}
40+
41+
else{
42+
balance -= bet;
43+
}
44+
45+
System.out.println("Spinning...");
46+
row = spinRow();
47+
printRow(row);
48+
payout = getPayout(row , bet);
49+
50+
if(payout > 0){
51+
System.out.println("You won $" + payout);
52+
balance += payout;
53+
}
54+
else{
55+
System.out.println("You lost this round.");
56+
}
57+
58+
System.out.println("Do you want to play again? (Y/N): ");
59+
playAgain = scanner.nextLine().toUpperCase();
60+
61+
if(!playAgain.equals("Y")){
62+
break;
63+
}
64+
}
65+
66+
System.out.println("Game over! Your final balance is $" + balance);
67+
68+
scanner.close();
69+
}
70+
71+
static String[] spinRow(){
72+
73+
String[] symbols = {"🍒" , "🍉" , "🍋" , "🔔" , "⭐"};
74+
String[] row = new String[3];
75+
Random random = new Random();
76+
77+
for (int i = 0 ; i < 3; i++){
78+
row[i] = symbols[random.nextInt(symbols.length)];
79+
}
80+
81+
return row;
82+
}
83+
84+
static void printRow (String[] row){
85+
86+
System.out.println("----------------------------");
87+
System.out.println(" " + String.join(" | ", row));
88+
System.out.println("----------------------------");
89+
}
90+
91+
static int getPayout(String[] row , int bet){
92+
93+
if(row[0].equals(row[1]) && row[1].equals(row[2]) ){
94+
return switch(row[0]){
95+
case "🍒" -> bet * 3;
96+
case "🍉" -> bet * 4;
97+
case "🍋" -> bet * 5;
98+
case "🔔" -> bet * 10;
99+
case "⭐" -> bet * 20;
100+
default -> 0;
101+
};
102+
}
103+
else if(row[0].equals(row[1])){
104+
return switch(row[0]){
105+
case "🍒" -> bet * 2;
106+
case "🍉" -> bet * 3;
107+
case "🍋" -> bet * 4;
108+
case "🔔" -> bet * 5;
109+
case "⭐" -> bet * 10;
110+
default -> 0;
111+
};
112+
}
113+
else if(row[1].equals(row[2])){
114+
return switch(row[1]){
115+
case "🍒" -> bet * 2;
116+
case "🍉" -> bet * 3;
117+
case "🍋" -> bet * 4;
118+
case "🔔" -> bet * 5;
119+
case "⭐" -> bet * 10;
120+
default -> 0;
121+
};
122+
}
123+
return 0;
124+
}
125+
}

games/SlotMachine/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# 🎰 Slot Machine (Java)
2+
3+
A console-based slot machine simulation built using Java fundamentals and random number generation.
4+
5+
## 📌 Features
6+
7+
- Randomized slot results
8+
- Pattern matching logic
9+
- Basic payout calculation
10+
- Interactive console interface
11+
12+
## 🛠 Concepts Used
13+
14+
- Random class
15+
- Conditional logic
16+
- Loops
17+
- Input handling
18+
- Game state control
19+
20+
## ▶ How to Run
21+
22+
Compile:
23+
javac Main.java
24+
25+
Run:
26+
java Main
27+
28+
## 🎯 Objective
29+
30+
This project focuses on implementing probability logic and decision-based outcomes in a structured Java program.

0 commit comments

Comments
 (0)