diff --git a/build.gradle b/build.gradle index 8175989..bfa2f5c 100644 --- a/build.gradle +++ b/build.gradle @@ -6,25 +6,28 @@ dependencies { testCompile fileTree(include: ['*.jar'], dir:'lib') testImplementation fileTree(include: ['*.jar'], dir:'lib') testRuntime fileTree(include: ['*.jar'], dir:'lib') - checkstyle files('lib/checkstyle-8.20-all.jar') + checkstyle files('lib/checkstyle-8.20-all.jar') } checkstyle { toolVersion '8.20' - configFile file('checkstyle.xml') + configFile file('checkstyle.xml') } sourceSets { - main { - java { - srcDir 'src/main' - } - } - test { - java { - srcDir 'src/test' - } - } + main { + java { + srcDir 'src/main' + } + resources { + srcDir "src/resources" + } + } + test { + java { + srcDir 'src/test' + } + } } test { useJUnitPlatform() @@ -34,18 +37,30 @@ test { } task run(type: JavaExec) { - group = 'Run' - description = 'Run main' + group = 'Run' + description = 'Run main' + standardInput = System.in + + classpath sourceSets.main.runtimeClasspath + main = "ui.Main" + //args "arg1", "arg2" +} + +task debug(type: JavaExec) { + group = 'Run' + description = 'Debug main' + standardInput = System.in - classpath sourceSets.main.runtimeClasspath - main = "ui" - //args "arg1", "arg2" + classpath sourceSets.main.runtimeClasspath + main = "ui.Main" + debug = true + //args "arg1", "arg2" } task tags(type: Exec) { - description = 'Update tags file' - - commandLine 'ctags', '-R', 'src' + description = 'Update tags file' + + commandLine 'ctags', '-R', 'src' } checkstyleMain { diff --git a/src/main/ui/Gui.java b/src/main/ui/Gui.java new file mode 100644 index 0000000..b7f6895 --- /dev/null +++ b/src/main/ui/Gui.java @@ -0,0 +1,16 @@ +import javax.swing.*; + +public class Gui { + //public Gui() { + // JLabel label = new JLabel("Hello World"); + + // JFrame.setDefaultLookAndFeelDecorated(true); + // JFrame f = new JFrame("Hello World"); + // f.setSize(300,150); + // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + // f.add(label); + + // f.setVisible(true); + //} +} diff --git a/src/main/ui/Iface.java b/src/main/ui/Iface.java index 06747f1..fed0592 100644 --- a/src/main/ui/Iface.java +++ b/src/main/ui/Iface.java @@ -1,18 +1,5 @@ -package ui; +import data.Options; -public class Iface { - public static void main(String[] args) { - System.out.println("Starting Main"); - helloWorld(); - helloWorld2(); - System.out.println("Exiting..."); - } - - public static void helloWorld() { - System.out.println("Hello world"); - } - - public static void helloWorld2() { - System.out.println("Hello world2"); - } +public abstract class Iface { + private Options ifaceOpts; } diff --git a/src/main/ui/IfaceFactory.java b/src/main/ui/IfaceFactory.java new file mode 100644 index 0000000..1ad1c8e --- /dev/null +++ b/src/main/ui/IfaceFactory.java @@ -0,0 +1,7 @@ +import data.Options; +//import ui.Iface; + +public class IfaceFactory { + //public Iface getIface(Options IfaceOptions){ + //} +} diff --git a/src/main/ui/Main.java b/src/main/ui/Main.java new file mode 100644 index 0000000..e162902 --- /dev/null +++ b/src/main/ui/Main.java @@ -0,0 +1,66 @@ +package ui; + +import java.util.*; + +public class Main { + public static final String PROGRAM_NAME = "Num guess"; + //public static final String USAGE_TEXT = "Usage"; + private int win; + private int games; + //private Iface iface; + //private Options allOptions; + + //Constructor, not the java main + public Main(String[] args) { + //options = new Options(); + System.out.println("Welcome to " + PROGRAM_NAME + "!"); + guess(); + } + + // java main + public static void main(String[] args) { + new Main(args); + } + + public void guess() { + Random rand = new Random(); + while (true) { + int range = rand.nextInt(1000); + int secret = rand.nextInt(range); + System.out.println("Can you guess my number? [0 - " + range + "]"); + System.out.println("Enter -1 to end"); + int user = getUserInt(); + if (user < 0) { + break; + } else { + guessResult(user, secret); + } + } + } + + public int getUserInt() { + Scanner scan = new Scanner(System.in); + int result = scan.nextInt(); + scan.close(); + return result; + } + + public void guessResult(int user, int secret) { + if (user < secret || user > secret) { + this.games++; + System.out.println("Too bad. You guessed " + + secret + " with " + user + "."); + } else { + this.games++; + this.win++; + System.out.println("Wonderful! You have correctly guessed: " + + secret + " with " + user + "!"); + } + } + + public void end() { + System.out.println("You have won: " + this.win + " out of " + this.games + + "!"); + System.out.println("Thank you for playing this game! Bye!"); + } +} diff --git a/src/main/ui/Tui.java b/src/main/ui/Tui.java new file mode 100644 index 0000000..0e89a16 --- /dev/null +++ b/src/main/ui/Tui.java @@ -0,0 +1,36 @@ +import java.util.*; +//import ui.Iface; +import java.io.BufferedReader; +import java.io.InputStreamReader; + + +public class Tui extends Iface { + private static final String SAVE_CURSOR = "\u001b[s"; + private static final String RESTORE_CURSOR = "\u001b[s"; + private static final String REQUEST_CURSOR = "\u001b[6n"; + private int maxcol; + private int maxrow; + private BufferedReader stdin; + + public Tui() { + // stdin = new BufferedReader(new InputStreamReader(System.in)); + } + + //public String getInput() { + //} + + //public getCursor(){ + // if (stdin.ready()) { + // System.out.print(REQUEST_CURSOR); + // stdin.skip(1); + // char c; + // while (char = (char)stdin.read() != ';') { + // row = + // } + // } + //} + + //public void moveCursor(int col, int row) { + // System.out.print("\u001b["+col+";"+row+"H"); + //} +}