“战争游戏”游戏的批处理文件输入问题

时间:2016-05-10 19:31:50

标签: batch-file cmd

如果你熟悉1983年的电影“战争游戏”,你应该记住计算机问他“我们应该玩游戏”的部分。我一直试图重新创造这个,这就是我到目前为止所拥有的。问题是在我输入密码后,命令提示符窗口关闭。有人能帮助我找到我的错误吗?

class Graph
{
    List<Node> nodes;
    List<Edge> edges;

    public Graph( ... ) { /* populate lists */ }

    public void AddEdges(params Edge[] edges) {
        foreach (var edge in edges) {
            edge.Node1.Parent = this;
            edge.Node2.Parent = this;
        }
    }
}

class Node {
    public Graph Parent { get; set; }

    public List<Node> GetNeighbours()
    {
        var neighbors = new List<Node>();
        foreach(var edge in parent.Edges) { 
            if (edge.Node1 == this && !neighbors.Contains(edge.Node2)) {
                neighbors.Add(edge.Node2);
            }
            else if (edge.Node2 == this && !neighbors.Contains(edge.Node1)) {
                neighbors.Add(edge.Node1);
            }
        }
    }
}

class Edge {
    public Node Node1 { get; set; }
    public Node Node2 { get; set; }
}

1 个答案:

答案 0 :(得分:1)

这应该是您尝试做的事情:

@echo off
title Shall We Play a Game?
color 0b

set /a "tries=3"
set "password=Joshua"
:top
echo  %tries% Tries Remaining
set /p "pass=Password: "
if "%pass%"=="%password%" (
goto correct
)
set /a "tries=%tries% -1"
if %tries%==0 (
goto penalty
)
cls
goto top
:penalty
echo CONNECTION TERMINATED
pause
exit
:correct
goto greeting

:greeting
echo Shall we play a game?
echo y/n
set /p "input="
if "%input%"=="y" goto y
if "%input%"=="n" goto n

:y
echo How about
echo Chess
echo Tic-Tac-Toe
echo Snake
echo Global Thermonuclear War
set /P "opt="
if "%opt%"=="Chess" goto Chess
if "%opt%"=="Tic-Tac-Toe" goto TicTacToe
if "%opt%"=="Snake" goto Snake
if "%opt%"=="Global Thermonuclear War" goto GlobalThermonuclearWar

:n 
echo Thats too bad! Maybe we should play some other day!
pause
exit

:chess

:tictactoe
echo Are you sure?
echo y/n
set /p response=
if %response%==y goto tictactoe1
if %response%==n goto tictactoe2

:tictactoe1
echo Go Back?
echo y/n
set /p feedback=
if %feedback%==y goto greeting
if %feedback%==n goto tictactoe2

:tictactoe2
echo testing
goto tictactoe2

您在一组中忘了​​/P几次,这用于获取用户输入。在您的set /a tries=%tries -1中,您还忘记了第二次%次尝试,这应该是set /a tries=%tries% -1。此外,如果您要对变量进行比较,则应在变量周围添加""双引号,这样可以防止脚本在变量不存在或为空时制动。您也不应该在标签中包含空格,并且应该在您的集合周围加上引号,如下所示:set "variable=value",这可以防止尾随空格进入变量