Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Choice help  (Read 6342 times)

0 Members and 2 Guests are viewing this topic.

shiverbob

    Topic Starter


    Beginner

    Thanked: 1
    • Yes
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows XP
Choice help
« on: September 21, 2014, 04:08:36 PM »
A few weeks ago I was asked to make an adventure game in batch, of all things, for a game competition. That will be all saved locally and then once the competition is over I will send it to the judges to judge how well they play and then they will be score and that it. So I started but I had some problems and was wandering if you guys could help.

My first problem is that I would like to have a grid but I cant figure out how to make it move. I am running a windows xp which I know doesn't have choice.com or choice.exe. I would prefer not for them having to click enter every time.

My second problem is that I didn't know if you could save your game with the "set<file name.txt" and then transfer it to a different computer and the load it up. But they are looking at the txt of that. The stuff they did would be there so the judges wouldn't have to look through the game to find what that player did.

My third and final problem, hopefully is that I don't know how to set up it up to where you have to enter a password to load a save file, delete a save file (in and out of game) ,and to make a file and if they get it wrong they can't go in the code and hack into someone's game.
I still have 6 months before it starts so I would like to have a grid and the password, save, create, and delete a file by 2 months in...
Any help is appreciated.
Thanks
Pff computers are easy, math is hard.

Lemonilla



    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: Choice help
« Reply #1 on: September 21, 2014, 08:57:41 PM »
Well, without choice it could be difficult.  I have seen it done, but still don't understand how it works.  It uses 'start /b' to run a controller that writes to a files, which is always being read for input, but that's as far as I could get.  Here is a link.
I would recommend getting a copy of choice.exe and putting it in the folder with your batch.  If you are moving between folders while the game runs, run this command at the beginning to add choice 'set path=%path%;%~pd0 '.  Don't forget to add %~pd0 to path, not override it or you will get some really ugly bugs.

To save your game to a text file, I would use these sets of commands (without having seen the code I cannot give you the optimized method.  This may not work depending on how you are structuring your game).
Code: (To Save Game) [Select]
set >save1.txt
Code: (To Load Game) [Select]
for /f "delims=" %%A in (save1.txt) do set %%A

All code written in batch is viewable if opened.  If you want your game 100% unhackable make a board game.  I would use a language that compiles to write the password generation and input if you really want it secure.  I think that for the arcade type of game you are talking about, a simple password will do.  Here is how I would write it.  This is the simplest (in terms of getting in) as I know, but it is also the easiest to code.
Code: (To Save) [Select]
cls
echo Input Name:
set /p saveFunc_name=^>

cls
echo Input Password for %saveFunc_name%:
set /p saveFunc_pass=^>

cls
echo Saving, Please Wait. . .
echo %saveFunc_name%/%saveFunc_pass% >>saves.txt
set >save_%saveFunc_name: =_%.txt
Code: (Password Input) [Select]
cls
echo Enter Username:
set /p loadFunc_name=^>

cls
echo Enter Password for %loadFunc_name%:
set /p loadFunc_pass=^>

cls
echo Loading Game, Please Wait. . .
for /f "delims=" %%A in (saves.txt) do (
if "%%A"=="%loadFunc_name%/%loadFunc_pass%" (
for /f "delims=" %%G in (save_%loadFunc_name: =_%.txt) do set %%G
) )
if not defined saveFunc_name goto :Error_noSaveDataFound

I doubt you will need a more secure save function, but if you do, ask.
*No code has been tested.
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

shiverbob

    Topic Starter


    Beginner

    Thanked: 1
    • Yes
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows XP
Re: Choice help
« Reply #2 on: September 22, 2014, 12:21:40 PM »
Thanks for the help. The problem is that all the players have access to the computer with out the judges and I knowing. Preferable I don't want them being able to delete a different players save. The website you showed me was quite confusing. I have yet to figure out how to install a choice.exe or choice.com, mainly because I didn't look much into it. But another problem I found was they can go in and change the variables.....how can I stop that? I don't want another exe compiler, because lately they have not been the best. Thanks tho.
« Last Edit: September 22, 2014, 12:56:05 PM by shiverbob »
Pff computers are easy, math is hard.

Lemonilla



    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: Choice help
« Reply #3 on: September 22, 2014, 02:23:02 PM »
To install choice.exe, simply place it in the same folder as the batch file that uses it (the working directory).  Or you can add the pathway to choice.exe's containing folder to the end of the %path% variable separating with a semi-colon (;).  You could save all of your files as read-only, but that is changeable.  Ultimately you will sooner or later have to assume that the testers are too stupid to change the game, or are honourable enough not to.
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

shiverbob

    Topic Starter


    Beginner

    Thanked: 1
    • Yes
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows XP
Re: Choice help
« Reply #4 on: September 22, 2014, 05:25:51 PM »
Thanks for the help, most of them aren't smart enough and they are 6 and then the teachers are going to play.  :) I ran into another problem today, I didnt know how to save a file in a different place. Like all the game parts are in a folder then in that folder are supposed the save games. I would have look it up but was going some where to watch someone play. Any help appreciated.
Pff computers are easy, math is hard.

Lemonilla



    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: Choice help
« Reply #5 on: September 22, 2014, 06:09:20 PM »
Not sure what you mean, but to save in a different place simply change the redirect.
Code: [Select]
set >saves\save1.txt
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

shiverbob

    Topic Starter


    Beginner

    Thanked: 1
    • Yes
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows XP
Re: Choice help
« Reply #6 on: September 23, 2014, 03:59:38 PM »
This is probably a bad question how can I check if a folder exists in a the save game folder and if it not make one for that player and put their save file in it?
Pff computers are easy, math is hard.

Lemonilla



    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: Choice help
« Reply #7 on: September 23, 2014, 05:26:34 PM »
For the sake of example, our folder we are checking is going to be called "folder1"

Code: [Select]
if not exist saves\folder1 md saves\folder1
set >saves\folder1\save.txt

Folder1 can be replaced with the player's username or some such if you so desired.  Simply replace it with the variable.
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: Choice help
« Reply #8 on: September 24, 2014, 06:33:29 AM »
Don't really even have to bother wit the IF EXIST.  Just use the make directory command and redirect standard error to nul.   If it already exists it will just error out and it won't overwrite anything.
Code: [Select]
md saves\folder1 2>nul

Lemonilla



    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: Choice help
« Reply #9 on: September 24, 2014, 01:11:56 PM »
It works, I personally dont like it though.  It reminds me of:
Code: (psudojava) [Select]
For (int a; a < 100; a++) {
Try {
Print(table[a]);
} catch outofboundsexeption e {
Return;
}
}
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

shiverbob

    Topic Starter


    Beginner

    Thanked: 1
    • Yes
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows XP
Re: Choice help
« Reply #10 on: September 24, 2014, 04:22:56 PM »
Thanks and what does that do?
Pff computers are easy, math is hard.

Lemonilla



    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: Choice help
« Reply #11 on: September 24, 2014, 05:15:38 PM »
It prints all values in the array table in java.  Its just not a conventional way to weite it.  It forces an error and breaks after the error.
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: Choice help
« Reply #12 on: September 24, 2014, 06:16:24 PM »
It prints all values in the array table in java.  Its just not a conventional way to weite it.  It forces an error and breaks after the error.

it's a bit of a poor example because it is doing something completely different from what foxidrive is suggesting. The direct equivalent in Java would be:

Code: [Select]
file.mkdir(sPath);



the only error that can occur that cannot occur in your version is a "directory already exists" error. Checking for existence first is redundant. in an Actual application tasks involving files should check that the file exists first, but if it is ensuring that it exists, than the item already existing is not an error.
I was trying to dereference Null Pointers before it was cool.

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: Choice help
« Reply #13 on: September 24, 2014, 09:39:47 PM »
completely different from what foxidrive Squashman is suggesting.

:D



I do agree that Squashman's code is what I'd use too.

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: Choice help
« Reply #14 on: September 25, 2014, 06:32:57 AM »
:D



I do agree that Squashman's code is what I'd use too.
Not sure how people confuse us.  We look nothing alike!  ;D

Lemonilla



    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: Choice help
« Reply #15 on: September 25, 2014, 07:17:15 AM »
You both post a lot, and people who dont frequent the board assume that there is only one of you. Maybe?
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: Choice help
« Reply #16 on: September 25, 2014, 10:33:31 AM »
Not sure how people confuse us.  We look nothing alike!  ;D

I've just metamorphosed.   

No Dr Who, I'm shocked!

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: Choice help
« Reply #17 on: September 25, 2014, 12:00:34 PM »
Both your nicknames have 9 letters, obviously that must be the cause.  ;D
I was trying to dereference Null Pointers before it was cool.

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: Choice help
« Reply #18 on: September 26, 2014, 03:38:53 AM »
Both your nicknames have 9 letters, obviously that must be the cause.  ;D

Hmmm... Lemonilla has 9 characters too. :D

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: Choice help
« Reply #19 on: September 26, 2014, 07:30:34 AM »
Hmmm... Lemonilla has 9 characters too. :D
Sounds like the start of a conspiracy!!!!  :o

shiverbob

    Topic Starter


    Beginner

    Thanked: 1
    • Yes
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows XP
Re: Choice help
« Reply #20 on: September 26, 2014, 08:29:01 AM »
Thanks but what I did

if exist  file name (
set >file name
) else (
md filename
set >filename
)
Pff computers are easy, math is hard.

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: Choice help
« Reply #21 on: September 26, 2014, 10:05:11 AM »
Foxidrive,
Didn't we have a discussion on DosTips about IF EXIST and what happens should you be checking if a file exists versus a folder existing.  I thought I remember something weird can happen.

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: Choice help
« Reply #22 on: September 26, 2014, 10:32:16 AM »
Foxidrive,
Didn't we have a discussion on DosTips about IF EXIST and what happens should you be checking if a file exists versus a folder existing.  I thought I remember something weird can happen.

One issue is checking if a folder exists in a UNC path - it fails.


You can use this to check for a folder first on a local drive, and take action on the result.

if exist "filename\" echo it's a folder