January 15, 2021, 05:44:05 PM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Algorithms
»
[bb] Game of Life by SytzeZ [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bb] Game of Life by SytzeZ [ 1+ years ago ] (Read 693 times)
BlitzBot
Jr. Member
Posts: 1
[bb] Game of Life by SytzeZ [ 1+ years ago ]
«
on:
June 29, 2017, 12:28:42 AM »
Title :
Game of Life
Author :
SytzeZ
Posted :
1+ years ago
Description :
I just made a Blitz3D version of the Game of Life.
It's a very simple algorithm but you can do alot of things with it.
The best we to find out what it is, is just do run the code.
[a
http://en.wikipedia.org/wiki/Conway's_Game_of_Life
]Click here[/a] for a few examples
Code :
Code: BlitzBasic
;My version of the Game of Life
;Keys:
; Spacebar : Play/Pause
; Left MB : Edit (while pausing)
; Numpad +/- : Change Speed
; S : Save
; O : Open
;You can change the window size
Graphics3D
1200
,
800
,
16
,
2
AppTitle
"Game Of Life"
SetBuffer
BackBuffer
(
)
Const
Size=
256
Dim
Grid
(
Size-
1
,Size-
1
)
Type
change
Field
x,y
End Type
Global
Play=
0
Global
Spd=
50
Cls
w=
GraphicsWidth
(
)
/Size
h=
GraphicsHeight
(
)
/Size
Color
127
,
127
,
127
For
x=
0
To
Size-
1
Line
0
,x*h,Size*w,x*h
Line
x*w,
0
,x*w,Size*h
;For y=0 To Size-1
; Rect x*w,y*h,w+1,h+1,0
;Next
Next
Repeat
For
x=
1
To
Size-
2
For
y=
1
To
Size-
2
o=Grid
(
x,y
)
n=-o
For
xx=-
1
To
1
For
yy=-
1
To
1
n=n+Grid
(
x+xx,y+yy
)
Next
Next
If
Play
Then
If
o=
0
And
n=
3
Then
o=
1
ElseIf
o=
1
And
(
n>
3
Or
n<
2
)
o=
0
End If
Else
If
RectsOverlap
(
MouseX
(
)
,
MouseY
(
)
,
1
,
1
,x*w,y*h,w,h
)
Then
If
MouseHit
(
1
)
Then
o=
1
-o
End If
EndIf
If
o<>Grid
(
x,y
)
Then
Color
0
,
0
,
0
Rect
x*w,y*h,w+
1
,h+
1
,
1
Color
127
+o*
127
,
127
+o*
127
,
127
+o*
127
Rect
x*w,y*h,w+
1
,h+
1
,o
ch.change=
New
change
chx=x
chy=y
EndIf
Next
Next
For
ch.change=
Each
change
Grid
(
chx,chy
)
=
1
-Grid
(
chx,chy
)
Delete
ch
Next
Flip
If
Play
Then
Delay
1000
/Spd
EndIf
Spd=Spd+
KeyHit
(
78
)
-
KeyHit
(
74
)
Spd=Spd+
(
Spd=
0
)
If
KeyHit
(
57
)
Then
Play=
1
-Play
If
KeyHit
(
31
)
Then
f=
WriteFile
(
"save.dat"
)
For
x=
0
To
Size-
1
For
y=
0
To
Size-
1
If
Grid
(
x,y
)
Then
WriteByte
f,x
WriteByte
f,y
End If
Next
Next
CloseFile
f
End If
If
KeyHit
(
24
)
Then
f=
ReadFile
(
"save.dat"
)
Repeat
x=
ReadByte
(
f
)
y=
ReadByte
(
f
)
Grid
(
x,y
)
=
1
Color
255
,
255
,
255
Rect
x*w,y*h,w,h,
1
Until
Eof
(
f
)
CloseFile
f
End If
Forever
Comments :
none...
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Algorithms
»
[bb] Game of Life by SytzeZ [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal