DEV Community

mnivoliez
mnivoliez

Posted on Edited on

Tell me a story I could code

Originally post on my blog

Hello everyone! Today one colleague and friend of mine, Gaetan, would like to propose you a simple (or not) concept!

It's a code of which you are the story teller!

"Whaaaaat?"

whaaaaat

Let me explain! We propose you to tell a story (a little one), sentence by sentence. Each time a sentences is selected, we will try to express the story into code.

An exemple is worth 1000 speech so here is the start of our story:

"Once upon a time, a young knight name Bob found a penny!"

#[derive(Debug)]
struct Story {
    pub time: &'static str,
    pub main_character: Character,
}

#[derive(Debug)]
struct Character {
    pub name: &'static str,
    pub money: i32,
}

fn found_a_strange_penny(character: &mut Character) {
    character.money += 1;
    println!("Oh a penny! \" said {}.\"", character.name);
}

fn main() {
    let mut story = Story {
        time: "Once upon a time",
        main_character: Character {
            name: "Bob",
            money: 0,
        },
    };

    found_a_strange_penny(&mut story.main_character);
}
Enter fullscreen mode Exit fullscreen mode

All the code will live in this repository.

So, it's up to you, reader, to continue the story.
Post a comment with one sentence or two and we will try to code that.
We will choose the comment that appeal us the most!

Start :p

--
Gaetan and Mathieu

Top comments (6)

Collapse
 
juz501 profile image
Julian Chan •

Bob ran back to his knight friend, Joe, to discuss what to do with Bob’s newfound fortune.

Collapse
 
codemouse92 profile image
Jason C. McDonald • • Edited

(Following from Julian Chen's comment)...

"You should invest the penny in the Sheriff of Nottingham's Bank," said Joe.

Collapse
 
faizanhussainrabbani profile image
Faizan Hussain Rabbani •

(Following from Jason's comment)

Bob replied "But I already have invested money in the bank, I want to buy a horse!".

Collapse
 
vasilvestre profile image
Valentin Silvestre •

Following from Faizan Rabbani's comment)

AND THEN A DRAGON IS FLYING TOWARD BOB AND BOB RUN TIL STAMINA DOWN

(sorry, I'm a bad game master..)

Collapse
 
sau_ban profile image
Sauban •

(Following from Valentin Silvestre)...

"The shiny thing belongs to me" said the dragon, when it caught up to Bob.

Collapse
 
ztickm profile image
Salim MAHBOUBI •

(Following from Sauban's comment)
Out of breath, Bob replied "Never! Founders keepers, you Reptilebug!"