This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-01-05 15:10:23

markdad
New Scratcher
Registered: 2011-12-28
Posts: 2

Defining visual arrays on a board: Noughts and crosses

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

 

#2 2012-01-06 11:54:38

schusteralex2
Scratcher
Registered: 2011-09-17
Posts: 1000+

Re: Defining visual arrays on a board: Noughts and crosses

So, is this like tic tac toe


http://i44.tinypic.com/2uj37ds.gif

Offline

 

#3 2012-01-06 15:06:08

Kileymeister_test
Scratcher
Registered: 2010-01-31
Posts: 100+

Re: Defining visual arrays on a board: Noughts and crosses

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)


Kileymeister's test account.  I upload engines and demos and stuff for public use.
Currently Working on: Grapple Arms!

Offline

 

#4 2012-01-06 15:08:25

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: Defining visual arrays on a board: Noughts and crosses

schusteralex2 wrote:

So, is this like tic tac toe

Yes, noughts and crosses is what we call it in UK  tongue


Why

Offline

 

#5 2012-01-09 11:49:28

schusteralex2
Scratcher
Registered: 2011-09-17
Posts: 1000+

Re: Defining visual arrays on a board: Noughts and crosses

RedRocker227 wrote:

schusteralex2 wrote:

So, is this like tic tac toe

Yes, noughts and crosses is what we call it in UK  tongue

ok


http://i44.tinypic.com/2uj37ds.gif

Offline

 

#6 2012-01-09 17:17:57

markdad
New Scratcher
Registered: 2011-12-28
Posts: 2

Re: Defining visual arrays on a board: Noughts and crosses

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

Offline

 

#7 2012-01-09 17:33:01

luiysia
Scratcher
Registered: 2011-07-05
Posts: 1000+

Re: Defining visual arrays on a board: Noughts and crosses

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.


http://i50.tinypic.com/dx00pd.gif

Offline

 

#8 2012-01-09 17:36:27

PythonDreamer
New Scratcher
Registered: 2012-01-08
Posts: 64

Re: Defining visual arrays on a board: Noughts and crosses

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

 

#9 2012-01-11 04:08:43

Liru
Scratcher
Registered: 2012-01-11
Posts: 1000+

Re: Defining visual arrays on a board: Noughts and crosses

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

 

#10 2012-01-11 04:31:51

my-chemical-romance
Scratcher
Registered: 2011-04-24
Posts: 1000+

Re: Defining visual arrays on a board: Noughts and crosses

Here.

Although winning doesn't work anymore, the code should still be there.

Offline

 

Board footer