Batch script crashes due to ASCII. What could I do?

234 Views Asked by At

I've "programmed" Rock, Paper, Scissors in a batch script. It used to work fine until I incorporated ASCII art. The script runs smoothly until I input a number between 1 and 3, after which the script abruptly terminates for some reason. Could someone please help me identify the problem? Batchskript:

@echo off
setlocal
chcp 65001 >nul

set Sieg=0
set Niederlage=0
set Unentschieden=0

:menu
cls
color f
echo Willkommen im Spiel!
echo.
echo 1. Schere
echo 2. Stein
echo 3. Papier
echo.
echo.
echo Ergebnisse:
echo Siege: %Sieg%
echo Niederlagen: %Niederlage%
echo Unentschieden: %Unentschieden%

set /p Userwahl="Bitte wählen Sie eine Zahl (1/2/3): "

set /a Scriptwahl=%random% %% 3 + 1

cls
if "%Userwahl%"=="1" set Userwahl=Schere
if "%Userwahl%"=="2" set Userwahl=Stein  
if "%Userwahl%"=="3" set Userwahl=Papier

if "%Scriptwahl%"=="1" set Scriptwahl=Schere
if "%Scriptwahl%"=="2" set Scriptwahl=Stein
if "%Scriptwahl%"=="3" set Scriptwahl=Papier

if "%Userwahl%"=="%Scriptwahl%" (
    if "%Userwahl%"=="Schere" (
        echo      _______                                   _______
        echo ---'   ____)____      #    #  ####       ____(____   '---
        echo           ______)     #    # #          (______
        echo        __________)    #    #  ####      (__________
        echo       (____)          #    #      #           (____)
        echo ---.__(___)            #  #  #    #           (___)__.---
        echo                         ##    ####
        timeout /t 3 > nul                   
    ) else if "%Userwahl%"=="Stein" (
        echo     _______                           _______
        echo ---'   ____)     #    #  ####        (____   '---
        echo       (_____)    #    # #           (_____)
        echo       (_____)    #    #  ####       (_____)
        echo       (____)     #    #      #       (____)
        echo ---.__(___)       #  #  #    #        (___)__.---
        echo                    ##    ####         
        timeout /t 3 > nul
    ) else if "%Userwahl%"=="Papier" (
        echo      _______                                  _______
        echo ---'    ____)____     #    #  ####       ____(____    '---
        echo            ______)    #    # #          (______
        echo           _______)    #    #  ####      (_______
        echo          _______)     #    #      #      (_______
        echo ---.__________)        #  #  #    #       (__________.---
        echo                         ##    ####
        timeout /t 3 > nul                       
    color 6
    echo #     #                                          
    echo #     # #    # ###### #    # #####  ####   ####  #    # # ###### #####  ###### #    # 
    echo #     # ##   # #      ##   #   #   #      #    # #    # # #      #    # #      ##   # 
    echo #     # # #  # #####  # #  #   #    ####  #      ###### # #####  #    # #####  # #  # 
    echo #     # #  # # #      #  # #   #        # #      #    # # #      #    # #      #  # # 
    echo #     # #   ## #      #   ##   #   #    # #    # #    # # #      #    # #      #   ##  
    echo  #####  #    # ###### #    #   #    ####   ####  #    # # ###### #####  ###### #    # 
    timeout /t 3 > nul
    set /a Unentschieden+=1
) else if "%Userwahl%"=="Schere" (
    if "%Scriptwahl%"=="Papier" (
        echo     _______                                   _______
        echo ---'   ____)____      #    #  ####       ____(____    '---
        echo           ______)     #    # #          (______
        echo        __________)    #    #  ####      (_______
        echo       (____)          #    #      #      (_______
        echo ---.__(___)            #  #  #    #       (__________.---
        echo                         ##    ####   
        timeout /t 3 > nul              
        color a
        echo  #####                  
        echo #     # # ######  ####  
        echo #       # #      #    # 
        echo  #####  # #####  #      
        echo       # # #      #  ### 
        echo #     # # #      #    # 
        echo  #####  # ######  #### 
        timeout /t 3 > nul
        set /a Sieg+=1
    ) else (
        echo     _______                               _______
        echo ---'   ____)____      #    #  ####       (____   '---
        echo           ______)     #    # #          (_____)
        echo        __________)    #    #  ####      (_____)
        echo       (____)          #    #      #      (____)
        echo ---.__(___)            #  #  #    #       (___)__.---
        echo                         ##    ####         
        timeout /t 3 > nul
        color 4
        echo #     #                                      
        echo ##    # # ###### #####  ###### #####  #        ##    ####  ###### 
        echo # #   # # #      #    # #      #    # #       #  #  #    # #      
        echo #  #  # # #####  #    # #####  #    # #      #    # #      #####  
        echo #   # # # #      #    # #      #####  #      ###### #  ### #      
        echo #    ## # #      #    # #      #   #  #      #    # #    # #      
        echo #     # # ###### #####  ###### #    # ###### #    #  ####  ######      
        timeout /t 3 > nul
        set /a Niederlage+=1
    )
) else if "%Userwahl%"=="Stein" (
    if "%Scriptwahl%"=="Schere" (
        echo     _______                               _______
        echo ---'   ____)     #    #  ####        ____(____   '---
        echo       (_____)    #    # #           (______
        echo       (_____)    #    #  ####      (__________
        echo       (____)     #    #      #           (____)
        echo ---.__(___)       #  #  #    #           (___)__.---
        echo                    ##    ####           
        timeout /t 3 > nul
        color a
        echo  #####                  
        echo #     # # ######  ####  
        echo #       # #      #    # 
        echo  #####  # #####  #      
        echo       # # #      #  ### 
        echo #     # # #      #    # 
        echo  #####  # ######  #### 
        timeout /t 3 > nul
        set /a Sieg+=1
    ) else (
        echo     _______                               _______
        echo ---'   ____)     #    #  ####        ____(____    '---
        echo       (_____)    #    # #           (______
        echo       (_____)    #    #  ####      (_______
        echo       (____)     #    #      #      (_______
        echo ---.__(___)       #  #  #    #       (__________.---
        echo                    ##    ####        
        timeout /t 3 > nul
        color 4
        echo #     #                                      
        echo ##    # # ###### #####  ###### #####  #        ##    ####  ###### 
        echo # #   # # #      #    # #      #    # #       #  #  #    # #      
        echo #  #  # # #####  #    # #####  #    # #      #    # #      #####  
        echo #   # # # #      #    # #      #####  #      ###### #  ### #      
        echo #    ## # #      #    # #      #   #  #      #    # #    # #      
        echo #     # # ###### #####  ###### #    # ###### #    #  ####  ###### 
        timeout /t 3 > nul 
        set /a Niederlage+=1
    )
) else if "%Userwahl%"=="Papier" (
    if "%Scriptwahl%"=="Stein" (
        echo      _______                              _______
        echo ---'    ____)____     #    #  ####       (____   '---
        echo            ______)    #    # #          (_____)
        echo           _______)    #    #  ####      (_____)
        echo          _______)     #    #      #      (____)
        echo ---.__________)        #  #  #    #       (___)__.---
        echo                         ##    ####    
        timeout /t 3 > nul
        color a
        echo  #####                  
        echo #     # # ######  ####  
        echo #       # #      #    # 
        echo  #####  # #####  #      
        echo       # # #      #  ### 
        echo #     # # #      #    # 
        echo  #####  # ######  #### 
        timeout /t 3 > nul
        set /a Sieg+=1
    ) else (
        echo      _______                                   _______
        echo ---'    ____)____     #    #  ####         ___(____   '---
        echo            ______)    #    # #           (______
        echo           _______)    #    #  ####      (__________
        echo          _______)     #    #      #           (____)
        echo ---.__________)        #  #  #    #           (___)__.---
        echo                         ##    ####    
        timeout /t 3 > nul
        color 4
        echo #     #                                      
        echo ##    # # ###### #####  ###### #####  #        ##    ####  ###### 
        echo # #   # # #      #    # #      #    # #       #  #  #    # #      
        echo #  #  # # #####  #    # #####  #    # #      #    # #      #####  
        echo #   # # # #      #    # #      #####  #      ###### #  ### #      
        echo #    ## # #      #    # #      #   #  #      #    # #    # #      
        echo #     # # ###### #####  ###### #    # ###### #    #  ####  ###### 
        timeout /t 3 > nul
        set /a Niederlage+=1
    )
)

goto menu

I've searched a bit, but no one seemed to have an issue with ASCII art similar to mine. All the other cases I found were related to problems with "|", but I'm not using this symbol.

5

There are 5 best solutions below

0
jeb On

Move your pictures into functions, then you can reuse them and closing parenthesis are harmless.

...
if "%Userwahl%"=="%Scriptwahl%" (
    if "%Userwahl%"=="Schere" (
       call :show_schere_schere
       timeout /t 3 > nul  
   ) else if "%Userwahl%"=="Stein" (
        call :show_stein_stein
        timeout /t 3 > nul    
        ...

:show_schere_schere
echo      _______                                   _______
echo ---'   ____)____      #    #  ####       ____(____   '---
echo           ______)     #    # #          (______
echo        __________)    #    #  ####      (__________
echo       (____)          #    #      #           (____)
echo ---.__(___)            #  #  #    #           (___)__.---
echo                         ##    ####
exit /b

:show_stein_stein
echo     _______                           _______
echo ---'   ____)     #    #  ####        (____   '---
echo       (_____)    #    # #           (_____)
echo       (_____)    #    #  ####       (_____)
echo       (____)     #    #      #       (____)
echo ---.__(___)       #  #  #    #        (___)__.---
echo                    ##    ####         
exit /b
7
Why Not On

After applying all the tips, the script now looks like this, and it still doesn't work for me:

@echo off
setlocal
chcp 65001 >nul

set Sieg=0
set Niederlage=0
set Unentschieden=0

:menu
cls
color f
echo Willkommen im Spiel!
echo.
echo 1. Schere
echo 2. Stein
echo 3. Papier
echo.
echo.
echo Ergebnisse:
echo Siege: %Sieg%
echo Niederlagen: %Niederlage%
echo Unentschieden: %Unentschieden%

choice /c 123 /n /m "Bitte wählen Sie eine Zahl (1/2/3): "
set Userwahl=%errorlevel%

set /a Scriptwahl=%random% %% 3 + 1

cls
if "%Userwahl%"=="1" set Userwahl=Schere
if "%Userwahl%"=="2" set Userwahl=Stein  
if "%Userwahl%"=="3" set Userwahl=Papier

if "%Scriptwahl%"=="1" set Scriptwahl=Schere
if "%Scriptwahl%"=="2" set Scriptwahl=Stein
if "%Scriptwahl%"=="3" set Scriptwahl=Papier

if "%Userwahl%"=="%Scriptwahl%" (
    if "%Userwahl%"=="Schere" (
        call :show_schere_schere
        timeout /t 3 > nul                   
    ) else if "%Userwahl%"=="Stein" (
        call :show_stein_stein
        timeout /t 3 > nul
    ) else if "%Userwahl%"=="Papier" (
        call :show_papier_papier
        timeout /t 3 > nul                       
        call :unentschieden
        timeout /t 3 > nul
        set /a Unentschieden+=1
) else if "%Userwahl%"=="Schere" (
    if "%Scriptwahl%"=="Papier" (
        call :show_schere_papier
        timeout /t 3 > nul              
        call :sieg
        timeout /t 3 > nul
        set /a Sieg+=1
    ) else (
        call :show_schere_stein
        timeout /t 3 > nul
        call :niederlage   
        timeout /t 3 > nul
        set /a Niederlage+=1
    )
) else if "%Userwahl%"=="Stein" (
    if "%Scriptwahl%"=="Schere" (
        call :show_stein_schere
        timeout /t 3 > nul
        call :sieg
        timeout /t 3 > nul
        set /a Sieg+=1
    ) else (
        call :show_stein_papier      
        timeout /t 3 > nul
        call :niederlage
        timeout /t 3 > nul 
        set /a Niederlage+=1
    )
) else if "%Userwahl%"=="Papier" (
    if "%Scriptwahl%"=="Stein" (
        call :show_papier_stein
        timeout /t 3 > nul
        call :sieg 
        timeout /t 3 > nul
        set /a Sieg+=1
    ) else (
        call :show_papier_schere
        timeout /t 3 > nul
        call :niederlage
        timeout /t 3 > nul
        set /a Niederlage+=1
    )
)

goto menu

:show_schere_schere
echo     _______                                    _______
echo ---'   ____^)____      #    #  ####        ____(^____   '---
echo           ______^)     #    # #           (^______
echo        __________^)    #    #  ####      (^__________
echo       (^____^)          #    #      #           (^____^)
echo ---.__(^___^)            #  #  #    #           (^___^)__.---
echo                         ##    ####                            
exit /b

:show_stein_stein
echo     _______                           _______
echo ---'   ____^)     #    #  ####        (^____   '---
echo       (^_____^)    #    # #           (^_____^)
echo       (^_____^)    #    #  ####       (^_____^)
echo       (^____^)     #    #      #       (^____^)
echo ---.__(^___^)       #  #  #    #        (^___^)__.---
echo                    ##    ####     
exit /b

:show_papier_papier
echo      _______                                  _______
echo ---'    ____^)____     #    #  ####       ____(^____    '---
echo            ______^)    #    # #          (^______
echo           _______^)    #    #  ####      (^_______
echo          _______^)     #    #      #      (^_______
echo ---.__________^)        #  #  #    #       (^__________.---
echo                         ##    ####
exit /b

:show_schere_papier
echo     _______                                   _______
echo ---'   ____^)____      #    #  ####       ____(^____    '---
echo           ______^)     #    # #          (^______
echo        __________^)    #    #  ####      (^_______
echo       (^____^)          #    #      #      (^_______
echo ---.__(^___^)            #  #  #    #       (^__________.---
echo                         ##    ####   
exit /b

:show_schere_stein
echo     _______                               _______
echo ---'   ____^)____      #    #  ####       (^____   '---
echo           ______^)     #    # #          (^_____^)
echo        __________^)    #    #  ####      (^_____^)
echo       (^____^)          #    #      #      (^____^)
echo ---.__(^___^)            #  #  #    #       (^___^)__.---
echo                         ##    ####   
exit /b

:show_stein_schere
echo     _______                               _______
echo ---'   ____^)     #    #  ####        ____(^____   '---
echo       (^_____^)    #    # #           (^______
echo       (^_____^)    #    #  ####      (^__________
echo       (^____^)     #    #      #           (^____^)
echo ---.__(^___^)       #  #  #    #           (^___^)__.---
echo                    ##    ####           
exit /b

:show_stein_papier
echo     _______                               _______
echo ---'   ____^)     #    #  ####        ____(^____    '---
echo       (_____^)    #    # #           (^______
echo       (_____^)    #    #  ####      (^_______
echo       (____^)     #    #      #      (^_______
echo ---.__(___^)       #  #  #    #       (^__________.---
echo                    ##    ####                  
exit /b

:show_papier_stein
echo      _______                              _______
echo ---'    ____^)____     #    #  ####       (^____   '---
echo            ______^)    #    # #          (^_____^)
echo           _______^)    #    #  ####      (^_____^)
echo          _______^)     #    #      #      (^____^)
echo ---.__________^)        #  #  #    #       (^___^)__.---
echo                         ##    ####    
exit /b

:show_papier_schere
echo      _______                                   _______
echo ---'    ____^)____     #    #  ####         ___(^____   '---
echo            ______^)    #    # #           (^______
echo           _______^)    #    #  ####      (^__________
echo          _______^)     #    #      #           (^____^)
echo ---.__________^)        #  #  #    #           (^___^)__.---
echo                         ##    ####
exit /b

:unentschieden
cls
color 6
echo #     #                                          
echo #     # #    # ###### #    # #####  ####   ####  #    # # ###### #####  ###### #    # 
echo #     # ##   # #      ##   #   #   #      #    # #    # # #      #    # #      ##   # 
echo #     # # #  # #####  # #  #   #    ####  #      ###### # #####  #    # #####  # #  # 
echo #     # #  # # #      #  # #   #        # #      #    # # #      #    # #      #  # # 
echo #     # #   ## #      #   ##   #   #    # #    # #    # # #      #    # #      #   ##  
echo  #####  #    # ###### #    #   #    ####   ####  #    # # ###### #####  ###### #    # 
exit /b

:sieg
cls
color a
echo  #####                  
echo #     # # ######  ####  
echo #       # #      #    # 
echo  #####  # #####  #      
echo       # # #      #  ### 
echo #     # # #      #    # 
echo  #####  # ######  #### 

:niederlage
cls
color 4
echo #     #                                      
echo ##    # # ###### #####  ###### #####  #        ##    ####  ###### 
echo # #   # # #      #    # #      #    # #       #  #  #    # #      
echo #  #  # # #####  #    # #####  #    # #      #    # #      #####  
echo #   # # # #      #    # #      #####  #      ###### #  ### #      
echo #    ## # #      #    # #      #   #  #      #    # #    # #      
echo #     # # ###### #####  ###### #    # ###### #    #  ####  ######     
3
Compo On

As you had a little too much code to help you to fix via comment, here is a quick rewrite of what you submitted as an answer, complete with my commented fix, but changing your script structure as little as possible.

@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
%SystemRoot%\System32\chcp.com 65001 >NUL

Set /A Sieg=Niederlage=Unentschieden=0

:menu
ClS
Color 0F
Echo Willkommen im Spiel!
Echo(
Echo 1. Schere
Echo 2. Stein
Echo 3. Papier
Echo(
Echo Ergebnisse:
Echo Siege: %Sieg%
Echo Niederlagen: %Niederlage%
Echo Unentschieden: %Unentschieden%
Echo(
%SystemRoot%\System32\choice.exe /C 123 /M "Bitte wählen Sie eine Zahl"
Set "Userwahl=%ErrorLevel%"

Set /A "Scriptwahl=(%RANDOM% %% 3) + 1"

ClS
If %Userwahl% Equ 1 (
    Set "Userwahl=Schere"
) Else (
    If %Userwahl% Equ 2 (
        Set "Userwahl=Stein"
    ) Else Set "Userwahl=Papier"
)

If %Scriptwahl% Equ 1 (
    Set "Scriptwahl=Schere"
) Else (
    If %Scriptwahl% Equ 2 (
        Set "Scriptwahl=Stein"
    ) Else Set "Scriptwahl=Papier"
)

If %Userwahl% Equ %Scriptwahl% (
    If "%Userwahl%" == "Schere" (
        Call :show_schere_schere
        %SystemRoot%\System32\timeout.exe /T 3 /NoBreak 1>NUL
    ) Else (
        If "%Userwahl%" == "Stein" (
            Call :show_stein_stein
            %SystemRoot%\System32\timeout.exe /T 3 /NoBreak 1>NUL
        ) Else (
            Call :show_papier_papier
            %SystemRoot%\System32\timeout.exe /T 3 /NoBreak 1>NUL
        )
    )
    Call :unentschieden
    %SystemRoot%\System32\timeout.exe /T 3 /NoBreak 1>NUL
    Set /A Unentschieden += 1
) Else (
    If "%Userwahl%" == "Schere" (
        If "%Scriptwahl%" == "Papier" (
            Call :show_schere_papier
            %SystemRoot%\System32\timeout.exe /T 3 /NoBreak 1>NUL
            Call :sieg
            %SystemRoot%\System32\timeout.exe /T 3 /NoBreak 1>NUL
            Set /A Sieg += 1
        ) Else (
            Call :show_schere_stein
            %SystemRoot%\System32\timeout.exe /T 3 /NoBreak 1>NUL
            Call :niederlage
            %SystemRoot%\System32\timeout.exe /T 3 /NoBreak 1>NUL
            Set /A Niederlage += 1
        )
    ) Else (
        If "%Userwahl%" == "Stein" (
            If "%Scriptwahl%" == "Schere" (
                Call :show_stein_schere
                %SystemRoot%\System32\timeout.exe /T 3 /NoBreak 1>NUL
                Call :sieg
                %SystemRoot%\System32\timeout.exe /T 3 /NoBreak 1>NUL
                Set /A Sieg += 1
            ) Else (
                Call :show_stein_papier
                %SystemRoot%\System32\timeout.exe /T 3 /NoBreak 1>NUL
                Call :niederlage
                %SystemRoot%\System32\timeout.exe /T 3 /NoBreak 1>NUL
                Set /A Niederlage += 1
            )
        ) Else (
            If "%Scriptwahl%" == "Stein" (
                Call :show_papier_stein
                %SystemRoot%\System32\timeout.exe /T 3 /NoBreak 1>NUL
                Call :sieg
                %SystemRoot%\System32\timeout.exe /T 3 /NoBreak 1>NUL
                Set /A Sieg += 1
            ) Else (
                Call :show_papier_schere
                %SystemRoot%\System32\timeout.exe /T 3 /NoBreak 1>NUL
                Call :niederlage
                %SystemRoot%\System32\timeout.exe /T 3 /NoBreak 1>NUL
                Set /A Niederlage += 1
            )
        )
    )
)

GoTo menu

:show_schere_schere
Echo     _______                                    _______
Echo ---'   ____)____      #    #  ####        ____(____   '---
Echo           ______)     #    # #           (______
Echo        __________)    #    #  ####      (__________
Echo       (____)          #    #      #           (____)
Echo ---.__(___)            #  #  #    #           (___)__.---
Echo                         ##    ####
Exit /B

:show_stein_stein
Echo     _______                           _______
Echo ---'   ____)     #    #  ####        (____   '---
Echo       (_____)    #    # #           (_____)
Echo       (_____)    #    #  ####       (_____)
Echo       (____)     #    #      #       (____)
Echo ---.__(___)       #  #  #    #        (___)__.---
Echo                    ##    ####
Exit /B

:show_papier_papier
Echo      _______                                  _______
Echo ---'    ____)____     #    #  ####       ____(____    '---
Echo            ______)    #    # #          (______
Echo           _______)    #    #  ####      (_______
Echo          _______)     #    #      #      (_______
Echo ---.__________)        #  #  #    #       (__________.---
Echo                         ##    ####
Exit /B

:show_schere_papier
Echo     _______                                   _______
Echo ---'   ____)____      #    #  ####       ____(____    '---
Echo           ______)     #    # #          (______
Echo        __________)    #    #  ####      (_______
Echo       (____)          #    #      #      (_______
Echo ---.__(___)            #  #  #    #       (__________.---
Echo                         ##    ####
Exit /B

:show_schere_stein
Echo     _______                               _______
Echo ---'   ____)____      #    #  ####       (____   '---
Echo           ______)     #    # #          (_____)
Echo        __________)    #    #  ####      (_____)
Echo       (____)          #    #      #      (____)
Echo ---.__(___)            #  #  #    #       (___)__.---
Echo                         ##    ####
Exit /B

:show_stein_schere
Echo     _______                               _______
Echo ---'   ____)     #    #  ####        ____(____   '---
Echo       (_____)    #    # #           (______
Echo       (_____)    #    #  ####      (__________
Echo       (____)     #    #      #           (____)
Echo ---.__(___)       #  #  #    #           (___)__.---
Echo                    ##    ####
Exit /B

:show_stein_papier
Echo     _______                               _______
Echo ---'   ____)     #    #  ####        ____(____    '---
Echo       (_____)    #    # #           (______
Echo       (_____)    #    #  ####      (_______
Echo       (____)     #    #      #      (_______
Echo ---.__(___)       #  #  #    #       (__________.---
Echo                    ##    ####
Exit /B

:show_papier_stein
Echo      _______                              _______
Echo ---'    ____)____     #    #  ####       (____   '---
Echo            ______)    #    # #          (_____)
Echo           _______)    #    #  ####      (_____)
Echo          _______)     #    #      #      (____)
Echo ---.__________)        #  #  #    #       (___)__.---
Echo                         ##    ####
Exit /B

:show_papier_schere
Echo      _______                                   _______
Echo ---'    ____)____     #    #  ####         ___(____   '---
Echo            ______)    #    # #           (______
Echo           _______)    #    #  ####      (__________
Echo          _______)     #    #      #           (____)
Echo ---.__________)        #  #  #    #           (___)__.---
Echo                         ##    ####
Exit /B

:unentschieden
ClS
Color 06
Echo #     #
Echo #     # #    # ###### #    # #####  ####   ####  #    # # ###### #####  ###### #    #
Echo #     # ##   # #      ##   #   #   #      #    # #    # # #      #    # #      ##   #
Echo #     # # #  # #####  # #  #   #    ####  #      ###### # #####  #    # #####  # #  #
Echo #     # #  # # #      #  # #   #        # #      #    # # #      #    # #      #  # #
Echo #     # #   ## #      #   ##   #   #    # #    # #    # # #      #    # #      #   ##
Echo  #####  #    # ###### #    #   #    ####   ####  #    # # ###### #####  ###### #    #
Exit /B

:sieg
ClS
Color 0A
Echo  #####
Echo #     # # ######  ####
Echo #       # #      #    #
Echo  #####  # #####  #
Echo       # # #      #  ###
Echo #     # # #      #    #
Echo  #####  # ######  ####
Exit /B

:niederlage
ClS
Color 04
Echo #     #
Echo ##    # # ###### #####  ###### #####  #        ##    ####  ######
Echo # #   # # #      #    # #      #    # #       #  #  #    # #
Echo #  #  # # #####  #    # #####  #    # #      #    # #      #####
Echo #   # # # #      #    # #      #####  #      ###### #  ### #
Echo #    ## # #      #    # #      #   #  #      #    # #    # #
Echo #     # # ###### #####  ###### #    # ###### #    #  ####  ######

Please remember, if you intend to define a codepage within your script, that it should be saved using that same codepage, (in this case Unicode UTF-8 no BOM [65001]).

P.S. I did not cater for a possible, though unlikely, CtrlBreak with your choice command, just in case you wish to do so yourself.

1
Aacini On

I liked your program, so I modified it a lot... ;)

@echo off

rem Program modified by Antonio Perez Ayala, AKA Aacini

REM Data definition
setlocal EnableDelayedExpansion

rem Left hand - Long fingers:
set "i=0"
for %%a in ("    _______       "
            "---'   ____)____  "
            "          ______) "
            "       __________)"
            "         ______)  "
            "---.__________)   "
           ) do (
   set /A i+=1
   set "LeftL[!i!]=%%~a"
)

rem Left hand - Short fingers:
set "i=0"
for %%a in ("    _______       "
            "---'   ____)      "
            "      (_____)     "
            "      (_____)     "
            "      (____)      "
            "---.__(___)       "
           ) do (
   set /A i+=1
   set "LeftS[!i!]=%%~a"
)

rem Right hand - Short fingers:
set "i=0"
for %%a in ("       _______    "
            "      (____   '---"
            "     (_____)      "
            "     (_____)      "
            "      (____)      "
            "       (___)__.---"
           ) do (
   set /A i+=1
   set "RightS[!i!]=%%~a"
)

rem Right hand - Long fingers:
set "i=0"
for %%a in ("       _______    "
            "  ____(____   '---"
            " (______          "
            "(___________      "
            "  (_______        "
            "   (__________.---"
           ) do (
   set /A i+=1
   set "RightL[!i!]=%%~a"
)

rem Versus:
set "i=0"
for %%a in ("#    #  #### "
            "#    # #     "
            "#    #  #### "
            "#    #      #"
            " #  #  #    #"
            "  ##    #### "
           ) do (
   set /A i+=1
   set "VS[!i!]=%%~a"
)

rem Fingers that comprises each figure (in Top-Bottom order):
set "Figure[1]=L L L L L L"  &  rem Papier: all fingers "long"
set "Figure[2]=L L L L S S"  &  rem Schere: two bottom fingers "short"
set "Figure[3]=S S S S S S"  &  rem Stein: all fingers "short"

rem If Papier=1, Schere=2 and Stein=3 then:
rem 2 win to 1 and 3 win to 2, but 3 lose vs 1, so:
rem set /A result=Userwahl-Scriptwahl
rem    Result= 0 -> Unentschieden, = 1 -> Sieg, = 2 -> Niederlage
rem If result is negative, the meaning is the opposite one; that is:
rem    Result=-1 -> Niederlage, =-2 -> Sieg
rem In this case we can change the sign and convert 1 -> 2 and 2 -> 1
rem This is achieved via a XOR operation with the number 3 (bits "11")
rem that converts "01" (1) -> "10" (2)  and  "10" (2) -> "01" (1)
rem if %Result% LSS 0 set /A "Result=-Result ^ 3"

rem In this way:
set "result[0]=Unentschieden:"
set "result[1]=Sieg:         "
set "result[2]=Niederlage:   "


for /L %%i in (0,1,2) do set "sum[%%i]=0"

:menu
cls
color 0F
echo Willkommen im Spiel^^!
echo/
echo 1. Papier
echo 2. Schere
echo 3. Stein
echo/
echo/
echo Ergebnisse
for %%i in (1,2,0) do echo !result[%%i]! !sum[%%i]!
echo/
choice /C 123x /M "Bitte wählen Sie eine Zahl "
if errorlevel 4 color & cls & goto :EOF

set /A "Userwahl=%errorlevel%, Scriptwahl=%random% %% 3 + 1, Result=Userwahl-Scriptwahl"
if %Result% LSS 0 set /A "Result=-Result ^ 3"

call :show_figures %Userwahl% %Scriptwahl%
REM cls
call :result_%Result%
ECHO/
PAUSE
REM timeout /t 3 > nul
set /A "sum[%Result%]+=1"
goto menu


:show_figures  Userwahl  Scriptwahl

rem Input values are *indices* that selects the figure: 1=Papier, 2=Schere, 3=Stein
rem Get an array of *fingers* that comprises each figure
set "i=0" & for %%a in (!Figure[%1]!) do set /A i+=1 & set "left[!i!]=%%a"
set "i=0" & for %%a in (!Figure[%2]!) do set /A i+=1 & set "right[!i!]=%%a"

REM cls
ECHO/
ECHO/
for /L %%i in (1,1,6) do call echo %%Left!left[%%i]![%%i]%%    !VS[%%i]!    %%Right!right[%%i]![%%i]%%
ECHO/
ECHO/
REM timeout /t 3 > nul                   
exit /B


:result_0  Unentschieden
color 06
echo #     #
echo #     # #    # ###### #    # #####  ####   ####  #    # # ###### #####  ###### #    #
echo #     # ##   # #      ##   #   #   #      #    # #    # # #      #    # #      ##   #
echo #     # # #  # #####  # #  #   #    ####  #      ###### # #####  #    # #####  # #  #
echo #     # #  # # #      #  # #   #        # #      #    # # #      #    # #      #  # #
echo #     # #   ## #      #   ##   #   #    # #    # #    # # #      #    # #      #   ##
echo  #####  #    # ###### #    #   #    ####   ####  #    # # ###### #####  ###### #    #
exit /B


:result_1  Sieg
color 0A
echo  #####
echo #     # # ######  ####
echo #       # #      #    #
echo  #####  # #####  #
echo       # # #      #  ###
echo #     # # #      #    #
echo  #####  # ######  ####
exit /B


:result_2  Niederlage
color 04
echo #     #
echo ##    # # ###### #####  ###### #####  #        ##    ####  ######
echo # #   # # #      #    # #      #    # #       #  #  #    # #
echo #  #  # # #####  #    # #####  #    # #      #    # #      #####
echo #   # # # #      #    # #      #####  #      ###### #  ### #
echo #    ## # #      #    # #      #   #  #      #    # #    # #
echo #     # # ###### #####  ###### #    # ###### #    #  ####  ######
exit /b
0
Mofi On

Here is my variant of the batch file posted by Why Not in an answer.

@echo off
setlocal EnableExtensions DisableDelayedExpansion
for /F "tokens=*" %%G in ('%SystemRoot%\System32\chcp.com') do for %%H In (%%G) do set /A "CodePage=%%H" 2>nul
%SystemRoot%\System32\chcp.com 850 >nul

set "Sieg=0"
set "Niederlage=0"
set "Unentschieden=0"
set "WarteZeit=10"
goto Info

:Menu
%SystemRoot%\System32\timeout.exe /T %WarteZeit% >nul
:Info
cls
color 0F
echo Willkommen im Spiel!
echo(
echo Bisherige Ergebnisse:
echo(
echo Siege:         %Sieg%
echo Niederlagen:   %Niederlage%
echo Unentschieden: %Unentschieden%
echo(
echo     1 ... Schere
echo     2 ... Stein
echo     3 ... Papier
echo     E ... Ende
echo(
%SystemRoot%\System32\choice.exe /C 123E /N /M "Bitte treffen Sie Ihre Wahl (1/2/3/E):"
if errorlevel 4 %SystemRoot%\System32\chcp.com %CodePage% >nul & color & exit /B
if not errorlevel 1 goto Info
set "Anwenderwahl=%errorlevel%"
set /A SKriptwahl=%random% %% 3 + 1
cls
if %Anwenderwahl% == %SKriptwahl% goto Unentschieden
if %Anwenderwahl% == 1 goto Schere
if %Anwenderwahl% == 2 goto Stein

call :Papier%Skriptwahl%
%SystemRoot%\System32\timeout.exe /T %WarteZeit% >nul
if %SKriptwahl% == 2 goto Sieg

:Niederlage
(set /A Niederlage+=1
cls
color 04
echo #     #
echo ##    # # ###### #####  ###### #####  #        ##    ####  ######
echo # #   # # #      #    # #      #    # #       #  #  #    # #
echo #  #  # # #####  #    # #####  #    # #      #    # #      #####
echo #   # # # #      #    # #      #####  #      ###### #  ### #
echo #    ## # #      #    # #      #   #  #      #    # #    # #
echo #     # # ###### #####  ###### #    # ###### #    #  ####  ######
goto Menu)

:Sieg
(set /A Sieg+=1
cls
color A
echo  #####
echo #     # # ######  ####
echo #       # #      #    #
echo  #####  # #####  #
echo       # # #      #  ###
echo #     # # #      #    #
echo  #####  # ######  ####
goto Menu)

:Unentschieden
(call :Unentschieden%Skriptwahl%
%SystemRoot%\System32\timeout.exe /T %WarteZeit% >nul
set /A Unentschieden+=1
cls
color 06
echo #     #
echo #     # #    # ###### #    # #####  ####   ####  #    # # ###### #####  ###### #    #
echo #     # ##   # #      ##   #   #   #      #    # #    # # #      #    # #      ##   #
echo #     # # #  # #####  # #  #   #    ####  #      ###### # #####  #    # #####  # #  #
echo #     # #  # # #      #  # #   #        # #      #    # # #      #    # #      #  # #
echo #     # #   ## #      #   ##   #   #    # #    # #    # # #      #    # #      #   ##
echo  #####  #    # ###### #    #   #    ####   ####  #    # # ###### #####  ###### #    #
goto Menu)

:Schere
(call :Schere%Skriptwahl%
%SystemRoot%\System32\timeout.exe /T %WarteZeit% >nul
if %SKriptwahl% == 3 (goto Sieg) else goto Niederlage)

:Stein
(call :Stein%Skriptwahl%
%SystemRoot%\System32\timeout.exe /T %WarteZeit% >nul
if %SKriptwahl% == 1 (goto Sieg) else goto Niederlage)

:Unentschieden1
(echo     _______                                    _______
echo ---'   ____^)____      #    #  ####        ____(^____   '---
echo           ______^)     #    # #           (^______
echo        __________^)    #    #  ####      (^__________
echo       (^____^)          #    #      #           (^____^)
echo ---.__(^___^)            #  #  #    #           (^___^)__.---
echo                         ##    ####
goto :EOF)

:Unentschieden2
(echo     _______                           _______
echo ---'   ____^)     #    #  ####        (^____   '---
echo       (^_____^)    #    # #           (^_____^)
echo       (^_____^)    #    #  ####       (^_____^)
echo       (^____^)     #    #      #       (^____^)
echo ---.__(^___^)       #  #  #    #        (^___^)__.---
echo                    ##    ####
goto :EOF)

:Unentschieden3
(echo      _______                                  _______
echo ---'    ____^)____     #    #  ####       ____(^____    '---
echo            ______^)    #    # #          (^______
echo           _______^)    #    #  ####      (^_______
echo          _______^)     #    #      #      (^_______
echo ---.__________^)        #  #  #    #       (^__________.---
echo                         ##    ####
goto :EOF)

:Schere2
(echo     _______                               _______
echo ---'   ____^)____      #    #  ####       (^____   '---
echo           ______^)     #    # #          (^_____^)
echo        __________^)    #    #  ####      (^_____^)
echo       (^____^)          #    #      #      (^____^)
echo ---.__(^___^)            #  #  #    #       (^___^)__.---
echo                         ##    ####
goto :EOF)

:Schere3
(echo     _______                                   _______
echo ---'   ____^)____      #    #  ####       ____(^____    '---
echo           ______^)     #    # #          (^______
echo        __________^)    #    #  ####      (^_______
echo       (^____^)          #    #      #      (^_______
echo ---.__(^___^)            #  #  #    #       (^__________.---
echo                         ##    ####
goto :EOF)

:Stein1
(echo     _______                               _______
echo ---'   ____^)     #    #  ####        ____(^____   '---
echo       (^_____^)    #    # #           (^______
echo       (^_____^)    #    #  ####      (^__________
echo       (^____^)     #    #      #           (^____^)
echo ---.__(^___^)       #  #  #    #           (^___^)__.---
echo                    ##    ####
goto :EOF)

:Stein3
(echo     _______                               _______
echo ---'   ____^)     #    #  ####        ____(^____    '---
echo       (_____^)    #    # #           (^______
echo       (_____^)    #    #  ####      (^_______
echo       (____^)     #    #      #      (^_______
echo ---.__(___^)       #  #  #    #       (^__________.---
echo                    ##    ####
goto :EOF)

:Papier1
(echo      _______                                   _______
echo ---'    ____^)____     #    #  ####         ___(^____   '---
echo            ______^)    #    # #           (^______
echo           _______^)    #    #  ####      (^__________
echo          _______^)     #    #      #           (^____^)
echo ---.__________^)        #  #  #    #           (^___^)__.---
echo                         ##    ####
goto :EOF)

:Papier2
(echo      _______                              _______
echo ---'    ____^)____     #    #  ####       (^____   '---
echo            ______^)    #    # #          (^_____^)
echo           _______^)    #    #  ####      (^_____^)
echo          _______^)     #    #      #      (^____^)
echo ---.__________^)        #  #  #    #       (^___^)__.---
echo                         ##    ####
goto :EOF)

It has some extra features:

  1. The user can exit the game by pressing key E.
  2. The choice prompt is handled correct on user presses Ctrl+C or Ctrl+Break and on prompt Terminate batch job (Y/N)? shown by cmd.exe presses the key N to continue playing the game.
  3. There is added the environment variable WarteZeit with value 10 for waiting by default 10 seconds before batch file execution continues. The user can press any key to reduce the wait time. That is an enhancement made by me mainly for easier testing the code but it is useful also for the users.
  4. There are used extra round brackets forcing cmd.exe reading from batch file always an entire command block beginning with ( after a label and ending with matching ) at the end of a command block to reduce the number of file system accesses while playing the game. There could be even more ( and ) used for further runtime optimizations but I did not want to make the code too difficult to read for batch file beginners.
  5. The batch file outputs all text in German but does not contain any non-ASCII character. This makes it possible to use the OEM code page 850 for interpreting the batch file and displaying the text as it is the default on a country with a German language configured for the user account. The batch file can be saved in ANSI using code page Windows-1252 and in UTF-8 without byte order mark (BOM) and everything is nevertheless correct displayed because of the batch file is encoded now identical in all three character encodings. There could be used also code page 437 which is the default for North American countries.
  6. The batch file determines the initial code page and restores it on user exits playing the game by pressing key E. It restores also the initial color settings of the console window. That is useful if a user runs the batch file from within a command prompt window instead of double clicking on the batch file and wants to use further the command prompt as configured by the user.
  7. The first two command lines define the required execution environment completely. The batch file does not depend anymore on settings defined outside of the batch file for command echo mode, command extensions and delayed variable expansion.
  8. The batch file works also for Windows Vista and Windows 7 with the OEM bitmap font Terminal as standard font for console windows. It would work also for Windows XP if the user copied choice.exe and timeout.exe from a Windows Server 2003 (computer or ISO image) into the Windows system directory of Windows XP.
  9. Each executable is referenced with its fully qualified file name making the batch file execution independent on the environment variables PATH and PATHEXT and avoids a lot of file system accesses while playing because of cmd.exe does not need searching for any executable at any time.

There can be read the following Stack Overflow answers for more details:

The DosTips forum topic ECHO. FAILS to give text or blank line - Instead use ECHO/ should be read as well. echo. results in cmd.exe using Windows file IO functions for searching in the current directory for a file system entry with name echo (dot removed by the file IO function). That is not good if just an empty line should be output as it causes an unnecessary file system access which even can result in running a program with name echo if there is one in current directory.

Compo's post in the DosTips forum topic Saving current codepage was used as source for the command line to determine the initial code page and assign its value to the environment variable CodePage for restoring this code page before exit.