Scripting

Páginas: 5 (1038 palabras) Publicado: 6 de noviembre de 2015
SISTEMAS OPERATIVOS

Realizado por:
Karen Barberán
Josué Burbano
Viviana Meza

SCRIPTS AVANZADOS
Proyecto Grupal








JUEGO DEL AHORCADO EN BASH
SCRIPT
Este juego está estructurado
por funciones.
Las variables de cada
función son globales.
Las funciones se pueden
llamar entre sí.
El script se complementa
con un archivo llamado
palabras de donde toma las
pistas y por supuesto laspalabras a adivinar.
No olvidar proporcionar
permisos de ejecución al
archivo ‘ahorcado’.

FUNCION MESSAGE

function message() {
case $mensaje in
game_banner) echo
tput rev
echo "$(tput setaf 4)EL JUEGO DEL AHORCADO EN BASH SCRIPT$(tput sgr0)"
echo
echo "$(tput setaf 7)$(tput bold)Contiene $(tput setaf 1)
$(( $long_palabra-$espacios ))$(tput setaf 7) \caracteres sin contar los espacios"
echo "$(tputsetaf 7)Puedes usar los comodines. Dispones de $(tput setaf 1)
$comodines$(tput setaf 7). \ Para usarlos pulsa $(tput setaf 1)+"
life=$(( vidas-intentos )); [[ $life -eq 1 ]] && vida="vida" || vida="vidas";
[[ $life -lt 0 ]] && life=0
echo "$(tput setaf 7)Dispones de $(tput setaf 1)$life $vida"
echo
echo "$(tput setaf 7)Pista: $(tput setaf 2)$definicion"
echo "$(tput setaf 7)La palabra es: $(tputsetaf 1)$word"

echo -n "$(tput setaf 7)Vidas: $(tput setaf 1)“
for (( i=1; i<=$(( vidas-intentos )); i++ )); do echo -n $'\342\231\245'; done; echo
echo -n "$(tput setaf 7)Comodines: $(tput setaf 1)“
for (( i=1; i<=$comodines; i++ )); do echo -n $'\342\230\245'; done; echo
echo "$(tput setaf 7)Caracteres restantes: $(tput setaf 1)$(( ($long_palabra-$espacios)-$aciertos ))“
echo -e "$(tput setaf7)Letras usadas: $(tput setaf 1)$(array3=($(echo ${array3[*]}|tr ' ' "\n"|sort));echo $
{array3[*]})"
echo "$(tput setaf 7)Puntuación: $(tput setaf 1)$score";;

game_over) echo "$(tput setaf 2)Fenomenal, eres un crack";;

game_read) read -n1 -p "$(tput setaf 7)Vida $(tput setaf 1)$intentos $(tput setaf 7)de $(tput setaf
1)$lifes$(tput setaf 7). \
Introduce una letra: $(tput setaf 1)" caracter
echo;; salir) echo
tput rev
echo "$(tput setaf 1)GameOver$(tput sgr0)"
echo "$(tput setaf 7)$(tput bold)Tu mejor puntuación es: $(tput setaf 1)$best_score"
echo "$(tput setaf 7)Tu puntuación acumulada es: $(tput setaf 1)$acumulado"
echo "$(tput setaf 7)La solución es: $(tput setaf 1)$palabra"
echo

echo "$(tput setaf 7)Que deseas hacer?"
read -n1 -p "$(tput setaf 7)Pulsa $(tput setaf 1)P $(tput setaf7)para ver $(tput setaf 2)\
Puntuaciones $(tput setaf 1)Q $(tput setaf 7)para $(tput setaf 2)Salir $(tput setaf 1)G $(tput setaf 7)\
para $(tput setaf 2)Volver a jugar$(tput setaf 7). \
Introduce una letra: $(tput setaf 1)" caracter
echo "$(tput setaf 7)";;

comodines_restantes) echo "$(tput setaf 4)Te dispones a usar un comodín. Suerte, sólo dispones de
$(tput setaf 1)$comodines"
echo "$(tputsetaf 2)Comodín = $(tput setaf 1)$caracter";;

comodines_finalizados) echo "$(tput setaf 4)Ups, has gastado todos los comodines";;

continuar) read -n1 -p "$(tput setaf 1)Pulsar cualquier tecla para continuar$(tput setaf
7)";;
acierto_mal) echo "$(tput setaf 4)Has fallado, ahora tienes un intento menos";;

acierto_bien) echo "$(tput setaf 2)Muy bien, ya casi lo tienes";;
acierto_repetido) echo"$(tput setaf 3)Upps, Esa letra ya la has introducido";;

esac
}

function init {
file="palabras.txt“
if [[ ! -f $file ]]; then clear; echo; echo "$(tput rev)$(tput setaf 1)ATENCIÓN: \
No existe el diccionario$(tput setaf 7)$(tput sgr0)"; echo; exit;fi

FUNCION INIT

max=$(cat $file | wc -l)
num=$(( $RANDOM%$max ))
frase=$(head -$num $file | tail -1)
aciertos=0
palabra=$(echo ${frase%%;*})palabra=$(echo ${palabra,,} | sed 's/á/a/g;s/é/e/g;s/í/i/g;s/ó/o/g;s/ú/u/g;s/-/ /g;s/Á/a/g')
definicion=$(echo ${frase#*;})
long_palabra=${#palabra}
comodines=$(( long_palabra/4 ))
[[ $comodines -ge 3 ]] && comodines=3
vidas=$(( long_palabra/3 ))

[[ $vidas -ge 5 ]] && vidas=5 || (( vidas++ ))
lifes=$(( vidas-1 ))
score=$(( (comodines*50)+(lifes*100) ))
[[ $long_palabra -lt 4 ]] && main;
unset array[*]...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Cross site scripting
  • Lenguajes de scripting en servidores web:
  • mIRC Scripting
  • Unity3D-Basic Scripting
  • Xss
  • Tutorial De Scripting
  • Lenguaje De Scripting Para Servidores Web
  • Scripting en Espa ol para mIRC

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS