Compare commits
3 Commits
320560f3c5
...
9d46f2c47a
Author | SHA1 | Date | |
---|---|---|---|
|
9d46f2c47a | ||
|
76257b7483 | ||
|
449c5fa85b |
1
falling/.gitignore
vendored
Normal file
1
falling/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
23
falling/roach.txt
Normal file
23
falling/roach.txt
Normal file
@ -0,0 +1,23 @@
|
||||
-__
|
||||
/ \
|
||||
| -___
|
||||
| / ________________________
|
||||
| / | |
|
||||
‾ |‾ / _ | Where is the princess? |
|
||||
/ | \ / | \ |________________________|
|
||||
/ ‾‾‾‾‾‾‾ \ / /
|
||||
__ / / \• •/ _|
|
||||
/ \ _/‾|‾\ / |
|
||||
_ / / \ / / |
|
||||
\/ / /|___/
|
||||
/ \
|
||||
/ \ / \
|
||||
| \ / \
|
||||
|\____\_/ \
|
||||
\ / / \ \ /
|
||||
\ / \ /
|
||||
/ / / /
|
||||
_| \ /_ |
|
||||
|
||||
|
||||
|
@ -25,7 +25,7 @@ fn generate_output(starting_level: u64, ending_level: u64, character_x_coord: u1
|
||||
} else {
|
||||
match object {
|
||||
-3 => output+="|", // Specific case for -3
|
||||
0 => output+="¯", // Specific case for 0
|
||||
0 => output+="■", // Specific case for 0
|
||||
-1 => output+="\\", // Specific case for -1
|
||||
-2 => output+="/", // Specific case for -2
|
||||
_ => output+=" " // Default, no print for other cases
|
||||
@ -61,8 +61,11 @@ fn generate_level(level_to_generate: u64, difficulty: i8, left_wall: &mut i16, r
|
||||
new_level.push(1)
|
||||
}
|
||||
|
||||
for i in *left_wall+1..*right_wall-1 {
|
||||
let object: i8 = rand::thread_rng().gen_range(0..difficulty);
|
||||
for i in *left_wall..*right_wall {
|
||||
let mut object: i8 = 1;
|
||||
if level_to_generate >= 5 || (i as f32) < (screen_width as f32 / 2.0)-5.0 || (i as f32) > (screen_width as f32 / 2.0)+5.0 {
|
||||
object = rand::thread_rng().gen_range(0..difficulty);
|
||||
}
|
||||
new_level[i as usize] = object;
|
||||
}
|
||||
for i in 0..*left_wall {
|
||||
@ -131,7 +134,6 @@ fn debug_mode_modify_variables(current_level: &mut u64) -> u8 {
|
||||
|
||||
fn check_if_alive(levels: &Vec<Vec<i8>>, level: usize, x_coord: usize) -> bool {
|
||||
if levels[level][x_coord] <= 0 {
|
||||
println!("GAME OVER");
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
@ -153,9 +155,9 @@ fn input() -> String{
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let debug_mode = true; // Enable or disable debugging mode, it will print some useful stats and
|
||||
let debug_mode = false; // Enable or disable debugging mode, it will print some useful stats and
|
||||
// let you modify stats midgame with e
|
||||
let can_die = false; // I can't spell invinsiblitlity but this lets you not die...
|
||||
let can_die = true; // I can't spell invinsiblitlity but this lets you not die...
|
||||
|
||||
let mut levels: Vec<Vec<i8>> = Vec::new(); // Define variables for level
|
||||
|
||||
@ -166,19 +168,19 @@ fn main() {
|
||||
screen_height = screen_height - 17;
|
||||
}
|
||||
else {
|
||||
screen_height = screen_height - 1;
|
||||
screen_height = screen_height - 2;
|
||||
}
|
||||
|
||||
let stdout = Term::buffered_stdout();
|
||||
|
||||
let mut current_level: u64 = 0;
|
||||
let mut character_icon: char = 'µ';
|
||||
let mut character_icon: char = '☺';
|
||||
let mut x_coord: u16 = (screen_width as f32/ 2.0) as u16; // Distance from left wall
|
||||
let mut left_wall: i16 = rand::thread_rng().gen_range(0..((screen_width as f32/ 2.0)-5.0) as i16) as i16;
|
||||
let mut right_wall: i16 = rand::thread_rng().gen_range(((screen_width as f32 /2.0)+5.0) as i16..screen_width as i16) as i16;
|
||||
let mut preference: f32 = rand::thread_rng().gen_range(-2.0..3.0);
|
||||
let mut alive: bool = true;
|
||||
let mut difficulty: i8 = 6;
|
||||
let mut difficulty: i8 = 2;
|
||||
|
||||
|
||||
for i in 0..screen_height {
|
||||
@ -235,4 +237,26 @@ fn main() {
|
||||
break 'game_loop
|
||||
}
|
||||
}
|
||||
println!("GAME OVER");
|
||||
println!("You fell {:?}m before going SPLAT",current_level-1);
|
||||
println!(" -__");
|
||||
println!(" / \\");
|
||||
println!(" | -___");
|
||||
println!(" | / ________________________");
|
||||
println!(" | / | |");
|
||||
println!(" ‾ |‾ / _ | Where is the princess? |");
|
||||
println!(" / | \\ / | \\ |________________________|");
|
||||
println!(" / ‾‾‾‾‾‾‾ \\ / /");
|
||||
println!(" __ / / \\• •/ _|");
|
||||
println!(" / \\ _/‾|‾\\ / |");
|
||||
println!("_ / / \\ / / |");
|
||||
println!(" \\/ / /|___/");
|
||||
println!(" / \\ ");
|
||||
println!(" / \\ / \\");
|
||||
println!(" | \\ / \\");
|
||||
println!(" |\\____\\_/ \\");
|
||||
println!(" \\ / / \\ \\ /");
|
||||
println!(" \\ / \\ /");
|
||||
println!(" / / / /");
|
||||
println!(" _| \\ /_ |");
|
||||
}
|
1
prophecies/.gitignore
vendored
Normal file
1
prophecies/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
7
prophecies/Cargo.toml
Normal file
7
prophecies/Cargo.toml
Normal file
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "prophecies"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
rand = "0.8.5"
|
148
prophecies/prophecies
Normal file
148
prophecies/prophecies
Normal file
@ -0,0 +1,148 @@
|
||||
If Under fell, if Over leaped,
|
||||
If life was death, if death life reaped,
|
||||
Something rises from the gloom
|
||||
To make the Underland a tomb.
|
||||
Hear it scratching down below,
|
||||
Rat of long forgotten snow,
|
||||
Evil cloaked in coat of white,
|
||||
Will the warrior drain your light?
|
||||
What will turn the warrior weak?
|
||||
What do burning Gnawers seek?
|
||||
Just a barely speaking pup
|
||||
Who holds the land of Under up.
|
||||
Die the baby die his heart,
|
||||
Die his most essential part.
|
||||
Die the peace that rules the hour.
|
||||
Gnawers have their key to power.
|
||||
Warmblood now a bloodborne death
|
||||
Will rob your body of its breath,
|
||||
Mark your skin, and seal your fate.
|
||||
The Underland becomes a plate.
|
||||
Turn and turn and turn again.
|
||||
You see the what but not the when.
|
||||
Remedy and wrong entwine,
|
||||
And so they form a single vine.
|
||||
Bring the warrior from above
|
||||
If yet his heart is swayed by love.
|
||||
Bring the princess or despair,
|
||||
No crawlers care without her there.
|
||||
Turn and turn and turn again.
|
||||
You see the what but not the when.
|
||||
Remedy and wrong entwine,
|
||||
And so they form a single vine.
|
||||
Those whose blood runs red and hot
|
||||
Must join to seek the healing spot.
|
||||
In the cradle find the cure
|
||||
For that which makes the blood impure.
|
||||
Turn and turn and turn again.
|
||||
You see the what but not the when.
|
||||
Remedy and wrong entwine,
|
||||
And so they form a single vine.
|
||||
Gnawer, human, set aside
|
||||
The hatreds that reside inside.
|
||||
If the flames of war are fanned,
|
||||
All warmbloods lose the Underland.
|
||||
Turn and turn and turn again.
|
||||
You see the what but not the when.
|
||||
Remedy and wrong entwine,
|
||||
And so they form a single vine.
|
||||
Beware, Underlanders, time hangs by a thread.
|
||||
The hunters are hunted, white water runs red.
|
||||
The gnawers will strike to extinguish the rest.
|
||||
The hope of the hopeless resides in a quest.
|
||||
An Overland warrior, a son of the sun,
|
||||
May bring us back light, he may bring us back none.
|
||||
But gather your neighbors and follow his call
|
||||
Or rats will most surely devour us all.
|
||||
Two over, two under, of royal descent,
|
||||
Two flyers, two crawlers, two spinners assent.
|
||||
One gnawer beside and one lost up ahead.
|
||||
And eight will be left when we count up the dead.
|
||||
The last who will die must decide where he stands.
|
||||
The fate of the eight is contained in his hands.
|
||||
So bid him take care, bid him look where he leaps,
|
||||
As life may be death and death life again reaps.
|
||||
On soft feet, by none detected,
|
||||
Dealing death, by most rejected,
|
||||
Killed by claw, since resurrected,
|
||||
Marked by X, two lines connected.
|
||||
Finally, they intersected,
|
||||
Two lines met, one unexpected.
|
||||
Dancing in the firelight,
|
||||
See the queen that conquers night.
|
||||
Gold flows from her, hot and bright.
|
||||
Father, mother, sister, brother,
|
||||
Off they go. I do not know
|
||||
If we will see another.
|
||||
Catch the nibblers in a trap.
|
||||
Watch the nibblers spin and snap.
|
||||
Quiet while they take a nap.
|
||||
Father, mother, sister, brother,
|
||||
Off they go. I do not know
|
||||
If we will see another.
|
||||
Now the guests are at our door
|
||||
Greet them as we have before.
|
||||
Some will slice and some will pour.
|
||||
Father, mother, sister, brother,
|
||||
Off they go. I do not know
|
||||
If we will see another.
|
||||
The war has been declared,
|
||||
Your ally been ensnared.
|
||||
It is now or it is never.
|
||||
Break the code or die forever.
|
||||
Time is running out
|
||||
Running out
|
||||
Running out.
|
||||
To the warrior give my blade.
|
||||
By his hand your fate is made.
|
||||
But do not forget the ticking
|
||||
Or the clicking, clicking, clicking.
|
||||
While a rat's tongue may be flicking,
|
||||
With its feet it does the tricking.
|
||||
For the paw and not the jaw
|
||||
Makes the Code of Claw.
|
||||
Time is standing still
|
||||
Standing still
|
||||
Standing still.
|
||||
Since the princess is the key
|
||||
To unlock the treachery,
|
||||
She cannot avoid the matching
|
||||
Or the scratching, scratching, scratching.
|
||||
When a secret plot is hatching,
|
||||
In the naming is the catching.
|
||||
What she saw, it is the flaw
|
||||
Of the Code of Claw.
|
||||
Time is turning back
|
||||
Turning back
|
||||
Turning back.
|
||||
When the monster's blood is spilled,
|
||||
When the warrior has been killed,
|
||||
You must not ignore the rapping,
|
||||
Or the tapping, tapping, tapping.
|
||||
If the gnawers find you napping,
|
||||
You will rot while they are mapping
|
||||
Out the law of those who gnaw
|
||||
In the Code of Claw.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
28
prophecies/src/main.rs
Normal file
28
prophecies/src/main.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use rand::Rng;
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
// Read the file that contains every prophecy line in the series
|
||||
let file_contents: String = fs::read_to_string("prophecies")?;
|
||||
|
||||
// Determine the name of the prophecy by picking a random word in file
|
||||
let split_into_words = file_contents.split_whitespace().collect::<Vec<_>>();
|
||||
let name = split_into_words[rand::thread_rng().gen_range(0..split_into_words.len())];
|
||||
println!("THE PROPHECY OF {}:\n", name.to_uppercase());
|
||||
|
||||
// Randomly decide how long the prophecy will be, range of 4 to 30
|
||||
let number_of_lines = rand::thread_rng().gen_range(4..30);
|
||||
|
||||
// Split file into lines
|
||||
let split_string = file_contents.split("\n").collect::<Vec<_>>();
|
||||
let lines_in_string = split_string.len();
|
||||
|
||||
// Iterate for "number_of_lines" and each time pick a random line in the file
|
||||
for _i in 0..number_of_lines {
|
||||
let line_index = rand::thread_rng().gen_range(0..lines_in_string); // Pick random line
|
||||
println!("{}",split_string[line_index]); // Print the random line
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
1
snake-wip/.gitignore
vendored
Normal file
1
snake-wip/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
9
snake-wip/Cargo.toml
Normal file
9
snake-wip/Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "snake"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rand = "0.8.5"
|
72
snake-wip/src/main.rs
Normal file
72
snake-wip/src/main.rs
Normal file
@ -0,0 +1,72 @@
|
||||
use rand::Rng;
|
||||
use std::io::{stdin,stdout,Write};
|
||||
|
||||
fn write_map(snake: char, apple: char, x_snake: u16, y_snake: u16, x_apple: u16, y_apple: u16, width: u16, height: u16) {
|
||||
print!("{}[2J", 27 as char);
|
||||
for y in 0..height {
|
||||
for x in 0..width {
|
||||
if x == x_snake && y == y_snake {
|
||||
print!("{}",snake);
|
||||
}
|
||||
else if x == x_apple && y == y_apple {
|
||||
print!("{}", apple);
|
||||
}
|
||||
else {
|
||||
print!(".");
|
||||
}
|
||||
}
|
||||
println!();
|
||||
}
|
||||
println!("Snake: {},{}\nApple: {},{}",x_snake,y_snake,x_apple,y_apple)
|
||||
}
|
||||
|
||||
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 rng = rand::thread_rng();
|
||||
|
||||
let width: u16 = 130;
|
||||
let height: u16 = 30;
|
||||
|
||||
let mut x_snake: u16 = 0;
|
||||
let mut y_snake: u16 = 0;
|
||||
let mut x_apple: u16 = rand::thread_rng().gen_range(0..width);
|
||||
let mut y_apple: u16 = rand::thread_rng().gen_range(0..height);
|
||||
println!("X apple: {}, Y apple: {}",x_apple,y_apple);
|
||||
|
||||
let snake: char = 'S';
|
||||
let apple: char = 'A';
|
||||
|
||||
let mut alive: bool = true;
|
||||
|
||||
write_map(snake, apple, x_snake, y_snake, x_apple, y_apple, width, height);
|
||||
while alive {
|
||||
let direction: &str = &input();
|
||||
// Movement
|
||||
if direction == "w" {
|
||||
if y_snake == 0 { y_snake = height - 1 }
|
||||
else { y_snake-=1 }
|
||||
}
|
||||
if direction == "a" {
|
||||
if x_snake == 0 { x_snake = width - 1 }
|
||||
else { x_snake-=1 }
|
||||
}
|
||||
if direction == "s" { y_snake+=1 }
|
||||
if direction == "d" { x_snake+=1 }
|
||||
// Looping over edge
|
||||
if x_snake > width { x_snake = 0 }
|
||||
if x_snake < 0 { x_snake = width }
|
||||
write_map(snake, apple, x_snake, y_snake, x_apple, y_apple, width, height);
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user