Pages: 1
Topic closed
I want to create a game of noughts and crosses in Scratch with my daughter. Please can someone give me some pointers towards:
1 Defining a space on the board that can be populated with a nought or cross
2 Testing whether a space has already been populated with a nought or a cross
Thanks,
Mark
Offline
You could have a list with nine entries- each one signifying a space on the board. At first all nine entries can be stated as "open", so you would have nine "open" entries in the list. Also include a variable called "turn" and set it to 1 when the green flag is clicked.
If you are newer to programming, the easiest way to define an area you can place a nought or cross on would be to have nine sprites occupying the places you can click. Such as Sprite1 occupying the top left space.
Then you can include a script like this:
If Sprite1 clicked
If item 1 of spaces = open
If Turn = 1
replace item 1 of spaces with nought
set turn to (3-turn)
else
replace item 1 of spaces with cross
set turn to (3-turn)
switch to costume (item 1 of spaces)
Click here for a visual of the above script
Give Sprite 1 three costumes- one blank named open, one with a nought, and one with a cross, and have it switch to item 1 of spaces.
The same can be repeated for each space. The "turn" variable decides whose turn it is- the person placing a nought or a cross.
Last edited by Kileymeister_test (2012-01-06 15:11:18)
Offline
schusteralex2 wrote:
So, is this like tic tac toe
Yes, noughts and crosses is what we call it in UK
Offline
RedRocker227 wrote:
schusteralex2 wrote:
So, is this like tic tac toe
Yes, noughts and crosses is what we call it in UK
ok
Offline
markdad wrote:
Thanks, that's really helpful, but I don't see the red block containing "replace" anywhere in Scratch. I'll write out the rules and have a go in the next few days
It's under variables, near the bottom.
Offline
markdad wrote:
Thanks, that's really helpful, but I don't see the red block containing "replace" anywhere in Scratch. I'll write out the rules and have a go in the next few days
Here's some help in finding your missing red block: 1. Open the Scratch Programming application window (I call it S.P.A. Window for short). 2. Click on the "Variables" section in the top left corner of the S.P.A.Window 3. Click "Make a list". 4. Type in your list name (ex. spaces). 5. Click "OK". 6. If you look at the fourth red block beneath your list spaces, the fourth block will read: replace item 1 of spaces with thing.
Hope this helps!
~PythonDreamer
Offline
My-chemical-romance has made noughts and crosses, not advertising it or anything, but you could open that and see how it's done. There's the list method too, but that's complicated if you're fairly new.
Offline
Here.
Although winning doesn't work anymore, the code should still be there.
Offline
Topic closed
Pages: 1