

[menu]

nomainwin
    button #1, "Nouvelle partie", [jeu], UL, 95, 20
    button #1, "Charger partie", [load], UL, 100, 50
    button #1, "Aide", [aide], UL, 135, 80
    button #1, "Crédit", [apropos], UL, 130, 110
    button #1, "Quitter", [quitter], UL, 127, 140
    open "Menu" for window_nf as #1
    print #1, "trapclose [quitter]"

    wait


    [quitter]
    close #1
    end




[jeu]
close #1
argent = 50
WindowWidth = 178
WindowHeight = 240
button #game.bt, "Manger" ,[manger],UL,1,162,80,15
button #game.bt, "Nettoyer" ,[nettoyer],UL,81,162,80,15
button #game.bt, "Vétérinaire" ,[veto],UL,1,180,80,15
button #game.bt, "Votre argent" ,[argent],UL,81,180,80,15
button #game.bt, "Votre santé",[sante],UL,1,198,80,15
button #game.bt, "Sauvegarder" ,[save],UL,81,198,80,15
graphicbox #game.grph, 1,1,160,160
open "Tamagotchi" for window as #game
#game ,"trapclose [quit]"


loadbmp "soleil","image\sun.bmp"
loadbmp "lune","image\moon.bmp"
loadbmp "fond","image\fond.bmp"
loadbmp "neutre","image\neutre.bmp"
loadbmp "mort","image\mort.bmp"
loadbmp "malade","image\malade.bmp"
loadbmp "smile","image\smile.bmp"
loadbmp "triste","image\triste.bmp"
loadbmp "crotte","image\crotte.bmp"

x=-100:y=-100
#game.grph ,"addsprite soleil soleil"
#game.grph ,"spritexy soleil ";x;" ";y

x=-100:y=-100
#game.grph ,"addsprite lune lune"
#game.grph ,"spritexy lune ";x;" ";y

x=0:y=80
#game.grph ,"addsprite fond fond"
#game.grph ,"spritexy fond ";x;" ";y

x=60:y=55
#game.grph ,"addsprite neutre neutre"
#game.grph ,"spritexy neutre ";x;" ";y
#game.grph ,"addsprite mort mort"
#game.grph ,"spritexy mort ";x;" ";y
#game.grph ,"addsprite malade malade"
#game.grph ,"spritexy malade ";x;" ";y
#game.grph ,"addsprite smile smile"
#game.grph ,"spritexy smile ";x;" ";y
#game.grph ,"addsprite triste triste"
#game.grph ,"spritexy triste ";x;" ";y

y=y+50
#game.grph ,"addsprite crotte crotte"
#game.grph ,"spritexy crotte ";x;" ";y

salete = 0
nourriture = 50
sante = 100
time = 0

delaiProchaineCrotte = int(rnd(0)*20 + (120 - nourriture))


#game.grph, "spritevisible neutre on"
#game.grph, "spritevisible mort off"
#game.grph, "spritevisible malade off"
#game.grph, "spritevisible smile off"
#game.grph, "spritevisible triste off"
#game.grph, "spritevisible crotte off"

timer 1000 , [timer]
wait

[quit]
close #game
end

[timer]

time = time + 1

if sante > 0 then
        delaiProchaineCrotte =  delaiProchaineCrotte - 1
    if delaiProchaineCrotte <= 0 then
        delaiProchaineCrotte = int(rnd(0)*20 + (120 - nourriture))

       salete = salete + 2
    end if

    sante = sante - salete/5

    nourriture = nourriture - 0.25
    if nourriture < 0 then nourriture = 0
    if nourriture > 100 then nourriture = 100

    sante = sante + (10-abs(50 - nourriture)) / 25

    if sante < 0 then sante = 0
    if sante > 100 then sante = 100
end if

select case
    case sante = 0
        #game.grph, "spritevisible neutre off"
        #game.grph, "spritevisible mort on"
        #game.grph, "spritevisible malade off"
        #game.grph, "spritevisible smile off"
        #game.grph, "spritevisible triste off"
    case sante < 75
        #game.grph, "spritevisible neutre off"
        #game.grph, "spritevisible mort off"
        #game.grph, "spritevisible malade on"
        #game.grph, "spritevisible smile off"
        #game.grph, "spritevisible triste off"
    case nourriture < 30 or salete >= 4
        #game.grph, "spritevisible neutre off"
        #game.grph, "spritevisible mort off"
        #game.grph, "spritevisible malade off"
        #game.grph, "spritevisible smile off"
        #game.grph, "spritevisible triste on"
    case nourriture > 40 and nourriture < 60 and salete = 0
        #game.grph, "spritevisible neutre off"
        #game.grph, "spritevisible mort off"
        #game.grph, "spritevisible malade off"
        #game.grph, "spritevisible smile on"
        #game.grph, "spritevisible triste off"
    case else
        #game.grph, "spritevisible neutre on"
        #game.grph, "spritevisible mort off"
        #game.grph, "spritevisible malade off"
        #game.grph, "spritevisible smile off"
        #game.grph, "spritevisible triste off"
end select

soleilx = 60 + cos(2.25 * time * 3.14 / 180) * 50
soleily = 60 + sin(2.25 * time * 3.14 / 180) * 50
#game.grph ,"spritexy soleil ";soleilx;" ";soleily

lunex = 60 + cos((2.25 * time + 180) * 3.14 / 180) * 50
luney = 60 + sin((2.25 * time + 180) * 3.14 / 180) * 50
#game.grph ,"spritexy lune ";lunex;" ";luney

if salete = 0 then
    #game.grph, "spritevisible crotte off"
else
    #game.grph, "spritevisible crotte on"
end if

#game.grph ,"drawsprites "
wait


[manger]
nourriture = nourriture + 5
salete = salete + 0.5
argent = argent - 10
wait

[nettoyer]
salete = 0
argent = argent + 15
wait

[veto]

argent = argent - 20
sante = sante + 20

wait

[argent]
    s$ = " Votre argent est de  : "
    s2$ = " ";argent;" "
    WindowWidth = 384
    WindowHeight = 336
    groupbox #about2.frame, "Argent", 22, 16, 336, 240
    statictext #about2.text, "", 38, 46, 304, 200
    button #about2.default, "Ok", [about2Ok], UL, 126, 270, 122, 25
    open "A propos" for dialog_nf_modal as #about2
    #about2, "trapclose [aboutOk]"
    #about2, "font ms_sans_serif 10"
    #about2.frame, "!font ms_sans_serif 12"
    #about2.text, s$ ; s2$ 
    wait

[about2Ok]
    close #about2
wait

[aboutOk]
close #about2
wait

[sante]
    s$ = " Votre santé est de : "
    s2$ = " ";sante;" "
    WindowWidth = 384
    WindowHeight = 336
    groupbox #about3.frame, "Santé", 22, 16, 336, 240
    statictext #about3.text, "", 38, 46, 304, 200
    button #about3.default, "Ok", [about3Ok], UL, 126, 270, 122, 25
    open "A propos" for dialog_nf_modal as #about3
    #about3, "trapclose [aboutOk2]"
    #about3, "font ms_sans_serif 10"
    #about3.frame, "!font ms_sans_serif 12"
    #about3.text, s$ ; s2$ 
    wait

[about3Ok]
    close #about3
wait

[aboutOk2]
close #about3
wait

[save]

open "santer.txt" for output as #1
print #1,sante
close #1


open "argent.txt" for output as #1
print #1,argent
close #1
close #game
end


[load]
close #1

open "santer.txt" for input as #monFichier

while eof(#monFichier) <> -1
    input #monFichier,vrais
    print vrais
wend

close #monFichier

open "argent.txt" for input as #argent

while eof(#argent) <> -1
    input #argent,vrai
    print vrai
wend

close #argent



argent = vrai
sante = vrais
WindowWidth = 178
WindowHeight = 240
button #game.bt, "Manger" ,[mangert],UL,1,162,80,15
button #game.bt, "Nettoyer" ,[nettoyert],UL,81,162,80,15
button #game.bt, "Vétérinaire" ,[vetot],UL,1,180,80,15
button #game.bt, "Votre argent" ,[argentt],UL,81,180,80,15
button #game.bt, "Votre santé",[santet],UL,1,198,80,15
button #game.bt, "Sauvegarder" ,[savet],UL,81,198,80,15
graphicbox #game.grph, 1,1,160,160
open "Tamagotchi" for window as #game
#game ,"trapclose [quitt]"


loadbmp "soleil","image\sun.bmp"
loadbmp "lune","image\moon.bmp"
loadbmp "fond","image\fond.bmp"
loadbmp "neutre","image\neutre.bmp"
loadbmp "mort","image\mort.bmp"
loadbmp "malade","image\malade.bmp"
loadbmp "smile","image\smile.bmp"
loadbmp "triste","image\triste.bmp"
loadbmp "crotte","image\crotte.bmp"

x=-100:y=-100
#game.grph ,"addsprite soleil soleil"
#game.grph ,"spritexy soleil ";x;" ";y

x=-100:y=-100
#game.grph ,"addsprite lune lune"
#game.grph ,"spritexy lune ";x;" ";y

x=0:y=80
#game.grph ,"addsprite fond fond"
#game.grph ,"spritexy fond ";x;" ";y

x=60:y=55
#game.grph ,"addsprite neutre neutre"
#game.grph ,"spritexy neutre ";x;" ";y
#game.grph ,"addsprite mort mort"
#game.grph ,"spritexy mort ";x;" ";y
#game.grph ,"addsprite malade malade"
#game.grph ,"spritexy malade ";x;" ";y
#game.grph ,"addsprite smile smile"
#game.grph ,"spritexy smile ";x;" ";y
#game.grph ,"addsprite triste triste"
#game.grph ,"spritexy triste ";x;" ";y

y=y+50
#game.grph ,"addsprite crotte crotte"
#game.grph ,"spritexy crotte ";x;" ";y

salete = 0
nourriture = 50
time = 0

delaiProchaineCrotte = int(rnd(0)*20 + (120 - nourriture))


#game.grph, "spritevisible neutre on"
#game.grph, "spritevisible mort off"
#game.grph, "spritevisible malade off"
#game.grph, "spritevisible smile off"
#game.grph, "spritevisible triste off"
#game.grph, "spritevisible crotte off"

timer 1000 , [timert]
wait

[quitt]
close #game
end

[timert]

time = time + 1

if sante > 0 then
        delaiProchaineCrotte =  delaiProchaineCrotte - 1
    if delaiProchaineCrotte <= 0 then
        delaiProchaineCrotte = int(rnd(0)*20 + (120 - nourriture))

       salete = salete + 2
    end if

    sante = sante - salete/5

    nourriture = nourriture - 0.25
    if nourriture < 0 then nourriture = 0
    if nourriture > 100 then nourriture = 100

    sante = sante + (10-abs(50 - nourriture)) / 25

    if sante < 0 then sante = 0
    if sante > 100 then sante = 100
end if

select case
    case sante = 0
        #game.grph, "spritevisible neutre off"
        #game.grph, "spritevisible mort on"
        #game.grph, "spritevisible malade off"
        #game.grph, "spritevisible smile off"
        #game.grph, "spritevisible triste off"
    case sante < 75
        #game.grph, "spritevisible neutre off"
        #game.grph, "spritevisible mort off"
        #game.grph, "spritevisible malade on"
        #game.grph, "spritevisible smile off"
        #game.grph, "spritevisible triste off"
    case nourriture < 30 or salete >= 4
        #game.grph, "spritevisible neutre off"
        #game.grph, "spritevisible mort off"
        #game.grph, "spritevisible malade off"
        #game.grph, "spritevisible smile off"
        #game.grph, "spritevisible triste on"
    case nourriture > 40 and nourriture < 60 and salete = 0
        #game.grph, "spritevisible neutre off"
        #game.grph, "spritevisible mort off"
        #game.grph, "spritevisible malade off"
        #game.grph, "spritevisible smile on"
        #game.grph, "spritevisible triste off"
    case else
        #game.grph, "spritevisible neutre on"
        #game.grph, "spritevisible mort off"
        #game.grph, "spritevisible malade off"
        #game.grph, "spritevisible smile off"
        #game.grph, "spritevisible triste off"
end select

soleilx = 60 + cos(2.25 * time * 3.14 / 180) * 50
soleily = 60 + sin(2.25 * time * 3.14 / 180) * 50
#game.grph ,"spritexy soleil ";soleilx;" ";soleily

lunex = 60 + cos((2.25 * time + 180) * 3.14 / 180) * 50
luney = 60 + sin((2.25 * time + 180) * 3.14 / 180) * 50
#game.grph ,"spritexy lune ";lunex;" ";luney

if salete = 0 then
    #game.grph, "spritevisible crotte off"
else
    #game.grph, "spritevisible crotte on"
end if

#game.grph ,"drawsprites "
wait


[mangert]
nourriture = nourriture + 5
salete = salete + 0.5
argent = argent - 10
wait

[nettoyert]
salete = 0
argent = argent + 15
wait
[vetot]

argent = argent - 20
sante = sante + 20

wait

[argentt]
    s$ = " Votre argent est de  : "
    s2$ = " ";argent;" "
    WindowWidth = 384
    WindowHeight = 336
    groupbox #about2.frame, "Argent", 22, 16, 336, 240
    statictext #about2.text, "", 38, 46, 304, 200
    button #about2.default, "Ok", [about2Okt], UL, 126, 270, 122, 25
    open "A propos" for dialog_nf_modal as #about2
    #about2, "trapclose [aboutOkt]"
    #about2, "font ms_sans_serif 10"
    #about2.frame, "!font ms_sans_serif 12"
    #about2.text, s$ ; s2$ 
    wait

[about2Okt]
    close #about2
wait

[aboutOkt]
close #about2
wait

[santet]
    s$ = " Votre santé est de : "
    s2$ = " ";sante;" "
    WindowWidth = 384
    WindowHeight = 336
    groupbox #about3.frame, "Santé", 22, 16, 336, 240
    statictext #about3.text, "", 38, 46, 304, 200
    button #about3.default, "Ok", [about3Okt], UL, 126, 270, 122, 25
    open "A propos" for dialog_nf_modal as #about3
    #about3, "trapclose [aboutOk2t]"
    #about3, "font ms_sans_serif 10"
    #about3.frame, "!font ms_sans_serif 12"
    #about3.text, s$ ; s2$ 
    wait

[about3Okt]
    close #about3
wait

[aboutOk2t]
close #about3
wait

[savet]

open "santer.txt" for output as #1
print #1,sante
close #1


open "argent.txt" for output as #1
print #1,argent
close #1
close #game
end


