Flexbox Farmer is a web-based game that allows players to buy seeds, grow crops, and sell their harvest. The player's farm, inventory, and bank are cached into local storage, so the fun doesn't have to end upon refresh.
The aim for this assignment was to create a web page with JavaScript that allow user interaction. To meet this goal, I decided to work on a Farming simulator game.
To make sure the fun lasts even after the window or browser is closed, I set up the plots, bank, and inventory in localStorage.
// Plots cache
let plots = localStorage.getItem("plots") ? JSON.parse(localStorage.getItem("plots")) : [{
'item': 'strawberry',
'label': 'Strawberry',
'timer': {
'minutes': 0,
'seconds': 45
}
}, '', '', '', '', '', '', '', '', '', '', ''];
// Bank cache
let bank = localStorage.getItem("bank") ? parseFloat(localStorage.getItem("bank")) : 5.00;
// Inventory cache
let yourInventory = localStorage.getItem("inventory") ? JSON.parse(localStorage.getItem("inventory")) : { 'carrotSeeds': 3 };
Flexbox Farmer is currently hosted on replit.