Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
N7 version 24.02.16 released
#1
Here comes a new release with the online high-score library (ohs), updated since I posted it in a thread a while ago, and the sfx library. 

2024-02-16
  • The compiler and the generated programs are from now and on 64 bit. libgcc_s_dw2-1.dll is no longer required for the programs to run. ibwinpthread-1.dll and libportaudio.dll are still required but have been replaced with 64 bit versions
  • Added the sfx library for creating sound effects with two examples in examples/sfx_library
  • Added the ohs library for online high-score lists with two examples in examples/ohs_library
  • Added some programs by members of the naalaa forum to examples/other
  • Fixed an issue with 'draw pixel'

https://naalaa.com/n7/N7_240216.zip
Reply
#2
Had some concern with the new version. At first, it failed to run. Apparently, my installed 32 bit version of Wine, would not run the new 64 bit version of N7. Problem solved by installing the 64 bit version of wine.
Logic is the beginning of wisdom.
Reply
#3
(02-18-2024, 10:12 AM)johnno56 Wrote: Had some concern with the new version. At first, it failed to run. Apparently, my installed 32 bit version of Wine, would not run the new 64 bit version of N7. Problem solved by installing the 64 bit version of wine.

I'm glad you could solve it!
Reply
#4
(02-18-2024, 10:12 AM)johnno56 Wrote: Had some concern with the new version. At first, it failed to run. Apparently, my installed 32 bit version of Wine, would not run the new 64 bit version of N7. Problem solved by installing the 64 bit version of wine.

If I remember correctly, you once reported that every n7 program creates two windows (a console window and a graphical window) even if the code includes a '#win32' flag. Is that still the case?
Reply
#5
Just a small test, so far so good

Code:
#win32

set window "test",320,160

do
    set color 255,0,0
    pln "write on console"
    wln "write on window"
    draw rect 10,10,50,50,1
    wait 1
until keydown(KEY_ESCAPE)

(02-18-2024, 10:51 AM)Marcus Wrote: ...
If I remember correctly, you once reported that every n7 program creates two windows (a console window and a graphical window) even if the code includes a '#win32' flag. Is that still the case?

I have a case here where n7 created two windows ( console and graphic ) even #win32 flag there
I ran the code in N7 version 24.02.16 released

Code:
#win32
'=======================================================
'              MASTERMIND simplified
'
' The board has 8 rows and 4 circles in each row
' - 8 rows      : eight chances to win the game
' - 4 circles   : guess what color

' There are 8 possible colors to choose.
' To help you win the game, watch the colored hints :
' - GREEN, correct in color and position
' - RED, color in wrong position
'
' Controls
' - Use Mouse and Left Click on the color
'   Your mouse is only visible on 'Choose' Layout
' - ESC to quit
' - F5 is a secret key to preview solution
'
'=======================================================

'-----------------
' INITIALIZATION
'-----------------
set window "MASTERMIND",450,480,false
set redraw off

visible cBlack      = [0,0,0]        'black
visible cWhite      = [255,255,255]  'white
visible cRed        = [255,0,0]      'red
visible cGreen      = [0,255,0]      'green
visible cGray       = [192,192,192]  'light gray
visible cColor      = []             'hold some colors
visible colorPaint  = []             'hold random colors to choose from
visible chosenColor = 10             'color which is chosen by mouse's left click
visible c  = -1                      'just a counter
visible countGreen  = []             'count how many correct answers in one line

'Sprite Class Definition
Sprite =
[
    '---Properties---
    'position (x,y) and radius (r1,r2). code is color's code
    x:0,y:0,r1:10,r2:14,code:0,     
       
    '---Methods---
    'Pos      : set sprite's position
    'Create   : create circle on certain coordinate, with certain color, and certain size
    'ColorIt  : only color and certain size
    Pos       : function(posX,posY);this.x=posX;this.y=posY;endfunc,
    Create    : function(posX,posY,rgb,scale)
                    this.Pos(posX,posY)
                    set color cBlack;draw ellipse this.x,this.y,scale*this.r2,scale*this.r2,1
                    set color rgb;draw ellipse this.x,this.y,scale*this.r1,scale*this.r1,1
                endfunc,
    ColorIt   : function(rgb,scale)
                    set color cBlack;draw ellipse this.x,this.y,scale*this.r2,scale*this.r2,1
                    set color rgb;draw ellipse this.x,this.y,scale*this.r1,scale*this.r1,1
                endfunc                     
]

visible Guess       = fill(Sprite,32)  '32 guess objects
visible Hint        = fill(Sprite,32)  '32 hints objects
visible Paint       = fill(Sprite,8)   '8 possible colors
visible Solution    = fill(Sprite,4)   'Solution to Mastermind

InitialValue()
Layout()

'--------------
' MAIN PROGRAM
'--------------
do
    if keydown(KEY_F5) then ShowSolution("Solution") 'secret key F5 to show solution
    LeftClick()
    redraw
    wait 1
until keydown(KEY_ESCAPE)


'-----------
' FUNCTIONS
'-----------
function InitialValue()     
    '8 possible colors       
    cColor[0]   = [225,29,72]   'red
    cColor[1]   = [59,130,246]  'blue
    cColor[2]   = [34,197,94]   'green
    cColor[3]   = [249,115,22]  'orange
    cColor[4]   = [124,58,137]  'purple
    cColor[5]   = [146,64,14]   'brown
    cColor[6]   = [148,168,184] 'gray
    cColor[7]   = [251,191,36]  'yellow
    cColor[10]  = [255,255,255] 'white

    'choose random colors to be assigned to Paint objects
    randomize clock()'randomize seed
    for i = 0 to 3
        randomColor = rnd(1,8)
        select randomColor
            case 1;colorPaint[i]=cColor[0];colorPaint[i].code=0
            case 2;colorPaint[i]=cColor[1];colorPaint[i].code=1
            case 3;colorPaint[i]=cColor[2];colorPaint[i].code=2
            case 4;colorPaint[i]=cColor[3];colorPaint[i].code=3
            case 5;colorPaint[i]=cColor[4];colorPaint[i].code=4
            case 6;colorPaint[i]=cColor[5];colorPaint[i].code=5
            case 7;colorPaint[i]=cColor[6];colorPaint[i].code=6
            case 8;colorPaint[i]=cColor[7];colorPaint[i].code=7
        endsel
    next
endfunc

function Layout()
    set color cWhite;cls 'clear screen

    'Layout partition
    set color cBlack;draw line 0,40,width(primary),40 'horizontal line 
    set color cBlack;draw line 0,370,width(primary),370 'horizontal line
    set color cBlack;draw line 250,40,250,height(primary)'vertical line 
    set color cGray;draw rect 1,371,249,height(primary)-1,1 'area to choose color from            

    'Title for each part of layout   
    set color cBlack
    set caret 180,20;wln "MASTERMIND"
    set caret 50,50 ;wln "Guess"
    set caret 300,50;wln "Hints"
    set caret 50,380;wln "Choose"

    'Layout #1 (Circles for guess) and Layout #2 (Circle for hints)
    for j = 0 to 28 step 4      '8 rows
        for i = 0 to 3          'each row has 4 circles    
            Guess[i+j].Create(50+i*50,80+j*8,cColor[chosenColor],1)     'Layout #1: circles for guess
            'set color cRed; set caret 50+i*50,80+j*8;wln (i+j) 'for debugging
           
            Hint[i+j].Create(300+i*25,80+j*8,cColor[chosenColor],0.5)   'Layout #2: circles for hints
            'set color cRed; set caret 300+i*25,80+j*8;wln (i+j) 'for debugging
        next
    next
   
    'Layout #3 : Paint objects, 8 colors to choose from                                                               
    for j = 0 to 4 step 4
        for i = 0 to 3
            Paint[i+j].Create(50+i*50,410+j*8,cColor[i+j],1)
            'set color cWhite; set caret 50+i*50,410+j*8;wln (i+j) 'for debugging   
        next
    next
endfunc

function LeftClick()
        'Your mouse is only visible on 'Choose' Layout
        if mousey()>=370 and mousey()<height(primary) and mousex()<250 then
            if mousey()>=400 and mousey()<420 then

            if mousebutton(0,true) 'mouse left click
                if mousex()>=40 and mousex()<=60    then chosenColor = 0
                if mousex()>=90 and mousex()<110    then chosenColor = 1
                if mousex()>=140 and mousex()<160   then chosenColor = 2
                if mousex()>=190 and mousex()<210   then chosenColor = 3
                c = c + 1
                if c>=32 then                                             
                    set color cBlack;set caret 300,430
                    Box("Sorry, you lose")
                    ShowSolution("The solution is")
                    end
                else
                    Guess[c].code = chosenColor
                    Guess[c].ColorIt(cColor[chosenColor],1)
                    Compare(c)
                endif
            endif
           
            elseif mousey()>432 and mousey()<452 then 

            if mousebutton(0,true) 'mouse left click
                if mousex()>=40 and mousex()<=60    then chosenColor = 4
                if mousex()>=90 and mousex()<110    then chosenColor = 5
                if mousex()>=140 and mousex()<160   then chosenColor = 6
                if mousex()>=190 and mousex()<210   then chosenColor = 7
                c = c + 1
                if c>=32 then                                             
                    set color cBlack;set caret 300,430
                    Box("Sorry, you lose")
                    ShowSolution("The solution is")
                    end
                else
                    Guess[c].code = chosenColor
                    Guess[c].ColorIt(cColor[chosenColor],1)
                    Compare(c)
                endif
            endif
                       
            endif

        else
            set mouse 50,410 'set mouse position back to red circle
        endif
       
        redraw
endfunc

function ShowSolution(myText)
    set color cWhite; draw rect 251,371,width(primary)-1,height(primary)-1,1 'clear
    for i = 0 to 3
        set color cBlack; set caret 300,380;wln myText
        Solution[i].Create(300+i*35,430,colorPaint[i],1)
    next
    redraw
    wait 2000
    set color cWhite; draw rect 251,371,width(primary)-1,height(primary)-1,1 'clear
endfunc

function Compare(c)
    'Identify in whichColumn and in whichLine   
    for i = 0 to 3; if (c-i)%4=0 then whichColumn = i;next
    for i = 0 to 28 step 4
        if c>=i and c<=(i+3) then whichLine = (i/4)   
    next
       
    'RED, color in wrong position
    'GREEN, color in right position   
    for i = 0 to 3
        if i = whichColumn and Guess[c].code = colorPaint[i].code then
            Hint[c].ColorIt(cGreen,0.5)
            countGreen[whichLine] = countGreen[whichLine]+1
            if countGreen[whichLine] = 4 then
                Box("Congratulation")
                ShowSolution("You Win")
                wait 2000
                end
            endif
            break 'the same color may appear in some circles
        elseif i<>whichColumn and Guess[c].code = colorPaint[i].code then
            Hint[c].ColorIt(cRed,0.5)
        endif
    next
                                           
endfunc

function Box(myText)
    set color 200,200,200,100;draw rect 110,90,250,180,1    'shadow
    set color cGray;draw rect 100,80,250,180,1              'filled box
    set color cBlack;draw rect 100,80,250,180               'box frame
    set caret 150,130;wln myText                            'write myText
    redraw
    wait 3000
endfunc
Reply
#6
(02-18-2024, 11:31 AM)1micha.elok Wrote: Just a small test, so far so good

Code:
#win32

set window "test",320,160

do
    set color 255,0,0
    pln "write on console"
    wln "write on window"
    draw rect 10,10,50,50,1
    wait 1
until keydown(KEY_ESCAPE)

(02-18-2024, 10:51 AM)Marcus Wrote: ...
If I remember correctly, you once reported that every n7 program creates two windows (a console window and a graphical window) even if the code includes a '#win32' flag. Is that still the case?

I have a case here where n7 created two windows ( console and graphic ) even #win32 flag there
I ran the code in N7 version 24.02.16 released

Code:
#win32
'=======================================================
'              MASTERMIND simplified
'
' The board has 8 rows and 4 circles in each row
' - 8 rows      : eight chances to win the game
' - 4 circles   : guess what color

' There are 8 possible colors to choose.
' To help you win the game, watch the colored hints :
' - GREEN, correct in color and position
' - RED, color in wrong position
'
' Controls
' - Use Mouse and Left Click on the color
'   Your mouse is only visible on 'Choose' Layout
' - ESC to quit
' - F5 is a secret key to preview solution
'
'=======================================================

'-----------------
' INITIALIZATION
'-----------------
set window "MASTERMIND",450,480,false
set redraw off

visible cBlack      = [0,0,0]        'black
visible cWhite      = [255,255,255]  'white
visible cRed        = [255,0,0]      'red
visible cGreen      = [0,255,0]      'green
visible cGray       = [192,192,192]  'light gray
visible cColor      = []             'hold some colors
visible colorPaint  = []             'hold random colors to choose from
visible chosenColor = 10             'color which is chosen by mouse's left click
visible c  = -1                      'just a counter
visible countGreen  = []             'count how many correct answers in one line

'Sprite Class Definition
Sprite =
[
    '---Properties---
    'position (x,y) and radius (r1,r2). code is color's code
    x:0,y:0,r1:10,r2:14,code:0,     
       
    '---Methods---
    'Pos      : set sprite's position
    'Create   : create circle on certain coordinate, with certain color, and certain size
    'ColorIt  : only color and certain size
    Pos       : function(posX,posY);this.x=posX;this.y=posY;endfunc,
    Create    : function(posX,posY,rgb,scale)
                    this.Pos(posX,posY)
                    set color cBlack;draw ellipse this.x,this.y,scale*this.r2,scale*this.r2,1
                    set color rgb;draw ellipse this.x,this.y,scale*this.r1,scale*this.r1,1
                endfunc,
    ColorIt   : function(rgb,scale)
                    set color cBlack;draw ellipse this.x,this.y,scale*this.r2,scale*this.r2,1
                    set color rgb;draw ellipse this.x,this.y,scale*this.r1,scale*this.r1,1
                endfunc                     
]

visible Guess       = fill(Sprite,32)  '32 guess objects
visible Hint        = fill(Sprite,32)  '32 hints objects
visible Paint       = fill(Sprite,8)   '8 possible colors
visible Solution    = fill(Sprite,4)   'Solution to Mastermind

InitialValue()
Layout()

'--------------
' MAIN PROGRAM
'--------------
do
    if keydown(KEY_F5) then ShowSolution("Solution") 'secret key F5 to show solution
    LeftClick()
    redraw
    wait 1
until keydown(KEY_ESCAPE)


'-----------
' FUNCTIONS
'-----------
function InitialValue()     
    '8 possible colors       
    cColor[0]   = [225,29,72]   'red
    cColor[1]   = [59,130,246]  'blue
    cColor[2]   = [34,197,94]   'green
    cColor[3]   = [249,115,22]  'orange
    cColor[4]   = [124,58,137]  'purple
    cColor[5]   = [146,64,14]   'brown
    cColor[6]   = [148,168,184] 'gray
    cColor[7]   = [251,191,36]  'yellow
    cColor[10]  = [255,255,255] 'white

    'choose random colors to be assigned to Paint objects
    randomize clock()'randomize seed
    for i = 0 to 3
        randomColor = rnd(1,8)
        select randomColor
            case 1;colorPaint[i]=cColor[0];colorPaint[i].code=0
            case 2;colorPaint[i]=cColor[1];colorPaint[i].code=1
            case 3;colorPaint[i]=cColor[2];colorPaint[i].code=2
            case 4;colorPaint[i]=cColor[3];colorPaint[i].code=3
            case 5;colorPaint[i]=cColor[4];colorPaint[i].code=4
            case 6;colorPaint[i]=cColor[5];colorPaint[i].code=5
            case 7;colorPaint[i]=cColor[6];colorPaint[i].code=6
            case 8;colorPaint[i]=cColor[7];colorPaint[i].code=7
        endsel
    next
endfunc

function Layout()
    set color cWhite;cls 'clear screen

    'Layout partition
    set color cBlack;draw line 0,40,width(primary),40 'horizontal line 
    set color cBlack;draw line 0,370,width(primary),370 'horizontal line
    set color cBlack;draw line 250,40,250,height(primary)'vertical line 
    set color cGray;draw rect 1,371,249,height(primary)-1,1 'area to choose color from            

    'Title for each part of layout   
    set color cBlack
    set caret 180,20;wln "MASTERMIND"
    set caret 50,50 ;wln "Guess"
    set caret 300,50;wln "Hints"
    set caret 50,380;wln "Choose"

    'Layout #1 (Circles for guess) and Layout #2 (Circle for hints)
    for j = 0 to 28 step 4      '8 rows
        for i = 0 to 3          'each row has 4 circles    
            Guess[i+j].Create(50+i*50,80+j*8,cColor[chosenColor],1)     'Layout #1: circles for guess
            'set color cRed; set caret 50+i*50,80+j*8;wln (i+j) 'for debugging
           
            Hint[i+j].Create(300+i*25,80+j*8,cColor[chosenColor],0.5)   'Layout #2: circles for hints
            'set color cRed; set caret 300+i*25,80+j*8;wln (i+j) 'for debugging
        next
    next
   
    'Layout #3 : Paint objects, 8 colors to choose from                                                               
    for j = 0 to 4 step 4
        for i = 0 to 3
            Paint[i+j].Create(50+i*50,410+j*8,cColor[i+j],1)
            'set color cWhite; set caret 50+i*50,410+j*8;wln (i+j) 'for debugging   
        next
    next
endfunc

function LeftClick()
        'Your mouse is only visible on 'Choose' Layout
        if mousey()>=370 and mousey()<height(primary) and mousex()<250 then
            if mousey()>=400 and mousey()<420 then

            if mousebutton(0,true) 'mouse left click
                if mousex()>=40 and mousex()<=60    then chosenColor = 0
                if mousex()>=90 and mousex()<110    then chosenColor = 1
                if mousex()>=140 and mousex()<160   then chosenColor = 2
                if mousex()>=190 and mousex()<210   then chosenColor = 3
                c = c + 1
                if c>=32 then                                             
                    set color cBlack;set caret 300,430
                    Box("Sorry, you lose")
                    ShowSolution("The solution is")
                    end
                else
                    Guess[c].code = chosenColor
                    Guess[c].ColorIt(cColor[chosenColor],1)
                    Compare(c)
                endif
            endif
           
            elseif mousey()>432 and mousey()<452 then 

            if mousebutton(0,true) 'mouse left click
                if mousex()>=40 and mousex()<=60    then chosenColor = 4
                if mousex()>=90 and mousex()<110    then chosenColor = 5
                if mousex()>=140 and mousex()<160   then chosenColor = 6
                if mousex()>=190 and mousex()<210   then chosenColor = 7
                c = c + 1
                if c>=32 then                                             
                    set color cBlack;set caret 300,430
                    Box("Sorry, you lose")
                    ShowSolution("The solution is")
                    end
                else
                    Guess[c].code = chosenColor
                    Guess[c].ColorIt(cColor[chosenColor],1)
                    Compare(c)
                endif
            endif
                       
            endif

        else
            set mouse 50,410 'set mouse position back to red circle
        endif
       
        redraw
endfunc

function ShowSolution(myText)
    set color cWhite; draw rect 251,371,width(primary)-1,height(primary)-1,1 'clear
    for i = 0 to 3
        set color cBlack; set caret 300,380;wln myText
        Solution[i].Create(300+i*35,430,colorPaint[i],1)
    next
    redraw
    wait 2000
    set color cWhite; draw rect 251,371,width(primary)-1,height(primary)-1,1 'clear
endfunc

function Compare(c)
    'Identify in whichColumn and in whichLine   
    for i = 0 to 3; if (c-i)%4=0 then whichColumn = i;next
    for i = 0 to 28 step 4
        if c>=i and c<=(i+3) then whichLine = (i/4)   
    next
       
    'RED, color in wrong position
    'GREEN, color in right position   
    for i = 0 to 3
        if i = whichColumn and Guess[c].code = colorPaint[i].code then
            Hint[c].ColorIt(cGreen,0.5)
            countGreen[whichLine] = countGreen[whichLine]+1
            if countGreen[whichLine] = 4 then
                Box("Congratulation")
                ShowSolution("You Win")
                wait 2000
                end
            endif
            break 'the same color may appear in some circles
        elseif i<>whichColumn and Guess[c].code = colorPaint[i].code then
            Hint[c].ColorIt(cRed,0.5)
        endif
    next
                                           
endfunc

function Box(myText)
    set color 200,200,200,100;draw rect 110,90,250,180,1    'shadow
    set color cGray;draw rect 100,80,250,180,1              'filled box
    set color cBlack;draw rect 100,80,250,180               'box frame
    set caret 150,130;wln myText                            'write myText
    redraw
    wait 3000
endfunc

Are you running on Windows or Linux (Wine)?
Reply
#7
I'm running on Windows 7 64 bit
Reply
#8
(02-18-2024, 12:27 PM)1micha.elok Wrote: I'm running on Windows 7 64 bit

How weird. Does NED also have two windows? I'll have to look into this and fix it.
Reply
#9
1micha.elok, I have attached a zip with n7.exe, renv_console.exe and renv_win.exe. Could you try replacing your files in the N7 folder with these?

What happens when you compile your program, does the console window still show? If so, what happens if you remove '#win32' and instead use 'set console off' (new command) before or after you call 'set window'?


Attached Files
.zip   binaries.zip (Size: 1.04 MB / Downloads: 2)
Reply
#10
(02-18-2024, 03:34 PM)Marcus Wrote: 1micha.elok, I have attached a zip with n7.exe, renv_console.exe and renv_win.exe. Could you try replacing your files in the N7 folder with these?

What happens when you compile your program, does the console window still show? If so, what happens if you remove '#win32' and instead use 'set console off' (new command) before or after you call 'set window'?

After replacing with new files :

First Experiment
#win32 ------> two windows, console and graphic windows


Second Experiment -------> one window only, graphic window
Code:
set console off
set window "MASTERMIND",450,480,false


Third Experiment ---------> one window only, graphic window
Code:
set window "MASTERMIND",450,480,false
set console off

Thanks Marcus  Big Grin
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)