'Mastermind game 'old program, changed by Dirk Noack 2014 'common variables dim code 'shake the random generator randomize() 'create the window frame = new wxFrame(nothing, -1, "Mastermind with sliders", wxPoint( 10, 10 ), wxSize( 360, 280 )) frame.Centre() 'place a panel in the window panel = new wxPanel( frame, -1 ) 'create the sliders slider1 = new wxSlider( panel, -1, 1 , 1, 5, wxPoint( 10, 10 ), wxSize( 130, 40 ), wxSL_AUTOTICKS | wxSL_LABELS ) slider2 = new wxSlider( panel, -1, 2 , 1, 5, wxPoint( 10, 60 ), wxSize( 130, 40 ), wxSL_AUTOTICKS | wxSL_LABELS ) slider3 = new wxSlider( panel, -1, 3 , 1, 5, wxPoint( 10, 110 ), wxSize( 130, 40 ), wxSL_AUTOTICKS | wxSL_LABELS ) slider4 = new wxSlider( panel, -1, 4 , 1, 5, wxPoint( 10, 160 ), wxSize( 130, 40 ), wxSL_AUTOTICKS | wxSL_LABELS ) slider1.SetBackgroundColor(wxCYAN) slider2.SetBackgroundColor(wxGREEN) slider3.SetBackgroundColor(wxBLUE) slider3.SetForegroundColor(wxWHITE) slider4.SetBackgroundColor(wxWHITE) 'add a button button1 = new wxButton(panel, -1, "Break it", wxPoint(10, 220), wxSize( 50, 20 ) ) button1.SetBackgroundColor(wxRED) ' add a button2 button2 = new wxButton(panel, -1, "New Code", wxPoint(70, 220), wxSize( 70, 20 ) ) 'add a listbox listbox = new wxListBox(panel, -1, wxPoint(160, 10), wxSize( 180, 230 ) ) listbox.Append("Try to break my 4-digit code") listbox.Append("Hint: + = digit ok but wrong pos.") listbox.Append("Hint: # = digit and position ok.") 'make code sub make_code() n4 = rnd(5)'+ 1 n3 = rnd(5)'+ 1 n2 = rnd(5)'+ 1 n1 = rnd(5)'+ 1 while n2 = n1 n2 = rnd(5)'+ 1 wend while (n3 = n2) or (n3 = n1) n3 = rnd(5)'+ 1 wend while (n4 = n3) or (n4 = n2) or (n4 = n1) n4 = rnd(5)'+ 1 wend code = str(n1) & str(n2) & str(n3) & str(n4) ' listbox.Append("Code: " & code) ' debug only please :-) end sub 'callback sub for button sub cl_Break_it(event) handles button1.buttonclicked mycode = str(slider1.GetValue()) & str(slider2.GetValue()) & str(slider3.GetValue()) & str(slider4.GetValue()) hint = mycode & " Hint: " if code = mycode then listbox.Append("*** YOU BROKE THE CODE ***") wxMessageBox( "*** YOU BROKE THE CODE ***", "Success", wxOK + wxICON_INFORMATION, frame ) else for i = 1 to 4 if mid$(mycode,i,1) = mid$(code,i,1) then hint = hint & " #" else for j = 1 to 4 if mid$(mycode,i,1) = mid$(code,j,1) then hint &= " +" end if next end if next listbox.Append(hint) end if End sub 'callback sub for button2 sub cl_New_Code(event) handles button2.buttonclicked make_code() end sub 'initial code make_code() ' show the frame frame.Show(True)