2015-12-11 7 views
-1
program Adventure; 
uses Crt; 
var 
    guess : integer ; 
    begin 
    TextColor(White); 
    TextBackground(Green); 
    writeln('Adventure'); 
    writeln('You are an adventurer. You are having an adventure in the forrest but you get lost in the way. You need to answer questions to escape from the forrest.'); 
    writeln('The game will start now.'); 

    writeln('Question1: You are hungry now. You find a mushroom. Will you eat it?'); 
    writeln('Press ',1,'=yes, ',2,'=no.'); 
    readln(guess); 

    if guess = 1 then 
     begin 
     {condition 1} 
     writeln('It is a toxic mushroom. You died.'); 
     writeln('This is the end of the game.'); 
     readln; 
     end 

    else if guess = 2 then 
    begin 
     {condition 2} 
     writeln('You do not eat the mushroom but you catch some fishes in the river.'); 
     writeln('You are full now and have energy to find the way to escape frome forest.'); 
     writeln('Question2:You see a bear and it keeps follow you. Will you climb up to a tree?'); 
     writeln('Press ',1,'=yes, ',2,'=no.'); 
     readln(guess); 

    if guess = 2 then 
    begin 
     {condition 1} 
     writeln('You are killed by the bear.'); 
     writeln('This is the end of the game.'); 
     readln; 
    end 

    else if guess = 1 then 
    begin 
     {condition 2} 
     writeln('You escape from the bear.'); 
     writeln('Question3:Will you get in the cave?'); 
     writeln('Press ',1,'=yes, ',2,'=no.'); 
     readln(guess); 
     readln; 

    if guess = 1 then 
    begin 
     {condition 1} 
     writeln('You are killed by the lion which live in the cave'); 
     writeln('This is the end of the game.'); 
     readln; 
    end 

    else if guess = 2 then 
    begin 
     {condition 2} 
     writeln('Although you get wet, but you find the way to escape from the forrest finally.'); 
     writeln('Congratulations!'); 
     writeln('This is the end of the game.'); 
     readln; 
    end; 
end. 

Это мини-игра о приключениях. Также программа не может отображать ожидаемый ответ. Ошибка pascal выбрасывается: Fatal: ошибка синтаксиса; ожидаемый, но. найденный. Я думал, что, может быть, моя логика ошибочна. Спасибо;)Fatal: ошибка синтаксиса; ожидаемый, но.

+1

Структуры блоков для операторов 'if' смещены. Проверьте все пар 'begin' и' end'. Код очень странный, поскольку он продолжает перепроверять, если 'guess = 1' или' guess = 2'. – lurker

+0

У вас есть пара отсутствующих команд 'end;' в блоках, где у вас есть 'begin'. Если вы научитесь правильно отступать от своего кода, места, где они отсутствуют, будут очевидны. Каждое использование 'begin' должно иметь соответствующий« конец ». –

+0

В конце инструкции if из if, если вы не должны иметь ';'. – Tim

ответ

1

Вам не хватало два «конца»; заявления. Я переформатировал, чтобы показать проблему (и решение).

program Adventure; 
uses Crt; 
var 
    guess : integer ; 
begin 
    TextColor(White); 
    TextBackground(Green); 
    writeln('Adventure'); 
    writeln('You are an adventurer. You are having an adventure in the forrest but you get lost in the way. You need to answer questions to escape from the forrest.'); 
    writeln('The game will start now.'); 

    writeln('Question1: You are hungry now. You find a mushroom. Will you eat it?'); 
    writeln('Press ',1,'=yes, ',2,'=no.'); 
    readln(guess); 

    if guess = 1 then 
    begin 
     {condition 1} 
     writeln('It is a toxic mushroom. You died.'); 
     writeln('This is the end of the game.'); 
     readln; 
    end 

    else if guess = 2 then 
    begin 
     {condition 2} 
     writeln('You do not eat the mushroom but you catch some fishes in the river.'); 
     writeln('You are full now and have energy to find the way to escape frome forest.'); 
     writeln('Question2:You see a bear and it keeps follow you. Will you climb up to a tree?'); 
     writeln('Press ',1,'=yes, ',2,'=no.'); 
     readln(guess); 

     if guess = 2 then 
     begin 
      {condition 1} 
      writeln('You are killed by the bear.'); 
      writeln('This is the end of the game.'); 
      readln; 
     end 

     else if guess = 1 then 
     begin 
      {condition 2} 
      writeln('You escape from the bear.'); 
      writeln('Question3:Will you get in the cave?'); 
      writeln('Press ',1,'=yes, ',2,'=no.'); 
      readln(guess); 
      readln; 

      if guess = 1 then 
      begin 
      {condition 1} 
      writeln('You are killed by the lion which live in the cave'); 
      writeln('This is the end of the game.'); 
      readln; 
      end 

      else if guess = 2 then 
      begin 
      {condition 2} 
      writeln('Although you get wet, but you find the way to escape from the forrest finally.'); 
      writeln('Congratulations!'); 
      writeln('This is the end of the game.'); 
      readln; 
      end; 
     end; 
    end; 
end. 
Смежные вопросы