PurePunch Contest July-August 2014

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: PurePunch Contest July-August 2014

Post by dobro »

@NicTheQuick

All my codes only work on Window XP and Seven
and PureBasic 5.22


ps: I added this precision at the beginning of my code ... Thanks
But it was specified in my code!
;Version Purebasic : PureBasic 5.22 LTS (Windows - x86)

The rules

1° The program will be created using Purebasic 5.22 (minimum), API allowed, demo version allowed, no userlib.
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
CSHW89
User
User
Posts: 30
Joined: Thu Sep 09, 2010 2:47 pm

Re: PurePunch Contest July-August 2014

Post by CSHW89 »

My Punch, a mastermind clone in 35 (now 28) lines :D :

Code: Select all

;*******************************************************************************
;*
;* July-August 2014 PurePunch contest
;* PureBasic 5.22
;* 50 lines of 80 chars, 2 months delay
;*
;* Name     :   Mastermind
;* Author   :   cshw89
;* Date     :   14/07/14
;* Notes    :   You have ten attempts to crack the code. Duplicates are
;*              allowed. Click or drag the colors to the respective positions.
;*
;*******************************************************************************
Global Dim i(3):Macro m:Macro:EndMacro:OpenWindow(0,0,0,250,480,"Mastermind",;;;
#PB_Window_SystemMenu|#PB_Window_ScreenCentered):Global Dim r(3):CanvasGadget(0,
0,0,250,480):Global s.s="$A0A0A0$0000FF$00D000$FF0000$00D0D0$0070D0$D000D0",x,y,
l=-2,a=0:Macro p:Procedure:EndMacro:p c(n=0):If StartDrawing(CanvasOutput(0));;;
m u(w):Val(Mid(s,(w)*7+1,7)):EndMacro:Box(0,400*n,250,480-400*n,$D0D0D0);;;;;;;;
DrawingMode(1):For k=n*10 To 10:For i=0 To 3:Circle(i*40+20,k*40+20,15,u(i(i)));
Next:Next:Box(170,405,70,30,$A0A0A0):DrawText(205-TextWidth("OK")/2,412,"OK",0);
For i=0 To 5:Circle(i*30+15,460,10,u(i+1)):Next:If l>0:Circle(x,y,15,u(l)):EndIf
StopDrawing():EndIf:End#p:For i=0 To 3:r(i)=Random(5)+1:Next:p a(i):If i<0:i*-1;
EndIf:p#Return i:End#p:c():m g(t):GetGadgetAttribute(0,t):End#m:Repeat:e=0+;;;;;
WaitWindowEvent():If e=#PB_Event_Gadget:t=EventType():x=g(#PB_Canvas_MouseX);;;;
y=g(#PB_Canvas_MouseY):b=-1:If y>=400:If x<160 And y<440:b=x/40:ElseIf x<180 And
y>=440:b=x/30+4:EndIf:EndIf:Select t:Case #PB_EventType_MouseMove:If f=0 And;;;;
g(#PB_Canvas_Buttons)&#PB_Canvas_LeftButton:If l=-2 And(a(x-lx)>1 Or a(y-ly)>1);
If b=-1:l=-1:ElseIf b<4:l=i(b):i(b)=0:Else:l=b-3:EndIf:EndIf:EndIf:Case 0+;;;;;;
#PB_EventType_LeftButtonUp:If l>0 And b>=0 And b<4:i(b)=l:EndIf:If l=-2:If b>-1+
0 And f=0:If b<4:i(b)=0:Else:For k=0 To 3:If i(k)=0:i(k)=b-3:Break:EndIf:Next;;;
EndIf:Else:If x>=160 And y>=400 And y<440:If f:For k=0 To 3:r(k)=Random(5)+1;;;;
i(k)=0:Next:f=0:a=0:c():Else:h=1:For k=0 To 3:If i(k)=0:h=0:EndIf:Next:If h:r=0;
w=0:For i=0 To 3:If r(i)=i(i):i(i)*-1:r(i)*-1:r+1:EndIf:Next:For i=0 To 3:m q;;;
MessageRequester("Mastermind":EndMacro:For k=0 To 3:If i(k)>0 And r(i)=i(k) And;
i<>k:i(k)*-1:w+1:Break:EndIf:Next:Next:If StartDrawing(CanvasOutput(0)):For i=0+
0 To 3:i(i)=a(i(i)):r(i)=a(r(i)):Circle(i*40+20,a*40+20,15,u(i(i))):i(i)=0:Next;
i=170:For k=1 To r:Box(i,a*40+12,16,16,0):i+20:Next:For k=1 To w:Box(i,a*40+12,;
16,16,$FFFFFF):i+20:Next:StopDrawing():EndIf:a+1:If r=4:f=1:q,"You Win!");;;;;;;
ElseIf a=10:For i=0 To 3:i(i)=r(i):Next:c(1):q,"You Lose!"):f=1:EndIf:EndIf;;;;;
EndIf:EndIf:EndIf:EndIf:l=-2:Case #PB_EventType_LeftButtonDown:If f=0:lx=x:ly=y;
EndIf:EndSelect:If y<415:y=415:EndIf:c(1):EndIf:Until e=#PB_Event_CloseWindow;;;
Last edited by CSHW89 on Mon Jul 14, 2014 4:41 pm, edited 3 times in total.
Image Image Image
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: PurePunch Contest July-August 2014

Post by heartbone »

CSHW89 wrote:My Punch, a mastermind clone in 35 lines :D :
Great minds think alike.
I was going to do this one, but you have already done such a nice job, and it works in Linux!

At first I was a bit confused as to which color, red or white, indicates the correct color in the correct position.
Usually black & white are used for this, as red is used for one of the six pattern colors.
But in the second game I hit it on my third guess!
I made a screen dump to show my kids.
Will I ever get it in two? I doubt it.
dobro wrote:My Punchs :)
All my codes only work on Window XP and Seven
and PureBasic 5.22
Those are some powerful punches.
If you can get that video player working in Linux, playing a few more video formats, then it along with your other creations (PureRadio) would be impressive additions to the forum section envisioned by IdeasVacuum.
I see a snake game has also made it into the punch bag. :o
Keep it BASIC.
CSHW89
User
User
Posts: 30
Joined: Thu Sep 09, 2010 2:47 pm

Re: PurePunch Contest July-August 2014

Post by CSHW89 »

@heartbone: Oh yes, you are right. I changed it to black & white ;)
Image Image Image
User avatar
NicTheQuick
Addict
Addict
Posts: 1226
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: PurePunch Contest July-August 2014

Post by NicTheQuick »

@CSHW89: Nice one! Image
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
NicTheQuick
Addict
Addict
Posts: 1226
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: PurePunch Contest July-August 2014

Post by NicTheQuick »

Some superformula fun! ;)

Code: Select all

;*******************************************************************************
;*
;* July-August 2014 PurePunch contest
;* PureBasic 5.22
;* 50 lines of 80 chars, 2 months delay
;*
;* Name     : Superformula
;* Author   : NicTheQuick
;* Date     : 13.07.2014
;* Notes    : Only tested on PB 5.30 b7 on Linux x64!
;*            You can also resize the window.
;*            l defines the precision of the line and it must not less than 20.
;* Used Variables: abcdefghijklmnopqrstuvwxyz
;*                 ^^^^^^^^^^^^^^^^ ^M^^^^^^^
;*******************************************************************************
l=1000:w=600:h=600:Define.d a,b,c,d,e,j,k,n,o,p,r,t,x,y,z:OpenWindow(0,0,0,w,
h,"Superformula",#PB_Window_MaximizeGadget):CanvasGadget(0,0,0,w,h):Macro s(a)
Sin(t*a):EndMacro:Repeat:v=WaitWindowEvent(9):f=WindowWidth(0):g=WindowHeight(0)
t=ElapsedMilliseconds():If f!w|g!h:w=f:h=g:ResizeGadget(0,0,0,w,h):ElseIf t>u+20
StartDrawing(CanvasOutput(0)):u=t:t/5000:m=2+2*Int(t)%20:t/2:d=9+9*s(3):e=9*s(5+
0)+9:c=10+9*s(2):a=Abs(s(7)*0.6)+0.1:b=Abs(s(11)*0.6)+0.1:y=Cos(t*9):x=100*s(1)+
150:GrabDrawingImage(0,0,0,w,h):DrawingMode(#PB_2DDrawing_Gradient):j=w/2*(1+y)
DrawAlphaImage(ImageID(0),w*y/x,h*s(9)/x,150):k=h/2*(1+s(9)):LinearGradient(j,k,
w-j,h-k):BackColor(RGB(127*(1+s(7)),127*(1+s(11)),127*(1+s(13)))):FrontColor(0+
RGB(127*(1+s(2)),127*(1+s(3)),127*(1+s(5)))):For i=0 To l:r=i*2*#PI/l:p+s(1+
0)/30000:z=Pow(Pow(Abs(Cos(m*r/4)/a),d)+Pow(Abs(Sin(m*r/4)/b),e),1/c):x=w/2*(1+
Cos(r+p)/z):y=h/2*(1+Sin(r+p)/z):If i:LineXY(n,o,x,y):EndIf:n=x:o=y:Circle(x,y,
Bool(i%(l/20)=0)*w/50/z):Next:StopDrawing():EndIf:Until v=#PB_Event_CloseWindow
Edit: Some bugfixes
Edit2: Better effects
Edit3: Shortened to 19 lines of code
Edit4: Shortened to 17 lines of code and better "randomness"
Edit5: Should now run on Windows
Edit6: Minor bugfix for the rotation speed
Edit7: Shrinked to 13 lines of code. Now EnabledExplicit will not work.
Edit8: Circles added. l defines the precision of the line and it must not less than 20.
Last edited by NicTheQuick on Mon Jul 14, 2014 6:15 pm, edited 8 times in total.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: PurePunch Contest July-August 2014

Post by davido »

@CSHW89 Very nice. Thank you. :D
@NicTheQuick
Looks great on Window 7 with PureBasic 5.30b6. Unfortunately it cannot be stopped by closing the window.
Also looks great on my Mac Book Pro. It exits at once by closing the window.
Thank you very much. 8) :D
DE AA EB
User avatar
NicTheQuick
Addict
Addict
Posts: 1226
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: PurePunch Contest July-August 2014

Post by NicTheQuick »

davido wrote:Looks great on Window 7 with PureBasic 5.30b6. Unfortunately it cannot be stopped by closing the window.
Maybe the problem is the last number "2", which originally was #PB_Event_CloseWindow. On Linux this constant has the number 2. :wink:

I have corrected the missing constant. Now it should work.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
idle
Always Here
Always Here
Posts: 5093
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: PurePunch Contest July-August 2014

Post by idle »

very nice NictheQuick
Windows 11, Manjaro, Raspberry Pi OS
Image
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: PurePunch Contest July-August 2014

Post by davido »

@NicTheQuick
Thank you for the amendment. Works OK, now.
DE AA EB
User avatar
kernadec
Enthusiast
Enthusiast
Posts: 146
Joined: Tue Jan 05, 2010 10:35 am

Re: PurePunch Contest July-August 2014

Post by kernadec »

hi,
@CSHW89 Thank you. :D
@NicTheQuick It's beautiful :D

best regards
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: PurePunch Contest July-August 2014

Post by dobro »

I added a Punch "Matrix" in my message Page 3

you can compile "Matrix.scr" and lay it in your folder "c: \ Windows"
to enjoy this Screensaver :)



if you try, without compiling .. run it, and do not touch the mouse ;)
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
User avatar
idle
Always Here
Always Here
Posts: 5093
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: PurePunch Contest July-August 2014

Post by idle »

CSHW89 wrote:My Punch, a mastermind clone in 35 lines :D :
you've got my vote, very good :mrgreen:
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
NicTheQuick
Addict
Addict
Posts: 1226
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: PurePunch Contest July-August 2014

Post by NicTheQuick »

I shrank my code to 13 lines. See above.
Last edited by NicTheQuick on Mon Jul 14, 2014 4:58 pm, edited 1 time in total.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
CSHW89
User
User
Posts: 30
Joined: Thu Sep 09, 2010 2:47 pm

Re: PurePunch Contest July-August 2014

Post by CSHW89 »

Wow, thanks all for your replies. I shrank the code from 35 to 28 lines :). Link
Image Image Image
Post Reply