-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
85 lines (69 loc) · 3.6 KB
/
Main.java
File metadata and controls
85 lines (69 loc) · 3.6 KB
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
import java.util.*;
public class Main {
private static void showInstructions() {
System.out.println("🧩 Welcome to Sudoku Console Edition!");
System.out.println("\nGeneral Rules:");
System.out.println("1. Fill each row, column, and 3x3 grid with numbers 1-9 without duplicates.");
System.out.println("2. You cannot change original (pre-filled) values.");
System.out.println("3. Choose a cell by entering its row and column (0-8), followed by a number (1-9).");
System.out.println("4. Difficulty level will determine feedback, lives, and re-editing rules.");
System.out.println("5. Game ends when the board is completely and correctly filled.");
System.out.println("6. Leaderboards are stored by difficulty in the 'results' folder.\n");
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
showInstructions();
System.out.print("Enter your name: ");
String playerName = scanner.nextLine();
System.out.println("Choose difficulty (easy / medium / hard / extreme): ");
String levelInput = scanner.nextLine().toUpperCase();
Difficulty level;
try {
level = Difficulty.valueOf(levelInput);
} catch (IllegalArgumentException e) {
System.out.println("Invalid difficulty. Defaulting to EASY.");
level = Difficulty.EASY;
}
Player player = new Player(playerName, level);
System.out.println("\n📘 Selected Difficulty: " + level);
switch (level) {
case EASY:
System.out.println(" Mode: EASY");
System.out.println(" Unlimited lives");
System.out.println(" Feedback: Shows if input is correct or wrong");
System.out.println(" You can re-edit your inputs freely\n");
break;
case MEDIUM:
System.out.println(" Mode: MEDIUM");
System.out.println(" Unlimited lives");
System.out.println(" No feedback on correctness");
System.out.println(" You can re-edit your inputs freely\n");
break;
case HARD:
System.out.println(" Mode: HARD");
System.out.println(" 5 lives");
System.out.println(" No feedback on correctness");
System.out.println(" You can re-edit inputs, but wrong answers cost a life\n");
break;
case EXTREME:
System.out.println(" Mode: EXTREME");
System.out.println(" 3 lives");
System.out.println(" No feedback on correctness");
System.out.println(" No re-editing allowed — wrong moves lock the cell");
System.out.println(" Game over after 3 wrong attempts\n");
break;
}
SudokuGenerator generator = new SudokuGenerator();
int[][] fullBoard = generator.generateFullBoard();
int[][] puzzleBoard = generator.generatePuzzleBoard(level);
long startTime = System.currentTimeMillis();
GameManager gameManager = new GameManager();
gameManager.startGame(scanner, fullBoard, puzzleBoard, player);
long endTime = System.currentTimeMillis();
long timeTaken = (endTime - startTime) / 1000;
player.setTimeTakenInSeconds(timeTaken);
System.out.println("\n🎉 Congratulations " + playerName + "!");
System.out.println(" Difficulty: " + level);
System.out.println("⏱ Time taken: " + timeTaken + " seconds");
}
}