• Embed Doc
  • Readcast
  • Collections
  • 1
    CommentGo Back
Download
 
Java Game (with Greenfoot) Lesson 2: Tic-Tac-Toe Game Board
1.
 
Quick intro on Programs, Functions, Classes, Subclasses, and ObjectsComputer programs are one way for humans to communicate with machines. Usually they are written in human-readable format such as Java, C++, python, and Ruby, but sometimes they are written in more cryptic languages such asassembly language (bytes and registries, anyone?). To compile a program is to convert the human-readable codes tomachine-readable codes, which are binary codes.00000101010000001010101000110001010101010101010A
function
is a unit of execution. A
class
is like a Lego mold and an object is like a Lego block. If a class is named Car, thenall
objects
of the
Car 
class will have whatever features (aka functions)
Car 
class has. You can also consider a class like atype. An object of the
Car 
class can be said to be of the
Car 
type. All objects of the
Car 
type will have features like
move,stop,
etc. Using the Lego theme, a subclass of a class
Car 
has a “mold” similar to that of the
Car 
class, but its “mold” isenhanced to include battery-related features. For example, if a class called
Hybrid Car 
is a subclass of the class
Car,
then
Hybrid Car 
will not only have the features of 
Car 
but also its own battery-related feature.2.
 
Create a new scenarioA Greenfoot
Scenario
is just a project. There are several scenarios that came with the Greenfoot install and they arelocated in <GREENFOOT_INSTALL_DIRECTORY>/scenarios. For example, if your Greenfoot software is installed inC:/Greenfoot, then the sample scenarios will in under C:/Greenfoot/scenarios.Select “Scenario”=>”New”, and then enter” TicTacToe” for the project name.
 
The new scenario would look like this. Feel free to close the “wombat” scenario if you’d like.3.
 
Change the world to be a 3-by-3 boardTo create the TicTacToe board, we need to create a subclass of the World. Right click on the World button and click“New subclass”.
 
Enter “Board” as the class name and then select the cell image from
backgrounds
category. Click OK.The Board class has been created. Next, we will make it draw the background.
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...

Revisions/Addition: 1. Changed code to populate the game board with all nine pieces 2. Explain default construction

You must be to leave a comment.
Submit
Characters: ...