Skip to content

Commit 2e9083f

Browse files
authored
Merge pull request #6 from eficode/hangperson
Simple hangman challenge
2 parents 4dd3ead + 2525fc5 commit 2e9083f

File tree

10 files changed

+129876
-0
lines changed

10 files changed

+129876
-0
lines changed

challenges/hangperson/README.md

+197
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
# Java Console Application Setup (HangpersonApp) with Copilot Assistance
2+
3+
This document describes how to set up a new testable Java console application using Maven, leveraging GitHub Copilot for assistance.
4+
5+
## Prerequisites
6+
7+
* Java Development Kit (JDK) installed (version 8 or later recommended).
8+
* Apache Maven installed.
9+
* GitHub Copilot extension enabled in your IDE.
10+
11+
## Setup Steps
12+
13+
1. **Create Project Structure:**
14+
Open your terminal or command prompt, navigate to the directory where you want to create the project (the directory containing this `README.md` file), and run the following Maven command to generate a basic project structure:
15+
16+
```bash
17+
mvn archetype:generate -DgroupId=com.example -DartifactId=hangpersonapp -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
18+
```
19+
20+
This will create a `hangpersonapp` subdirectory with the standard Maven layout (`src/main/java`, `src/test/java`, `pom.xml`).
21+
22+
1. **Navigate into the Project:**
23+
```bash
24+
cd hangpersonapp
25+
```
26+
27+
1. **Create a new vscode window to contain only this app**
28+
```bash
29+
code .
30+
```
31+
Start using copilot in that new window (you can open this md file on that window also if needed)
32+
33+
1. **Update `pom.xml` for Testing and Java Version:**
34+
Open the `pom.xml` file.
35+
* **Prompt Copilot:** "Set the Java compiler source and target versions to 1.8."
36+
* **Prompt Copilot:** "Ensure the JUnit 5 Jupiter engine dependency is included for testing."
37+
* **Prompt Copilot:** "Add the maven-surefire-plugin configured for JUnit 5."
38+
* **Prompt Copilot:** (Optional) "Add the maven-assembly-plugin to create an executable JAR with dependencies, setting the main class to com.example.App."
39+
40+
*Example `pom.xml` structure after Copilot's changes:*
41+
```xml
42+
<!-- filepath: pom.xml -->
43+
<properties>
44+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
45+
<maven.compiler.source>1.8</maven.compiler.source>
46+
<maven.compiler.target>1.8</maven.compiler.target>
47+
<junit.jupiter.version>5.8.2</junit.jupiter.version> <!-- Or latest -->
48+
</properties>
49+
50+
<dependencies>
51+
<dependency>
52+
<groupId>org.junit.jupiter</groupId>
53+
<artifactId>junit-jupiter-engine</artifactId>
54+
<version>${junit.jupiter.version}</version>
55+
<scope>test</scope>
56+
</dependency>
57+
<!-- Other dependencies -->
58+
</dependencies>
59+
60+
<build>
61+
<plugins>
62+
<plugin>
63+
<groupId>org.apache.maven.plugins</groupId>
64+
<artifactId>maven-surefire-plugin</artifactId>
65+
<version>3.0.0-M5</version> <!-- Or latest compatible -->
66+
</plugin>
67+
<!-- Optional Assembly Plugin -->
68+
<plugin>
69+
<groupId>org.apache.maven.plugins</groupId>
70+
<artifactId>maven-assembly-plugin</artifactId>
71+
<version>3.3.0</version> <!-- Or latest -->
72+
<configuration>
73+
<archive>
74+
<manifest>
75+
<mainClass>com.example.App</mainClass> <!-- Verify this -->
76+
</manifest>
77+
</archive>
78+
<descriptorRefs>
79+
<descriptorRef>jar-with-dependencies</descriptorRef>
80+
</descriptorRefs>
81+
</configuration>
82+
<executions>
83+
<execution>
84+
<id>make-assembly</id>
85+
<phase>package</phase>
86+
<goals>
87+
<goal>single</goal>
88+
</goals>
89+
</execution>
90+
</executions>
91+
</plugin>
92+
</plugins>
93+
</build>
94+
```
95+
96+
4. **Create/Modify Main Application Class:**
97+
Navigate to `src/main/java/com/example/App.java`.
98+
* **Prompt Copilot:** "Create a basic main method that prints 'Hello HangpersonApp!'."
99+
* **Prompt Copilot:** "Add a public method `getGreeting` that returns the string 'Hello HangpersonApp!'."
100+
101+
*Example `App.java` after Copilot's changes:*
102+
```java
103+
// filepath: src/main/java/com/example/App.java
104+
package com.example;
105+
106+
public class App {
107+
public static void main(String[] args) {
108+
System.out.println("Hello HangpersonApp!");
109+
// Add application logic here
110+
}
111+
112+
public String getGreeting() {
113+
return "Hello HangpersonApp!";
114+
}
115+
}
116+
```
117+
118+
1. **Create/Modify Test Class:**
119+
Navigate to `src/test/java/com/example/AppTest.java`.
120+
* **Prompt Copilot:** "Convert this test class to use JUnit 5."
121+
* **Prompt Copilot:** "Write a JUnit 5 test method named `testGetGreeting` that asserts the `getGreeting` method of the `App` class returns 'Hello HangpersonApp!'."
122+
123+
*Example `AppTest.java` after Copilot's changes:*
124+
```java
125+
// filepath: src/test/java/com/example/AppTest.java
126+
package com.example;
127+
128+
import org.junit.jupiter.api.Test;
129+
import static org.junit.jupiter.api.Assertions.*;
130+
131+
class AppTest {
132+
@Test
133+
void shouldAnswerWithTrue() {
134+
assertTrue(true); // Keep or remove placeholder
135+
}
136+
137+
@Test
138+
void testGetGreeting() {
139+
App app = new App();
140+
assertEquals("Hello HangpersonApp!", app.getGreeting());
141+
}
142+
}
143+
```
144+
145+
## Building and Running
146+
147+
1. **Compile:**
148+
```bash
149+
mvn compile
150+
```
151+
152+
2. **Run Tests:**
153+
```bash
154+
mvn test
155+
```
156+
157+
3. **Package (Create JAR):**
158+
```bash
159+
mvn package
160+
```
161+
This will create JAR files in the `target/` directory. If you included the `maven-assembly-plugin`, it will create an executable JAR with dependencies.
162+
163+
4. **Run the Application (using the executable JAR):**
164+
```bash
165+
java -jar target/hangpersonapp-1.0-SNAPSHOT-jar-with-dependencies.jar
166+
```
167+
*(Adjust the JAR filename based on your project's version)*
168+
169+
Alternatively, run directly using Maven:
170+
```bash
171+
mvn exec:java -Dexec.mainClass="com.example.App"
172+
```
173+
*(Make sure to replace `com.example.App` with your actual main class if different)*
174+
175+
## Actual game implementation
176+
177+
1. Start implementing a console game where you guess a random word.
178+
179+
Hangperson (traditionally known as Hangman) is a classic word-guessing game. One player thinks of a word or phrase, and the other player tries to figure it out by guessing letters one at a time. For each incorrect guess, a part of a stick figure being hanged is drawn. The goal is to guess the word before the drawing is completed.
180+
181+
You can use that description for Copilot, but try to ask only for small parts of the implementation at once.
182+
183+
You can, e.g., first use ask mode to plan what parts you could ask agent mode to implement at once and how to limit agent mode not to try to do the whole game in one go.
184+
185+
There are nouns and verbs available in this directory for you to use as words or in any way you would like. Please see `wordnet.md` for the license for nouns and verbs.
186+
187+
2. When the game is ready or in good shape, consider adding tests if none exist yet.
188+
189+
Before adding tests, it would be good to refactor the game to be modular enough. Try to extract the game engine, input parsing, and rendering. If you can come up with better modules with Copilot, try to use those.
190+
191+
## Challenging features
192+
193+
1. Make a game server and a client.
194+
195+
2. Make bots (AI opponents).
196+
197+
3. Implement chat between clients

challenges/hangperson/note.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
AI opponents
2+
split words to easy medium and hard ones

0 commit comments

Comments
 (0)