#!/bin/bash # Ping Pong Game Script # Define game variables PLAYER1="Player 1" PLAYER2="Player 2" # Initialize scores score1=0 score2=0 # Function to display score display_score() { echo "Score: $score1 - $score2" } # Function to increment score increment_score() { if [ "$1" == "1" ]; then ((score1++)) elif [ "$1" == "2" ]; then ((score2++)) fi } # Game loop while true; do # Display current score display_score # Ask player 1 to ping read -p "Enter 'P' to ping Player 2, or 'Q' to quit: " input # Process input case $input in p|P) increment_score 2 ;; q|Q) break ;; esac done # End of game echo "Game Over! Final Scores:" display_score