Results 1 to 10 of 15

Thread: Glitch on my game

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    After changing Inc in your code to Income the game seems to work for me. I belive there is a bug in your game thou. Everytime I increased my security one of the prisoners escaped. I tried tracking this bug but had no luck. The reason for this is that your code is badly organized. Or atleast it sems to me likeway.
    So here are some recomendations for beter code organization.
    1. When creatung procedures, functions etc. try to use selfexplanatory names and not etc and etc1.
    2. Try to avoid writing same code in multiple parts of your program. You can do this by moving parts of code wich repeat several times into procedures. This wil make your code more readable and wil save you some time for not needint to type same code multiple types.
    3. When using if conditional clauses you can check for multiple parameters if needed. Below is part of your code where you are checking the value for rnd1 and if it is either 1 or 2 you then cal virtualy the same code.
    Code:
    if (rnd1 = 1) then
    begin
        clrscr;
        turn := turn + 1;
        etc1;
        repeat
            write(pris,
              ' prisoners are hungry. Feed them? (Y/N): ');
            readln(key);
            key := upcase(key);
        until (key = 'Y') or (key = 'N');    if (key = 'N') then
        begin
            stats := stats - 2;
            writeln('--------------------------------------');
            writeln('The prisoners are not satisfied for today!');
            writeln('Unsatisfied prisoners count: ', stats);
        end;
        if (key = 'Y') then
        begin
            stats := stats + 2;
            writeln('--------------------------------------');
            writeln('Good job! the prisoners are fullfiled for today!');
            bank := bank - 150;
            writeln('-150 cash');
            writeln('Satisfied prisoners count: ', stats);
            bank := bank + income;
            etc;
        end;
    end;
    if (rnd1 = 2) then
    begin
        turn := turn + 1;
        clrscr;
        etc1;
        repeat
            write(pris - 1,
              ' prisoner is hungry. Feed him? (Y/N): ');
            readln(key);
            key := upcase(key);
        until (key = 'Y') or (key = 'N');
        if (key = 'N') then
        begin
            stats := stats - 1;
            writeln('--------------------------------------');
            writeln('The prisoner is not satisfied for today!');
            writeln('Unsatisfied prisoners count: ', stats);
        end;
        if (key = 'Y') then
        begin
            stats := stats + 1;
            writeln('--------------------------------------');
            writeln('Good job! the prisoners are fullfiled for today!');
            bank := bank - 100;
            writeln('-100 cash');
            writeln('Satisfied prisoners count: ', stats);
            bank := bank + income;
            etc;
        end;
    end;
    This could be fixed by using one if clause and checking for two parameters like this:
    Code:
    if (rnd1 = 1) or (rnd1 = 2) then
    begin
        clrscr;
        turn := turn + 1;
        etc1;
        repeat
            write(pris,
              ' prisoners are hungry. Feed them? (Y/N): ');
            readln(key);
            key := upcase(key);
        until (key = 'Y') or (key = 'N');
        if (key = 'N') then
        begin
            stats := stats - 2;
            writeln('--------------------------------------');
            writeln('The prisoners are not satisfied for today!');
            writeln('Unsatisfied prisoners count: ', stats);
        end;
        if (key = 'Y') then
        begin
            stats := stats + 2;
            writeln('--------------------------------------');
            writeln('Good job! the prisoners are fullfiled for today!');
            bank := bank - 150;
            writeln('-150 cash');
            writeln('Satisfied prisoners count: ', stats);
            bank := bank + income;
            etc;
        end;
    end;
    EDIT:
    @Will
    The code button is only available in Advanced mode for posting reply and not for quick reply mode. Could this be changed?

    @smexhy
    You can acces advanced post mode first by clicking reply inder the post and then on Go Advanced button below the text box.
    Last edited by SilverWarior; 07-04-2012 at 08:32 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •