Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.67 KB | None | 0 0
  1. #!/bin/bash
  2. # Copyright (c) 2011 Cubox ( Andy Pilate ) <cubox@e-noob.eu>
  3. # All rights reserved.
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions are met:
  7. #
  8. #     * Redistributions of source code must retain the above copyright notice,
  9. #      this list of conditions, and the following disclaimer.
  10. #     * Redistributions in binary form must reproduce the above copyright notice,
  11. #      this list of conditions, and the following disclaimer in the
  12. #      documentation and/or other materials provided with the distribution.
  13. #     * Neither the name of the author of this software nor the name of
  14. #      contributors to this software may be used to endorse or promote products
  15. #      derived from this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  21. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  23. # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24. # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  25. # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. # Petit jeu de "C'est plus ou c'est moins"
  28. # Pour tout bug >> cubox@e-noob.eu
  29. # Versions :
  30. # V 1.0 : Création du script, il marche.
  31.  
  32. count="1"
  33.         echo "Bienvenue sur ce programme de \"C'est plus ou c'est moins\"."
  34. read -p 'Entrez ici le nombre maximal à deviner. ' max_tmp
  35.         echo "Vous venez d'entrer $max_tmp comme nombre maximal."
  36. if [[ $max_tmp = *[^0-9]* ]] || [ -z $max_tmp ] || (($max_tmp < 5))
  37. then
  38. echo "Maisheu tu es pas drole TRICHEUR ! Un NOMBRE et pas trop petit !"
  39. exit
  40. fi
  41. let "max = max_tmp + 1"
  42.         echo "Géneration du nombre secret à deviner"
  43. rand=`rand -M $max`
  44. while true
  45. do
  46.         while true
  47.         do      read -p 'Entrez un nombre ' nombre
  48.         if [[ $nombre != *[^0-9]* ]] && [ -n $nombre ]
  49.         then break
  50.         else
  51.         echo "J'ai dit UN NOMBRE"
  52.         fi
  53. done
  54. if (($nombre == $rand))
  55. then echo "Bravo tu as gagné"
  56. break
  57. fi
  58. if (($nombre < $rand))
  59. then let "count = count + 1"
  60. echo "C'est plus"
  61. else let "count = count + 1"
  62. echo "C'est moins"
  63. fi
  64. done
  65. echo "Tu as fait $count tentatives"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement