簡體   English   中英

批處理文件未正確更新余額

[英]Batch file not updating balance correctly

余額變量為“ bal”

我希望它隨着每次贏/輸而更新,但始終保持在100。我將值設置在一個單獨的文件中,以便以后如果您希望將硬設置值作為%bal%的基本開始值,則可以設置保存機制。 %bal%是100。

@echo off
cls

:menu
echo hello and welcome to Gamble bot 2000!
echo you start off with 100 credits and as you climb
echo you can start to place larger and better bets!
echo do your best to not run out of money or you will
echo have to start over
echo have fun :)
echo .
echo Version alpha 0.2.1
echo .
echo To start type "start" and hit enter

set /p menu=
if %menu% == start (
goto start )
goto sry1

:sry1
cls
echo you typed an invalid response please try agian.
pause
goto menu

:start
cls 
set /p bal=<value.txt
echo the game is simple guess a number between 0 and 9
echo for 3 instance for example 123, 456, 789, 111 and so on
echo a dice will roll and if you guess the number you get a
echo winning based on the amount of numbers you guessed correct
echo .
echo 1 numbers gives you a 2x win
echo 2 numbers gives you a 3x win
echo 3 numbers gives you a 4x win
echo and of course no numbers means u lost
pause
goto g1

:g1
cls
set g1=nul
set g2=nul
set g3=nul
Echo please make your 1st number selection!!!
set /p g1=
goto g2

:g2
cls
Echo please make your 2nd number selection!!!
set /p g2=
goto g3

:g3
cls
Echo please make your 3rd number selection!!!
set /p g3=
goto bet

:bet
cls 
echo place your bet.
echo your current balance is %bal%c
set /p bet=
if %bet% GTR %bal% (
goto inf )
goto num1

:inf
cls
echo you dont have enough credits for that bet, please choose another bet!
pause
goto bet

:num1
cls
echo Getting results, please wait.
set /a g11=%random% %% 10
goto num2

:num2
cls
echo Getting results, please wait..
set /a g22=%random% %% 10
goto num3

:num3
cls
echo Getting results, please wait...
set /a g33=%random% %% 10
goto results

:results
if %g1%==%g11% if %g2%==%g22% if %g3%==%g33% goto w3
if not %g1%==%g11% if %g2%==%g22% if %g3%==%g33% goto w2
if %g1%==%g11% if not %g2%==%g22% if %g3%==%g33% goto w2
if %g1%==%g11% if %g2%==%g22% if not %g3%==%g33% goto w2
if not %g1%==%g11% if not %g2%==%g22% if %g3%==%g33% goto w1
if not %g1%==%g11% if %g2%==%g22% if not %g3%==%g33% goto w1
if %g1%==%g11% if not %g2%==%g22% if not %g3%==%g33% goto w1
if not %g1%==%g11% if not %g2%==%g22% if not %g3%==%g33% goto Lose

:w3
cls
set /p win=%bet%*4
set /p %bal%+%win%
echo Congratulations you have guessed all three numbers correctly!
echo the numbers were: %g1%%g2%%g3%!
echo .
echo You have won "%win%" credits!
echo .
echo Your new credit balance is %bal%C
echo .
echo would you like to make another bet? 
echo (Y/N)
set /p ha= 
if %ha% == y goto g1
if %ha% == n goto save

:w2
cls
set /p win=%bet%*3
set /p %bal%+%win%
echo Congratulations you have guessed two numbers correctly!
echo the numbers were: %g1%%g2%%g3%!
echo .
echo You have won "%win%" credits!
echo .
echo Your new credit balance is %bal%C
echo .
echo would you like to make another bet? 
echo (Y/N)
set /p ha= 
if %ha% == y goto g1
if %ha% == n goto save

:w1
cls
set /p win=%bet%*2
set /p %bal%+%win%
echo Congratulations you have guessed one correctly!
echo the numbers were: %g1%%g2%%g3%!
echo .
echo You have won "%win%" credits!
echo .
echo Your new credit balance is %bal%C
echo .
echo would you like to make another bet? 
echo (Y/N)
set /p ha= 
if %ha% == y goto g1
if %ha% == n goto save

:lose
cls
set /p %bal%-%bet%
echo Im sorry but you did not guess any of the numbers correclty.
echo .
echo you have lost %bet% credits
echo .
echo your new credit balance is %bal%C
echo would you like to make another bet? 
echo (Y/N)
set /p ha= 
if %ha% == y goto g1
if %ha% == n goto save

:save
cls
echo Im sorry but the save mechanic is not yet set up it will be coming
echo in a future update, anyway thanks for playing I hope you had fun!
pause
end
set /p %bal%-%bet%

應該

set /a bal-=%bet%

要么

set /a bal-=bet

要么

set /a bal=bal - bet

對於win案例也同樣如此。

Here is the finished code if anyone wants to check it out :D


@echo off
cls

:menu
echo Hello. Welcome to Gamblebot 2000!
echo You will start off with 100 credits. As you climb,
echo you can start to place larger and better bets!
echo Do your best to not run out of money, or you will
echo have to start over.
echo Have fun :)
echo .
echo Version 1.2.4
echo .
pause

:start
cls 
set bal=100
echo The game is simple. Guess a number between 0 and 9
echo for 3 instances. (For example: 123, 456, 789, 111)
echo A dice will be rolled. If you guess the number, you get a
echo winning based on the amount of numbers guessed correctly.
echo .
echo 1 numbers gives you a 2x win.
echo 2 numbers gives you a 3x win.
echo 3 numbers gives you a 4x win.
echo No numbers means you lost.
pause
goto curr

:curr
cls
echo First, start by naming the currency.
echo Name it whatever you like. Then press enter.
set /p curr=
goto g1

:currchange
cls
echo Enter name of new currency.
set /p curr=
goto g1

:g1
cls
echo Please make your first number selection!!!
set /p g1=
goto g2

:g2
cls
echo Please make your second number selection!!!
set /p g2=
goto g3

:g3
cls
echo Please make your third number selection!!!
set /p g3=
goto bet

:bet
cls 
echo Your balance is %bal% %curr%
echo Place your bet.
set /p bet=
if %bet% GTR %bal% (
goto inf )
goto num1

:inf
cls
echo You do not have enough credits for that bet. Please choose another bet!
pause
goto bet

:num1
echo Getting results! Please wait.
set /a g11=%random% %% 10
goto num2

:num2
cls
echo Getting results! Please wait..
set /a g22=%random% %% 10
goto num3

:num3
cls
echo Getting results! Please wait...
set /a g33=%random% %% 10
goto results

:results
if %g1%==%g11% if %g2%==%g22% if %g3%==%g33% goto w3
if not %g1%==%g11% if %g2%==%g22% if %g3%==%g33% goto w2
if %g1%==%g11% if not %g2%==%g22% if %g3%==%g33% goto w2
if %g1%==%g11% if %g2%==%g22% if not %g3%==%g33% goto w2
if not %g1%==%g11% if not %g2%==%g22% if %g3%==%g33% goto w1
if not %g1%==%g11% if %g2%==%g22% if not %g3%==%g33% goto w1
if %g1%==%g11% if not %g2%==%g22% if not %g3%==%g33% goto w1
if not %g1%==%g11% if not %g2%==%g22% if not %g3%==%g33% goto Lose

:w3
cls
set /a win=%bet%*4
set /a bal=%bal%+%win%
echo Congratulations you have guessed all three numbers correctly!
echo the numbers were: %g11%%g22%%g33%!
echo .
echo You have won "%win%" %curr%!
echo .
echo Your new credit balance is %bal% %curr%.
echo .
echo Would you like to make another bet? 
echo (Y/N)
set /p ha= 
if %ha% == y goto change
if %ha% == Y goto change
if %ha% == n goto save
if %ha% == N goto save

:w2
cls
set /a win=%bet%*3
set /a bal=%bal%+%win%
echo Congratulations you have guessed two numbers correctly!
echo the numbers were: %g11%%g22%%g33%!
echo .
echo You have won "%win%" %curr%!
echo .
echo Your new credit balance is %bal% %curr%.
echo .
echo Would you like to make another bet? 
echo (Y/N)
set /p ha= 
if %ha% == y goto change
if %ha% == Y goto change
if %ha% == n goto save
if %ha% == N goto save

:w1
cls
set /a win=%bet%*2
set /a bal=%bal%+%win%
echo Congratulations you have guessed one correctly!
echo the numbers were: %g11%%g22%%g33%!
echo .
echo You have won "%win%" %curr%!
echo .
echo Your new credit balance is %bal% %curr%.
echo .
echo Would you like to make another bet? 
echo (Y/N)
set /p ha= 
if %ha% == y goto change
if %ha% 
cls
set /a bal=%bal%-%bet%
echo I am sorry but you did not guess any of the numbers correctly.
echo .
echo You have lost %bet% %curr%.
echo .
echo Your new credit balance is %bal% %curr%.
echo Would you like to make another bet? 
echo (Y/N)
set /p ha= 
if %ha% == y goto change
if %ha% == Y goto change
if %ha% == n goto save
if %ha% == N goto save

:change
cls
echo Would you like to change or keep the name of your currency?
echo Type k for keep or c for change.
set /p ha=
if %ha% == k goto g1
if %ha% == K goto g1
if %ha% == c goto currchange
if %ha% == C goto currchange

:save
cls
echo Sorry. The save mechanic is not yet set up. It will be coming
echo in a future update Thanks for playing. I hope you had fun!
pause
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM