Hey there, farmer-coders! Ready to combine the fun of Stardew Valley with the power of Python? Let's grow some code! 🌱💻
Python Valley is like Stardew Valley, but instead of using a controller, you're using a keyboard to write code! You'll learn how to:
- Create your own farmer (that's an object!)
- Plant and harvest crops (using functions!)
- Manage your backpack (that's like a dictionary!)
- Deal with weather (if statements are like seasons for your code!)
- Make sure you have Python installed on your computer. It's free!
- Download the
python_valley.py
file from this repo. - Open your favorite code editor (that's like your farming tools, but for code).
- Run the game by typing
python python_valley.py
in your terminal or command prompt.
Just like how Stardew Valley has different crops for different seasons, we want to add more variety to our game!
- Find the
Game
class in the code. - Look for the comment about adding a new crop.
- Try adding a strawberry crop! (Hint: it's like the other crops, but with different numbers)
In Stardew Valley, you can upgrade your backpack to carry more items. Let's upgrade our code backpack!
- Find the
Farmer
class. - Look at the
add_to_backpack
andshow_backpack
methods. - Can you add a method to remove items from the backpack?
- Bonus: Can you make it so you can't add more than 20 items total?
Weather affects your crops in Stardew Valley. Let's make it affect our Python crops too!
- Find the
Crop
class. - Look at the commented-out
grow
method that includes weather. - Uncomment it and make it work with the rest of the code.
- Bonus: Can you add a special "double growth" day, like the Speed-Gro fertilizer?
Every farmer needs seeds! Let's add Pierre's General Store to our game.
- Find the
Store
class at the bottom of the file. - Uncomment it and add it to the
Game
class. - Add a new option in the game loop to visit the store.
- Make sure the farmer can buy seeds and they go into the backpack!
Once you've made these changes, your Python Valley farm will be thriving! Here are some extra challenges:
- Can you add animal objects, like chickens or cows?
- What about adding a mining mini-game?
- Could you create different farms for each season?
Remember, in coding (and farming), every mistake is just a chance to grow! Don't be afraid to experiment and ask for help if you need it.
Happy farming and happy coding! 🚜💻🌾