-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLauncher.java
130 lines (119 loc) · 3.88 KB
/
Launcher.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import java.util.Scanner;
import javax.swing.SwingUtilities;
import Game.Board;
import Swing.StartMenu;
/**
* Filename: Launcher.java
*
* @author Tina Hague
* @version 1.0
* @since 1.0
*
* Last Updated:
*/
public class Launcher {
public static void main(String[] args) {
// SwingUtilities.invokeLater(new Runnable() {
// @Override
// public void run() {
// StartMenu menu = new StartMenu();
// //ControlsDisplay controls = new ControlsDisplay();
// //GameDisplay game = new GameDisplay();
// menu.setVisible(true);
// }
// });
Board board = new Board();
Scanner scanner = new Scanner(System.in);
Board.clearScreen();
System.out.println("Welcome to Tetris!");
System.out.println("To play, it is best to extend your terminal.");
addDelay();
System.out.println("Are you ready to play? (yes/no)");
String input;
boolean lost = false;
Board.addNewShape();
while(true) {
input = scanner.nextLine();
if (input.equals("yes")){
break;
}
else if (input.equals("no")) {
System.out.println("Have a lovely day!");
System.exit(0);
}
else {
System.out.println("Please enter 'yes' or 'no'.");
}
}
Board.clearScreen();
Board.printBoard();
while (!lost) {
// Board.clearScreen();
//Board.printBoard();
System.out.println("Which way would you like to move the block?");
System.out.println("l -> left");
System.out.println("r -> right");
System.out.println("s -> shoot down");
System.out.println("q -> quit");
while(true) {
input = scanner.nextLine();
if (input.equals("l") || input.equals("r") || input.equals("s") || input.equals("q")) {
break;
}
else {
System.out.println("Please enter valid input (l, r, s, q)");
}
}
switch (input) {
case "l":
try{
Board.moveLeft();
}
catch(Exception e){
System.out.println(e.getMessage());
}
break;
case "r":
try {
Board.moveRight();
}
catch(Exception e) {
System.out.println(e.getMessage());
}
break;
case "s":
Board.shootShapeDown();
break;
case "q":
System.out.println("Have a lovely day!");
System.exit(0);
break;
}
Board.clearScreen();
Board.moveDown();
Board.addNewShape();
// Board.clearFullLines();
System.out.println(Board.canMoveDown());
Board.printBoard();
lost = Board.isGameOver() ? true : false;
}
}
/**
* Add a delay to the program for a specified duration.
*/
private static void addDelay() {
addDelay(600);
}
/**
* Add a delay to the program for a specified duration.
*
* @param duration to delay the program for in milliseconds.
*/
private static void addDelay(long duration) {
try {
Thread.sleep(duration);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}