Compare commits

...

22 Commits

Author SHA1 Message Date
deadvey
40b8e7e4c7 removed swp file 2025-01-12 01:24:18 +00:00
deadvey
af9cac3a1b added insults 2025-01-12 01:22:45 +00:00
deadvey
e41e86779f removed noun from adjectives 2025-01-12 01:14:10 +00:00
deadvey
eb627344ad more insults 2025-01-12 01:12:28 +00:00
deadvey
7305b69fcb insults 2025-01-12 01:04:27 +00:00
deadvey
87af9b73a0 Added timer so you can have a highscore rustsweeper 2025-01-06 02:52:34 +00:00
deadvey
8ed27b637a Made flags ⚑ character 2025-01-05 18:49:37 +00:00
deadvey
553b9c1971 readme, added <br/> 2025-01-05 17:36:23 +00:00
deadvey
a754491f68 rustsweeper proper win conditions 2025-01-05 17:35:49 +00:00
deadvey
10d452ec33 rustsweeper screenshot 2025-01-05 16:46:10 +00:00
deadvey
c0c9e1db28 proper game over screen for rustsweeper 2025-01-05 16:45:03 +00:00
deadvey
90ac4c5e2e readme 2025-01-05 16:44:35 +00:00
deadvey
40dbc40526 rustsweeper 2025-01-05 16:20:39 +00:00
deadvey
31b95ad12e bug fix for prophecies 2025-01-05 03:14:15 +00:00
deadvey
96b28a74c2 added rubiks cube to readme 2025-01-05 03:09:17 +00:00
deadvey
483b383806 rubiks cube thingy (WIP) 2025-01-05 03:04:23 +00:00
d8843f57cb Update README.md
Spelling
2025-01-02 05:42:42 +01:00
deadvey
10e1908c25 readme 2025-01-02 04:41:43 +00:00
deadvey
beeeb93556 roman numerals 2025-01-02 04:38:47 +00:00
d7e4816e05 Update falling/src/main.rs 2024-12-25 02:08:29 +01:00
deadvey
bd051d24a8 ascii characters for WIP tuc_vs game 2024-12-25 00:40:00 +00:00
deadvey
7a3e71255c clarification in license 2024-12-24 21:13:14 +00:00
19 changed files with 976 additions and 2 deletions

View File

@@ -9,6 +9,11 @@ TO DO: documentation, commenting ¬_¬<br/>
BUGS: Can pass between diagonally conencted blocks, is this a 'bug'?<br/>
![example image for falling](screenshots/falling.png)
# Rustsweeper
A Minesweeper clone written in rust, instead of mines,<br/>
it's rusty nails that give you tetanus<br/>
![example game over screen for rustsweeper, at the top is a game of rustsweeper that has ended then the text 'GAME OVER' followed by ascii art of a man stepping on a nail and a collection of nails](screenshots/rustsweeper.png)
# Prophecies
Generates a random prophecy based on prophecies from <br/>
The Underland Chronicles by Suzanne Collins<br/>
@@ -32,11 +37,30 @@ And so they form a single vine.
Greet them as we have before.
Watch the nibblers spin and snap.
```
# Insults
Generates an insulting phrase for someone :D
# Rubiks Cube thing (WIP)
It's just a rubiks cube in the terminal, written in rust.<br/>
![example image for rubiks](screenshots/rubiks.png)
# Roman Numerals (WIP)
Converts numbers between Roman Numerals and Arabic Numerals<br/>
### Example:
```
# Currently no Arabic -> Roman support
$ cargo run
input: MMXXV
output: 2025
```
TO DO: Functionality to convert Arabic to Roman, currently only does Roman to Arabic :)
# Snake (WIP)
Classic Snake game<br/>
TO DO: all of it...
# License
GPL 3.0 applies to all the projects which are all<br/>
GPL 3.0 applies to all these projects, which are all<br/>
written by me.

View File

@@ -112,7 +112,7 @@ fn generate_level(level_to_generate: u64, difficulty: i8, left_wall: &mut i16, r
else if i == *left_wall-1 && left_wall_change < 0 {
new_level[i as usize] = -2;
}
// If its not on the left wall, mark the space with another value (-3) which is a straight
// If it's not on the left wall, mark the space with another value (-3) which is a straight
// wall "|".
else {
new_level[i as usize] = -3;

7
insults/Cargo.toml Normal file
View File

@@ -0,0 +1,7 @@
[package]
name = "insults"
version = "0.1.0"
edition = "2021"
[dependencies]
rand = "0.8.5"

257
insults/insults Normal file
View File

@@ -0,0 +1,257 @@
apish
bald-pated
artless
barren-spirited
beslubbering
beast-eating
calmunating
cautelous
churlish
coldblooded
concupscible
covetous
crudy
cuckoldly
deceptious
degenerate
facinerious
fawning
finical
fusty
goastish
gorbellied
greasy
heinous
incontinent
inexecrable
insolent
lecherous
lisping
loathly
lubberly
lumpish
mammering
musty
naughty
obscene
overgorged
panderly
pestiferous
plumfy
puking
rascally
reeky
sanctimonious
sickly
solbbery
sneaping
spongy
stinking
superserviceable
thrasonical
unhandsome
unwiped
viperous
wanton
warped
witless
breast-eating
beef-witted
boiled-brained
clay-brained
dirt-rotten
dizzy-eyed
dull-brained
eye-offending
fat-kidneyed
flap-eared
foul-mouthed
half-blooded
hard-haired
hell-governed
hollow-eyed
hook-nosed
ill-tempered
knotty-pated
leaden-footed
leptus leering
lily-livered
logger-headed
lust-breathed
motley-minded
mouse-eaten
muddy-mettled
nook-shotten
one-trunk-inheriting
pale-hearted
pigeon-livered
puke-stocking
puppy-headed
rank-scented
rug-headed
rump-fed
self-glorious
senseless-obstinate
sheep-biting
shrill-tongued
snail-paced
sodden-witted
stretch-mouthed
stubborn-hard
swag-bellied
tardy-gaited
thick-eyed
three-suited
thripe-visaged
under-honest
uneducated
useless
white-livered
barmy
gormless
manky
minging
naffy
idiotic
bigotted
stupid
blue-balled
arrogant
retarded
petulent
bigoted
phscopathic
small-minded
non-linux-user
pengiunless
crude
muppet
pikey
dodgy
micro-cocked
flaccid-cocked
shit-faced
piss-taking
sloppy
aggressive
ugly
abomination
arch-villain
baggage
bed-presser
blockhead
braggart
bugbear
bull's pizzle
codpiece
capocchia
cornuto
costermonger
cot-quean
coxcomb
cozener
dissembler
dullard
dunghill
fashion-monger
fleshmonger
foot-licker
fustilarian
geck
giglet
horn-beast
horse-back-breaker
idiot-worshipper
jack-a-nape
lewdster
malignancy
malmsey-butt
measle
miscreant
mushrump
ox-head
parasite
pig-nut
pin-buttock
potato-finger
princox
purpose-chnager
quatch-buttock
rabbit-sucker
rampallian
rat-catcher
ratsbane
renegatho
scum
scut
starve-lackey
stock-fish
ticklebrain
under-skinner
villiago
cum-bucket
retard
tosser
wheevil
cretin
wanker
slag
daft-cow
arsehole
chav
git
nutter
pillock
plonker
prat
trollop
twat
knob-head
bell-end
skiver
wazzock
ninny
berk
airy-fairy
ankle-biter
arse-licker
arsemonger
chuffer
gannet
ligger
maggot
mingebag
two-dicked-dog
window
apple
cunt
dick
cock
cum-sock
phallus
pussy
bigot
capitalist
cock-sucker
child
pedo
nonce
pedophile
apple-fanboy
nerd
geek
weeb
neek
swot
goblin
crumpet
piss-taker
shit-face
sucker
loser
minger
minge
battery-eater
toenail-clipping
tik-toker

35
insults/src/main.rs Normal file
View File

@@ -0,0 +1,35 @@
use std::fs;
use std::io;
use rand::Rng;
fn main() -> io::Result<()> {
let file_contents: String = fs::read_to_string("insults")?;
let lines: Vec<&str> = file_contents.split('\n').collect();
let mut adjectives: Vec<String> = Vec::new();
let mut nouns: Vec<String> = Vec::new();
let mut noun = false; // nouns is set to true when we have reached the nouns section in the file
// so should start pushing insults to nouns instead of adjectives
let num_of_adjectives: u64 = 2;
for line in lines {
if line == "" {
noun = true;
continue;
}
if noun {
nouns.push(line.to_string());
}
else if noun != true {
adjectives.push(line.to_string());
}
}
for _x in 0..num_of_adjectives {
let random_adjective = adjectives[rand::thread_rng().gen_range(0..adjectives.len())].clone();
print!("{}, ", random_adjective);
}
let random_noun = nouns[rand::thread_rng().gen_range(0..nouns.len())].clone();
print!("{}\n", random_noun);
Ok(())
}

View File

@@ -19,9 +19,14 @@ fn main() -> io::Result<()> {
let lines_in_string = split_string.len();
// Iterate for "number_of_lines" and each time pick a random line in the file
let mut previous_line_index = 0;
for _i in 0..number_of_lines {
let line_index = rand::thread_rng().gen_range(0..lines_in_string); // Pick random line
if split_string[previous_line_index] == split_string[line_index] {
continue;
}
println!("{}",split_string[line_index]); // Print the random line
previous_line_index = line_index;
}
Ok(())

View File

@@ -0,0 +1,6 @@
[package]
name = "roman-numerals"
version = "0.1.0"
edition = "2021"
[dependencies]

View File

@@ -0,0 +1,70 @@
use std::collections::HashMap;
use std::io::{stdin,stdout,Write};
fn input() -> String{
let mut s=String::new();
let _=stdout().flush();
stdin().read_line(&mut s).expect("Did not enter a correct string");
if let Some('\n')=s.chars().next_back() {
s.pop();
}
if let Some('\r')=s.chars().next_back() {
s.pop();
}
return s;
}
fn main() {
let mut numerals: HashMap<String, u64> = HashMap::new();
numerals.insert("I".to_string(), 1);
numerals.insert("V".to_string(), 5);
numerals.insert("X".to_string(), 10);
numerals.insert("L".to_string(), 50);
numerals.insert("C".to_string(), 100);
numerals.insert("D".to_string(), 500);
numerals.insert("M".to_string(), 1000);
let number = input();
let mut value: u64 = 4000;
let mut sum: u64 = 0;
let mut iteration = 0;
let mut skip_next = false;
let mut vector: Vec<String> = Vec::new();
for char in number.chars() {
vector.push(char.to_string());
};
for digit in vector {
if let Some(next_value) = numerals.get(&digit) {
if iteration > 0 && skip_next == false {
//println!("{}", skip_next);
//print!("{}: ", iteration);
if *next_value > value {
sum = sum + (*next_value - value);
//println!("{} = sum + ({} - {})", sum, *next_value, value);
skip_next = true;
value = *next_value;
continue;
}
else {
sum = sum + value;
//println!("{} = sum + {}", sum, value);
}
}
value = *next_value;
if skip_next {
skip_next = false;
}
} else {
println!("digit {} does not exist (My roman numerals only go up to M)!", digit);
}
iteration += 1;
}
if skip_next == false {
sum = sum + value;
}
println!("{}",sum);
}

1
rubiks/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

7
rubiks/Cargo.toml Normal file
View File

@@ -0,0 +1,7 @@
[package]
name = "rubiks"
version = "0.1.0"
edition = "2021"
[dependencies]
colored = "2.2.0"

BIN
rubiks/cube.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

26
rubiks/cube.txt Normal file
View File

@@ -0,0 +1,26 @@
Colors:
WWW
WWW
WWW
OOO GGG RRR BBB
OOO GGG RRR BBB
OOO GGG RRR BBB
YYY
YYY
YYY
Indexs:
012 0
345
678
901 234 567 890 10, 20
123 456 789 012 30
345 678 901 234 40
567 50
890
123

173
rubiks/src/main.rs Normal file
View File

@@ -0,0 +1,173 @@
use std::io::{stdin,stdout,Write};
use colored::*;
fn print_coloured(output: char) {
match output {
'R' => print!("{}", "R".on_truecolor(255,0,0)),
'G' => print!("{}", "G".on_truecolor(0,255,0).purple()),
'B' => print!("{}", "B".on_truecolor(0,0,255).red()),
'Y' => print!("{}", "Y".on_truecolor(255,255,0).black()),
'W' => print!("{}", "W".on_truecolor(255,255,255).black()),
'O' => print!("{}", "O".on_truecolor(255, 128, 0)),
_ => print!("{}", output),
}
}
fn output_cube(cube: &Vec<char>) {
// White square
print!(" ");
for i in 0..=2 {
print_coloured(cube[i]);
}
println!();
print!(" ");
for i in 3..=5 {
print_coloured(cube[i]);
}
println!();
print!(" ");
for i in 6..=8 {
print_coloured(cube[i]);
}
// First layer
println!();
for i in 9..=20 {
print_coloured(cube[i]);
}
// Second layer
println!();
for i in 21..=32 {
print_coloured(cube[i]);
}
// Third layer
println!();
for i in 33..=44 {
print_coloured(cube[i]);
}
// Yellow square
println!();
print!(" ");
for i in 45..=47 {
print_coloured(cube[i]);
}
println!();
print!(" ");
for i in 48..=50 {
print_coloured(cube[i]);
}
println!();
print!(" ");
for i in 51..=53 {
print_coloured(cube[i]);
}
println!()
}
fn move_cube(rotation: String, mut cube: &mut Vec<char>) {
let mut initial_cube = cube.clone();
// Up clockwise
if rotation == "U" {
cube[0] = initial_cube[6];
cube[1] = initial_cube[3];
cube[2] = initial_cube[0];
cube[3] = initial_cube[7];
// Cube 4 remains the same
cube[5] = initial_cube[1];
cube[6] = initial_cube[8];
cube[7] = initial_cube[5];
cube[8] = initial_cube[2];
let indices = vec![12, 13, 14, 15, 16, 17, 18, 19, 20, 9, 10, 11];
for (i, &index) in indices.iter().enumerate() {
cube[9 + i] = initial_cube[index];
}
}
if rotation == "D" {
cube[45] = initial_cube[51];
cube[46] = initial_cube[48];
cube[47] = initial_cube[45];
cube[48] = initial_cube[52];
// Cube 49 remains the same
cube[50] = initial_cube[46];
cube[51] = initial_cube[53];
cube[52] = initial_cube[50];
cube[53] = initial_cube[47];
let indices = vec![42, 43, 44, 33, 34, 35, 36, 37, 38, 39, 40, 41];
for (i, &index) in indices.iter().enumerate() {
cube[33 + i] = initial_cube[index];
}
}
if rotation == "R" {
cube[15] = initial_cube[39];
cube[16] = initial_cube[27];
cube[17] = initial_cube[15];
cube[27] = initial_cube[40];
// Cube 28 remains the same
cube[29] = initial_cube[16];
cube[39] = initial_cube[41];
cube[40] = initial_cube[29];
cube[41] = initial_cube[17];
// Other edge peices around the Right side
cube[42] = initial_cube[2];
cube[30] = initial_cube[5];
cube[18] = initial_cube[8];
cube[2] = initial_cube[14];
cube[5] = initial_cube[26];
cube[8] = initial_cube[38];
cube[14] = initial_cube[47];
cube[26] = initial_cube[50];
cube[38] = initial_cube[53];
cube[47] = initial_cube[42];
cube[50] = initial_cube[30];
cube[53] = initial_cube[18];
}
}
fn input() -> String{
let mut s=String::new();
let _=stdout().flush();
stdin().read_line(&mut s).expect("Did not enter a correct string");
if let Some('\n')=s.chars().next_back() {
s.pop();
}
if let Some('\r')=s.chars().next_back() {
s.pop();
}
return s;
}
fn main() {
// Create a net of a cube, see cube.jpeg or cube.txt in the root of this project for a
// visualisation
let mut cube: Vec<char> = vec![
'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', // 0-8 (W)
'O', 'O', 'O', // 9-11 (O)
'G', 'G', 'G', // 12-14 (G)
'R', 'R', 'R', // 15-17 (R)
'B', 'B', 'B', // 18-20 (B)
'O', 'O', 'O', // 21-23 (O)
'G', 'G', 'G', // 24-26 (G)
'R', 'R', 'R', // 27-29 (R)
'B', 'B', 'B', // 30-32 (B)
'O', 'O', 'O', // 33-35 (O)
'G', 'G', 'G', // 36-38 (G)
'R', 'R', 'R', // 39-41 (R)
'B', 'B', 'B', // 42-44 (B)
'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', // 45-53 (Y)
];
output_cube(&cube);
'game_loop: loop {
let rotation = input();
if rotation == "q" {
break 'game_loop;
}
move_cube(rotation, &mut cube);
output_cube(&cube);
}
}

1
rustsweeper/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

9
rustsweeper/Cargo.toml Normal file
View File

@@ -0,0 +1,9 @@
[package]
name = "rustsweeper"
version = "0.1.0"
edition = "2021"
[dependencies]
rand = "0.8.5"
colored = "2.2.0"
console = "0.15.10"

324
rustsweeper/src/main.rs Normal file
View File

@@ -0,0 +1,324 @@
use std::io::{stdin,stdout,Write};
use rand::Rng;
use colored::*;
use console::Term;
use std::time::Instant;
fn output_board(board: &Vec<Vec<i64>>, state: &Vec<Vec<char>>, x_hovered: i64, y_hovered: i64) {
let mut output: String = "".to_string();
for y in 0..board.len() {
for x in 0..board[y].len() {
let background_color: u8;
if state[y][x] != 'u' {
background_color = 128;
}
else {
background_color = 196;
}
if x == x_hovered as usize && y == y_hovered as usize {
output.push_str(&"X".truecolor(0,0,0).on_truecolor(background_color,background_color,background_color).to_string());
}
else if state[y][x] == 'u' {
if board[y][x] == -1 {
output.push_str(&"".truecolor(128,64,0).on_truecolor(background_color,background_color,background_color).to_string());
}
else if board[y][x] == 0 {
output.push_str(&" ".on_truecolor(background_color,background_color,background_color).to_string());
}
else if board[y][x] == 1 {
output.push_str(&"1".truecolor(1,0,254).on_truecolor(background_color,background_color,background_color).to_string());
}
else if board[y][x] == 2 {
output.push_str(&"2".truecolor(1,127,1).on_truecolor(background_color,background_color,background_color).to_string());
}
else if board[y][x] == 3 {
output.push_str(&"3".truecolor(254,0,0).on_truecolor(background_color,background_color,background_color).to_string());
}
else if board[y][x] == 4 {
output.push_str(&"4".truecolor(1,0,128).on_truecolor(background_color,background_color,background_color).to_string());
}
else if board[y][x] == 5 {
output.push_str(&"5".truecolor(129,1,2).on_truecolor(background_color,background_color,background_color).to_string());
}
else if board[y][x] == 6 {
output.push_str(&"6".truecolor(0,128,129).on_truecolor(background_color,background_color,background_color).to_string());
}
else if board[y][x] == 7 {
output.push_str(&"7".truecolor(0,0,0).on_truecolor(background_color,background_color,background_color).to_string());
}
else if board[y][x] == 8 {
output.push_str(&"8".truecolor(128,128,128).on_truecolor(background_color,background_color,background_color).to_string());
}
}
else if state[y][x] == 'm' {
output.push_str(&"".truecolor(228,16,32).on_truecolor(background_color,background_color,background_color).to_string());
}
else if state[y][x] == '?' {
output.push_str(&"?".truecolor(0,0,0).on_truecolor(background_color,background_color,background_color).to_string());
}
else {
output.push_str(&" ".on_truecolor(background_color,background_color,background_color).to_string());
}
}
output.push_str("\n");
}
print!("{}[2J", 27 as char);
println!("{}",output);
}
fn input() -> String{
let mut s=String::new();
let _=stdout().flush();
stdin().read_line(&mut s).expect("Did not enter a correct string");
if let Some('\n')=s.chars().next_back() {
s.pop();
}
if let Some('\r')=s.chars().next_back() {
s.pop();
}
return s;
}
fn place_nails(board: &mut Vec<Vec<i64>>, number_of_nails: i64, width: i64, height: i64) {
for _nail in 0..number_of_nails {
// Generate coordinates for nails, if there is already a nail there, then generate new
// coordinates, should add case for if there are more mines than locations, but why would
// someone do that?
let mut x_coord = rand::thread_rng().gen_range(0..width);
let mut y_coord = rand::thread_rng().gen_range(0..height);
while board[y_coord as usize][x_coord as usize] == -1 {
x_coord = rand::thread_rng().gen_range(0..width);
y_coord = rand::thread_rng().gen_range(0..height);
}
board[y_coord as usize][x_coord as usize] = -1;
}
}
fn determine_nails_in_range(board: &mut Vec<Vec<i64>>) {
for x in 0..board.len() {
for y in 0..board[x].len() {
if board[x][y] != -1 {
let mut num_of_nails = 0;
for i in -1..2 {
for j in -1..2 {
// Check if index is in range (>= 0 and < length of vector)
if (x as i64 + i >= 0 && (x as i64 + i) < board.len() as i64) && (y as i64 + j >= 0 && (y as i64 + j) < board[x].len() as i64) {
if board[(x as i64 + i) as usize][(y as i64 + j) as usize] == -1 {
num_of_nails += 1; // Increment the nail count
}
}
}
}
board[x][y] = num_of_nails;
}
}
}
}
fn find_connected_coordinates(grid: &Vec<Vec<i64>>, start_row: usize, start_col: usize) -> Vec<(usize, usize)> {
let rows = grid.len();
let cols = grid[0].len();
let target_value = grid[start_row][start_col];
// Directions for 8 possible moves (vertical, horizontal, and diagonal)
let directions: [(i64, i64); 8] = [
(-1, 0), // Up
(1, 0), // Down
(0, -1), // Left
(0, 1), // Right
(-1, -1),// Top-left diagonal
(-1, 1), // Top-right diagonal
(1, -1), // Bottom-left diagonal
(1, 1), // Bottom-right diagonal
];
// Visited cells
let mut visited = vec![vec![false; cols]; rows];
// Vector to store the reachable coordinates
let mut result = Vec::new();
// DFS function
fn dfs(
grid: &Vec<Vec<i64>>,
row: usize,
col: usize,
target_value: i64,
visited: &mut Vec<Vec<bool>>,
result: &mut Vec<(usize, usize)>,
directions: &[(i64, i64)],
) {
// Check if the position is out of bounds or already visited or doesn't match the target value
if row >= grid.len() || col >= grid[0].len() || visited[row][col] || grid[row][col] != target_value {
return;
}
// Mark the cell as visited and add the coordinate to the result
visited[row][col] = true;
result.push((row, col));
// Flag to check if we're at the boundary of the connected region
let mut is_boundary = false;
for &direction in directions.iter() {
let (dx, dy) = direction;
let new_row = row as i64 + dx;
let new_col = col as i64 + dy;
if new_row >= 0 && new_row < grid.len() as i64 && new_col >= 0 && new_col < grid[0].len() as i64 {
let new_row = new_row as usize;
let new_col = new_col as usize;
if grid[new_row][new_col] != target_value {
is_boundary = true;
}
dfs(grid, new_row, new_col, target_value, visited, result, directions);
}
}
if is_boundary {
for &direction in directions.iter() {
let (dx, dy) = direction;
let new_row = row as i64 + dx;
let new_col = col as i64 + dy;
if new_row >= 0 && new_row < grid.len() as i64 && new_col >= 0 && new_col < grid[0].len() as i64 {
let new_row = new_row as usize;
let new_col = new_col as usize;
// Add cells with a different value to the result
if grid[new_row][new_col] != target_value && !visited[new_row][new_col] {
result.push((new_row, new_col));
}
}
}
}
}
dfs(grid, start_row, start_col, target_value, &mut visited, &mut result, &directions);
result
}
fn uncover(board: &Vec<Vec<i64>>, state: &mut Vec<Vec<char>>, x_hovered: usize, y_hovered: usize, alive: &mut bool) {
state[y_hovered][x_hovered] = 'u';
if board[y_hovered][x_hovered] == -1 {
*alive = false;
}
if board[y_hovered][x_hovered] == 0 {
let connected = find_connected_coordinates(&board, y_hovered, x_hovered);
for (y,x) in connected.iter() {
state[*y][*x] = 'u';
}
}
}
fn detect_win(state: &Vec<Vec<char>>, number_of_nails: i64, start: Instant) {
let mut number_of_covered_cells: i64 = 0;
for y in 0..state.len() {
for x in 0..state[y].len() {
if state[y][x] != 'u' {
number_of_covered_cells = number_of_covered_cells + 1;
}
}
}
if number_of_covered_cells == number_of_nails {
println!("Congratulations, you won!!!");
let end = std::time::Instant::now();
println!("In {:?}", end-start);
std::process::exit(0);
}
}
fn main() {
let stdout = Term::buffered_stdout();
let mut board: Vec<Vec<i64>> = Vec::new();
let mut state: Vec<Vec<char>> = Vec::new(); // u = uncovered, c = covered, m = marked
let height: i64 = 8;
let width: i64 = 8;
let number_of_nails: i64 = 10;
//let percentage_of_cells_are_nails: i64 = 15;
//let number_of_nails: i64 = ((percentage_of_cells_are_nails / 100) as i64) * ((width * height) as i64) as i64;
let mut x_hovered: i64 = 0;
let mut y_hovered: i64 = 0;
let mut alive: bool = true;
for y in 0..height {
board.push(Vec::new());
state.push(Vec::new());
for x in 0..width {
board[y as usize].push(0);
state[y as usize].push('c');
//board[x as usize][y as usize] = -1;
}
}
let start = std::time::Instant::now();
place_nails(&mut board, number_of_nails, width, height);
determine_nails_in_range(&mut board);
output_board(&board, &state, x_hovered, y_hovered);
'gameloop: loop {
if let Ok(character) = stdout.read_char() {
match character {
'w' | 'k' => if y_hovered > 0 { y_hovered -= 1 },
'a' | 'h' => if x_hovered > 0 { x_hovered -= 1},
's' | 'j' => if y_hovered < height-1 { y_hovered += 1 },
'd' | 'l' => if x_hovered < width-1 {x_hovered += 1},
'u' => uncover(&board, &mut state, x_hovered as usize, y_hovered as usize, &mut alive),
'm' => {
if state[y_hovered as usize][x_hovered as usize] == 'm' {
state[y_hovered as usize][x_hovered as usize] = 'c'
}
else {
state[y_hovered as usize][x_hovered as usize] = 'm'
}
},
'?' => {
if state[y_hovered as usize][x_hovered as usize] == '?' {
state[y_hovered as usize][x_hovered as usize] = 'c'
}
else {
state[y_hovered as usize][x_hovered as usize] = '?'
}
},
'q' => break 'gameloop,
_ => (),
}
}
if alive {
output_board(&board, &state, x_hovered, y_hovered);
detect_win(&state, number_of_nails, start);
}
else if alive == false {
println!("GAME OVER!\nYou got Tetanus!");
println!("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡀⠀⠀⠀⠀⠀⠀⠀");
println!(" ⢀⣾⣿O⣷");
println!(" ⠸⣿⣿⣿C- HOLY SHIT");
println!(" ⣀⣤⡈⠛⢉⠀⠀⠀⠀⠀⠀⠀");
println!(" ⢀⣴⣿⣿⣿⣿⣿⣿⠃⠀⠀⠀⠀⠀⠀");
println!(" ⣴⣿⣿⢿⣿⣿⣿⣿⣿⠀⡄⠀⠀⠀⠀⠀");
println!(" ⠀⠀⠀⠀⢰⣿⡏⠀⢸⣿⣿⣿⣿⡇⢸⣷⣤⣀⠀⠀⠀");
println!(" ⠀⠀⠀⠀⣼⣿⠁⠀⢸⣿⣿⣿⣿⠁⠀⠙⠻⢿⣿⣶⠀");
println!(" ⠀⠀⠀⠀⠛⠋⠀⠀⠸⣿⣿⣿⡏⠀⠀⠀⠀⠀⠈⠉⠀");
println!(" ⠀⠀⠀⠀⠀⠀⠀⠀⣄⠙⣿⣿⣷⡄⠀⠀⠀⠀⠀⠀⠀");
println!(" ⠀⠀⠀⠀⠀⠀⠀⢸⣿⣦⠈⢿⣿⣿⣦⠀⠀⠀⠀⠀⠀");
println!(" ⠀⠀⠀⠀⠀⠀⠀⣼⣿⡟⠀⠀⠻⣿⣿⣧⠀⠀⠀⠀⠀");
println!(" ⠀⠀⠀⠀⠀⣠⣾⣿⠟⠁⠀⠀⠀⠘⢿⣿⣧/");
println!(" ⠀⠀⠀⠀⢾⣿⠟⠁⠀⠀⠀⠀⠀⠀⠈⢻⣿⠇⠀⠀⠀");
break 'gameloop;
}
}
}

BIN
screenshots/rubiks.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 KiB

BIN
screenshots/rustsweeper.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 501 KiB

29
tuc_vs/ascii_characters Normal file
View File

@@ -0,0 +1,29 @@
Gregor: Back
__ _
/ \ //
\__/ //
-' '- //
|/ ||//
(| //--
'\__.'
|/-\|
// \\
|| \\
|| ||
|| ||
''- ''-
Front:
_ __
\\ /--\
\\ \__/
\\ -' '-
\\|/ ||
---- __//
\8__/'
|/-\|
// \\
|| \\
|| ||
|| ||
-'' -''