Skip to content

Instantly share code, notes, and snippets.

@killjoy1221
Forked from infideleraser/WhatGame.java
Last active September 7, 2018 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save killjoy1221/2c9f91a1ee25d8ca894926f8aefa6862 to your computer and use it in GitHub Desktop.
Save killjoy1221/2c9f91a1ee25d8ca894926f8aefa6862 to your computer and use it in GitHub Desktop.
import java.awt.Desktop
import java.io.IOException
import java.net.URI;
class EpicGame extends Game {
private final String game;
public EpicGame(String game, String name) {
super(name);
this.game = game;
}
@Override
public void launch() throws IOException {
Desktop.getDesktop().browse(URI.create("com.epicgames.launcher://apps/" + game + "?action=launch&silent=true"));
}
}
import java.io.IOException;
abstract class Game {
private final String name;
protected Game(String name) {
this.name = name;
}
public abstract void launch() throws IOException;
public String getName() {
return name;
}
}
import java.io.File;
import java.io.IOException;
class OtherGame extends Game {
private final File exe;
public OtherGame(File exe, String name) {
super(name);
this.exe = exe;
}
@Override
public void launch() throws IOException {
Runtime.getRuntime().exec(exe.toString(), null, exe.getParentFile());
}
}
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
class SteamGame extends Game {
private final int gameId;
public SteamGame(int gameId, String name) {
super(name);
this.gameId = gameId;
}
@Override
public void launch() throws IOException {
Desktop.getDesktop().browse(URI.create("steam://rungameid/" + gameId));
}
}
import java.awt.Desktop;
import java.io.File;
import java.util.Random;
import javax.swing.JOptionPane;
class WhatGame {
private static Game[] games = {
new SteamGame(379720, "End some demons"),
new SteamGame(359550, "Monty is sheild daddy"),
new SteamGame(365720, "Slay some dragons"),
new SteamGame(377160, "Initiate nuclear fallout"),
new EpicGame("Fortnite", "Abortnite"),
new OtherGame(new File("D:\\rockstar\\PlayGTAV.exe"), "Be a Criminal"),
new SteamGame(275850, "Explore a new galaxy"),
new SteamGame(578080, "The real Battle Royale")
};
public static void main(String[] args) throws Exception {
String[] options = {"Play Game", "Quit"};
Random rand = new Random();
Game game = games[rand.nextInt(games.length)];
int x = JOptionPane.showOptionDialog(null, game.getName(),
"Select one",
JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
if (x == 0) {
game.launch();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment