Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #23 from BEAN-Tastic/feature/play-offline
Browse files Browse the repository at this point in the history
Adding Offline Data, and enabling playing offline (without auth)
  • Loading branch information
Dutchua authored Mar 16, 2024
2 parents 15221c2 + 48683dc commit d40c211
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 108 deletions.
168 changes: 63 additions & 105 deletions src/main/java/com/beantastic/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import java.util.Random;
import java.util.Scanner;

import com.beantastic.api.Apit;
import com.beantastic.api.ApitController;
import com.beantastic.api.ApitOffline;
import com.beantastic.enemies.Enemy;
import com.beantastic.enemies.EnemyManager;
import com.beantastic.event.*;
Expand All @@ -18,14 +20,11 @@
import com.beantastic.path.PathManager;
import com.beantastic.player.Player;
import com.beantastic.player.PlayerClass;
import com.beantastic.player.PlayerClassManager;
import com.beantastic.player.PlayerManager;
import com.beantastic.stats.StatBlock;

public class Main {

private final Random random;

private final Logger logger;
private final Scanner scanner;
private final EnemyManager enemyManager;
Expand All @@ -43,17 +42,21 @@ public Main(Random random, Logger logger, Scanner scanner, EnemyManager enemyMan
}

public static void main(String[] args) throws IOException, InterruptedException {

String accessToken = GitHubOAuth.getAccessToken();

Random random = new Random();
Scanner scanner = new Scanner(System.in);
Logger logger = new Logger(System.out);

printBean(logger);
ApitController apitController = new ApitController(accessToken);

LoadingAnimation(logger);
UserChoice<Boolean> runOffline = new UserChoice<>(scanner, logger, "Do you want To run online or offline", List.of(
new ChoiceOption<>("Online", () -> false),
new ChoiceOption<>("Offline", () -> true)
));
Boolean offline = runOffline.getChoice().outcome().get();
Apit apitController = offline
? new ApitOffline()
: new ApitController(GitHubOAuth.getAccessToken());
if (!offline) LoadingAnimation(logger);
List<PlayerClass> playerClasses = apitController.getClasses();
PlayerManager playerManager = new PlayerManager(logger, scanner, playerClasses);

Expand All @@ -66,52 +69,8 @@ public static void main(String[] args) throws IOException, InterruptedException

// START GAME
boolean play;
do {
play = main.startGame();
} while (play);

}

// TEMP DATA INSERTION\\
public static PlayerClassManager addClass() {
return new PlayerClassManager(
new PlayerClass("Green Bean Warrior",
"A sturdy bean skilled in close combat, wielding the might of beans with brute force.",
new StatBlock(5, 3, 2, 2)),
new PlayerClass("Magic Coffee Bean",
"A magical bean adept at harnessing the mystical energies of beans to cast powerful spells.",
new StatBlock(3, 2, 3, 3)),
new PlayerClass("Sneaky Black Bean",
"A nimble bean with a knack for stealth and deception, striking enemies from the shadows.",
new StatBlock(5, 3, 2, 2)),
new PlayerClass("Divine Lima Bean",
"A benevolent bean with divine powers, healing allies and smiting foes with righteous fury.",
new StatBlock(5, 3, 2, 2)),
new PlayerClass("Arrowhead Pinto Bean",
"A skilled bean archer, raining down arrows upon enemies with deadly precision.",
new StatBlock(5, 3, 2, 2)));
}

public static ItemManager addItems(Logger logger, Random random, Scanner scanner) {
return new ItemManager(
logger,
random,
scanner,
new ItemClass("SHOE", "HOT PINK HIGH HEEL", new StatBlock(0, 0, 0, 1), "Common"),
new ItemClass("tea cup", "steaming black tea", new StatBlock(0, 0, -1, 0), "Rare"));
}

public static EnemyManager addEnemies(Random random) {
return new EnemyManager(random,
new Enemy("Sorcerer Soup", new StatBlock(3, 0, 1, 2), "Easy",
"Fiery Ladle Strike- The Sorcerer Soup hurls a fiery ladle at you, inflicting heavy damage to your health.",
"A mystical soup with potent magical properties."),
new Enemy("Cursed Carrot", new StatBlock(5, 0, 2, 3), "Medium",
"Toxic Root Slam- The Cursed Carrot slams its toxic roots into the ground, weakening your defenses.",
"A carrot cursed by dark magic, capable of unleashing havoc."),
new Enemy("Haunted Hamburger", new StatBlock(7, 0, 3, 4), "Hard",
"Seductive Sizzle- The Haunted Hamburger emits a seductive sizzle, enchanting you and lowering your charisma.",
"A haunted hamburger possessed by vengeful spirits."));
do play = main.startGame();
while (play);
}

public boolean startGame() {
Expand Down Expand Up @@ -146,12 +105,12 @@ public boolean gameOver(boolean won) {
}

logger.println("""
____ _ __ __ _____ _____ _______ ____ \s
/ ___| / \\ | \\/ | ____| / _ \\ \\ / / ____| _ \\ \s
| | _ / _ \\ | |\\/| | _| | | | \\ \\ / /| _| | |_) | \s
| |_| |/ ___ \\| | | | |___ | |_| |\\ V / | |___| _ < _\s
\\____/_/ \\_\\_| |_|_____| \\___/ \\_/ |_____|_| \\_(_)
""");
____ _ __ __ _____ _____ _______ ____ \s
/ ___| / \\ | \\/ | ____| / _ \\ \\ / / ____| _ \\ \s
| | _ / _ \\ | |\\/| | _| | | | \\ \\ / /| _| | |_) | \s
| |_| |/ ___ \\| | | | |___ | |_| |\\ V / | |___| _ < _\s
\\____/_/ \\_\\_| |_|_____| \\___/ \\_/ |_____|_| \\_(_)
""");

UserChoice<Boolean> playAgain = new UserChoice<>(scanner, logger, "Play again?",
List.of(
Expand All @@ -166,56 +125,55 @@ public static void LoadingAnimation(Logger logger) {
for (int i = 0; i < 10; i++) {
logger.print(".");
try {
Thread.sleep(600);
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
logger.print("\n\n\n\n");

logger.println();
logger.println();
logger.println();
}

public static void printBean(Logger logger){
logger.println( """
@@@
@@@@
@@@@@@@@@@@@@@ @@@@
@@@@@@@@@@@@@@@@@@@@ @@@@
@@@@@@@ @@@@@@@ @@@@@
@@@@@@ @@@@@ @@@@@
@@@@@ @@@@@ @@@@@
@@@@@ @@ @@ @@@@ @@@@@@
@@@@@ @@@@ @@@@ @@@@ @@@@@@
@@@@@ @@ @@ @@@@@ @@@@@@
@@@@ @@@@@ @@@@@@@
@@@@ @@@@@@@ @@@@@ @@@@@@@@@
@@@@ @@@@@ @@@@@@@@@
@@@@ @@@@ @@@@
@@@@@ @@@@ @@@@@@@@@@@@@
@@@@ @@@@ @@@@@@@@@@@@@
@@@@@ @@@@ @@@@
@@@@ @@@@ @@@@
@@@@ @@@@@ @@@@
@@@@ @@@@@
@@@@@ @@@@@
@@@@@ @@@@@@
@@@@@@@ @@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@
@@@@ @@@@
@@@@ @@@@
@@@@@@ @@@@@@
@@@@@@ @@@@@
""");
logger.println("""
____ _ _ _ _ _ \s
| _ \\ | | | | (_) /\\ | | | | \s
| |_) | ___ __ _ _ __ ______| |_ __ _ ___| |_ _ ___ / \\ __| |_ _____ _ __ | |_ _ _ _ __ ___ \s
| _ < / _ \\/ _` | '_ \\______| __/ _` / __| __| |/ __| / /\\ \\ / _` \\ \\ / / _ \\ '_ \\| __| | | | '__/ _ \\\s
| |_) | __/ (_| | | | | | || (_| \\__ \\ |_| | (__ / ____ \\ (_| |\\ V / __/ | | | |_| |_| | | | __/\s
|____/ \\___|\\__,_|_| |_| \\__\\__,_|___/\\__|_|\\___| /_/ \\_\\__,_| \\_/ \\___|_| |_|\\__|\\__,_|_| \\___|\
""");

}
____ _ _ _ _ _ \s
| _ \\ | | | | (_) /\\ | | | | \s
| |_) | ___ __ _ _ __ ______| |_ __ _ ___| |_ _ ___ / \\ __| |_ _____ _ __ | |_ _ _ _ __ ___ \s
| _ < / _ \\/ _` | '_ \\______| __/ _` / __| __| |/ __| / /\\ \\ / _` \\ \\ / / _ \\ '_ \\| __| | | | '__/ _ \\\s
| |_) | __/ (_| | | | | | || (_| \\__ \\ |_| | (__ / ____ \\ (_| |\\ V / __/ | | | |_| |_| | | | __/\s
|____/ \\___|\\__,_|_| |_| \\__\\__,_|___/\\__|_|\\___| /_/ \\_\\__,_| \\_/ \\___|_| |_|\\__|\\__,_|_| \\___|\
""");
logger.println( """
@@@ \s
@@@@ \s
@@@@@@@@@@@@@@ @@@@ \s
@@@@@@@@@@@@@@@@@@@@ @@@@ \s
@@@@@@@ @@@@@@@ @@@@@ \s
@@@@@@ @@@@@ @@@@@ \s
@@@@@ @@@@@ @@@@@ \s
@@@@@ @@ @@ @@@@ @@@@@@ \s
@@@@@ @@@@ @@@@ @@@@ @@@@@@ \s
@@@@@ @@ @@ @@@@@ @@@@@@ \s
@@@@ @@@@@ @@@@@@@ \s
@@@@ @@@@@@@ @@@@@ @@@@@@@@@
@@@@ @@@@@ @@@@@@@@@
@@@@ @@@@ @@@@ \s
@@@@@ @@@@ @@@@@@@@@@@@@ \s
@@@@ @@@@ @@@@@@@@@@@@@ \s
@@@@@ @@@@ @@@@ \s
@@@@ @@@@ @@@@ \s
@@@@ @@@@@ @@@@ \s
@@@@ @@@@@ \s
@@@@@ @@@@@ \s
@@@@@ @@@@@@ \s
@@@@@@@ @@@@@@@@@ \s
@@@@@@@@@@@@@@@@@@@@@@@@@ \s
@@@@@@@@@@@@@@@@@@ \s
@@@@ @@@@ \s
@@@@ @@@@ \s
@@@@@@ @@@@@@ \s
@@@@@@ @@@@@ \s
""");
}
}
13 changes: 13 additions & 0 deletions src/main/java/com/beantastic/api/Apit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.beantastic.api;

import com.beantastic.enemies.Enemy;
import com.beantastic.items.ItemClass;
import com.beantastic.player.PlayerClass;

import java.util.List;

public interface Apit {
List<PlayerClass> getClasses();
List<ItemClass> getItems();
List<Enemy> getEnemies();
}
6 changes: 3 additions & 3 deletions src/main/java/com/beantastic/api/ApitController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import com.beantastic.items.ItemClass;
import com.beantastic.player.PlayerClass;

public class ApitController {
public class ApitController implements Apit {

private String accessToken;
private final String accessToken;

public ApitController(String accessToken) {
this.accessToken = accessToken;
Expand Down Expand Up @@ -47,7 +47,7 @@ private ItemClass getItem(ItemDTO itemDTO) {
itemDTO.getQuality());
}

public Enemy getEnemy(EnemyDTO enemyDTO) {
private Enemy getEnemy(EnemyDTO enemyDTO) {
StatBlockMaker statBlockMaker = new StatBlockMaker();

for (Map<String, Integer> stat : enemyDTO.getStatistics())
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/com/beantastic/api/ApitOffline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.beantastic.api;

import com.beantastic.enemies.Enemy;
import com.beantastic.items.ItemClass;
import com.beantastic.player.PlayerClass;
import com.beantastic.stats.StatBlock;

import java.util.List;

public class ApitOffline implements Apit {

@Override
public List<PlayerClass> getClasses() {
return List.of(
new PlayerClass("Green Bean Warrior", "A sturdy bean skilled in close combat, wielding the might of beans with brute force.", new StatBlock(100,73,41,13)),
new PlayerClass("Magic Coffee Bean", "A magical bean adept at harnessing the mystical energies of beans to cast powerful spells.", new StatBlock(55,24,67,84)),
new PlayerClass("Sneaky Black Bean", "A nimble bean with a knack for stealth and deception, striking enemies from the shadows.", new StatBlock(57,77,40,97)),
new PlayerClass("Divine Lima Bean", "A benevolent bean with divine powers, healing allies and smiting foes with righteous fury.", new StatBlock(50,36,93,69)),
new PlayerClass("Arrowhead Pinto Bean", "A skilled bean archer, raining down arrows upon enemies with deadly precision.", new StatBlock(84,15,75,27))
);
}

@Override
public List<ItemClass> getItems() {
return List.of(
new ItemClass("Mystic Carrot", "A mystical carrot that seems to be glowing green.", new StatBlock(15, -5, 0, 0), "Common"),
new ItemClass("Enchanted Banana", "An enchanted banana covered in strange runes. It smells slightly off.", new StatBlock(0, 0, 15, -5), "Common"),
new ItemClass("Sorcerer's Walnut", "A magical walnut that is very hard to crack.", new StatBlock(-5, 25, 0, 0), "Uncommon"),
new ItemClass("Fairy Fig", "A sparkly fig that looks exceptionally tasty.", new StatBlock(0, 0, -5, 25), "Uncommon"),
new ItemClass("Witch's Watermelon", "An exceptionally juicy and vibrant watermelon.", new StatBlock(15, 15, 15, 15), "Epic"),
new ItemClass("Wizard's Strawberry", "An oddly coloured strawberry with multicoloured seeds.", new StatBlock(-5, -5, -5, -5), "Cursed"),
new ItemClass("Enchanter's Eggplant", "A normal looking eggplant with the letters E.B. carved into its flesh.", new StatBlock(-15,0, 0, 0), "Cursed"),
new ItemClass("Sorceress' Spinach", "A magical leaf with potent powers. Its consumption promises mystical insights and enchanting flavors.", new StatBlock(-10, -10, 20, 20), "Uncommon"),
new ItemClass("Spellbound Apple", "A bewitched fruit with mystical allure.", new StatBlock(15, 15, -5, -5), "Uncommon")
);
}

@Override
public List<Enemy> getEnemies() {
return List.of(
new Enemy("Sorcerer Soup", new StatBlock(40, 25, 50, 50), "Easy", "The Sorcerer Soup hurls a fiery ladle at you.", "A mystical soup with potent magical properties."),
new Enemy("Cursed Carrot", new StatBlock(100, 40, 75, 90), "Medium", "The Cursed Carrot slams its toxic roots into the ground.", "A carrot cursed by dark magic, capable of unleashing havoc."),
new Enemy("Haunted Hamburger", new StatBlock(150, 90, 110, 60), "Hard", "The Haunted Hamburger whips you with one of its macon rashers.", "A haunted hamburger possessed by vengeful spirits."),
new Enemy("Ghoulish Grapes", new StatBlock(75, 75, 10, 20), "Easy", "The Ghoulish Grapes deliver a bitter bite.", "Sinister grapes with an eerie glow, hungry for souls."),
new Enemy("Sinister Sushi", new StatBlock(110, 60, 60, 50), "Medium", "The Sinister Sushi unleashes a whirlwind of wasabi.", "A malevolent sushi roll infused with dark energy."),
new Enemy("Menacing Muffin", new StatBlock(160, 75, 100, 70), "Hard", "The Menacing Muffin shoots you with one of it's raisins, yuck.", "A muffin with a menacing aura, tempting fate itself."),
new Enemy("Wayward Waffle", new StatBlock(140, 80, 80, 120), "Hard", "The Wayward Waffle throws syrup everywhere", "A Waffle fueled by syrup that enhances all attributes."),
new Enemy("Cursed Cauliflower", new StatBlock(105, 70, 105, 10), "Medium", "The Cursed Cauliflower beats you up with its might muscles", "A cauliflower cursed to wither its foes with dread."),
new Enemy("Wicked Watermelon", new StatBlock(150, 90, 25, 250), "Hard", "The Wicked Watermelon squirts its juices in your eye.", "A watermelon imbued with wickedness, thirsting for chaos."),
new Enemy("Spooky Spaghetti", new StatBlock(45, 75, 60, -25), "Easy", "The Spooky Spaghetti pokes you with its sharp head.", "Spaghetti possessed by spectral entities, haunting the kitchen.")
);
}
}

0 comments on commit d40c211

Please sign in to comment.