Errors with code in a Simple Game

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
HISCORECODES
Posts: 3
Joined: 25 Mar 2016 13:58

Errors with code in a Simple Game

#1 Post by HISCORECODES » 25 Mar 2016 14:08

Hey, guys. I'm new to DOS and am trying to program a simple game. I'm trying to get it to where when I press a key, "0" will move without me having to press enter. Here's my code:
:x1y1
color 70
cls
echo ================+======
echo =======================
echo =======================
echo =======-============-==
echo =======================
echo =======================
echo 0======================
set /pinput0=Enter
if %input0% equ s goto x1y6
if %input0% equ d goto x2y1
if %input0% equ w goto x1y2
if %input0% equ a goto x23y1

as you can see, when I press a,s,w, or d, I would have to press enter before it goes to the next coordinates. Can you please help?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Simple Game

#2 Post by foxidrive » 25 Mar 2016 16:50

You can use the choice command, or you can examine a snake game in a bat file that uses very advanced techniques to provide movement, using the xcopy command.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: SNAKE.BAT - A pure native Windows batch implementation of the classic game
:: ------------------------------------------------------------------------------
:: Written by Dave Benham with some debugging help and technique pointers from
:: DosTips users - See viewtopic.php?f=3&t=4741

HISCORECODES
Posts: 3
Joined: 25 Mar 2016 13:58

Re: Simple Game

#3 Post by HISCORECODES » 03 Apr 2016 13:18

Okay, so I changed my approach. The problem? My game won't even open.
@echo off
title MOLE!
goto mainmenu

:mainmenu
cls
color 0a
echo MM MM OOO L EEEEE !!!!
echo M M M M O O L E !!!!
echo M M M M O O L EEEE !!!!
echo M M M O O L E !!
echo M M O O L E
echo M M OOO LLLL EEEEE !!
echo.
echo.
echo Would you like to play? (y/n)
set /pchoice1=
if %choice1% equ y goto drawmap
if %choice1% equ n exit
goto mainmenu

:drawmap
set x1=1
set x2=2
set x3=3
set y1=1
set y2=2
set y3=3
echo ■■■■■
echo ■ ■
echo ■@ ■
echo ■ ■
echo ■■■■■
echo ♥♥♥
pause

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Simple Game

#4 Post by foxidrive » 05 Apr 2016 08:12

HISCORECODES wrote:set /pchoice1=


The first error is a space missing here.

EDIT: This is a mistake on my part - it looks very odd but it works fine.

HISCORECODES
Posts: 3
Joined: 25 Mar 2016 13:58

Re: Simple Game

#5 Post by HISCORECODES » 16 Apr 2016 15:11

foxidrive wrote:
HISCORECODES wrote:set /pchoice1=


The first error is a space missing here.



Thanks. Also, when I try to save it, I have to save it in Unicode to use my ASCII characters. When I try to open a Unicode batch file, it doesn't work. :/

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Simple Game

#6 Post by foxidrive » 17 Apr 2016 04:18

HISCORECODES wrote:When I try to open a Unicode batch file, it doesn't work. :/


CMD.exe doesn't have a lot of Unicode support.

There is a switch you can read about in the help.

Code: Select all

cmd /?


Using the type command with a file containing the text may be part of the solution.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Simple Game

#7 Post by foxidrive » 17 Apr 2016 13:59

foxidrive wrote:
HISCORECODES wrote:set /pchoice1=


The first error is a space missing here.


I was wrong above - it was pointed out to me that although it looks very odd, it works fine.

With regard to the characters in your map: the codepage can make a difference in displaying certain characters: the code page changes in various areas of the world as the character sets change.

You can display alternate characters with the right codepage in force, and there are characters that change appearance from what you see in your text editor, to what you see on your screen when the batch file is running. This means that your batch file map looks wrong in your editor, but when the script is run the characters are correct.

This is the help for the chcp change codepage command, and I believe there is a codepage for unicode.
65000 and 65001 according to this page https://en.wikipedia.org/wiki/Windows_code_page

Code: Select all

q:\>chcp
Active code page: 850

q:\>chcp /?
Displays or sets the active code page number.

CHCP [nnn]

  nnn   Specifies a code page number.

Type CHCP without a parameter to display the active code page number.


You can thank penpen for my updated reply.

Post Reply