Batch file mafia game [Little help]

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Sookrat
Posts: 3
Joined: 18 Oct 2012 18:06

Batch file mafia game [Little help]

#1 Post by Sookrat » 02 May 2018 12:15

I made a text based mafia game (Mouse click support). and i need to add some gui like buttons, is that possible? or is there any plugin to help me in this?
also i need to know how to make limitation for characters in line or space.
for example:
Money: 50 | HP: 100 | Some text.
when money rising to 10,000 the HP getting out of the screen. i want to make limitation number of character.

Thnx

Image

Image

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Batch file mafia game [Little help]

#2 Post by ShadowThief » 02 May 2018 13:25

Sookrat wrote:
02 May 2018 12:15
I made a text based mafia game (Mouse click support). and i need to add some gui like buttons, is that possible? or is there any plugin to help me in this?
I've seen batbox do this, and I can pretty much guarantee that misol101 will come in here and tell you to use cmdgfx. That said, if you're looking for actual buttons like
Image
then you're out of luck.
Sookrat wrote:
02 May 2018 12:15
also i need to know how to make limitation for characters in line or space.
Use substrings (https://www.dostips.com/DtTipsStringOpe ... LeftString) to crop the text on the end.

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Batch file mafia game [Little help]

#3 Post by misol101 » 02 May 2018 15:05

Dude, you totally need to use cmdgfx!!

:lol:

Seriously though, everything seems to be in place already, so no need for that.

I seem to recall that Aacinis GetInput utility had support for mouse dialogs. I would recommend that.



EDIT: Just to elaborate slightly: This game does not look like it would have any need for:

1. High FPS, smooth animation, or moving objects
2. Key or mouse input while the game or animation runs in the background
3. Any need for 3d or fancy special effects
4. Any need for dialogs or buttons that look fancy or non-standard

So, for these reasons, using cmdgfx would not only be unnecessary, but also a waste of time (its flexibility comes with a higher setup and complexity cost).

Sookrat
Posts: 3
Joined: 18 Oct 2012 18:06

Re: Batch file mafia game [Little help]

#4 Post by Sookrat » 06 May 2018 06:59

Could you please give me example about making gui menus, buttons, colors?
Thnx

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Batch file mafia game [Little help]

#5 Post by Compo » 06 May 2018 08:46

You could use hta, javascript/vbscript or powershell if it is available on that OS to create GUI message boxes.

PowerShell examples:

Code: Select all

@PowerShell -Command^
 "[Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')|Out-Null;"^
 "[System.Windows.Forms.MessageBox]::Show('Money: 50 | HP: 100 | Some text')">Nul]
on separate lines…

Code: Select all

@PowerShell -Command^
 "[Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')|Out-Null;"^
 "[System.Windows.Forms.MessageBox]::Show(\"Money: 50`nHP: 100`nSome text\")">Nul
Although I'm guessing that that isn't really what you want, because as soon as you create GUI boxes you no longer have a text based game!

Would something like this not work for you instead?

Code: Select all

@Start "Inventory" /Wait Cmd /Q /C "Mode 16,7&Color 5E&Echo(&Echo Money: 50&Echo    HP: 100&Echo(&Echo SomeText&Echo(&Timeout 5 >Nul"

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch file mafia game [Little help]

#6 Post by aGerman » 06 May 2018 13:43

As everyone already told you - "text based" and "GUI" don't go together. Neither do "Batch window" and "GUI" (even if misol101 is a wizard who tries to overcome all limitations). And neither do "text based" and "mouse input". Why is everybody so keen on making a console window what it never will be?

Nevermind.
I used conin.exe to be found in post #62 of that thread
viewtopic.php?p=51138#p51138
because I wrote it (only because someone requested it) and am familiar with its functionality.
In the same thread you'll find a lot of useful tools btw.

Code: Select all

@echo off &setlocal
:: print the buttons (I used ASCII characters to make sure everybody sees the same independing on locale settings)
echo(
echo  @@@@@@@
echo  @@ A @@
echo  @@@@@@@         @@@@@@@
echo                  @@ C @@
echo       @@@@@@@    @@@@@@@
echo       @@ B @@
echo       @@@@@@@
echo(
echo click on a button
echo(


:: label where to jump in order to run conin again
:loop

:: conin.exe - Read Console Input
:: timeout: %errorlevel% = 0
:: type:    %errorlevel%>>29 (0=keyboard, 1=left click, 2=right click, 3=mouse move)
:: key:     %errorlevel% (either character code or (for extended keys) 256 + key code)
:: mouse:   row = (%errorlevel%>>14)&0x3FFF, column = %errorlevel%&0x3FFF
:: the utility times out after the passed number of milliseconds, it will wait infinite if you don't pass an argument
conin.exe

:: calculate the values according to the explanation above
set /a "key=%errorlevel%, type=key>>29, y=(key>>14)&0x3FFF, x=key&0x3FFF"

:: if the input type was not 1 (left mouse click) then run conin again
if %type% neq 1 goto loop

:: else call a subroutine to check if a button was clicked; each passed group of values represents a button and consists of:
:: "top_left_corner_horizontal_offset,top_left_corner_vertical_offset,bottom_right_corner_horizontal_offset,bottom_right_corner_vertical_offset"
:: note that the coordinates are zero-based (that is, the top left corner of the window has coordinates 0,0 and is the origin of the button coordinates)
:: the subroutine returns 0 if the click was outside of any button rectangles (run conin again in that case),
:: otherwise it returns the index of the matched group (1 for the first group, 2 for the second group, etc.)
call :check "1,1,7,3" "6,5,12,7" "17,3,23,6" && goto loop

:: assign the returned index to a variable
set "n=%errorlevel%"

echo  button #%n% clicked
pause
exit /b


:check
setlocal EnableDelayedExpansion
set "idx=1"
:: enumerate all passed value groups and check if the x and y coordinates of the mouse click fits into one of the rectangles
for %%i in (%*) do (
  for /f "tokens=1-4 delims=, " %%j in (%%i) do (
    if %x% geq %%j if %y% geq %%k if %x% leq %%l if %y% leq %%m for %%n in (!idx!) do (endlocal&exit /b %%n)
  )
  set /a "idx+=1"
)
endlocal
exit /b 0
Carefully read the comments in the code in order to understand how it works.

Steffen

Post Reply