Skip to content

Commit e3c9e88

Browse files
committed
upload everything
1 parent 335f205 commit e3c9e88

File tree

15 files changed

+2004
-0
lines changed

15 files changed

+2004
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
.tmp/
3+
build/**/*
4+
!build/manifest.txt

README.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Asscii Games
2+
![Ascii Games](assets/title.png)
3+
## Description
4+
This is a game manager for all of your java ascii games. It is super easy to add games to the manager.
5+
6+
## Inspiration
7+
I wanted a way to easily have asscii games all in one place.
8+
9+
## Current Games
10+
- Battleship - The classic game of Battleship. [@allancoding](https://github.com/allancoding)
11+
- Rock Paper Scissors - A really simple game of Rock Paper Scissors. [@allancoding](https://github.com/allancoding)
12+
- Tic Tac Toe - A simple version of Tick Tack Toe. [@allancoding](https://github.com/allancoding)
13+
14+
## How to play
15+
1. Run the `manager` class.
16+
2. Select a game to play.
17+
3. Play the game and have fun!
18+
19+
![Game Selection](assets/game.png)
20+
21+
22+
## How to add a game
23+
1. Create a new class inside of the games folder.
24+
2. Create nested class inside of the main class name it `Game`
25+
3. the method `start` should be the main method for the game.
26+
5. You can add a description and name to the game by adding a `description` & `name` variable to the `Game` class.
27+
6. 2 booleans should be passed to the `start` method. The first will be true and the second will be false.
28+
Example:
29+
```java
30+
public class Chess {
31+
public static class Game {
32+
public static final String Name = "Chess";
33+
public static final String Description = "The classic game of Chess.";
34+
public static void start(boolean, instructions, boolean main) {
35+
// Game code here
36+
}
37+
}
38+
}
39+
```
40+
Note: The methods will need to be static.
41+
42+
## Build
43+
You can easily build the project by running the `build.sh` script. It will out put a jar called `asciiGames.jar`.
44+
```bash
45+
chmod +x build.sh
46+
./build.sh
47+
```
48+
49+
## Run
50+
To run the jar file:
51+
```bash
52+
java -jar asciiGames.jar
53+
```
54+
55+
## Dependencies
56+
- [Java](https://www.java.com/) 8 or higher is required.
57+
- [Janis](https://github.com/fusesource/jansi) 2.4.1 or higher is required.
58+
59+
## Docs for the `ascii` class
60+
The asscii class is used as a helper class for asscii. It has a few methods that can be used to help with the game.
61+
62+
### Methods:
63+
| Method | Description | Parameters | Returns |
64+
| --- | --- | --- | --- |
65+
| `ascii.clear` | Clears the screen. | null | null |
66+
| `ascii.print` | Prints a string to the screen. | `String` - The string to print. | null |
67+
| `ascii.println` | Prints a string to the screen with a new line. | `String` - The string to print. | null |
68+
| `ascii.printerror` | Prints an error message to the screen. | `String` - The error message to print. | null |
69+
| `ascii.printRepeated` | Prints a string repeated a number of times. | `String` - The string to print. <br>`int` - The number of times to print the string. <br>`boolean` - Whether to print a new line at the end. | null |
70+
| `ascii.wait` | Waits for a number of milliseconds. | `int` - The number of milliseconds to wait. | null |
71+
| `ascii.waitForEnter` | Waits for the user to press enter. | `String` - The message to print before waiting. | null |
72+
| `ascii.toS` | Converts a char to a string. | `char` - The char to convert. | `String` - The converted string. |
73+
74+
### Variables:
75+
#### Ascii Characters:
76+
| Variable | Value | Returns |
77+
| --- | --- | --- |
78+
| `ascii.emDash` || Char |
79+
| `ascii.rectangle` || Char |
80+
| `ascii.box` || Char |
81+
82+
#### Colors:
83+
| Variable | Description | Returns |
84+
| --- | --- | --- |
85+
| `ascii.ANSI_RESET` | Resets the color. | String |
86+
| `ascii.ANSI_BLACK` | Black color. | String |
87+
| `ascii.ANSI_RED` | Red color. | String |
88+
| `ascii.ANSI_GREEN` | Green color. | String |
89+
| `ascii.ANSI_YELLOW` | Yellow color. | String |
90+
| `ascii.ANSI_BLUE` | Blue color. | String |
91+
| `ascii.ANSI_PURPLE` | Purple color. | String |
92+
| `ascii.ANSI_CYAN` | Cyan color. | String |
93+
| `ascii.ANSI_WHITE` | White color. | String |
94+
| `ascii.ANSI_BLACK_BACKGROUND` | Black background color. | String |
95+
| `ascii.ANSI_RED_BACKGROUND` | Red background color. | String |
96+
| `ascii.ANSI_GREEN_BACKGROUND` | Green background color. | String |
97+
| `ascii.ANSI_YELLOW_BACKGROUND` | Yellow background color. | String |
98+
| `ascii.ANSI_BLUE_BACKGROUND` | Blue background color. | String |
99+
| `ascii.ANSI_PURPLE_BACKGROUND` | Purple background color. | String |
100+
| `ascii.ANSI_CYAN_BACKGROUND` | Cyan background color. | String |
101+
| `ascii.ANSI_WHITE_BACKGROUND` | White background color. | String |
102+
103+
#### Table:
104+
| Variable | Description | Value | Returns |
105+
| --- | --- | --- | --- |
106+
| `ascii.topCornerLeft` | Top left corner of a table. || Char |
107+
| `ascii.topCornerRight` | Top right corner of a table. || Char |
108+
| `ascii.bottomCornerLeft` | Bottom left corner of a table. || Char |
109+
| `ascii.bottomCornerRight` | Bottom right corner of a table. || Char |
110+
| `ascii.side` | Side of a table. || Char |
111+
| `ascii.topT` | Top T of a table. || Char |
112+
| `ascii.bottomT` | Bottom T of a table. || Char |
113+
| `ascii.leftT` | Left T of a table. || Char |
114+
| `ascii.rightT` | Right T of a table. || Char |
115+
| `ascii.cross` | Cross of a table. || Char |
116+
| `ascii.horizontal` | Horizontal line of a table. || Char |
117+
| `ascii.vertical` | Vertical line of a table. || Char |
118+
119+
120+
## How to contribute
121+
Contributing is super easy. Just add a new game to the games folder and follow the instructions above. Then create a pull request and I will review it.

asciiGames.jar

280 KB
Binary file not shown.

assets/game.png

12.5 KB
Loading

assets/title.png

3.96 KB
Loading

build.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
# Build the project
3+
echo "Building asciiGames"
4+
# create the .tmp directory
5+
mkdir -p .tmp/games
6+
# copy the source files to the tmp directory
7+
cp -r src/asciiGames/*.java .tmp
8+
cp -r src/asciiGames/games/*.java .tmp/games
9+
# get all of the files
10+
cd .tmp
11+
find ./ -name "*.java" > sources.txt
12+
# compile the source files
13+
javac -encoding UTF-8 -cp ../lib/* -d ../build @sources.txt
14+
cd ..
15+
unzip -q -o lib/*.jar -d build
16+
# add the jar dependencies to the classpath
17+
jar cmf build/manifest.txt asciiGames.jar -C build .
18+
# remove the .tmp directory
19+
rm -r .tmp
20+
echo "Done!"

build/manifest.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Manifest-Version: 1.0
2+
Main-Class: asciiGames.manager

lib/jansi.jar

251 KB
Binary file not shown.

src/asciiGames/animation.java

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package asciiGames;
2+
3+
public class animation {
4+
private static String[] colors = {ascii.color.ANSI_RED, ascii.color.ANSI_YELLOW, ascii.color.ANSI_GREEN, ascii.color.ANSI_CYAN, ascii.color.ANSI_BLUE, ascii.color.ANSI_PURPLE};
5+
6+
public static void slidein() throws InterruptedException {
7+
String[] frames = {
8+
"_______ __________ _________ ______",
9+
"___ |_______________(_)__(_) __ ____/_____ _______ __________________ /",
10+
"__ /| |_ ___/ ___/_ /__ / _ / __ _ __ `/_ __ `__ \\ _ \\_ ___/_ / ",
11+
"_ ___ |(__ )/ /__ _ / _ / / /_/ / / /_/ /_ / / / / / __/(__ ) /_/ ",
12+
"/_/ |_/____/ \\___/ /_/ /_/ \\____/ \\__,_/ /_/ /_/ /_/\\___//____/ (_) "
13+
};
14+
int frameWidth = frames[0].length();
15+
ascii.clear();
16+
System.out.flush();
17+
for (int i = 0; i <= frameWidth; i++) {
18+
if (i != frameWidth) {
19+
ascii.clear();
20+
System.out.flush();
21+
}
22+
for (String line : frames) {
23+
ascii.print("\033[" + i + "D");
24+
if (frameWidth - i > 0) {
25+
ascii.print(colors[i/14] + line.substring(frameWidth - i) + ascii.color.ANSI_RESET);
26+
}
27+
ascii.println("");
28+
}
29+
ascii.wait(20);
30+
}
31+
}
32+
public static void slideout() throws InterruptedException {
33+
String[] frames = {
34+
"_______ __________ _________ ______",
35+
"___ |_______________(_)__(_) __ ____/_____ _______ __________________ /",
36+
"__ /| |_ ___/ ___/_ /__ / _ / __ _ __ `/_ __ `__ \\ _ \\_ ___/_ / ",
37+
"_ ___ |(__ )/ /__ _ / _ / / /_/ / / /_/ /_ / / / / / __/(__ ) /_/ ",
38+
"/_/ |_/____/ \\___/ /_/ /_/ \\____/ \\__,_/ /_/ /_/ /_/\\___//____/ (_) "
39+
};
40+
int frameWidth = frames[0].length();
41+
int frameHeight = frames.length;
42+
System.out.flush();
43+
for (int lineIndex = 0; lineIndex < frameHeight; lineIndex++) {
44+
for (int i = frameWidth; i >= 0; i--) {
45+
ascii.clear();
46+
System.out.flush();
47+
ascii.print("\033[" + (lineIndex + 1) + ";1H");
48+
if (frameWidth - i > 0 && frameHeight - lineIndex > 0) {
49+
ascii.print(colors[i/14] + frames[lineIndex].substring(frameWidth - i) + ascii.color.ANSI_RESET);
50+
}
51+
ascii.println("");
52+
for (int j = lineIndex + 1; j < frameHeight; j++) {
53+
ascii.print(frames[j]);
54+
ascii.println("");
55+
}
56+
ascii.wait(20);
57+
}
58+
}
59+
}
60+
public static void show() throws InterruptedException {
61+
String[] frames = {
62+
" ___ ______ __",
63+
" / | _____ _____ (_) (_) / ____/ ____ _ ____ ___ ___ _____ / /",
64+
" / /| | / __// ___/ / / / / / / __ / __ `/ / __ `__ \\/ _ \\ / ___/ / / ",
65+
" / ___ |(__ )/ /__ / / / / / /_/ / / /_/ / / / / / / / __/(__ ) /_/ ",
66+
" /_/ |_/____/ \\___/ /_/ /_/ \\____/ \\__,_/ /_/ /_/ /_/\\___//____/ (_) "
67+
};
68+
ascii.clear();
69+
System.out.flush();
70+
int i = 0;
71+
for (String line : frames) {
72+
ascii.println(colors[i] + line + ascii.color.ANSI_RESET);
73+
i++;
74+
}
75+
}
76+
}

src/asciiGames/ascii.java

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package asciiGames;
2+
import java.io.Console;
3+
4+
public class ascii {
5+
public static final char emDash = 0x2500;
6+
public static final char rectangle = 0x2588;
7+
public static final char box = 0x25A0;
8+
9+
public static class color {
10+
public static final String ANSI_RESET = "\u001B[0m";
11+
public static final String ANSI_BLACK = "\u001B[30m";
12+
public static final String ANSI_RED = "\u001B[31m";
13+
public static final String ANSI_GREEN = "\u001B[32m";
14+
public static final String ANSI_YELLOW = "\u001B[33m";
15+
public static final String ANSI_BLUE = "\u001B[34m";
16+
public static final String ANSI_PURPLE = "\u001B[35m";
17+
public static final String ANSI_CYAN = "\u001B[36m";
18+
public static final String ANSI_WHITE = "\u001B[37m";
19+
public static final String ANSI_BLACK_BACKGROUND = "\u001B[40m";
20+
public static final String ANSI_RED_BACKGROUND = "\u001B[41m";
21+
public static final String ANSI_GREEN_BACKGROUND = "\u001B[42m";
22+
public static final String ANSI_YELLOW_BACKGROUND = "\u001B[43m";
23+
public static final String ANSI_BLUE_BACKGROUND = "\u001B[44m";
24+
public static final String ANSI_PURPLE_BACKGROUND = "\u001B[45m";
25+
public static final String ANSI_CYAN_BACKGROUND = "\u001B[46m";
26+
public static final String ANSI_WHITE_BACKGROUND = "\u001B[47m";
27+
}
28+
29+
public static class table {
30+
public static final char topCornerLeft = 0x250C;
31+
public static final char topCornerRight = 0x2510;
32+
public static final char bottomCornerLeft = 0x2514;
33+
public static final char bottomCornerRight = 0x2518;
34+
public static final char side = 0x2502;
35+
public static final char topT = 0x252C;
36+
public static final char bottomT = 0x2534;
37+
public static final char leftT = 0x251C;
38+
public static final char rightT = 0x2524;
39+
public static final char cross = 0x253C;
40+
public static final char horizontal = 0x2500;
41+
public static final char vertical = 0x2502;
42+
}
43+
44+
public static void clear() {
45+
print("\033[H\033[2J");
46+
}
47+
48+
public static void print(String message) {
49+
System.out.print(message);
50+
}
51+
52+
public static void println(String message) {
53+
System.out.println(message);
54+
}
55+
56+
public static void printerror(String error) {
57+
if (error != "") {
58+
println(color.ANSI_RED_BACKGROUND + color.ANSI_BLACK + error + color.ANSI_RESET + " ");
59+
}
60+
}
61+
62+
public static void printRepeated(String character, int times, boolean newline) {
63+
for (int i = 0; i < times; i++) {
64+
if (newline && i == times - 1) {
65+
println(character);
66+
} else {
67+
print(character);
68+
}
69+
}
70+
}
71+
72+
public static void wait(int milliseconds) throws InterruptedException{
73+
Thread.sleep(milliseconds);
74+
}
75+
76+
public static void waitForEnter(String message, Object... args) {
77+
Console c = System.console();
78+
if (c != null) {
79+
if (message != null) {
80+
c.format(message, args);
81+
}
82+
c.format("\n");
83+
c.readLine();
84+
}
85+
}
86+
87+
public static String toS(char string) {
88+
return string + "";
89+
}
90+
}
91+

0 commit comments

Comments
 (0)