Board Logo
« mastermind challenge »

Welcome Guest. Please Login or Register.
Jan 16th, 2018, 3:36pm


Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Please use the forums Search feature before asking.
Please post code using the code box described in Format Your Messages.
This will keep indentation, separate it better form the message and prevent gibberish.
If the code is too long for one post or additional files are needed, upload a ZIP archive to the Just BASIC Files Archive Site.

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: mastermind challenge  (Read 1815 times)
intellectual
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 2
xx mastermind challenge
« Thread started on: Apr 15th, 2014, 6:44pm »

a fun logic game

Code:

'************************
'mastermind, a
'deductive reasoning game
'************************

nomainwin
UpperLeftX = 500
UpperLeftY = 70
WindowWidth = 300
WindowHeight = 620
blue$ = "0 70 255"
green$ = "0 200 0"
yellow$ = "255 245 0"
orange$ = "255 100 0"
red$ = "240 0 0"
white$ = "230 230 230"
menu #mm, "&game", "&New Game",[start],_
 "&Help",[help], "&Cheat",[cheat], "&Exit",[end]
open "mastermind" for graphics_nsb_nf as #mm


[start] 'draw grid
y=583
x=76
play$=""
print #mm, "cls; home; north; up"
print #mm, "go 200; turn -90; go 70"
for o=1 to 10
 print #mm, "down; circle 20"
  for oo=1 to 3
   print #mm, "up; go -45;down; circle 20"
  next oo
 print #mm, "up; turn -90;go 50; turn 90; go 135"
next o
print #mm, "backcolor ";blue$    'color bar
print #mm, "down; place ";x-66;" ";y-210;"; boxfilled ";x-36;" "; y-230
print #mm, "place 21 ";y-215;";\1"
print #mm, "backcolor ";green$;"; place ";x-66;" ";y-230;"; boxfilled ";x-36;" "; y-250
print #mm, "place 21 ";y-235;";\2"
print #mm, "backcolor ";yellow$;"; place ";x-66;" ";y-250;"; boxfilled ";x-36;" "; y-270
print #mm, "place 21 ";y-255;";\3"
print #mm, "backcolor ";orange$;"; place ";x-66;" ";y-270;"; boxfilled ";x-36;" "; y-290
print #mm, "place 21 ";y-275;";\4"
print #mm, "backcolor ";red$;"; place ";x-66;" ";y-290;"; boxfilled ";x-36;" "; y-310
print #mm, "place 21 ";y-295;";\5"
print #mm, "backcolor ";white$;"; place ";x-66;" ";y-310;"; boxfilled ";x-36;" "; y-330
print #mm, "place 21 ";y-315;";\6"
print #mm, "flush; setfocus"
color$= blue$
a=1
turn = 0
c1=int(rnd(1)*6) + 1 ' random code
c2=int(rnd(1)*6) + 1
c3=int(rnd(1)*6) + 1
c4=int(rnd(1)*6) + 1

[turn]
s1=0
s2=0
s3=0
s4=0
y=y-50
right=0
turn=turn+1
s1$="";x;" "; y;""
s2$="";x+45;" "; y;""
s3$="";x+90;" "; y;""
s4$="";x+135;" "; y;""
[input]
print #mm, "backcolor ";color$
print #mm, "when characterInput [color]"
print #mm, "when leftButtonUp [select]"
 wait

[select]
if MouseX > x-66 and MouseX < x-36 then [bar]
if MouseY > y+20 or MouseY < y-20 or_
 MouseX <= x-20 or MouseX >= x+155 then  [input]
if MouseX > x-20 and MouseX < x+20 then
  print #mm, "place ";s1$;";circlefilled 20"
  s1=1
  sc1=a   'spot color
 end if
 if MouseX > x+25 and MouseX < x+65 then
  print #mm, "place ";s2$;";circlefilled 20"
  s2=1
  sc2=a
 end if
 if MouseX > x+75 and MouseX < x+110 then
  print #mm, "place ";s3$;";circlefilled 20"
  s3=1
  sc3=a
 end if
 if MouseX > x+115 and MouseX < x+155 then
  print #mm, "place ";s4$;";circlefilled 20"
  s4=1
  sc4=a
 end if
 print #mm,"flush"
if s1+s2+s3+s4=4 then [total]
goto [input]

[total]
if sc1=c1 then right=right+1
if sc2=c2 then right=right+1
if sc3=c3 then right=right+1
if sc4=c4 then right=right+1
if right=0 then right$="0"
if right=1 then right$="1"
if right=2 then right$="2"
if right=3 then right$="3"
if right=4 then right$="4"
print #mm, "backcolor white"
print #mm, "place ";x+180;" ";y
print #mm, "\";right$
if right=4 then [win]
if turn=10 then [lose]
goto [turn]

[color]
a$=Inkey$
if a$="1" then color$= blue$ 
if a$="1" then a=1
if a$="2" then color$= green$ 
if a$="2" then a=2
if a$="3" then color$= yellow$
if a$="3" then a=3
if a$="4" then color$= orange$
if a$="4" then a=4
if a$="5" then color$= red$
if a$="5" then a=5
if a$="6" then color$= white$
if a$="6" then a=6
goto [input]
[bar] 'color bar
if MouseY < 373 and MouseY > 353 then
 color$= blue$
 a=1
end if
if MouseY < 353 and MouseY > 333 then
 color$= green$
 a=2
end if
if MouseY < 333 and MouseY > 313 then
 color$= yellow$
 a=3
end if
if MouseY < 313 and MouseY > 293 then
 color$= orange$
 a=4
end if
if MouseY < 293 and MouseY > 273 then
 color$= red$
 a=5
end if
if MouseY < 273 and MouseY > 253 then
 color$= white$
 a=6
end if
goto [input]

[cheat]
notice "shh...the code is ";c1;", ";c2;", ";c3;", ";c4
goto [input]

[help]
notice "Help"+ chr$(13)+"Start at the bottom and try to crack the code. Use the number keys or side bar to change the color, and the apearing number will tell you how close you are."
goto [input]

[lose]
confirm "I win. go again?";play$
goto [end]
[win]
confirm "Success! Crack another?";play$
[end]
if play$="yes" then [start]
close #mm
end







 

I cleaned it up and added the menu with a cheat.

( :
« Last Edit: Sep 30th, 2014, 3:31pm by intellectual » User IP Logged

Mallot1
Full Member
ImageImageImageImage


member is offline

Avatar

Mallot1


Homepage PM

Gender: Male
Posts: 194
wink Re: mastermind game
« Reply #1 on: Apr 15th, 2014, 6:49pm »

very nice smiley I would try it but I'm currently developing iOS apps on my Macbook pro cheesy I'll go back to my Windows 8 PC and see if i can give your game a shot smiley We also have JustBASIC Game Programming tutorials if your interested wink
User IP Logged

User Image
User Image
Game Development Blog: http://mallot1development.wordpress.com
High Flyer! cheesy http://gamegrapestudios.com/highflyer
jaba
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1049
wink Re: mastermind game
« Reply #2 on: Apr 16th, 2014, 12:14am »

Nice game! You asked about a menu.
  • I added a menu with item for Instructions and a Cheat for the computer's solution. This goes right before the open window command: menu #mm, "How to play", "Instructions", [instructions], "Cheat", [cheat]
  • To align the graphics after adding the menu bar, I added 20 to the WindowHeight, so it is WindowHeight = 620.
  • I commented out the nomainwin so the mainwin could be used to print to.
  • I added a trapclose statement, which is always good policy, so it is #mm "trapclose [quit]" right after the open window statement.


These are the branches I added right before the end statement:
Code:
[instructions]
print "This is how to play the game:"
'print instructions here...
    wait

[cheat]
    print c1;" ";c2;" ";c3;" ";c4
    wait

[quit]
close #mm
end
 

Hope this helps. It's a fun game to play.


User IP Logged

JACK - Windows 8.1 64-bit; 2.5 GHz Intel i3 processor; 6.00 GB RAM;
Valentin
Full Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 130
xx Re: mastermind challenge
« Reply #3 on: Jul 25th, 2016, 4:08pm »

I take it here
Code:
  'mastermind v4_ Fonctionnel
   nomainwin
    WindowWidth  = 560
    WindowHeight = 600
    UpperLeftX   = (DisplayWidth-WindowWidth)/2
    UpperLeftY   = (DisplayHeight-WindowHeight)/2

    ' button #w.ne, "Start", [Start], UL, 310, 330
     button #w.tt, "Test", [test], UL, 360, 155,110, 30
    button #w.so, "1", [sou1], UL, 308, 240
    button #w.so, "2", [sou2], UL, 357, 240
    button #w.so, "3", [sou3], UL, 407, 240
    button #w.so, "4", [sou4], UL, 458, 240
    button #w.so, "5", [sou5], UL, 504, 240
   TEXTBOX #w.so1, 305, 270,25, 25
   TEXTBOX #w.so2, 354, 270,25, 25
   TEXTBOX #w.so3, 404, 270,25, 25
   TEXTBOX #w.so4, 455, 270,25, 25
   TEXTBOX #w.so5, 502, 270,25, 25
    STATICTEXT #w, "Combinaison Machine", 360, 220, 150, 15
    STATICTEXT #w.av, "Whith Doublons >", 415, 315, 85, 15
     button #w.av, "*", [ave], UL, 500, 310, 35, 20
    STATICTEXT #w.sa, "Less Doublons >", 415, 345, 85, 15
    STATICTEXT #w, "(By Default)", 415, 365, 85, 15
    STATICTEXT #w, "BLACK = Good color; Good place", 300, 400, 200, 20
    STATICTEXT #w, "WHITE = Good color; Bad place", 300, 430, 250, 20
    button #w.sa, "*", [san], UL, 500, 340, 35, 20
    button #w.r1, "Red", jeu, UL, 290, 10, 50, 25 'choix place boutons ligne
    button #w.r2, "Red", jeu, UL, 340, 10, 50, 25 'choix couleurs boutons colonnes
    button #w.r3, "Red", jeu, UL, 390, 10, 50, 25
    button #w.r4, "Red", jeu, UL, 440, 10, 50, 25
    button #w.r5, "Red", jeu, UL, 490, 10, 50, 25
    button #w.g1, "Green", jeu, UL, 290, 35, 50, 25
    button #w.g2, "Green", jeu, UL, 340, 35, 50, 25
    button #w.g3, "Green", jeu, UL, 390, 35, 50, 25
    button #w.g4, "Green", jeu, UL, 440, 35, 50, 25
    button #w.g5, "Green", jeu, UL, 490, 35, 50, 25
    button #w.y1, "Yellow", jeu, UL, 290, 60, 50, 25
    button #w.y2, "Yellow", jeu, UL, 340, 60, 50, 25
    button #w.y3, "Yellow", jeu, UL, 390, 60, 50, 25
    button #w.y4, "Yellow", jeu, UL, 440, 60, 50, 25
    button #w.y5, "Yellow", jeu, UL, 490, 60, 50, 25
    button #w.p1, "pink", jeu, UL, 290, 85, 50, 25
    button #w.p2, "pink", jeu, UL, 340, 85, 50, 25
    button #w.p3, "pink", jeu, UL, 390, 85, 50, 25
    button #w.p4, "pink", jeu, UL, 440, 85, 50, 25
    button #w.p5, "pink", jeu, UL, 490, 85, 50, 25
    button #w.b1, "blue", jeu, UL, 290, 110, 50, 25
    button #w.b2, "blue", jeu, UL, 340, 110, 50, 25
    button #w.b3, "blue", jeu, UL, 390, 110, 50, 25
    button #w.b4, "blue", jeu, UL, 440, 110, 50, 25
    button #w.b5, "blue", jeu, UL, 490, 110, 50, 25
  graphicbox #w.a, 5,5,180,555
  graphicbox #w.b, 195,5,80,555
    open "Mastermind..." for window_nf as #w
    #w "trapclose [quit]"

 global c$, pro$, prop$
 global bcp, bc, y, p, f1, f2, x
 DIM comb$(5):DIM propo$(5)
 fl2=0:fl1=0:y=20

    'good practice to start with a clean sheet
    #w.a "cls ; down"
    #w.b "cls ; down"
    avec=0
    print #w.sa, "sans"

    #w.a "fill lightgray"
    #w.a "flush videcreensegment" 'nettoyage
    #w.b "fill lightgray"
    #w.b "flush videcreensegment"

[astart]

 ' wait
 [Start]      '*******************************Début**********
 print  #w.tt,  "!enable"
  print  #w.tt,  "test"
  fl2=1      'temoin de start
    #w.a "redraw videcreensegment"  'efface l'ancien
    #w.b "redraw videcreensegment"
    PRINT #w.so1,"":PRINT #w.so2,"":PRINT #w.so3,""
    PRINT #w.so4,"":PRINT #w.so5,""
    for k=1 to 5
      propo$(k-1)="q"
    next k
  if avec=0 then gosub [sans] 'doublons
  if avec=1 then gosub [avec] 'doublons
      '------------------------------Tour-------------
  wait

  sub jeu handle$ 
      pc = instr("rgypb",mid$(handle$,4,1))  ' la ligne qui t'assome
      couleur$ = word$("red green yellow pink blue",pc) ' celle qui t'achève
      x = val(right$(handle$,1))                        ' et celle qui te ranime
                ' ici: grosse prise de tete
      #w.a "backcolor ";couleur$;"; color ";couleur$
      #w.a "place ";20+35*(x-1);" ";y;"; circlefilled 15"
      #w.a "flush redsegment"
      #w.a "flush greensegment"
      #w.a "flush yellowsegment"
      #w.a "flush pinksegment"
      #w.a "flush bluesegment"

        prop$=right$(handle$,2) 'r2 de w.r2 ,r3,r4,b1,b2....
        pro$=left$(prop$,1)     'r de r2 de #w.r2
        p$=right$(prop$,1)      '2 de r2
        propo$(val(p$))=pro$ 
       f1=0
  end sub
  wait
[test]
   if fl2=0 then goto [clign] 'appui de test avant start
   bcp=0:bc=0:x=10:f1=f1+1   'F1 témoin d'appui répétés
   x=10
   bc=0
     for j=1 to 5
       if propo$(j)=comb$(j-1) then ' Bonne Coul Place..
         bcp=bcp+1:propo$(j)="z"   ' z neutralise
       end if                       'bcp lue plus bas
     next        'toutes les bonnes coul/place sont neutralisées
     if bcp=0 then x=10  ' assure x=10 suite bug aucune couleur

     for j=1 to 5
       if propo$(j)=comb$(0) then  'Bonne Coul mauvaise place
         bc=bc+1: propo$(j)="z"      'z neutralise
       end if
     next
     for j=1 to 5
       if propo$(j)=comb$(1) then
         bc=bc+1: propo$(j)="z"
       end if
     next
     for j=1 to 5
       if propo$(j)=comb$(2) then
         bc=bc+1: propo$(j)="z"
       end if
     next
     for j=1 to 5
       if propo$(j)=comb$(3) then
         bc=bc+1: propo$(j)="z"
       end if
     next
     for j=1 to 5
       if propo$(j)=comb$(4) then
         bc=bc+1: propo$(j)="z"
       end if
     next
   x=10     'affichage...bcp=total Bonne Coul/Place...bc=total Bonne Coul
     if bcp<>0 then   'au moins 1 bonne couleur bonne place
       for u=1 to bcp
         #w.b "backcolor black; color black"
         #w.b "place ";x;" ";y;"; circlefilled 5"
         #w.b "flush blacksegment"
         x=x+10
       next
     end if

     if bc<>0 then xx=x 'report dernier x si bcp<>0
       if bc<>0 then  'au moins 1 bonne couleur mauvaise place
         for u=1 to bc
            #w.b "backcolor white; color white"
            #w.b "place ";xx;" ";y;"; circlefilled 5"
            #w.b "flush whitesegment"
            xx=xx+10
         next
       end if
       'x=10
     if f1=1 then y=y+35 'flag appui test non repété>incrémente descente/tour
    p=0
    if y>535 then
      print #w.tt, "PERDU": goto [astart] ' PERDU
    end if
    if bcp=5 then
      print #w.tt, "GAGNE": goto [astart] ' GAGNE
    end if
 wait

[sou1]                   ' Affiche combi machine
    PRINT #w.so1, UPPER$(comb$(0));
 wait
[sou2]
    PRINT #w.so2, UPPER$(comb$(1));
 wait
[sou3]
    PRINT #w.so3, UPPER$(comb$(2));
 wait
[sou4]
    PRINT #w.so4, UPPER$(comb$(3));
 wait
[sou5]
    PRINT #w.so5, UPPER$(comb$(4));
 wait

[ave]
avec=1
    print #w.av, "avec" 'rappel option sur bouton
    print #w.sa, "*"
    goto [Start]
   wait
[san]
avec=0
    print #w.sa, "sans"
    print #w.av, "*"
    goto [Start]
   wait

[avec]  ' avec doublons
    y=20 :p=0        'première ligne affichée
    source$="r g y p b"  'les initiales des couleurs(et le left handle$)
          for i=0 to 4
      co=int(rnd(1)*5)+1  'génération combi
      comb$(i)=word$(source$,co) 'méfiance y'a un comb$(0)
    next i
 return
[sans]  ' sans doublons
    y=20 :p=0        'première ligne affichée
    source$="r g y p b"  'les initiales des couleurs(et le left handle$)
    for i=0 to 4
      co=int(rnd(1)*5)+1  'génération combi
      comb$(i)=word$(source$,co) 'méfiance y'a un comb$(0)
    next i
      if comb$(0)<>comb$(1)and comb$(0)<>comb$(2) and comb$(0)<>comb$(3) and comb$(0)<>comb$(4) then
       if comb$(1)<>comb$(2)and comb$(1)<>comb$(3) and comb$(1)<>comb$(4) then
        if comb$(2)<>comb$(3)and comb$(2)<>comb$(4) then
         if comb$(3)<>comb$(4) then return 'pas de doublons retour à l'appelant
        end if
        end if
       end if
       goto [sans]  'il y a doublons > nouvelle génération
  wait

 [clign]
 [ess]
 timer 0
     print  #w.tt,  "!disable"
     scan     'garde un oeil sur action joueur
     print  #w.tt,  "!enable"
     print  #w.tt,  "Doublons ? Start ?"

 timer 1000
 goto  [ess]
wait
    [quit]
       #w.a "discard" 'libère mémoire
       #w.b "discard"

    close #w
    end
 



User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls