Looking for help from other programmers

BlitzPlus Forums/BlitzPlus Beginners Area/Looking for help from other programmers

Nivlac(Posted 2010) [#1]
I have been a member since December 2005, trying to teach myself programming off and on. I have been reading and working with "Game Programming for Teens" second edition and "Programming for the Absolute Beginner" among others. I have no formal training, just the desire to learn to program my own games. I would like to create a memory matching game for my girls using BlitzPlus. I am not sure where or how to begin. I am looking for insight from other programmers. I have created 13 images, one for the back of the cards and 6 pairs of matching images. I would really appreciate some information or advice to get me going in the right direction as I am having trouble turning my ideas into source code. Thanks, Nivlac


lid(Posted 2010) [#2]
As a programmer you should really stop and ask yourself; what kind of program am i going to create here?

you should try using "command reference" to help you out ( say you didn't have any idea on how a command works there you can find out )

next i would recommend going here: http://membres.lycos.fr/blitzcoder/articles.shtml
( i learned to much here...to be honest i found this site from a user here called Hotshot2005 )

that should get you going :D

pardon my imperfect english


Sauer(Posted 2010) [#3]
Here is a good plan of attack for a matching game:

1) Take every image pair and assign it a number
2) Make a two dimensional array of rows and columns, and assign every "cell" a number. This will be your card layout.
3) Draw card's backside on the table, in rows and columns.
4) When the user clicks a card:
a) If it is the first guess, show the correct card using the information in the array corresponding to its row and col.
b) If it is the second guess, overturn the card, check if the elements in the array of the first guess and this guess are equal. If they're not, turn them back over. Otherwise leave them face up.
5) Mark the array cell as "matched" by giving it a negative value, or something unique. When all the elements of the array have this value, the game is over.

Hopefully that helps you get started with a plan of attack. Try accomplishing each step one by one, and it'll start to come together.

If you have any code questions don't hesitate to ask.


Nivlac(Posted 2010) [#4]
Thank you lid and sauer for taking the time to give your advice and insight. I don't have any source code to post now but will be working on it. I'm looking forward to being a programmer and an active member of this site and may be able to help someone or others in the future. Hope to be able to post some code soon! Thanks again NIVLAC


Nivlac(Posted 2010) [#5]
I am posting code for a memory match game that I have been working on. I am stuck and am hoping that someone can review what I have done so far and give me some suggestions on how to move forward. As a reminder, I have no formal programming background, just the desire to learn as much as I can.




Who was John Galt?(Posted 2010) [#6]
Not everyone that can help has Blitz plus. It is useful to say what exactly the problem is. You can paste all your images together in one big strip, then use loadanimimage to load them. Your array can then store the image frames for the card at each location, so in the loop you will do something like:

drawanimimage cards,x,y,c(row,column)


Nivlac(Posted 2010) [#7]
I'm not sure how to match each image pair and then draw them to the table(the array)and make them random so they don't end up in the same space every time. I know then i need to use the mouse to click on the the image to show what is behind it, if the images match mark them as match or turn them back over, just not sure how to do so


CS_TBL(Posted 2010) [#8]
Bah! The comfort of five years o' BMax makes B+ code look extremely sloppy and lame. Nonetheless, I think it works. Some of the mechanics here are just sooo easy 'n tidy in BMax!

Make sure you download that png mentioned above in the code, save it somewhere and match the path. The PNG doesn't line up to the grid correctly (so there are some stripes and thingies here and there), but it's rather hard to find anything on the net that does line up nicely and doesn't have a thick bar around the whole picture.

; Memory! - CS_TBL 2010
;
; 
; 12 icons, individual size in this particular image appears to be 120x101
Global icons=12
Global image=LoadAnimImage("c:\Bplus\vector-icons.png",120,101,0,icons)
Global tablewidth=6 ; table size should be the amount of icons*2
Global tableheight=4
Global imw=ImageWidth(image)
Global imh=ImageHeight(image)
Global opencards
Global clicks

SeedRnd MilliSecs()

window=CreateWindow("Match",48,48,imw*tablewidth,imh*tableheight,0,1+32)
Global canvas=CreateCanvas(0,0,ClientWidth(window),ClientHeight(window),window)

; make back of a card ******************************************************************************
Global cardback=CreateImage(imw,imh)
SetBuffer ImageBuffer(cardback)
	ClsColor 160,128,128:Cls
	For t=0 To 1023
		r#=Rnd(.75,1.25)
		Color 160*r,128*r,128*r
		Rect Rnd(imw),Rnd(imh),4,4
	Next
	Color 224,224,224
	Rect 0,0,2,imh
	Rect 0,0,imw,2
	Rect 0,imh-2,imw,2
	Rect imw-2,0,2,imh
	
; make back of the table ***************************************************************************
Global tableback=CreateImage(64,64)
SetBuffer ImageBuffer(tableback)
For t=0 To 63
	r#=Rnd(-.2,.2)
	Color 192+32*r,128+32*r,32+32*r
	Line 0,t,63,t
Next

; the deck o' cards ********************************************************************************
Dim table(tablewidth*tableheight)



	
SetBuffer DesktopBuffer()

Resettable
Update

Repeat
	WaitEvent()
	Game
	If EventID()=$803 Exit
Forever
SetBuffer DesktopBuffer()
End

Function Game()
	x=EventX()/imw
	y=EventY()/imh
	
	If EventID()=$201 ; mousedown
		clicks=clicks+1
		If table(x+y*tablewidth)<0
			table(x+y*tablewidth)=table(x+y*tablewidth)*-1
			opencards=opencards+1
			If opencards=2
				opencards=0
				Update
				If Check()=0
					Notify "W000t!  All this in "+clicks+" clicks! Next plz.."
					ResetTable
				EndIf
				Delay 2000
				
			EndIf
		EndIf
		Update
	EndIf
End Function

Function Check()
	
	While Not found
		If table(i)>0 found=1	
		i=i+1
	Wend
	card1=i-1
	found=0
	
	While Not found
		If table(i)>0 found=1	
		i=i+1
	Wend
	card2=i-1
	
	If table(card1)=table(card2) ; match!
		table(card1)=0
		table(card2)=0
	Else ; no match ._.
		table(card1)=table(card1)*-1
		table(card2)=table(card2)*-1
	EndIf
	
	For t=0 To tablewidth*tableheight-1
		total=total+table(t)
	Next
	
	Return total
End Function

Function Update()
	SetBuffer CanvasBuffer(canvas)
		TileImage tableback
		For y=0 To tableheight-1
			For x=0 To tablewidth-1
				Select Sgn(table(x+y*tablewidth))
					Case -1 DrawBlock cardback,x*imw,y*imh
					Case  1 DrawBlock image,x*imw,y*imh,table(x+y*tablewidth)-1
				End Select
			Next
		Next
	FlipCanvas canvas
End Function

Function Resettable()
	i=1
	clicks=0
	For y=0 To tableheight*tablewidth-1 Step 2
		table(y+0)=-i
		table(y+1)=-i
		i=i+1
	Next
	Shuffletable
End Function

Function Shuffletable()
	For t=0 To (tablewidth*tableheight)*30
		i1=Rnd(tablewidth*tableheight-1)
		i2=Rnd(tablewidth*tableheight-1)
		s=table(i1)
		table(i1)=table(i2)
		table(i2)=s
	Next
End Function



CS_TBL(Posted 2010) [#9]
Uh.. that's nice. The forum shows an image in a code area :D

Let's see..

; http://maxcdn.webappers.com/img/2007/11/vector-icons. png

Wipe that bogus space before the 'png'



I can actually see people taking (mis)advantage of having graphics in a code area ^_^