Page 1 of 1

Batch IF-Condition click once for getting the loot only once

Posted: 27 Apr 2018 06:39
by Dr.Hebeneben
Guten Tag liebe DosTips Community,

Ich habe folgendes Problem das ich anhand des Codes besser erklären kann.
Ich programmiere ein Spiel in Batch und habe eine Mausfunktion implementiert.

< Problem >

Im Spiel befinden wir uns in einem Discounter und können diesen an vorgegebenen Orten looten: z.B. Kasse, Regal etc.

Code: Select all

:Discounter
cls
echo -------------------------------------------------
echo                 RANDOM DUNGEON
echo -------------------------------------------------
echo  [ Zentrum ] [ Discounter ]
echo -------------------------------------------------
echo [b] ^< Kasse ^>[/b]
echo  ^< Regal ^>
echo  ^< Regal ^>
echo  ^< Kuehlschrank ^>
echo  ^< Regal ^>
echo  ^< Regal ^>
echo  ^< Regal ^>
echo  ^< Abstellraum ^>
echo  ^< Abteilungsraum ^>
echo -------------------------------------------------
:DiscounterChoose
for /f "tokens=1,2,3" %%a in ('!mouse! mouse') do set/a x=%%b, y=%%c
if !y! geq 6 if !y! leq 6 if !x! geq 3 if !x! leq 13 goto Checkout
if !y! geq 6 if !y! leq 6 if !x! geq 6 if !x! leq 14 exit
goto DiscounterChoose



[b]:Checkout[/b]
::Variables
(
set /a dollar=%random% %% 4 + 2   [b]Hier wird erstmal ein zufälliger Wert für das Geld das in der Kasse liegt festgelegt.[/b]
)
cls
echo -------------------------------------------------
echo ^< [%dollar%] Dollar ^>  [b]Dann klickt man auf [?] Dollar und bekommt das Geld.[/b]
echo -------------------------------------------------
:CheckoutChoose
for /f "tokens=1,2,3" %%a in ('!mouse! mouse') do set/a x=%%b, y=%%c
if !y! geq 2 if !y! leq 2 if !x! geq 2 if !x! leq 24 
goto CheckoutChoose
< Frage >

Meine Frage nun ist: Wie kann man die IF-Bedingung umgehen so das man nicht unendlich mal drauf klicken kann.
Zurzeit läuft der Code noch so:
Klick + Geld
Klick + Geld
Klick + Geld
...

Und nach dem Geld erhalt soll man ja wieder zurück um die restlichen Orte zulooten. Dann kann man ja aber wieder auf Kasse klicken und wieder Geld farmen.
Sozusagen gleiches Problem bei beiden Jumps :Discounter und :Checkout.

Jemand eine Idee wäre extrem hilfreich, weil ich bei Google nichts finde und das meine Batch Erfahrungen übersteigt. Das zerstört mir jedoch mein ganze Spielidee

Re: Batch IF-Bedingung übergehen

Posted: 27 Apr 2018 07:09
by penpen
This is an anglophone forum, so you probably would get more replies if you write your topic and posts in english.
What do you mean with "go around the if-expression"? The conditional if-statement is controlled by the if-expression, so you should just use an expression which is appropriate to the use-case.

Da dies ein englischsprachiges Forum, daher wirst du wahrscheinlich mehr Antworten erhalten, wenn du dein Thema und deine Beiträge in Englisch Sprache verfasst.
Was meinst du mit "IF-Bedingung umgehen"? Die bedingte If-Anweisung wird von der If-Bedingung gesteuert, also sollte man einfach eine an den bedingung wählen, die dem Anwendungsfall angepasst ist.


penpen

Re: Batch IF-Bedingung übergehen

Posted: 27 Apr 2018 09:15
by Dr.Hebeneben
Good day dear DosTips community,

I have the following problem that I can explain better with the help of the code.
I program a game in batch and implemented a mouse function.

<Problem>

In the game we are in a discount store and can loot it at given locations: e.g. Cash register, shelf etc.

Code: Select all

: Discounter
cls
echo -------------------------------------------------
echo RANDOM DUNGEON
echo -------------------------------------------------
echo [center] [discounter]
echo -------------------------------------------------
echo ^ <checkout ^>
echo ^ <shelf ^>
echo ^ <shelf ^>
echo ^ <fridge ^>
echo ^ <shelf ^>
echo ^ <shelf ^>
echo ^ <shelf ^>
echo ^ <storage room ^>
echo ^ <department room ^>
echo -------------------------------------------------
: DiscounterChoose
for / f "tokens = 1,2,3" %% a in ('! mouse! mouse') do set / ax = %% b, y = %% c
if! y! geq 6 if! y! leq 6 if! x! geq 3 if! x! leq 13 goto checkout
if! y! geq 6 if! y! leq 6 if! x! geq 6 if! x! leq 14 exit
goto DiscounterChoose



:Check out
:: Variables
(
set / a dollar =% random% %% 4 + 2 Here, a random value for the money in the cash register is set.
)
cls
echo -------------------------------------------------
echo ^ <[% dollar%] Dollars ^> Then click on [?] Dollars and get the money.
echo -------------------------------------------------
: CheckoutChoose
for / f "tokens = 1,2,3" %% a in ('! mouse! mouse') do set / ax = %% b, y = %% c
if! y! geq 2 if! y! leq 2 if! x! geq 2 if! x! leq 24
goto CheckoutChoose
<Question>

My question now is: how can you bypass the IF condition so that you can not click on it indefinitely.
At the moment the code runs like this:
Click + money
Click + money
Click + money
...

And after receiving the money you should go back to the remaining places to loot. Then you can but yes again click on cash and farm money again.
The same problem with both jumps: Discounter and: Checkout.

Someone an idea would be extremely helpful, because I find nothing at Google and that exceeds my batch experiences. But this destroys my whole game idea

Re: Batch IF-Condition click once for getting the loot only once

Posted: 27 Apr 2018 09:48
by pieh-ejdsch
Hallo,
Deine Idee kannst Du auf einem Blatt erstmal skizzieren bzw. ausschreiben.
Dann legst Du eine Variable fest, mit deren Hilfe Du bestimmst wann etwas gemacht werden darf.
Eine IF-Bedingung ist nichts anderes als: Was wäre wenn.
Wenn Geld erhalten wurde kann kein weiteres Geld erhalten werden. Lege dazu eine Variable an.
Wenn Geld da ist kann der Inhalt von Einkaufskorb bezahlt werden.
usw.
If N geq x if N leq x then
the same thing is
if N equ x