An Introduction to Programming Using Alice 2 2 2nd Edition Charles W. Herbert 2024 Scribd Download
An Introduction to Programming Using Alice 2 2 2nd Edition Charles W. Herbert 2024 Scribd Download
https://ebookultra.com/download/an-introduction-to-programming-using-
visual-basic-2008-with-visual-studio-expression-edition-dvd-schneider/
ebookultra.com
https://ebookultra.com/download/an-introduction-to-programming-in-
emacs-lisp-2nd-edition-robert-j-chassell/
ebookultra.com
https://ebookultra.com/download/doing-time-an-introduction-to-the-
sociology-of-imprisonment-2-ed-edition-matthews/
ebookultra.com
https://ebookultra.com/download/foundations-of-object-oriented-
programming-using-net-2-0-patterns-1st-edition-christian-gross-auth/
ebookultra.com
Computability Theory An Introduction to Recursion Theory
1st Edition Herbert B. Enderton
https://ebookultra.com/download/computability-theory-an-introduction-
to-recursion-theory-1st-edition-herbert-b-enderton/
ebookultra.com
https://ebookultra.com/download/struts-2-design-and-programming-a-
tutorial-2nd-edition-budi-kurniawan/
ebookultra.com
https://ebookultra.com/download/introduction-to-scientific-
programming-and-simulation-using-r-1st-edition-owen-jones/
ebookultra.com
https://ebookultra.com/download/the-life-and-letters-of-charles-
darwin-volume-2-including-an-autobiographical-chapter-1st-edition-
charles-darwin/
ebookultra.com
https://ebookultra.com/download/programming-wireless-devices-with-the-
java-2-platform-2nd-edition-roger-riggs/
ebookultra.com
An Introduction to Programming Using Alice 2 2 2nd
Edition Charles W. Herbert Digital Instant Download
Author(s): Charles W. Herbert
ISBN(s): 9780538478663, 0538478667
Edition: 2
File Details: PDF, 68.37 MB
Year: 2010
Language: english
An Introduction
to Programming
Using Alice 2.2
Second Edition
pi
ii ' H i '
Charles W. Herbert
m to Programming Using A
« COURSE TECHNOLOGY
ond Edition Herbert «• C t N i j A G E Learning"
Leilehua Maly graduated from the University of Hawaii
at Hilo in 2003 with a B.S. in Computer Science. After
graduation, he moved to Seattle to work as a software
engineer at Amazon.com. Leilehua is currently
employed as a software engineer in the Windows
Mobile and Embedded division of Microsoft.
J
You knew you were headed for a career in Computer Science when...
I realized how much fun it was to make a computer do what I want.
AN INTRODUCTION
PROGRAMMING
2.2
S E C O N D EDITION
by Charles W. Herbert
; COURSE TECHNOLOGY
t% CENGAGE Learning-
Purchase any of our products at your local college store or at our preferred
online store www.cengagebrain.com
Some of the product names and company names used in this Course Technology, a part of Cengage Learning, reserves the
book have been used for identification purposes only and may right t o revise this publication and make changes f r o m t i m e t o
be trademarks or registered trademarks o f their respective t i m e in its c o n t e n t w i t h o u t notice.
manufacturers and sellers.
The programs in this book are for instructional purposes only.
Any fictional data related t o persons or companies or URLs used
throughout this book is intended for instructional purposes only. They have been tested w i t h care, but are not guaranteed for any
At the time this book was printed, any such data was fictional particular intent beyond educational purposes. The author and
and not belonging t o any real persons or companies. the publisher do not offer any warranties or representations, nor
do they accept any liabilities w i t h respect t o the programs.
CHAPTER T W O
Methods 31
CHAPTER THREE
Events 63
CHAPTER FOUR
Algorithms 97
C H A P T E R FIVE
C H A P T E R SIX
CHAPTER SEVEN
C H A P T E R EIGHT
C H A P T E R NINE
CHAPTER TEN
APPENDIX A
APPENDIX B
APPENDIX C
GLOSSARY 321
INDEX 327
Table of Contents
PREFACE ix
FOREWORD TO THE FIRST EDITION xv
CHAPTER ONE
A n Introduction t o Alice a n d O b j e c t - O r i e n t e d P r o g r a m m i n g 1
Object-Oriented Programming and Alice 2
Tutorial 1A—Exploring the Alice Interface 4
The Main Work Areas of the Alice Interface 7
Other Elements of the Alice Interface 9
Menus 9
Tutorial 1 B — P l a y i n g an Alice World 10
Tutorial 1 C — C r e a t i n g Your First Alice World 12
Adding Objects to an Alice World 14
Object Classes and Instances in Alice 15
Positioning Objects 17
Adding Some Action 18
Closing and Reloading a Saved World 22
Tutorial 1 D — P r i n t i n g Code from an Alice World 22
Tutorial 1 E — S a v i n g an Alice World as a Movie File 23
Chapter Summary 26
Review Questions 26
Exercises 27
CHAPTER TWO
Methods 31
Top-Down Design and Modular Development 32
The Software Development Cycle 36
Designing Methods 36
Coding Methods in Alice 37
Testing and Debugging Alice Methods 37
Tutorial 2 A — W o r k i n g with Primitive Methods in Alice 39
Running Primitive Methods Directly 41
Using Primitive Camera Methods to Find a Lost Object 43
Tutorial 2 B — C r e a t i n g New Methods in Alice 45
Setting the Scene 46
Designing a Method 49
Coding the J u m p Methods 50
Creating the Main Method 52
Testing (and Debugging) Your Finished Software 53
Tutorial 2 C — M e t h o d s With Parameters 54
Creating a Parameter 55
Using a Parameter 56
Chapter Summary 58
Review Questions 59
Exercises 59
Table of Contents V
CHAPTER THREE
Events 63
Event-Driven Software 64
Three-Dimensional Space 65
Tutorial 3 A — E v e n t s in Alice 70
Exploring Events 70
Creating a Sample World for Event Exploration 71
Alice Event Types 74
The When a Key is Typed Event 76
The While a Key Is Pressed Event 78
The When the Mouse Is Clicked on Anything Event 78
Additional Notes About Mouse Events 79
Tutorial 3 B — B u i l d i n g Camera Controls with Events 80
Open an Existing World 80
The Let the Mouse Orient the Camera Event 82
The Let the Mouse Move the Camera Event 82
The Let the Arrow Keys Move the Camera Event 83
Tutorial 3 C — B u i l d i n g a Flying Machine in Alice 84
Software Specifications 84
Refining Specifications 84
Code the World—Specification 1 , Create a World with a Seaplane 87
Code the World—Specification 2, Animate the Seaplane 89
Code the World—Specification 3, Add Turn Controls 89
Code the World—Specification 4 , Add a Find Control 90
Test the World 90
Debug the World 91
Chapter Summary 92
Review Questions 93
Exercises 94
CHAPTER FOUR
Algorithms 97
Elements of Logical Structure 98
Flowcharts 99
Flowcharting Template 100
Flowchart Symbols 100
Linear Sequences 101
Selection S e q u e n c e s — B r a n c h i n g Routines 103
Binary and Multiple Branching 103
Binary Branching 104
Pseudocode 104
Repetition S e q u e n c e s — L o o p i n g 105
Pretest and Posttest Loops 106
Count-Controlled and Sentinel Loops 108
Parallel Algorithms 110
Tutorial 4 A — B r a n c h i n g in Alice Methods 110
User Functions in Alice 111
Tutorial 4 B — A Simple Count-Controlled Loop 116
Tutorial 4 C — U s i n g the While Instruction 118
VI An Introduction to Programming Using Alice 2.2
CHAPTER EIGHT
Lists a n d A r r a y s in Alice 213
Data Structures in Alice 214
The Need for Different Data Structures 214
Lists in Alice 217
Arrays in Alice 219
Tutorial 8 A — E i g h t Ballerinas 220
Exploring the Ballerina Movement Methods 221
Creating a List of the Ballerinas 222
Creating a Dance Routine for the Ballerinas 224
Tutorial 8 B — M a r c h i n g Toy Soldiers 227
The Toy Soldiers World 227
Creating a Marching Routine 229
Tutorial 8 C — S a l u t i n g Toy Soldiers 232
Creating a Generic Salute Method 232
Making All of the Soldiers Salute 237
Tutorial 8 D — S o r t i n g an Array of Sixteen Ballerinas 238
Chapter Summary 241
Review Questions 242
Exercises 243
CHAPTER NINE
M a k i n g A n i m a t e d M o v i e s with Alice 245
Introduction 246
The Moviemaking Process 247
Tutorial 9 A — R e c o r d i n g a Movie from Alice 248
Preproduction 250
Movie Types 252
Movie Topics 253
Outlining the Plot: Scenes, Shots, and Storyboarding 254
Tutorial 9 B — S t o r y b o a r d i n g 257
Camera Placement And Shot Transitions 258
Tutorial 9 C — S i m u l a t i n g Multiple Cameras 259
Tutorial 9 D — R e c o r d i n g Camera Positions for a Multi-Shot Scene 261
Postproduction 266
Chapter Summary 267
Review Questions 268
Exercises 269
CHAPTER TEN
Video G a m e Programming 271
What Is a Video Game? 272
Video Game Careers 274
Game Development Project Management 274
Game Design 275
Script Writing 275
Graphics Arts 275
Music and Sound Engineering 276
Programming 276
Quality Assurance 277
viii An Introduction to Programming Using Alice 2.2
Three things have been changed in this new edition of the text:
Alice 2.2
The second edition of this book is based on Alice 2.2 because this is the best current version
of Alice for learning introductory programming for most students. Some of the features that
did not work well, or at all, in Alice 2.0 now work in Alice 2.2, such as the ability to export
movie files. Alice 3.0 is still not yet ready for prime time, and when it is it may not be the
best vehicle for a general introduction to programming. It is significantly more complicated
and more difficult to use than Alice 2.2. Alice 3.0 will probably be a better vehicle for a
course in which students wish to develop more sophisticated programming skills, or for stu-
dents who wish to dive deeper into things like the nature of events or human computer inter-
action in second-level Java courses. Because it is not as easy to use as Alice 2.0 or Alice 2.2,
Alice 3.0 could be a barrier to getting started with programming for many students.
Therefore, this book, which is intended to introduce students to the nature of computer pro-
gramming, is based on Alice 2.2.
New Chapters
The two new chapters on making animated movies and video game programming aren't
included to displace any of the previous chapters, but rather to extend them. The chapters
should provide students with a good foundation in each area. The animated movie chapter
teaches students about things like camera angles, fades, and transitions so that they can use
An Introduction to Programming Using Alice 2.2
these in programming virtual worlds or in making movies. The video game chapter discusses
careers in the video game industry and exposes students to the kinds of programming needed
for video games.
These chapters aren't intended for courses in filmmaking or game development, but to intro-
duce these areas to students learning programming because these are things that many mod-
ern professional programmers need to learn. Moviemaking and gaming are also areas of
interest to most students, which could spark an interest in computer programming and
related math and physics.
Many years ago, Galileo and others explored the most fundamental concepts in the universe—
optics, heat, mechanics, and so on—as a foundation for understanding and developing the
newest technologies of the day. And so it is with modern computer science. The more we
understand things that don't change, the more we can explore and affect things that do
change. Conversely, the more we wish to know about today's newest and hottest technologies,
the more we find ourselves learning about the immutable foundations of the universe in
which we live. Today's emerging technologies that motivate people to learn include personal
moviemaking and interactive gaming. It may seem like they have been around forever, but
moviemaking and video gaming are relatively new topics that are becoming increasingly
important for computer programmers, are motivating for students, and are just beginning to
appear in most introductory computer programming courses.
R e v i s i o n in E x i s t i n g C h a p t e r s
The chapters that were in the first edition have been revised for this new edition in response
to feedback from instructors and students. More images are included, the language of the text
has been clarified in places, and some of the examples and exercises have been changed. The
fundamental goals and approach of the text remain the same.
O r g a n i z a t i o n o f t h e Text
Each lesson in this text is composed of two parts—lecture and lab. The lecture part of the les-
son includes reading material for the student and lecture material for the teacher that
parallels the reading material. For the most part, the reading material is relatively brief and is
intended to establish a foundation for the lab component. The new chapter on video game
development contains a bit more reading material than most chapters, providing students
with an overview of video game development careers and the kinds of programming used in
video games.
The lab component includes hands-on tutorials in Alice, and sometimes related work intended
to help them explore the concepts of the lesson. The lab component consists of one or more
hands-on step-by-step tutorials, followed by review questions and open-ended exercises the
students should be able to complete on their own, either individually, or in groups, once they
Preface
understand the step-by-step exercises. The exercises contain notes directing the students'
attention to what they should be learning as they carry out the exercise. It is not enough to com-
plete the steps in the exercise, each student should understand what was done, why it was
done, and should be able to repeat the exercise without the directions.
This edition of the book is organized in ten chapters, with goals as follows:
The notion of objects is introduced in the first chapter. Understanding the nature of an object
as a collection of properties and methods that can manipulate those properties is critical in
modern computer programming. The text mentions but does not explore more sophisticated
concepts of object-oriented programming, such as inheritance and polymorphism. In that
sense, like Alice, it is not truly object-oriented, but might better be described as object-based.
I have found that attempts to introduce students to a complete understanding of objects upon
their first exposure to programming is counterproductive. Students can learn more about
inheritance and polymorphism after they have some experience with objects and program-
ming. This approach actually enables students to develop a better grasp of important funda-
mental concepts, like Boolean logic and the nature of algorithms, and to more deeply explore
in a second course how inheritance—with public, private, and protected properties, sub-
classes, super-classes, and so on—really works.
Chapters 7 and 8 present topics that are not covered by everyone in an introductory pro-
gramming course. They are intended to provide students with a first exposure to recursion
and to data structures. Some preliminary work with developmental math and English stu-
dents has shown that the chapters work in making this material accessible to them.
Lesson plans, course outlines, and additional instructional materials for all three approaches,
as well as a complete proposal for a course based on Alice, can be found on the Web site for
the text.
Acknowledgements
May people are responsible for the production of this book, and I am grateful to them all.
Mary Pat Shaffer was the Development Editor, who worked most closely with me in creating
the book's second edition. I appreciate her hard work, and thank her for her patience and
guidance in working with me. This is a much better book because of her efforts.
The book's copy editor was Harold Johnson. Copy editors are the unsung heroes of the pub-
lishing world; guardians of language and thought who painstakingly sift through material
with a fresh eye, finding things that others miss. Chris Scriver and Serge Palladino served as
quality assurance testers, checking each of the tutorials and exercises in the manuscript to
make sure that the final text, the student data files, and the solutions for instructors are cor-
rect. Course Technology stands out among publishers in part because of their attention to
such details.
I am grateful to Alyssa Pratt, Senior Product Manager and Amy Jollymore, Acquisitions
Editor for Computer Science & Programming, two key people at Course Technology who
helped make this edition of the book possible. Thanks also to Melissa Panagos, Content
Product Manager, who guided this book through the production process, and to Marissa
Falco, Art Director, who led the efforts to create the new cover and update the interior design
for this edition.
The original manuscript for the second edition of this book was reviewed by:
I am grateful for their time and the influential insights they offered. Many improvements
were made because of their efforts.
I'd like to thank Walt Johnson, one of my colleagues at Community College of Philadelphia,
who provided the IBM flowchart template shown in chapter 4. Walt is retired now, but for
years I had the opportunity to teach with him and learn much about programming from him.
Early in his career, Walt worked with some now-primitive IBM equipment, like the 1401 and
360 series, and became a master at improvising and inventing new techniques to get a pro-
gramming job done. Many things change rapidly in the world of computing, but one thing that
will never change is the need for people like Walt, filled with intelligence, enthusiasm, and
the ability to work well with computers and with the people who use them.
This book is dedicated to my father, George William Herbert, Jr., who passed away during the
week when the first edition of the book went to press. He was the athletic director for the
Maplewood School District in Colonie, NY for more than 30 years, but spent most of his sum-
mers driving our family around the country to visit as many of America's national parks as
possible. There are many heroes in the world, but few as important as a good father.
The Alice software can be found at www.Alice.org, the official Alice Web site.
Each chapter of this book has clearly stated objectives, one or more readings related to those
objectives, and several hands-on tutorials. A chapter summary, review questions, and further
exercises are included at the end of each chapter. Note that Appendix A of this text contains
technical information about the Alice software, which is easy to install and use.
Note that the text was quality assurance tested using Alice v. 2.2 on Windows 7 Ultimate.
Student Data Files These are provided on the Course Technology Web site at www.cengage.com/
coursetechnology. The student data files contain all of the Alice worlds, image files, and so on
that are needed within the tutorials.
Solution Files Solutions to the review questions and exercises found in the book are
provided for instructors on the text's Companion Site at www.cengage.com/coursetechnology.
The solutions are password protected. The solution files contain the completed Alice worlds
that are the final product of each tutorial.
Foreword to the First Edition
Note from the author: I asked Randy Pausch, Dennis Cosgrove, and Caitlin Kelleher to tell us
about the development of Alice, the current state of affairs regarding Alice, and where things
seem to be headed in the future. The sections that follow are what they wrote in reply. We've
also included their individual bios at the end of this foreword.
All A b o u t A l i c e
So far there have been three distinct phases in the development of Alice, the Goggles and
Gloves phase, the "rapid prototyping 3D graphics phase," and the Teaching Introductory
Programming phase.
The Goggles and Gloves phase started in the early 1990's at the University of Virginia, where
Randy was on the faculty, heading a 20-person User Interface Group investigating the bound-
ary where people and technology interact. We were trying to make virtual reality more acces-
sible by developing improved interfaces and lower-cost human computer interaction
hardware and software. The paper Virtual Reality on Five Dollars a Day, which was pub-
lished in the April 1991 edition of the ACM SIGCHI's journal Human Factors in Computing
Systems, describes some of our work. It's available online through www.alice.org, where we
provide links to publications related to our work on Alice.
We call that first phase the Goggles and Gloves phase because we really were focusing on the
development of virtual reality systems in which the participant (the term user really doesn't
seem to capture the sense of it; Disney Imagineering uses the term "guest") enters a virtual
world by putting on a VR helmet and gloves. One mantra was "If it doesn't have a glove, it's
not VR." At the time, virtual reality was in its infancy. So, in addition to developing VR inter-
faces, we were working on software systems to test the interfaces. One of our early reseach
projects was SUIT, the Simple User Interface Toolkit, to which Matt Conway and Rob DeLine
contributed heavily. Matt was instrumental in recognizing that vocabulary matters—that the
choice of names for behaviors is critically important in a system for novices. His work was
very influential in shaping the direction of the development work that led to the Alice sys-
tem we have today. His doctoral dissertation, Alice: Easy-to-Learn 3D Scripting for Novices
should be required reading for people interested in how to design systems for novices. It's
available on the Web at www.alice.org.
The language for programming VR systems required one to think in terms of X,Y,Z coordi-
nates, and to use terms like translate, scale, and rotate to describe things happening in a vir-
tual world. On the early Silicon Graphics machines, angles were measured in integers
representing tenths of a degree, so commands like rotate -3600 were common. A person
needed fairly advanced mathematics skills to program graphical objects in a 3D system.
An Introduction to Programming Using Alice 2.2
Engineers and physicists had the keys to get in, but many other intelligent, talented and cre-
ative people, such as artists, and filmmakers, did not. Matt saw that the language of VR was
a part of the problem and that if we could change the language, then VR systems would be
easier to use, and thus more accessible for novices and more powerful for experts at the same
time. In his dissertation he wrote that "the tradeoff between power and simplicity is often a
false one." He led us in discovering that using more everyday terms terms like move, turn,
and resize instead of technically-oriented terms like translate, rotate, and scale could go a
long way toward achieving the powerful simplicity that would become one of the hallmarks
of Alice. Turn left 1 revolution makes sense to a lot more people than rotate X -3600.
The first version of Alice emerged as an easy-to-use scripting system for building virtual
worlds. The system itself was a combination of C and Python code, with which one could
rapidly create virtual worlds by iterating Python scripts. Over the years, the programming
features of Python have been replaced with dragging and dropping code elements.
It's important to note that even early versions of Alice could not have been created without
the efforts of a dedicated team of people. In particular, PhD student Rich Gossweiler, was
responsible for the implementation of the very early versions of Alice, and its co-system
DIVER. Tommy Burnette was also responsible for a great deal of the early Alice software
implementation. A complete listing of people who have contributed to the Alice project over
the years is available at www.alice.org .
At about this time (the mid 1990's) our work was funded by a variety of sources, including
the National Science Foundation (NSF) and the Defense Advanced Research Projects Agency
(DARPA). These are two of the most amazing agencies in the federal government, when it
comes to return on investment of public money. A while back, NSF and DARPA asked for
funding to explore using computers as tools for communication among educators, scientists,
and engineers, and the result is the Internet. We believe that any time they ask for money,
Congress should jump at the chance to spend public funds so wisely. One day one of the peo-
ple from the Department of Defense who was overseeing our project said that we should for-
get about the virtual reality hardware and concentrate on the software we were building. He
argued that our most important contribution was the way in which our software could be
used as a rapid development system for 3D graphics prototyping.
During the summer and fall of 1995, Randy spent a sabbatical at Walt Disney Imagineering's
Virtual Reality Studio working on the "Aladdin" project which was featured at EPCOT
Center and, later, at DisneyQuest. The experience working with the Imagineering team
helped to make it clear that we were moving into a realm of work that would require both
artists and engineers. In the spirit of bringing artists and engineers together, Randy created a
course called "Building Virtual Worlds" in which teams of artists and engineers work together
Foreword to the First Edition xvii
to create interactive virtual worlds. In the Spring of 1997, the research group moved to
Carnegie Mellon University, in order to take advantage of the fairly unique cross-disciplinary
focus at CMU. However, no story of the Alice system would be complete without acknowl-
edging how gracious the University of Virginia was in allowing us to continue work on Alice
seamlessly, by allowing us to transfer our funding and research to another university, and we
are very grateful for their support. We have fond memories of the University of Virginia and
highly recommend it to students looking for a great place to go to school.
Over the next few years we gradually moved into the third phase of our work as we devel-
oped better ways to build virtual worlds. Alice became a workhorse for the "Building Virtual
Worlds" course, which was then being taught at Carnegie Mellon, for several years, finally
realizing our dream of allowing "a 1,000 creative flowers to bloom." However, with respect to
making 3D graphics programming easier, we slowly began to realize that we had the problem
inside-out. Instead of thinking about how to improve programming to make 3D graphics
more accesible, it started to become clear that 3D graphics could make programming more
accesible. A seminal event occured one day when Randy was on a family trip to
DisneyWorld. His ten year old nephew Christopher spent the day working with Alice on a
laptop as they drove. Chris programmed 3D graphics for eight hours straight, never really
having trouble with the 3D part, but constantly asking for help about "where the commas and
semicolons had to go." In Randy's words: "I immediately realized that this was a problem we
could solve." Some work had already been done on the drop and drag interface, but now the
creation of a drag and drop interface for creating Alice programs became a priority.
Wanda Dann and Steve Cooper both became important contributors to the future of Alice at
about this time. Wanda, who teaches Computer Science at Ithaca College, and Steve, who
teaches at St. Joseph's University, have long been interested in how visualization can be used to
teach object-oriented programming concepts. They began to work with us to shape Alice as a
better tool to teach introductory programming. We were all beginning to recognize that Alice
works well for teaching introductory programming for three primary reasons: minimization of
the problems of syntax, the ability to see the results of object-oriented programming in a live
virtual world, and the motivation provided by working in such an exciting environment.
Since 1999 Steve and Wanda's efforts developing educational materials based on Alice, test-
ing Alice in the classroom, and providing feedback to Dennis and company as the software
was refined have been instrumental in shaping the current look and feel of Alice.
In addition to helping students with the technical hurdles, Alice is allowing us to begin
changing the ways in which we introduce students to computer programming. The way we
teach computer programming hasn't changed much in the past 50 years, despite the fact
that the way we use computers has. The first computers that appeared in the middle of the
20 th
century were literally used to help bombs hit their targets. The early high-level pro-
gramming language, FORTRAN, was designed to help scientists and engineers with their
An Introduction to Programming Using Alice 2.2
number crunching. Today, how many high school students are excited about writing code
to generate the first 10 Fibonacci numbers? Using Alice, students learn the basics of pro-
gramming while creating animated stories and games. Wanda Dann has been a strong pro-
ponent for using Alice to introduce programming through storytelling at the college-level,
and Caitlin has been studying using the activity of storytelling in Alice to interest middle-
school girls in learning to program. In addition to being more motivating than assignments
like sorting a list of numbers, creating animated stories helps to make computer program-
ming seem less foreign. Not many people are familiar with the concept of mathematical
algorithms, but everyone is familiar with storytelling. By using Alice to tell story in a vir-
tual world, young people become engaged in linear sequencing, modular development,
and planning before implementation—three of the most important skills for early success
in computer programming.
One highly desirable side effect of using Alice to introduce programming through story-
telling is that more young women are attracted to the discipline. It's no secret that Computer
Science, unlike Law and Medicine, has failed to attract women in significant numbers.
Currently, women constitute less than one-third of all Computer Science majors in the US,
and less than one-fourth of those earning Ph.Ds in Computer Science. According to Caitlin s
research (her dissertation, when completed, will be available at www.alice.org), Alice has the
power to begin to change that; thereby changing the culture of the Computer Science class-
room and workplace.
So where do things stand now? Well, Chuck Herbert's programming textbook is only the second
book to use Alice as a tool to teach programming. The Dann, Cooper and Pausch book was the
first. Course Technology's Alice CourseCard is the first widely available reference material for
Alice 2.0. More material is sure to follow as the number and type of schools using Alice
increases. Last year we knew of approximately 30 colleges and universities using Alice. This
year we are aware of about 60 colleges and universities and at least that many high schools, as
well—and there are probably more folks using Alice that we don't know about.
Currently most people who use Alice seem to be doing so to teach introductory program-
ming, although it is starting to be used in other disciplines. The most widespread educa-
tional model for the use of Alice is to use Alice for the first half of an introductory
programming course, followed by the use of Java or a similar commercial programming
language in the second half of the semester. That model seems to be working remarkably
well in places like Duke University, the University of Mississippi, Haverford College, and
here at Carnegie Mellon.
Foreword to the First Edition xix
Within the past three years other models for the use of Alice have emerged, particularly in
the community colleges, and in courses other than computer programming. Here are just a
few of the efforts we know about:
The most common question people ask us these days is about the future of Alice. Right now,
the 04/05/2005 Version of Alice 2.0 is reasonably stable and reliable, and runs on Windows and
the Macintosh. There are no plans develop it further. Instead, work is beginning on Alice 3.0.
How will Alice 3.0 be different? Well, to start with, one thing about it will be the s a m e —
it will continue to be provided free of charge to the public from Carnegie Mellon University.
The University has been very gracious in supporting us, and we are committed to maintain-
ing Alice as an open source, non-commercial, piece of software. This "purity" is important;
many students have worked hard over the years to contribute to the Alice effort, and we
believe it must continue to be "for the people." All of Randy Pausch's royalties from the
Dann, Cooper and Pausch book are donated by him to Carnegie Mellon, to help support the
software development. We are glad to hear that Chuck Herbert has also pledged a portion of
his royalties from this book to the Alice effort. We had various corporate sponsors over the
years, most notably Intel and Microsoft, and we are pleased to say that Electronic Arts (EA) is
a major sponsor of Alice version 3.0.
xx An Introduction to Programming Using Alice 2.2
We expect that Alice 3.0 will be a pure Java implementation, and that you will be able to dump
the Java code for an Alice 3.0 world and then work with it in Java. That's a big change from
Alice 2.0, which does not create Java code, but works more like an interpreter that directly exe-
cutes Alice methods. This should serve several purposes, including helping to make the transi-
tion form Alice to Java smoother in introductory programming courses.
You can expect the new version of Alice to be more truly object-oriented than the current
version. Alice 2.0 is a good tool to introduce the concept of an object as a collection of prop-
erties and methods, but it does not provide the ability to create true class-level methods, true
inheritance, or the overriding necessary for polymorphism. Alice 3.0 should have some, if
not all, of these features.
Caitlin's work has shown that users, especially young people, can do more and learn more
with objects that have higher order primitive methods, such as walk, sit, and touch instead of
just move, turn, and so on. There will probably be more methods that manipulate objects and
their sub-parts together, and the gallery of available objects will probably be richer that the
current Alice gallery.
The overall look and feel of Alice will also probably be less toy-like. Anyone who has used Alice
for more than a few minutes knows it's not a toy, but it looks like a toy. The new version should
still be easy to use, but people probably won't think "Fisher Price" when they first see it.
The team that started working on virtual reality interfaces years ago at the University of
Virginia had no idea that our work would lead to Alice and that it would become such an
important tool in Computer Science education. As is the case with many NSF funded projects,
the taxpayers have gotten more than their money's worth, but just not in the way one would
have thought reading the original proposals. Such is the path of science and exploration. Now
that we know where we are headed, our goal is to make Alice the vehicle of choice for some-
one's first exposure to computer programming, for everyone—worldwide—from 5 th
grade
through college.
Randy Pausch
Dennis Cosgrove
Caitlin Kelleher
Carnegie Melon University,
December 2005
Foreword to the First Edition
Dennis Cosgrove is a Human Computer Interaction Project Scientist (formerly Senior Research
programmer) at Carnegie Mellon University, where he has spent the last several years as the pri-
mary software architect and implementer for Alice 2.0, 2.2, and 3.0. He was one of the principal
developers of the earlier PC/Windows 95 Alice implementation at the University of Virginia.
In addition to his work on Alice, he has contributed to the development of an eye-tracking sys-
tem that allows quadriplegics to interact with a computer.
Run the Alice software and locate and describe the following components of the Alice
interface: World window, Object tree, Details area, Editor area, Events area, menu bar,
Trash can icon, Clipboard icon, Play button, Undo button, and Redo button
Create a new Alice world by adding objects to a blank world, positioning them, and
using simple methods to animate those objects
An object can be something in the physical world or just an abstract idea. An airplane, for
example, is a physical object that can be manipulated by an autopilot—a computer that can
fly the plane. To the computer, the airplane is an object.
Most objects that computers manipulate are not physical objects. A bank transaction is an
example of an object that is not physical. There is usually a paper record of a transaction;
however, the transaction itself is simply a concept. It is an object, but not a physical object.
Whether an object exists in the physical world doesn't matter much in terms of what hap-
pens inside a computer. To a computer, an object is simply something that can be repre-
sented by data in the computer's memory and manipulated by computer programs. The data
that represents the object is organized into a set of properties. Each property describes the
object in some way. For example, the weight of an airplane, its location, the direction in
which it is facing, and so on are all properties of the airplane. A computer manipulates an
object by changing some of its properties or some of the properties of parts of the object. For
instance, the autopilot might change the angle of a wing flap, which in turn affects the
entire airplane.
Sometimes the hardware in a computer translates these changes in properties into actions
that affect the physical world—as an airplane's autopilot does—and sometimes the changes
in an object only affect information in the computer's memory and have no direct effect on
the physical world. For example, when a bank deposit is recorded on a computer, the
amount of money in the bank balance property of the bank account object is changed, but
there is no other immediate effect on the physical world.
The programs that manipulate the properties of an object are called the object's methods.
An object is a collection of properties along with the methods that are used to manipulate
those properties. The values stored in the properties of an object at any given time are col-
lectively called the state of an object. This modern approach to computer programming is
known as object-oriented programming, or OOP for short.
Object-Oriented Programming and Alice 3
Learning to program a computer is often a difficult task because it requires learning about
programming concepts and the language of programming at the same time. It's also difficult
because people find it hard to visualize all of the changes that are occurring as a computer
program runs. Alice can make it easier to learn to program a computer by helping with both
of these problems.
Alice uses an object-oriented style of programming. The objects in Alice exist in a three-
dimensional virtual world, much like a modern video game. In fact, the virtual world itself
is an object in Alice—it has properties and methods that can be used to manipulate those
properties. Alice is similar to other modern object-oriented programming languages, such as
Java, C++, or Visual Basic. However, as you will see, Alice is constructed so that you don't
need to memorize the grammar and syntax of the language to write computer programs. As
you are learning Alice, you can concentrate on learning about the ideas of computer pro-
gramming, such as the logic of your algorithms, instead of having to worry about the
spelling and grammar of a new language at the same time.
The virtual world of Alice is one that you can see. Like the real world, it has three-dimensional
space (and time), and each object has properties just like physical objects have properties;
these include color, size, position, the direction in which the object is facing, and so on. Alice
has a camera that allows you to see its virtual world on a computer screen, just as you might
view a movie or a video game. This ability to see what happens to objects in your virtual world
makes it easier to learn computer programming with Alice than with almost any other system
of programming. For instance, if you try to program a white rabbit to run around in a circle,
and instead he simply stays in one spot and spins, you can see that happening on the screen.
You can get instant feedback from viewing the way Alice runs the programs you have created.
Not every programming system is so easy to use.
For more information on computer programming languages, see Appendix C of this book.
Chapter 1 • An Introduction to Alice and Object-Oriented Programming
In summary, there are three things about Alice that make it a more effective tool for learning
programming than almost any other system of programming:
You will also find that Alice is fun and interesting to use, which never hurts when one is
trying to learn something new.
Anyone attempting this exercise should have experience using a computer. You certainly
don't need to be an expert, but you should have some experience with things like word pro-
cessing and accessing the Internet so that you are familiar with Windows, a mouse, a key-
board, and a printer.
1. Start the Alice software. You will see the Welcome to Alice! dialog box
open in front of the Alice Integrated Development Environment (IDE), as
shown in Figure 1-1. If Alice opens without showing you the Welcome to
Alice! dialog box, click File, and then click New World to open this win-
dow. An Integrated Development Environment (IDE) is a computer pro-
gram that is used to write other computer programs. Most modern
programming languages have IDEs with everything you need to create and
run computer programs. Alice is no exception, but its IDE is simpler than
most. The Alice IDE is often called the Alice interface.
The Show this dialog at start check box appears in the lower-left corner o f the Welcome
H W I * to Alice! dialog box. It should be checked so that the Welcome to Alice! dialog box will
appear when Alice starts.
Tutorial 1 A—Exploring the Alice Menace
FIGURE 1 - 1 : The Alice interface with the Welcome to Alice! dialog box
j lit
ft"*" Alice
H Tutora
il "(Recent Wod
rls T
(empa
ltes "| Examp
e
ls ( O p a n a world
Vcfeli*! m
[ ethods f rations create new variable
myfNSt method
DoUiotdtrr ftjtotjother l*Hu> Loop wti.le Foradmorder Fo. allio.jettier Wad prmt
2. Notice that the Welcome to Alice! dialog box has five tabs: Tutorial, Recent
Worlds, Templates, Examples, and Open a world. You can return to this
dialog box at any time while using Alice by clicking File on the menu bar,
and then clicking New World or Open World. Let's look at each of these
tabs before continuing.
3. Click the Tutorial tab and you will see four Alice tutorials. You won't use
the tutorials now, but you may want to come back to them later as an exer-
cise on your own. When you are ready to use the tutorials, either click the
tutorial you would like to run, or click the large Start the Tutorial button to
follow them in order. They are quite easy to follow.
Dr. Caitlin Kelleher from Washington University in St. Louis created the original version
of these tutorials while she was a graduate student at Carnegie Mellon University.
4 . Click the Recent Worlds tab. You will see thumbnail sketches of the most
recently saved Alice worlds. If no worlds have been saved since the Alice
software was installed on your system, this tab will say No recent worlds.
6 Chapter 1 • An Introduction to Alice and Object-Oriented Programming
5. Click the Templates tab. Alice comes with six blank templates for starting a
new virtual world—dirt, grass, sand, snow, space, and water. Each of the
templates includes a texture for the surface, which is called the ground in
Alice, and a background color for the sky.
6. Click the Examples tab. Several example worlds created by the Alice devel-
opers are provided with the Alice software. We'll return to the Examples
tab later in this tutorial.
7. Click the Open a world tab. This tab is used to access Alice worlds saved
on your computer. Click the Browse button to open the Open dialog box, as
shown in Figure 1-2. This dialog box is very similar to the Open File dialog
boxes seen in other programs, such as Microsoft Windows, with navigation
icons across the top, a list of folders and Alice worlds from the current
directory in the middle, and some controls to view and open files at the
bottom. Notice that the Alice world files end with the extension .a2w. This
extension indicates that the files were created with either version 2.0 or
version 2.2 of the Alice software, the two most recent versions. Alice uses a
generic interface that looks the same when using the Windows, Apple, or
UNIX operating systems. Click the Cancel button to return to the Open a
world tab when you are ready to move on.
w
Jim Watson's Worlds
Recent Ray Sweeney's Worlds folders
Walt Johnson's Worlds
airport.a2w
baseball.a2w
Desktop boat game.a2w Alice worlds
chicken is tasty.a2w
cows.a2w
My haunted house.a2w
Documents tiny dancer.a2w
toy soldiers.a2w
My
Computer controls
8. Next, you will look at the Alice interface with an Alice world open. Click
the Examples tab, click the lakeSkater thumbnail, and then click the Open
button to open the lakeSkater Alice world. It will take a few seconds for
Alice to load all of the elements of the world. The name of each element
will briefly appear in a small window in the center of the screen while this
happens. When Alice is finished loading the world, your screen should
resemble Figure 1-3.
FIGURE 1-3: The Alice interface after loading the lakeSkater world
World window
Events area
Object tree
T h e M a i n W o r k A r e a s of t h e Alice Interface
The Alice interface has five main work areas, as shown in Figure 1-3: the World window, the
Object tree, the Details area, the Editor area, and the Events area. There are also several ele-
ments across the top of the interface—a menu bar, three control buttons, a Trash can icon,
and a Clipboard icon. Let's look at each of these before playing the lakeSkater world.
The World window contains a view of the lakeSkater virtual world. The set of blue arrows
below the window controls the Alice camera, which provides you with the view in the win-
dow. Next to the arrows is a large green ADD OBJECTS button, which you will use in
Tutorial l C when you create your first Alice world.
8 Chapter 1 • An Introduction to Alice and Object-Oriented Programming
The Object tree appears to the left of the World window. It shows the objects in the current
Alice world organized as a tree of tiles, with a tile for each object. The plus sign next to an
object shows that it has sub parts, which may be seen by clicking the plus sign. Click the plus
sign to see the parts of the IceSkater object, and then click the minus sign to hide its parts.
T h e Details A r e a
The Details area of the Alice interface is located below the Object tree. It has tabs to show
properties, methods, and functions for the currently selected Alice object. Properties con-
tain information about an object, such as its color and position in the world. Methods are
programs that manipulate an object. A function is a method that returns a value, such as the
distance between two objects.
You may select an object by clicking that object in the World window or by clicking its tile in the
Object tree. Information about the currently selected object will be displayed in the Details area.
Click the World tile in the Object tree to see the World's details in the
Details area.
Click the lake tile to see the lake's details in the Details area.
Click the IceSkater tile in the Object tree and then the properties tab in
the Details area to see the IceSkater's properties.
• Click the methods tab to see the IceSkater's methods.
Click the functions tab to see the IceSkater's functions.
T h e Editor A r e a
The largest area of the Alice interface is the Editor area, which appears to the right of the
Details area. Here, you assemble and edit methods by clicking and dragging tiles from other
parts of the interface. The bottom of the Editor area has a row of logic and control tiles that
can be used to put branching, looping, and other logical structures into the algorithms that
will make up an object's methods. Most of the time that you spend working with Alice will
be spent using the Editor area.
The Events area in Alice is above the Editor area. The Events area shows existing events
and is used to create new events. An event consists of a condition, called an event trigger,
and a method, called an event handler. Whenever the event trigger occurs, the event han-
dler is called into action. For example, you might want the sound of a splash to occur if an
ice skater falls through the ice. Falling through the ice would be the event trigger, and the
method that makes the splash sound would be the event handler.
Tutorial 1A—Exploring the Alice Interface
Some events, such as causing a method to run when a key is pressed, provide user interac-
tion for an Alice world. The flight simulator world that can be accessed through the
Examples tab is an interactive world that you might want to take a look at after finishing
this chapter. Events are very important for interactive simulations and gaming and are cov-
ered in detail in Chapter 3.
O t h e r E l e m e n t s o f t h e Alice I n t e r f a c e
In addition to the main work areas that you have just explored, the Alice interface also has
two icons, three buttons, and a menu bar near the top of the screen.
The Trash can icon and the Clipboard icon are used for editing Alice worlds.
You can delete an item in an Alice world, such as an object or instruction tile, by dragging
and dropping it in the Alice Trash can. You can also right-click an object or tile, and select
delete from the menu that appears.
You can copy any object, event, or method in the Editor area by dragging and dropping its
tile onto the Clipboard icon in the top-right corner of the interface, and then dragging it
from the Clipboard icon to a new location. You can also duplicate a method tile by right-
clicking it and selecting make copy from the menu that appears; however, this does not
work with Alice objects or events.
The Undo and Redo buttons near the top-left corner of the interface are also useful for edit-
ing an Alice world. You can undo the last change you made by clicking the Undo button.
The effects of the Undo button can be reversed by using the Redo button. Alice can remem-
ber the last several dozen changes that you made. The Ctrl+Z and Alt+U shortcut keys can
be used for Undo. The Ctrl+Y and Alt+R shortcut keys can be used for Redo. There are no short-
cut keys for cut, copy, and paste.
Menus
The Alice interface has a menu bar at the top of the screen with four menus: File, Edit,
Tools, and Help. The menus in Alice are used much less frequently than in many other
computer programs. For now, you will look at only a few of the items on these menus. All
of the features on the Alice menus are listed in Appendix B.
File M e n u The Alice File menu has commands for opening and saving Alice worlds, and
for exiting Alice. It also has several other items that you will explore later, including options
for exporting an Alice world as a Web page or as a video, and exporting code from an Alice
world for printing. You will use these options in later tutorials throughout this book.
10 Chapter 1 • An Introduction to Alice and Object-Oriented Programming
Edit M e n u Currently the only option on the Alice Edit menu is Preferences, which is
used to change settings for the Alice software. Appendix B of this book lists and describes
these settings. The most important thing to know for now is that the Alice Edit menu is not
used to edit Alice methods in the same way that an Edit menu might be used in other soft-
ware. Instead, Alice emphasizes the use of a drag-and-drop interface, which uses the editing
icons and buttons described throughout this book.
T o o l s M e n u The Alice Tools menu contains three options: Text Output, Error Console,
and World Statistics. The Text Output option allows you to see system messages generated
as you play Alice worlds, and the Error Console can be used to look at detailed Alice error
messages. Both of these are rather sophisticated, and are not very useful for novice program-
mers. The World Statistics option allows you to see statistics, such as the number of objects
in a world, the time the world has been open, and many other useful items. Only some of
the information here will be meaningful to you until you learn more about Alice and com-
puter graphics.
H e l p M e n u The Help menu does not contain an option to look up the features of Alice as
you might expect. By not providing a way to look up features, the developers of Alice were
hoping to encourage people to learn about Alice by experimenting with it.
The Help menu does have three options: Tutorials, Example Worlds, and About Alice.
Example Worlds and Tutorials will both take you back to the Welcome to Alice! dialog box.
The About Alice option provides general information about Alice and the Alice Web site,
www.alice.org.
Mil From time to time you may encounter errors while using the Alice software. The Alice
error message box contains a button to copy the error message to the clipboard. You can then
paste the message into programs such as Word or Notepad, although they are often too sophis-
ticated for novice programers to read. You may submit bugs and suggestions about Alice
through the Alice Web site. The Alice team wants to hear from the users of Alice.
In this tutorial, you will experiment with playing an Alice world. Alice worlds fit into one
of two different categories—some Alice worlds are interactive in the way a video game is;
others are simply run and viewed like a movie. In either case, experienced Alice users refer
to "playing" an Alice world the way most software developers talk about "running" a com-
puter program.
The Alice world you will play in this tutorial is the lakeSkater world discussed in Tutorial 1 A.
It is not an interactive world; rather, it is more like watching a movie of an ice-skater's
Tutorial 1B—Playing an Alice World
performance. If you have just finished Tutorial 1A and still have the lakeSkater world open,
then continue with the steps that follow. If not, you will need to run the Alice software and
open the lakeSkater world before starting this tutorial.
1. There are three buttons near the top of the Alice interface, labeled Play,
Undo, and Redo. Undo and Redo are used for editing, as described in
Tutorial 1A. The Play button is used to play the current Alice world. When
this button is clicked, the world will play in a larger version of the World
window, with player controls at the top of the window, as shown in
Figure 1-4. Click the Play button now and watch the show unfold. Let the
world play through to the end at least once before proceeding.
2. Notice that the new window has a speed slider control and five buttons
across the top of the window in which the Alice world plays. The buttons
are labeled Pause, Play, Restart, Stop, and Take Picture.
3 . The Restart button is used to begin playing the current world again from the
beginning. The Pause and Play buttons work like the pause and play buttons
on a DVD player. Click the Restart button now to restart the lakeSkater
world, and then experiment with the Pause and Play buttons.
4. The speed slider is used to change the speed of the world while it is play-
ing. Restart the world, and experiment with the speed slider control.
12 Chapter 1 • An Introduction to Alice and Object-Oriented Programming
5. The Take Picture button captures an image of the currently playing world
and saves it in a data file. Restart the world and click the Take Picture but-
ton to take a picture of the world. An Image captured and stored dialog box
will appear, showing you the full path name of the file that was saved. The
stored image file can be viewed and used as any other computer image file
can be. By default, the images are saved as JPEG files to the desktop.
Appendix B has more information on changing the settings for Alice's
screen capture feature. Click OK to close the dialog box.
6. The Stop button stops the world that is currently playing and returns you
to the standard Alice interface. Once the Stop button is pressed, you will
need to click the standard interface's Play button to replay the world. Try
this now. After you have finished experimenting, click the Stop button one
last time to return to the standard Alice interface.
Alice is a graphics-intensive program that can use a lot of a computer's memory, so you
should exit the Alice program when it is not in use. Now that you are finished with this
tutorial, you should exit the Alice program.
While you are viewing or editing an Alice world, a dialog box will appear every 15 min-
utes, warning you that you have not saved your Alice world. If this happens while you are
playing an Alice world, such as in Tutorial 1B, then it's probably safe to ignore the warn-
ing. If it happens while you are creating or editing your own Alice world, then you should
save your world.
In this tutorial, you will create, play, and save a new Alice world. You should finish
Tutorials 1A and I B before starting this tutorial. You will create an Alice world in which a
bunny will move from the right side of the screen to the center, turn to face the camera, and
then say "Hello, World!" This is an Alice equivalent of the Hello, World! program that stu-
dents traditionally write as their first program in a new programming language.
This tutorial begins with the Alice software closed. If you have an Alice world open, then
exit Alice before continuing.
Tutorial 1C—Creating Your First Alice World 13
FIGURE 1-5: The Templates tab with six templates for new Alice worlds
3. Thumbnail sketches for the six new world templates are now available—
dirt, grass, sand, snow, space, and water. The templates appear to be very
simple, but looks can be deceiving. There is actually a great deal of com-
puter programming behind a new Alice world, with a camera, ambient
light, and other elements already in place. Click the grass thumbnail, and then
click the Open button.
A new Alice world based on the grass template is now open, and you can see the standard
Alice interface that you used earlier in the chapter. Notice that the Object tree in the upper-left
part of the interface contains the four tiles that appear in every new Alice world: world,
camera, light, and ground, as shown in Figure 1-6. You can see from the way the tree is
organized that the other objects are subobjects of the world object.
world
iff camera
C n light
ground
14 Chapter 1 • An Introduction to Alice and Object-Oriented Programming
The new world also has the default event—When t h e world s t a r t s , do world.my first
method—in the Events area, and a blank default method—world.my f i r s t method—in the
Editor area.
A d d i n g O b j e c t s t o a n Alice W o r l d
The next several steps will introduce you to the Alice object galleries and the process of
adding objects to an Alice world. Many people get carried away with creating big worlds
with many objects when they first start to use Alice. In this tutorial, you will start with a
very small Alice world with a minimum number of objects. Objects are added to an Alice
world in Scene Editor mode.
1. Click the large green ADD OBJECTS button in the bottom-right corner of
the World window to enter Alice's Scene Editor mode, which is used to
add objects and position them in an Alice world.
2. Note that the Alice interface now looks different, as shown in Figure 1-7.
The Object tree and the Details area are still visible on the left, but there is
a new area on the right side of the screen. This new area is called the
Scene Editor.
Tutorial 1C—,
tin Crea
9 Your First Alice
Web
nection
Gallery maintained
to use the Web Gallery.)
Scene Editor mode, as shown
by Carnegie
in Figure
Mellon
The Local
1-7.
VmveVSlty.
Gallery is the (N>U
visible at
The galleries are organized
IW
the bottom Ot
as a tree of folders
SCTWU
containing related ob)ects. You can navigate the tree of galleries by clicking a gallery folder
to enter that gallery, or by using the gallery navigation bar, which is just above the galleries.
You will explore the galleries a bit before preparing to add objects to your new world.
1. Click the folder icon on the gallery navigation bar to move up one level in
the tree of galleries, so that you can see the top level in the tree, as shown
in Figure 1-8. Two icons are visible: one for the Local Gallery and one for
the Web Gallery.
Home
2. Click the Local Gallery icon to go back to the Local Gallery. Scroll left and
right through the Local Gallery using the scroll bar below the gallery fold-
ers, and you will see some of the many categories of objects available in Alice.
3. Find and click the Animals folder icon to open the folder. Scroll left and
right through this gallery to see some of the animal objects available in Alice.
O b j e c t C l a s s e s a n d I n s t a n c e s in Alice
Each of the tiles in the Animals folder represents a class of objects. A class is a group of
objects with the same properties and the same methods. Objects in the same class are virtu-
ally identical to each other, except that the values stored in some of their properties may be
different. For example, you could have an Alice world with two Penguin objects. They
16 Chapter 1 • An Introduction to Alice and Object-Oriented Programming
would both have the same methods and the same properties, but the values of some of those
properties, such as location or color, might be different.
Each copy of an object from a particular class is called an instance of the object. As you use
Alice, you will notice that the object class tiles in the object galleries have the word class in
their title and each begins with a capital letter, such as Class Bunny or Class Chicken, but
once an instance of an object is placed in a particular Alice world, its name begins with a
lowercase letter. Of course, it is possible to rename objects, so this distinction is not always
maintained.
The act of adding an instance of an object class to an Alice world is called instantiation.
The same terminology—classes, instances, and instantiation—is used in most object-
oriented programming languages.
You are going to add an instance of an object from the Animals folder in the Local Gallery
to your new Alice world. You are going to instantiate a Bunny class object.
1. Click the Class Bunny icon. A window with information about Bunny class
objects, like the one in Figure 1-9, should appear.
* Bunny X
2. Click the Add instance to world button to put a bunny into the world. This is
sometimes called dropping an object into the world. You should see a bunny
appear in the center of the World window.
3. You can also add an object to an Alice world by clicking an object class tile
and dragging it into place in the World window. Try this now: drag and
drop a chicken tile into your Alice world. This approach lets you place the
new object wherever you would like on the ground in the World window;
however, it does not show you the object's information window first.
4. You should now have an Alice world with two objects—a bunny and a
chicken. Notice that tiles for the new objects have also been added to the
Object tree. You really don't need the chicken for the rest of this exercise.
Tutorial 1C—Creating Your First Alice World 15
The Scene Editor has new controls, a larger World window, and object galleries on the bot-
tom. The Scene Editor replaces the Events area and the Editor area when you are in Scene
Editor mode.
There are two Alice object galleries: a Local Gallery provided with the Alice software, and a
Web Gallery maintained by Carnegie Mellon University. (You need an active Internet con-
nection to use the Web Gallery.) The Local Gallery is visible at the bottom of the screen in
Scene Editor mode, as shown in Figure 1-7. The galleries are organized as a tree of folders
containing related objects. You can navigate the tree of galleries by clicking a gallery folder
to enter that gallery, or by using the gallery navigation bar, which is just above the galleries.
You will explore the galleries a bit before preparing to add objects to your new world.
1. Click the folder icon on the gallery navigation bar to move up one level in
the tree of galleries, so that you can see the top level in the tree, as shown
in Figure 1-8. Two icons are visible: one for the Local Gallery and one for
the Web Gallery.
Home
2. Click the Local Gallery icon to go back to the Local Gallery. Scroll left and
right through the Local Gallery using the scroll bar below the gallery fold-
ers, and you will see some of the many categories of objects available in Alice.
3. Find and click the Animals folder icon to open the folder. Scroll left and
right through this gallery to see some of the animal objects available in Alice.
O b j e c t C l a s s e s a n d I n s t a n c e s in Alice
Each of the tiles in the Animals folder represents a class of objects. A class is a group of
objects with the same properties and the same methods. Objects in the same class are virtu-
ally identical to each other, except that the values stored in some of their properties may be
different. For example, you could have an Alice world with two Penguin objects. They
16 Chapter 1 • An Introduction to Alice and Object-Oriented Programming
would both have the same methods and the same properties, but the values of some of those
properties, such as location or color, might be different.
Each copy of an object from a particular class is called an instance of the object. As you use
Alice, you will notice that the object class tiles in the object galleries have the word class in
their title and each begins with a capital letter, such as Class Bunny or Class Chicken, but
once an instance of an object is placed in a particular Alice world, its name begins with a
lowercase letter. Of course, it is possible to rename objects, so this distinction is not always
maintained.
The act of adding an instance of an object class to an Alice world is called instantiation.
The same terminology—classes, instances, and instantiation—is used in most object-
oriented programming languages.
You are going to add an instance of an object from the Animals folder in the Local Gallery
to your new Alice world. You are going to instantiate a Bunny class object.
1. Click the Class Bunny icon. A window with information about Bunny class
objects, like the one in Figure 1-9, should appear.
ftiBunny X
4
M M
u..,rl.-l.-.HV
ii4i«ed by-
pans:
a o
2. Click the Add instance to world button to put a bunny into the world. This is
sometimes called dropping an object into the world. You should see a bunny
appear in the center of the World window.
3 . You can also add an object to an Alice world by clicking an object class tile
and dragging it into place in the World window. Try this now: drag and
drop a chicken tile into your Alice world. This approach lets you place the
new object wherever you would like on the ground in the World window;
however, it does not show you the object's information window first.
4. You should now have an Alice world with two objects—a bunny and a
chicken. Notice that tiles for the new objects have also been added to the
Object tree. You really don't need the chicken for the rest of this exercise.
Tutorial 1C—Creating Your First Alice World
To delete the chicken, right-click the object or the object's tile in the Object
tree and select delete from the menu that appears.
Positioning Objects
The layout tools to the right of the World window in Scene Editor mode can be used to
manipulate objects. This area contains the seven standard tools listed in Table 1-1.
n Pointer tool Selects an object and moves the object parallel to the ground
m Turn tool Turns an object along its X-Y plane parallel to the ground
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookultra.com