repl.it
@vedprad1/

The Game of 15

Java

No description

fork
loading
Files
  • Main.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int count = 2;
    int ask;
    int a;
    int b;
    String computer = "\u001B[32m";
    String user = "\u001B[33m";
    String winner = "\u001B[36m";
    String reset = "\u001B[0m";
    String title = "\033[1;35m";
    System.out.println("Try to beat your computer in this game!\n");
    System.out.println(title + "   THE GAME OF");
    System.out.print("  __    _______   \n /  |  |  _____|  \n `| |  | |____    \n  | |  '_.____''. \n _| |_  ______) | \n|_____||______.' \n                " + reset + "\n");
    System.out.println("Objective: Make the computer say 15.");
    System.out.println("Rules:\n1: You can say either 1, 2, or 3 numbers at a time.\n2: Numbers only appear in consecutive order.\n");
    System.out.println("Announcement: If you win this game, please post a screenshot in the comments on the previous screen (I Built This). Your name will appear here:");
    System.out.println(winner + "No one has beaten the game yet." + reset + "\n");
    System.out.println("Let's begin!");
    System.out.println(computer + "Computer says:\n1, 2," + reset);
    for (a = 0; a < 3; a++) {
      System.out.println("How many numbers would you like to say?");
      ask = scan.nextInt();
      if (ask == 1 || ask == 2 || ask == 3) {
        System.out.println(user + "User says: ");
        for (b = 0; b < ask; b++) {
          count++;
          System.out.print(count + ", ");
        }
        ask = 4 - ask;
        System.out.println(computer + "\nComputer says: ");
        for (b = 0; b < ask; b++) {
          count++;
          System.out.print(count + ", ");
        }
        System.out.println(reset);
      }
      else {
        System.out.println("That is an unacceptable answer! Please rerun this program.");
        return;
      }
    }
    System.out.println("How many numbers would you like to say?");
      ask = scan.nextInt();
      if (ask == 1 || ask == 2 || ask == 3) {
        System.out.println(user + "User says: ");
        for (b = 0; b < ask; b++) {
          count++;
          System.out.print(count + ", ");
        }
        System.out.println(reset + "\nOh no! You said 15! You lose.");
      }
      else {
        System.out.println("That is an unacceptable answer! Please rerun this program.");
        return;
      }
  }
}
?