Skip to content

Commit d3d7e46

Browse files
Merge pull request #4 from thembaxaba157/PickWordSession
Main game flow
2 parents d030024 + 2bf98d8 commit d3d7e46

File tree

19 files changed

+1120
-71
lines changed

19 files changed

+1120
-71
lines changed

.github/workflows/main.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
jobs:
99
release:
1010
runs-on: ubuntu-latest
11+
1112
steps:
1213
- name: Checkout Repository
1314
uses: actions/checkout@v4
@@ -24,10 +25,14 @@ jobs:
2425
uses: actions/setup-node@v3
2526
with:
2627
node-version: '20.8.1'
27-
28+
2829
- name: Install Node.js dependencies
2930
run: |
30-
npm install @semantic-release/git @semantic-release/git @semantic-release/exec
31+
npm install @semantic-release/git @semantic-release/exec @semantic-release/github
32+
33+
- name: Build with Maven
34+
run: mvn clean install
35+
3136
- name: Run Semantic Release
3237
env:
3338
GITHUB_TOKEN: ${{ secrets.HANGMAN_TOKEN }}

.releaserc.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1+
# plugins:
2+
# - "@semantic-release/commit-analyzer"
3+
# - "@semantic-release/release-notes-generator"
4+
# - - "@semantic-release/exec"
5+
# - verifyReleaseCmd: 'mvn versions:set -DnewVersion="${nextRelease.version}" && echo "NEXT_VERSION=${nextRelease.version}" >> build.env'
6+
# - "@semantic-release/github"
7+
# - - "@semantic-release/git"
8+
# - assets:
9+
# - pom.xml
10+
# message: "chore(release): bump ${nextRelease.version}"
11+
12+
# branches:
13+
# - "main"
14+
# - "+([0-9])?(.{+([0-9]),x}).x"
15+
116
plugins:
217
- "@semantic-release/commit-analyzer"
318
- "@semantic-release/release-notes-generator"
4-
- - "@semantic-release/exec"
5-
- verifyReleaseCmd: 'mvn versions:set -DnewVersion="${nextRelease.version}" && echo "NEXT_VERSION=${nextRelease.version}" >> build.env'
19+
- "@semantic-release/exec"
20+
verifyReleaseCmd: 'mvn versions:set -DnewVersion="${nextRelease.version}" && echo "NEXT_VERSION=${nextRelease.version}" >> build.env'
621
- "@semantic-release/github"
7-
- - "@semantic-release/git"
8-
- assets:
9-
- pom.xml
10-
message: "chore(release): bump ${nextRelease.version}"
22+
- "@semantic-release/git"
23+
assets:
24+
- target/*.jar
25+
message: "chore(release): bump ${nextRelease.version}"
1126

1227
branches:
1328
- "main"

src/main/java/com/example/DatabaseHandling/DatabaseManager.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.example.DatabaseHandling;
22

33
import java.sql.Connection;
4+
import java.sql.Date;
45
import java.sql.DriverManager;
56
import java.sql.PreparedStatement;
67
import java.sql.ResultSet;
78
import java.sql.SQLException;
89
import java.sql.Statement;
910
import java.util.ArrayList;
10-
import java.sql.Date;
1111

1212
import com.example.UserHandling.Score;
1313
import com.example.UserHandling.User;
@@ -259,5 +259,39 @@ public void deletePlayer(String string) {
259259
System.err.println("Failed to delete player");
260260
}
261261
}
262+
263+
public void addScoreEntry(User user) {
264+
try {
265+
String addScoreSql = """
266+
INSERT INTO scores (player_id, highscore, date_played)
267+
VALUES (?, ?, ?)
268+
""";
269+
PreparedStatement addScoreStatement = this.connection.prepareStatement(addScoreSql);
270+
addScoreStatement.setInt(1, user.getId());
271+
addScoreStatement.setInt(2, user.getCurrScore().getScoreValue());
272+
addScoreStatement.setDate(3, user.getCurrScore().getDate());
273+
addScoreStatement.executeUpdate();
274+
} catch (SQLException e) {
275+
System.err.println("Failed to add score entry");
276+
}
277+
278+
}
279+
280+
public void updatePoints(User user) {
281+
try {
282+
String updatePointsSql = """
283+
UPDATE points
284+
SET points = ?
285+
WHERE player_id = ?
286+
""";
287+
PreparedStatement updatePointsStatement = this.connection.prepareStatement(updatePointsSql);
288+
updatePointsStatement.setInt(1, user.getPoints());
289+
updatePointsStatement.setInt(2, user.getId());
290+
updatePointsStatement.executeUpdate();
291+
} catch (SQLException e) {
292+
System.err.println("Failed to update points");
293+
}
294+
295+
}
262296
}
263297

src/main/java/com/example/DisplayManager.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.example;
22

33
import java.util.ArrayList;
4+
import java.util.Set;
45

6+
import com.example.GameHandler.HintSystem;
57
import com.example.UserHandling.User;
68

79
public class DisplayManager {
@@ -50,4 +52,72 @@ public static void showUser(User user) {
5052

5153
}
5254

55+
public static void showPlayMenu() {
56+
57+
System.out.println("\nPlay:");
58+
System.out.println("1. START");
59+
System.out.println("2. View Available Categories");
60+
System.out.println("3. View Rules");
61+
System.out.println("0. Menu\n");
62+
63+
}
64+
65+
public static void displayWordProgress(String wordToGuess, Set<Character> guessedLetters) {
66+
StringBuilder displayedWord = new StringBuilder();
67+
for (char letter : wordToGuess.toCharArray()) {
68+
if (guessedLetters.contains(letter)) {
69+
displayedWord.append(letter).append(" ");
70+
} else {
71+
displayedWord.append("_ ");
72+
}
73+
}
74+
System.out.println("Word: " + displayedWord.toString().trim());
75+
76+
77+
78+
}
79+
80+
public static void displayPlayerHud(int attemptsLeft, int points) {
81+
System.out.println("Attempts left: " + attemptsLeft);
82+
System.out.println("Points: " + points); // Show user points
83+
System.out.println("Enter a letter, or type 'hint' (You will pick a hint type)");
84+
}
85+
86+
public static void displayWordFact(String hint) {
87+
System.out.println("Fact about: "+hint);
88+
89+
}
90+
91+
public static void hintOptions() {
92+
System.out.println("\nHint Options:");
93+
System.out.println("1. Reveal a random letter(costs "+ HintSystem.getRevealRandomWordValue() + " points)");
94+
System.out.println("2. Add an extra random word(costs "+ HintSystem.getRevealRandomWordValue() + " points)");
95+
System.out.println("3. Reveal a fact(costs "+ HintSystem.getRevealWordFactValue() + " points)");
96+
97+
98+
99+
}
100+
101+
public static void continuePlay() {
102+
System.out.println("\nDo you want to continue playing with the current category and difficulty to increase score?");
103+
System.out.println("1. Yes");
104+
System.out.println("2. No");
105+
}
106+
107+
public static void showRules(){
108+
System.out.println("\n📜 HANGMAN RULES 📜");
109+
System.out.println("1️⃣ The game randomly selects a word.");
110+
System.out.println("2️⃣ You must guess one letter at a time.");
111+
System.out.println("3️⃣ If the letter is correct, it is revealed.");
112+
System.out.println("4️⃣ If incorrect, you lose an attempt.");
113+
System.out.println("6️⃣ The game ends when you guess the word or run out of attempts.");
114+
}
115+
116+
public static void display(ArrayList<String> categoryNames) {
117+
System.out.println("\nAvailable Categories: ");
118+
for (int i = 0; i < categoryNames.size(); i++) {
119+
System.out.println((i+1) + " " + categoryNames.get(i));
120+
}
121+
}
122+
53123
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.example.GameHandler;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import com.example.WordDataHandling.Category.Difficulty;
7+
8+
public class DifficultyManager {
9+
private static final Map<Difficulty, Integer> difficultyLevels = new HashMap<>();
10+
11+
static {
12+
difficultyLevels.put(Difficulty.EASY, 1);
13+
difficultyLevels.put(Difficulty.MEDIUM, 2);
14+
difficultyLevels.put(Difficulty.HARD, 3);
15+
}
16+
17+
public static int getDifficultyMultiplier(Difficulty difficulty) {
18+
return difficultyLevels.getOrDefault(difficulty, 1);
19+
}
20+
}

0 commit comments

Comments
 (0)