-
-
Save mattmess1221/2c9f91a1ee25d8ca894926f8aefa6862 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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