Add files via upload

Multi Jeux style Roblox
-Création d'un menu pour ajouter des jeux 
- Jeu Puissance 4 

Possibilité de rajouter dans le script Menu.sh
This commit is contained in:
SiriusTuks 2024-02-05 16:31:22 +01:00 committed by GitHub
parent 3e9b4a2e81
commit fbf236b0e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 178 additions and 0 deletions

View File

@ -0,0 +1,5 @@
# config.sh
ROWS=6
COLS=7
PLAYER1_TOKEN="X"
PLAYER2_TOKEN="O"

View File

@ -0,0 +1,34 @@
#!/bin/bash
while true; do
clear
echo "Menu Principal"
echo "1. Puissance 4"
echo "2. Autre Jeu (à ajouter)"
echo "3. Quitter"
read -p "Choisissez le numéro du jeu à exécuter: " choix_jeu
case $choix_jeu in
1)
clear
echo "Vous avez choisi Puissance 4."
# Ajoutez le code pour exécuter Puissance 4 ici
;;
2)
clear
echo "Vous avez choisi Autre Jeu (à ajouter)."
# Ajoutez le code pour exécuter l'autre jeu ici
;;
3)
clear
echo "Au revoir!"
exit 0
;;
*)
echo "Choix invalide. Veuillez sélectionner un numéro valide."
sleep 2
;;
esac
done

View File

@ -0,0 +1,58 @@
#!/bin/bash
################################################################################
# Author: Tuuake
# Version: 1.0
# Cours de scripting M1 Master Cyberséc
################################################################################
source ./Config.sh
source ./fonctions.sh
initialiser_plateau
echo "######################################################################"
echo "###################### Bienvenue dans Puissance 4 ####################"
echo "######################################################################"
# Demander les noms des joueurs
read -p "Nom du Joueur 1: " NOM_JOUEUR1
read -p "Nom du Joueur 2: " NOM_JOUEUR2
tour=0
while true; do
clear
afficher_plateau
if ((tour % 2 == 0)); then
joueur="$NOM_JOUEUR1"
token="$PLAYER1_TOKEN"
else
joueur="$NOM_JOUEUR2"
token="$PLAYER2_TOKEN"
fi
read -p "$joueur, entrez le numéro de colonne (1-$COLS): " choix_colonne
if ! [[ $choix_colonne =~ ^[1-$COLS]$ ]]; then
echo "Veuillez entrer un numéro de colonne valide."
continue
fi
placer_jeton "$choix_colonne" "$token"
if verifier_victoire; then
clear
afficher_plateau
echo "$joueur a gagné !"
break
fi
((tour++))
done
# Afficher le plateau une dernière fois à la fin du jeu
clear
afficher_plateau

View File

@ -0,0 +1,81 @@
# fonctions.sh
source config.sh
initialiser_plateau() {
for ((i = 0; i < ROWS * COLS; i++)); do
board[i]=" "
done
}
afficher_plateau() {
for ((i = 0; i < ROWS; i++)); do
for ((j = 0; j < COLS; j++)); do
echo -n "${board[i * COLS + j]} "
done
echo
done
}
placer_jeton() {
local colonne=$1
local token=$2
for ((i = ROWS - 1; i >= 0; i--)); do
if [ "${board[i * COLS + colonne - 1]}" == " " ]; then
board[i * COLS + colonne - 1]=$token
break
fi
done
}
verifier_victoire() {
# Vérification des alignements horizontaux
for ((i = 0; i < ROWS; i++)); do
for ((j = 0; j < COLS - 3; j++)); do
if [ "${board[i * COLS + j]}" != " " ] && \
[ "${board[i * COLS + j]}" == "${board[i * COLS + j + 1]}" ] && \
[ "${board[i * COLS + j]}" == "${board[i * COLS + j + 2]}" ] && \
[ "${board[i * COLS + j]}" == "${board[i * COLS + j + 3]}" ]; then
return 0 # Victoire
fi
done
done
# Vérification des alignements verticaux
for ((j = 0; j < COLS; j++)); do
for ((i = 0; i < ROWS - 3; i++)); do
if [ "${board[i * COLS + j]}" != " " ] && \
[ "${board[i * COLS + j]}" == "${board[(i + 1) * COLS + j]}" ] && \
[ "${board[i * COLS + j]}" == "${board[(i + 2) * COLS + j]}" ] && \
[ "${board[i * COLS + j]}" == "${board[(i + 3) * COLS + j]}" ]; then
return 0 # Victoire
fi
enddone
done
# Vérification des alignements diagonaux (de gauche à droite)
for ((i = 0; i < ROWS - 3; i++)); do
for ((j = 0; j < COLS - 3; j++)); do
if [ "${board[i * COLS + j]}" != " " ] && \
[ "${board[i * COLS + j]}" == "${board[(i + 1) * COLS + j + 1]}" ] && \
[ "${board[i * COLS + j]}" == "${board[(i + 2) * COLS + j + 2]}" ] && \
[ "${board[i * COLS + j]}" == "${board[(i + 3) * COLS + j + 3]}" ]; then
return 0 # Victoire
fi
done
done
# Vérification des alignements diagonaux (de droite à gauche)
for ((i = 0; i < ROWS - 3; i++)); do
for ((j = 3; j < COLS; j++)); do
if [ "${board[i * COLS + j]}" != " " ] && \
[ "${board[i * COLS + j]}" == "${board[(i + 1) * COLS + j - 1]}" ] && \
[ "${board[i * COLS + j]}" == "${board[(i + 2) * COLS + j - 2]}" ] && \
[ "${board[i * COLS + j]}" == "${board[(i + 3) * COLS + j - 3]}" ]; then
return 0 # Victoire
fi
done
done
return 1 # Pas de victoire
}