Brutus2D
« FourGame »

Welcome Guest. Please Login or Register.
Feb 1, 2012, 10:04pm




Brutus2D :: Brutus2D :: ShowCase :: FourGame
   [Search This Thread] [Share Topic] [Print]
 AuthorTopic: FourGame (Read 845 times)
peter
Full Member
***
member is offline





Joined: Aug 2007
Gender: Male
Posts: 179
 FourGame
« Thread Started on Jan 9, 2010, 1:20pm »

Hello,

Exercise for your brain cells.
In this game you have to get four stones in a series.
Horizontal,Vertical or diagonal.
You choose a slot if you press a number [1 to 9].
The game describes it itself what you have to do.

If you are ready: you get it from here.
http://brutus.pewtersoftware.com/upload/files/FourGame.rar
much fun.

Hi Guilect,
if you want, then add it to the front page!

another thing:
if I'm starting my program from the Editor and I return to the Editor, the keyboard buffer has still all
pressed key codes and writes them in the
source code of the Editor! Can be annoying.
It's usual?
Link to Post - Back to Top  IP: Logged
matthew
Senior Member
****
member is offline

[avatar]

[icq] [yim] [msn] [aim]
[homepage]

Joined: Sept 2006
Gender: Male
Posts: 325
Location: England
 Re: FourGame
« Reply #1 on Jan 10, 2010, 6:27am »

Nice Peter, I used to play Connect Four a lot when I was younger. :)
Link to Post - Back to Top  IP: Logged

Guilect
Administrator
*****
member is offline




[homepage]

Joined: May 2005
Posts: 879
 Re: FourGame
« Reply #2 on Jan 10, 2010, 10:31am »

Hi peter,

nice game. I will adventually put a notice about it on the front page.
(It's been a while since I updated it, that I need to remember the login password :P )

The key presses showing up in the editor is not typical.

I tried to duplicate your issue with the code below:
Code:
' Return the ASCII value of the key pressed

option explicit

dim bRunning
bRunning = True

dim background, Font

sub main()

if (graphics.initialize <> True) then exit sub

Font = graphics.CreateFont("system", 24)

graphics.setTitle "Demo - Keyboard - press n to exit"

key.initialize

do while bRunning = True

if key.pressed(vk_n) or key.pressed(0) = True then bRunning = False
graphics.clear 255
graphics.settext Chr(dll.CallAPI("user32", "MapVirtualKeyA", key.pressedany(), 1)), 200,200, Font
graphics.display
loop

key.terminate
graphics.terminate

end sub

Call Main()

but it always worked fine.
Link to Post - Back to Top  IP: Logged
peter
Full Member
***
member is offline





Joined: Aug 2007
Gender: Male
Posts: 179
 Re: FourGame
« Reply #3 on Jan 10, 2010, 11:28am »

Hi Guilect,

I mean: you write an program with Brutus2d.
You want to test it.
You click on start and the program will run.
The test was good and you go back to brutus2d.
And now: the whole keyboard buffer or the rest of the keyboard buffer apperars
in you source code!

cheers.
Link to Post - Back to Top  IP: Logged
Guilect
Administrator
*****
member is offline




[homepage]

Joined: May 2005
Posts: 879
 Re: FourGame
« Reply #4 on Jan 10, 2010, 6:39pm »

peter,
I understood perfectly.
I just provided a simple example above as a test case, which when I run from the IDE and then stop the program and
go back to the IDE everything is fine.
Did you try the example above?
Do you get extra characters in the IDE when you stop the program and return to the IDE?????
Does this happen to any of the other examples supplied with B2D for you?
I have run many programs in B2D and do not see this.
Link to Post - Back to Top  IP: Logged
peter
Full Member
***
member is offline





Joined: Aug 2007
Gender: Male
Posts: 179
 Re: FourGame
« Reply #5 on Jan 10, 2010, 7:23pm »

Hi Guilect,

I am sorry, I haven't been attentive!
I can nothing see in the source code!

Okay, I guess that's an API routine that it causes.
I'm going to check it.
It's my fault! Thanks for your open ear.

cheerio.
« Last Edit: Jan 10, 2010, 7:27pm by peter »Link to Post - Back to Top  IP: Logged
Guilect
Administrator
*****
member is offline




[homepage]

Joined: May 2005
Posts: 879
 Re: FourGame
« Reply #6 on Jan 11, 2010, 6:58pm »

Hi peter,
I would gladly look into it, if some means of repeatedly reproducing it could be explained.
It may be an issue with B2D, it is just that if the issue does not show itself, how can it be fixed.
Let me know if you can give me the smallest example code that displays the behavior and the steps necessary to reproduce the problem.

Best Regards,
Guilect
Link to Post - Back to Top  IP: Logged
u9
God
*****
member is offline

[avatar]

"...there's plenty of Sid to go around" - Ice Age


[homepage]

Joined: Jun 2006
Gender: Male
Posts: 574
Location: Faroe Islands
 Re: FourGame
« Reply #7 on Jan 18, 2010, 6:06am »

Hey guys

Nice game peter. I wonder how did you implement the AI? I am always pretty bad at making AIs.

Guilect, i have had the same problem regarding the keyboard buffer. Maybe the keyboard should be terminated before you close the window? Or a need to call processmessages, or something, i am not sure. And i don't really remember how i solved it :)
Link to Post - Back to Top  IP: Logged

The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents. (Nathaniel Borenstein)
www.wirednerd.com
Guilect
Administrator
*****
member is offline




[homepage]

Joined: May 2005
Posts: 879
 Re: FourGame
« Reply #8 on Jan 18, 2010, 8:49pm »

The best theory about the keys that I can come up with is this.
If you use a printable key like 'Q' for quit for example, and you are in your game,
you press 'Q' and the game quits, focus goes back to the IDE editor window while you are still leaning on the 'Q' key and 'Q's are put into the editor until you release the key.
Is this what is being seen? If so, make the last key a user might press in the game a non-printable one like 'ESC'.
Link to Post - Back to Top  IP: Logged
peter
Full Member
***
member is offline





Joined: Aug 2007
Gender: Male
Posts: 179
 Re: FourGame
« Reply #9 on Jan 19, 2010, 6:14am »

I'm sorry Guilect,

I can't give any part of the source code, the context is too complex.

Try these few lines and see what happens.
This small program works correct for me.
I get no numbers in my source code!
And what about you ? That same ?

Best Regards.

Code:

Option Explicit
Dim Num,KeyF,Font,a

Sub Main()
Graphics.Initialize 580,400,True,32
Key.Initialize
Font = Graphics.CreateFont("comic",16,True)
KeyF = 0 : Num = 0
While Key.Pressed(vk_escape) = False
Graphics.Clear(&hFFD00000)
HitNumber()
TextOut()
Graphics.Display
Graphics.SetFPS 10
Wend
Graphics.Terminate
Key.Terminate
End Sub

Call Main

Sub HitNumber()
iF Key.Pressed(vk_0) And KeyF =0 Then
KeyF =1: Num = 0
ElseiF Key.pressed(vk_0) = False Then
KeyF =0
End iF
iF Key.pressed(vk_1) And KeyF =0 Then
KeyF =1: Num = 1
ElseiF Key.pressed(vk_1) = False Then
KeyF =0
End iF
iF Key.pressed(vk_2) And KeyF =0 Then
KeyF =1: Num = 2
ElseiF Key.pressed(vk_2) = False Then
KeyF =0
End iF
iF Key.pressed(vk_3) And KeyF =0 Then
KeyF =1: Num = 3
ElseiF Key.pressed(vk_3) = False Then
KeyF =0
End iF
iF Key.pressed(vk_4) And KeyF =0 Then
KeyF =1: Num = 4
ElseiF Key.pressed(vk_4) = False Then
KeyF =0
End iF
iF Key.pressed(vk_5) And KeyF =0 Then
KeyF =1: Num = 5
ElseiF Key.pressed(vk_5) = False Then
KeyF =0
End iF
iF Key.pressed(vk_6) And KeyF =0 Then
KeyF =1: Num = 6
ElseiF Key.pressed(vk_6) = False Then
KeyF =0
End iF
iF Key.pressed(vk_7) And KeyF =0 Then
KeyF =1: Num = 7
ElseiF Key.pressed(vk_7) = False Then
KeyF =0
End iF
iF Key.pressed(vk_8) And KeyF =0 Then
KeyF =1: Num = 8
ElseiF Key.pressed(vk_8) = False Then
KeyF =0
End iF
iF Key.Pressed(vk_9) And KeyF =0 Then
KeyF =1: Num = 9
ElseiF Key.pressed(vk_9) = False Then
KeyF =0
End iF
End Sub

Sub TextOut()
Graphics.SetRect 96,98,318,24,&hFF649000
Graphics.SetText "Press a number [1-9]",160,32,Font,&hFF0088FF
Graphics.SetText Num,100+Num*16,100,Font,&hFFFFFF00
Graphics.Setbox (100+Num*16)-2,100,14,20,&hFFFFFFFF
Graphics.SetText Num,400-Num*16,100,Font,&hFFFFFF00
Graphics.Setbox (400-Num*16)-2,100,14,20,&hFFFFFFFF
Graphics.SetText "Escape key ends the Test",160,300,Font,&hFFB084FF
TextMe(Num)
End Sub

Function TextMe(Nummer)
Graphics.SetText "you pressed " & Nummer & ",you win " & Nummer *4 & " eggs.",130,260,Font,&hFF00FF00
End Function



Link to Post - Back to Top  IP: Logged
Guilect
Administrator
*****
member is offline




[homepage]

Joined: May 2005
Posts: 879
 Re: FourGame
« Reply #10 on Jan 19, 2010, 9:47am »

Hi peter,
it works ok for me. I typed all sorts of numbers and letters and multiple keypresses at once and etc.
(I like the look of this little test program by the way.)

BTW: I put a message on the Brutus2D homepage about your FourGame.
Link to Post - Back to Top  IP: Logged
peter
Full Member
***
member is offline





Joined: Aug 2007
Gender: Male
Posts: 179
 Re: FourGame
« Reply #11 on Jan 22, 2010, 12:36pm »

Hello,

Here is the key test two.
It is a simple test, for the rotation in six directions.
Does it work well for you ?

Code:
option explicit

'xx, yy, zz 3D coordinates of a point.
'ax viewing angle to the x-axis
'ay viewing angle to the y-axis
'xm x-distance to the origin of the 2D axis.
'ym y-distance to the origin of the 2D axis.
'fp vanishing point.

Public x,y,z,x1,y1,z1,x2,y2,z2,xx,yy,zz,xm,ym,xp,yp,ax,ay,zp,fp,pk
Public dp,sw,rw,dh,pi,x3,y3,z3,Font,Color

Dim xa(8)
Dim ya(8)
Dim za(8)
Dim xb(8)
Dim yb(8)
Dim zb(8)
Dim a1(8)
Dim a2(8)
Dim b1(8)
Dim b2(8)

Sub Main()
Graphics.Initialize 640,480,True,32
Key.Initialize
Mouse.Initialize
Font = Graphics.CreateFont("comic",12,True)
Initial()
Do While Key.Pressed (1) = False
Start()
Graphics.Display
Graphics.SetFPS 85
Loop
Graphics.Terminate
Mouse.Terminate
Key.Terminate
End Sub

Call Main

Sub Initial()
pi = 4 * Atn(1)
dh = 8
fp = 512
xm = 320
ym = 240
ax = 0: ay = 0
sw = 1: rw = 6
x = 0: y = 0: z = 0
xx = 0: yy = 0: zz = 0
x1 = 0: y1 = 0: z1 = 0
x2 = 0: y2 = 0: z2 = 0
x3 = 0: y3 = 0: z3 = 0
xa(0) = 50:xa(1) =-50:xa(2) = 50:xa(3) = 50:xa(4) = 50:xa(5) = 50:xa(6) =-50:xa(7) = 50
ya(0) = 50:ya(1) = 50:ya(2) =-50:ya(3) =-50:ya(4) = 50:ya(5) =-50:ya(6) =-50:ya(7) =-50
za(0) = 50:za(1) = 50:za(2) = 50:za(3) =-50:za(4) = 50:za(5) = 50:za(6) = 50:za(7) = 50
xb(0) = 50:xb(1) =-50:xb(2) = 50:xb(3) =-50:xb(4) =-50:xb(5) =-50:xb(6) =-50:xb(7) = 50
yb(0) = 50:yb(1) = 50:yb(2) =-50:yb(3) =-50:yb(4) = 50:yb(5) =-50:yb(6) = 50:yb(7) = 50
zb(0) =-50:zb(1) =-50:zb(2) =-50:zb(3) =-50:zb(4) = 50:zb(5) = 50:zb(6) = 50:zb(7) = 50
End Sub

Sub Math()
x1 = xx * Cos(ax) - zz * Sin(ax)
y1 = yy
z1 = xx * Sin(ax) + zz * Cos(ax)
x2 = x1 + xp
y2 = y1 * Cos(ay) - z1 * Sin(ay) + yp
z2 = y1 * Sin(ay) + z1 * Cos(ay) + zp
x = xm + (x2 * fp) / (fp - z2)
y = ym + (y2 * fp) / (fp - z2)
End Sub

Sub Calculation()
For pk =0 To dh
For dp =0 To pk
xx = xa(dp): yy = ya(dp): zz = za(dp)
Math(): a1(dp) = x: b1(dp) = y
xx = xb(dp): yy = yb(dp): zz = zb(dp)
Math(): a2(dp) = x: b2(dp) = y
Next: Next
End Sub

Sub Start()
Graphics.Clear(&hFFFF8400)
Graphics.SetText "3D Key-Test",254,16,Font,&hFFFFFF00
Graphics.SetText "Use arrow keys and (a) for origin",190,40,Font,&hFFFFFF00
CalCulation()
For pk =0 To dh
For dp =0 To pk
Graphics.SetRect a1(dp),b1(dp),a2(dp)-350,b2(dp)-250,&hFF0000FF
Graphics.SetBox a1(dp),b1(dp),a2(dp)-350,b2(dp)-250,&hFFFFFF00
Graphics.SetText "3D",a2(dp)-60,b2(dp),Font,&hFF00FF64
Next: Next
iF Key.Pressed(vk_right) Then ax = ax - 2 * pi / 360
iF Key.Pressed(vk_up) Then ay = ay - 2 * pi / 360
iF Key.Pressed(vk_left) Then ax = ax + 2 * pi / 360
iF Key.Pressed(vk_down) Then ay = ay + 2 * pi / 360
iF Key.Pressed(vk_a) Then Initial
End Sub
« Last Edit: Jan 23, 2010, 2:22pm by peter »Link to Post - Back to Top  IP: Logged
Guilect
Administrator
*****
member is offline




[homepage]

Joined: May 2005
Posts: 879
 Re: FourGame
« Reply #12 on Jan 24, 2010, 8:18am »

That is a nice effect.
Link to Post - Back to Top  IP: Logged
   [Search This Thread] [Share Topic] [Print]

Google
Web brutus2d.proboards44.com
Click Here To Make This Board Ad-Free


This Board Hosted For FREE By ProBoards
Get Your Own Free Message Boards & Free Forums!
Terms of Service | Privacy Policy | Report Abuse | Mobile