I have written some code to track buffs as a side addition to the popular game League of Legends.
My code is incredibly repetitive and I also have the issue of not being able to track multiple buffs, although that might not be on topic for the question so feel free to not consider this when answering.
import java.util.Scanner;
public class MainProgram {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Jungle Timers v1.0");
System.out.println("\nSelect a buff to time:");
System.out.println("\n1. Blue");
System.out.println("2. Enemy Blue");
System.out.println("3. Red");
System.out.println("4. Enemy Red");
System.out.println("5. Dragon");
System.out.println("6. Baron");
System.out.print("\n> ");
int timerChoice = keyboard.nextInt();
keyboard.close();
switch (timerChoice) {
case 1:
friendlyBlue();
case 2:
enemyBlue();
case 3:
friendlyRed();
case 4:
enemyRed();
case 5:
Dragon();
case 6:
Baron();
}
}
public static void friendlyBlue() {
System.out.println("\nTracking your blue...");
System.out.println("5 Minutes left");
int friendlyBlue = 300;
long startTime = System.currentTimeMillis() / 1000;
long endTime = startTime + friendlyBlue;
while (System.currentTimeMillis() / 1000 < endTime) {
while (startTime != System.currentTimeMillis() / 1000) {
startTime += 1;
if (endTime - startTime > 1)
if (endTime - startTime == 240)
System.out.println("4 Minutes left");
if (endTime - startTime == 180)
System.out.println("3 Minutes left");
if (endTime - startTime == 120)
System.out.println("2 Minutes left");
if (endTime - startTime == 60)
System.out.println("1 Minute left");
if (endTime - startTime == 30)
System.out.println("30 Seconds left");
if (endTime - startTime == 15)
System.out.println("15 Seconds left");
if (endTime - startTime == 5)
System.out.println("5 Seconds left");
else if (endTime - startTime == 1) {
System.out.println("Blue Buff is up!");
}
}
}
}
public static void enemyBlue() {
System.out.println("\nTracking enemy blue...");
System.out.println("5 Minutes left");
int enemyBlue = 300;
long startTime = System.currentTimeMillis() / 1000;
long endTime = startTime + enemyBlue;
while (System.currentTimeMillis() / 1000 < endTime) {
while (startTime != System.currentTimeMillis() / 1000) {
startTime += 1;
if (endTime - startTime > 1)
if (endTime - startTime == 240)
System.out.println("4 Minutes left");
if (endTime - startTime == 180)
System.out.println("3 Minutes left");
if (endTime - startTime == 120)
System.out.println("2 Minutes left");
if (endTime - startTime == 60)
System.out.println("1 Minute left");
if (endTime - startTime == 30)
System.out.println("30 Seconds left");
if (endTime - startTime == 15)
System.out.println("15 Seconds left");
if (endTime - startTime == 5)
System.out.println("5 Seconds left");
else if (endTime - startTime == 1) {
System.out.println("Enemy Blue Buff is up!");
}
}
}
}
public static void friendlyRed() {
System.out.println("\nTracking your red...");
System.out.println("5 Minutes left");
int friendlyRed = 300;
long startTime = System.currentTimeMillis() / 1000;
long endTime = startTime + friendlyRed;
while (System.currentTimeMillis() / 1000 < endTime) {
while (startTime != System.currentTimeMillis() / 1000) {
startTime += 1;
if (endTime - startTime > 1)
if (endTime - startTime == 240)
System.out.println("4 Minutes left");
if (endTime - startTime == 180)
System.out.println("3 Minutes left");
if (endTime - startTime == 120)
System.out.println("2 Minutes left");
if (endTime - startTime == 60)
System.out.println("1 Minute left");
if (endTime - startTime == 30)
System.out.println("30 Seconds left");
if (endTime - startTime == 15)
System.out.println("15 Seconds left");
if (endTime - startTime == 5)
System.out.println("5 Seconds left");
else if (endTime - startTime == 1) {
System.out.println("Red Buff is up!");
}
}
}
}
public static void enemyRed() {
System.out.println("\nTracking enemy red...");
System.out.println("5 Minutes left");
int enemyRed = 300;
long startTime = System.currentTimeMillis() / 1000;
long endTime = startTime + enemyRed;
while (System.currentTimeMillis() / 1000 < endTime) {
while (startTime != System.currentTimeMillis() / 1000) {
startTime += 1;
if (endTime - startTime > 1)
if (endTime - startTime == 240)
System.out.println("4 Minutes left");
if (endTime - startTime == 180)
System.out.println("3 Minutes left");
if (endTime - startTime == 120)
System.out.println("2 Minutes left");
if (endTime - startTime == 60)
System.out.println("1 Minute left");
if (endTime - startTime == 30)
System.out.println("30 Seconds left");
if (endTime - startTime == 15)
System.out.println("15 Seconds left");
if (endTime - startTime == 5)
System.out.println("5 Seconds left");
else if (endTime - startTime == 1) {
System.out.println("Enemy Red Buff is up!");
}
}
}
}
public static void Dragon() {
System.out.println("\nTracking dragon...");
System.out.println("6 Minutes left");
int dragon = 360;
long startTime = System.currentTimeMillis() / 1000;
long endTime = startTime + dragon;
while (System.currentTimeMillis() / 1000 < endTime) {
while (startTime != System.currentTimeMillis() / 1000) {
startTime += 1;
if (endTime - startTime > 1)
if (endTime - startTime == 300)
System.out.println("5 Minutes left");
if (endTime - startTime == 240)
System.out.println("4 Minutes left");
if (endTime - startTime == 180)
System.out.println("3 Minutes left");
if (endTime - startTime == 120)
System.out.println("2 Minutes left");
if (endTime - startTime == 60)
System.out.println("1 Minute left");
if (endTime - startTime == 30)
System.out.println("30 Seconds left");
if (endTime - startTime == 15)
System.out.println("15 Seconds left");
if (endTime - startTime == 5)
System.out.println("5 Seconds left");
else if (endTime - startTime == 1) {
System.out.println("Dragon is up!");
}
}
}
}
public static void Baron() {
System.out.println("\nTracking baron...");
System.out.println("7 Minutes left");
int baron = 420;
long startTime = System.currentTimeMillis() / 1000;
long endTime = startTime + baron;
while (System.currentTimeMillis() / 1000 < endTime) {
while (startTime != System.currentTimeMillis() / 1000) {
startTime += 1;
if (endTime - startTime > 1)
if (endTime - startTime == 360)
System.out.println("6 Minutes left");
if (endTime - startTime == 300)
System.out.println("5 Minutes left");
if (endTime - startTime == 240)
System.out.println("4 Minutes left");
if (endTime - startTime == 180)
System.out.println("3 Minutes left");
if (endTime - startTime == 120)
System.out.println("2 Minutes left");
if (endTime - startTime == 60)
System.out.println("1 Minute left");
if (endTime - startTime == 30)
System.out.println("30 Seconds left");
if (endTime - startTime == 15)
System.out.println("15 Seconds left");
if (endTime - startTime == 5)
System.out.println("5 Seconds left");
else if (endTime - startTime == 1) {
System.out.println("Baron is up!");
}
}
}
}
}
hello world
exists 100584902 times, and someone new codes it every day. OP surely learned something valuable about methods/functions here. \$\endgroup\$