Greetings, aspiring script mage! In this side quest, you will forge a terminal-based game using the arcane arts of Bash scripting. Starting with bashrun as your foundation, you will enhance and expand it into a fully interactive adventure β complete with inventory, combat, and save systems.
cd, ls, cat, echo)Starting with bashrun as a base and building upon it is a great way to create an advanced terminal-based game. bashrun is typically built using shell scripts, which can be a bit limiting but also provides a good foundation for learning and expanding.
Hereβs a step-by-step guide to start with bashrun and build upon it:
git clone https://github.com/commandlineadventure/bashrun.git bashrun
cd bashrun
Note: If the above repository is unavailable, you can create your own bashrun project from scratch using the code examples below, or search for βbash text adventureβ on GitHub for similar projects.
Example of adding a new level (level2.sh):
#!/bin/bash
echo "Welcome to Level 2!"
echo "You need to find the hidden key to unlock the treasure."
# Player actions and logic here
Improve Navigation and Interaction: Add more commands for interaction, such as examining objects or using items.
Example of an interaction command:
function examine {
case $1 in
"key")
echo "It's a shiny golden key. It might unlock something."
;;
"door")
echo "It's a sturdy wooden door. It seems to be locked."
;;
*)
echo "You can't examine that."
;;
esac
}
Add an Inventory System: Implement a simple inventory system to manage items collected by the player.
Example inventory system:
inventory=()
function add_to_inventory {
inventory+=("$1")
echo "$1 added to your inventory."
}
function show_inventory {
echo "Your inventory: ${inventory[@]}"
}
Implement Save/Load Functionality: Allow players to save their progress and load it later.
Example save/load system:
function save_game {
echo "${inventory[@]}" > savefile.txt
echo "Game saved."
}
function load_game {
if [ -f savefile.txt ]; then
inventory=($(cat savefile.txt))
echo "Game loaded."
else
echo "No saved game found."
fi
}
Add a Combat System: Create a simple combat system where players can encounter enemies and engage in battles.
Example combat system:
function combat {
local enemy_health=10
local player_health=20
echo "You encounter an enemy!"
while [ $enemy_health -gt 0 ] && [ $player_health -gt 0 ]; do
echo "Choose an action: [attack/run]"
read action
case $action in
"attack")
enemy_health=$((enemy_health - 2))
player_health=$((player_health - 1))
echo "You attack the enemy. Enemy health: $enemy_health"
echo "The enemy attacks you. Your health: $player_health"
;;
"run")
echo "You run away!"
return
;;
*)
echo "Invalid action."
;;
esac
done
if [ $player_health -le 0 ]; then
echo "You have been defeated."
else
echo "You defeated the enemy!"
fi
}
Enhance User Interface: Improve the display and user interface to make the game more visually appealing. Use ASCII art for maps and objects.
Add More Interactions and Puzzles: Introduce complex puzzles and more interactive elements to keep the game engaging.
Create a Comprehensive Tutorial: Provide a detailed tutorial at the beginning to help new players understand the game mechanics.
Test and Iterate: Continuously test your game and gather feedback. Use this feedback to make iterative improvements.
bashrun/
βββ maps/
β βββ level1.txt
β βββ level2.txt
βββ scripts/
β βββ level1.sh
β βββ level2.sh
β βββ common.sh # Contains common functions like inventory and combat
βββ resources/
β βββ ascii_art/
β βββ items.txt
βββ savefile.txt
βββ README.md
common.sh#!/bin/bash
# Inventory system
inventory=()
function add_to_inventory {
inventory+=("$1")
echo "$1 added to your inventory."
}
function show_inventory {
echo "Your inventory: ${inventory[@]}"
}
# Combat system
function combat {
local enemy_health=10
local player_health=20
echo "You encounter an enemy!"
while [ $enemy_health -gt 0 ] && [ $player_health -gt 0 ]; do
echo "Choose an action: [attack/run]"
read action
case $action in
"attack")
enemy_health=$((enemy_health - 2))
player_health=$((player_health - 1))
echo "You attack the enemy. Enemy health: $enemy_health"
echo "The enemy attacks you. Your health: $player_health"
;;
"run")
echo "You run away!"
return
;;
*)
echo "Invalid action."
;;
esac
done
if [ $player_health -le 0 ]; then
echo "You have been defeated."
else
echo "You defeated the enemy!"
fi
}
# Save/Load system
function save_game {
echo "${inventory[@]}" > savefile.txt
echo "Game saved."
}
function load_game {
if [ -f savefile.txt ]; then
inventory=($(cat savefile.txt))
echo "Game loaded."
else
echo "No saved game found."
fi
}
This guide should help you get started with building upon bashrun to create a more advanced and engaging terminal game. Enjoy the process and happy coding!