another game problem

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
iPires
Newbie
Posts: 9
Joined: Mon Jul 02, 2007 1:54 pm

another game problem

Post by iPires »

so i was tryin to do nother game
and i did it
it is a game where the player has to give the orders of what to do in the city (build houses, etc...)

and the game ends when the conditions of the people (if they are happy, like when i build roads their condition goes up :D) is = 15

but my problem is that when i tell to build something ( like houses or roads or sewers) their conditions dont go up and their money dont go down

and yes i put money% = money% - 200 (for example)

heres the code

Code: Select all

CLS
COLOR 12
PRINT "GOVERNADOR"
COLOR 15
PRINT "FEITO POR JO?O PIRES"
PRINT
PRINT "O OBJECTIVO DESTE JOGO ? CRIAR UMA CIDADE"
PRINT "COM TODAS AS CONDI??ES PARA O BEM-ESTAR"
PRINT "DAS POPULA??ES."
PRINT
INPUT "INSERE EM [C] PARA CONTINUAR: ", press$
IF press$ = "c" THEN
CLS
COLOR 12
PRINT "GOVERNADOR"
COLOR 15
PRINT "FEITO POR JO?O PIRES"
PRINT
PRINT "COMANDOS DE JOGO"
PRINT "esgotos = CRIAR SISTEMA DE ESGOTOS"
PRINT "electricidade = CRIAR POSTES DE ELECTRICIDADE"
PRINT "gas = CRIAR CONDUTAS DE G?S"
PRINT "estradas = CRIAR ESTRADAS"
PRINT "casas = CRIAR CASAS"
PRINT "empresas = CRIAR EMPRESAS"
PRINT
INPUT "[C]ONTINUAR"; continue$
END IF
IF continue$ = "c" THEN
CLS
DO
conditions% = 0
money% = 2000
PRINT "CONDI??ES POPULA??O: "; conditions%
PRINT "DINHEIRO: "; money%
fazer: INPUT "O QUE FAZER: ", do$
        IF do$ = "esgotos" THEN
                money% = money% - 200
                conditions% = conditions% + 2
                PRINT "A POPULA??O AGORA TEM ESGOTOS."
        END IF
        IF do$ = "electricidade" THEN
                IF conditions% >= 2 THEN
                        money% = money% - 200
                        conditions% = conditions% + 1
                        PRINT "A POPULA??O AGORA TEM ELECTRICIDADE."
                ELSE
                        PRINT "PRIMEIRO TENS DE CONSTRUIR ESGOTOS."
                        GOTO fazer
                END IF
        END IF
        IF do$ = "gas" THEN
                IF conditions% >= 3 THEN
                        money% = money% - 100
                        conditions% = conditions% + 1
                        PRINT "A POPULA??O AGORA TEM G?S."
                ELSE
                        PRINT "H? COISAS QUE TENS DE CRIAR PRIMEIRO."
                        GOTO fazer
                END IF
        END IF
        IF do$ = "estradas" THEN
                IF conditions% >= 4 THEN
                        money% = money% - 400
                        conditions% = conditions% + 3
                        PRINT "A POPULA??O AGORA TEM ESTRADAS."
                ELSE
                        PRINT "H? COISAS QUE TENS DE CRIAR PRIMEIRO."
                        GOTO fazer
                END IF
        END IF
        IF do$ = "casas" THEN
                IF conditions% >= 7 THEN
                        money% = money% - 600
                        conditions% = conditions% + 5
                        PRINT "A POPULA??O AGORA TEM CASAS."
                ELSE
                        PRINT "H? COISAS QUE TENS DE CRIAR PRIMEIRO."
                        GOTO fazer
                END IF
        END IF
        IF do$ = "empresas" THEN
                IF conditions% >= 12 THEN
                        money% = money% - 350
                        conditions% = conditions% + 3
                        PRINT "A POPULA??O AGORA TEM EMPRESAS."
                ELSE
                        PRINT "H? COISAS QUE TENS DE FAZER PRIMEIRO."
                        GOTO fazer
                END IF
        END IF
        IF do$ = "sair" THEN
                END
        END IF
LOOP
IF money% < 1 THEN
        PRINT "FOSTE ? FAL?NCIA!"
        PRINT "O JOGO ACABOU!"
        END
END IF
IF conditions% = 15 THEN
        PRINT "CONSEGUISTE DAR ? POPULA??O AS CONDI??ES!"
        PRINT "GANHASTE!"
        END
END IF
END IF
PS: the print and input things
are in portuguese because im portuguese
........
'T......\
.I.......)
.I....../
.I
,I
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post by Patz QuickBASIC Creations »

Spanish and Portuguese are very similar. (of course, they're neighbors)

Your problem is this part right here:

Code: Select all

DO 
conditions% = 0 
money% = 2000 
Every time your loop goes around, it sets the conditions% and money% to their default values. Try replacing it with this..

Code: Select all

conditions% = 0 
money% = 2000
DO 
iPires
Newbie
Posts: 9
Joined: Mon Jul 02, 2007 1:54 pm

Post by iPires »

ok
thank you
:D

EDIT: the money now goes down and the condition goes up
but, i dunno why
the game doesnt end. the money even goes to negative values if i keep saying "empresas" or sumthing ...
and it has that
IF conditions% = 15 THEN
CLS
PRINT "bla bla bla ..."
END
END IF

and the same thing if the money goes down to 0 :?
........
'T......\
.I.......)
.I....../
.I
,I
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post by Patz QuickBASIC Creations »

Note: I didn't test your program since I don't know Portuguese, sorry.


That error is at the end of your code:

Code: Select all

LOOP 
IF money% < 1 THEN 
        PRINT "FOSTE ? FAL?NCIA!" 
        PRINT "O JOGO ACABOU!" 
        END 
END IF 
IF conditions% = 15 THEN 
        PRINT "CONSEGUISTE DAR ? POPULA??O AS CONDI??ES!" 
        PRINT "GANHASTE!" 
        END 
END IF 
See how the LOOP comes before you test for any conditions? You should move them to inside of the loop, so your code will check it.

Fixed:

Code: Select all

IF money% < 1 THEN 
        PRINT "FOSTE ? FAL?NCIA!" 
        PRINT "O JOGO ACABOU!" 
        END 
END IF 
IF conditions% = 15 THEN 
        PRINT "CONSEGUISTE DAR ? POPULA??O AS CONDI??ES!" 
        PRINT "GANHASTE!" 
        END 
END IF 
LOOP
iPires
Newbie
Posts: 9
Joined: Mon Jul 02, 2007 1:54 pm

Post by iPires »

thank you!! :D
it now works :P
........
'T......\
.I.......)
.I....../
.I
,I
Post Reply