关闭

关闭

封号提示

内容

首页 Introduction to Programming with Greenfoot.pdf

Introduction to Programming with Greenfoot.pdf

Introduction to Programming wit…

上传者: xuzhe1992 2011-10-02 评分 0 0 0 0 0 0 暂无简介 简介 举报

简介:本文档为《Introduction to Programming with Greenfootpdf》,可适用于高等教育领域,主题内容包含CompanionWebsiteAdditionalmaterialandresourcesforthisbookcanbefoundathttp:符等。

CompanionWebsiteAdditionalmaterialandresourcesforthisbookcanbefoundathttp:wwwgreenfootorgbookForstudents:TheGreenfootsoftwareThescenariosdiscussedinthisbookTheGreenfootGalleryascenarioshowcaseTutorialvideosAdiscussionforumTechnicalsupportForteachers:AteacherdiscussionforumAdditionalexercisesrelatedtothebookThe“GreenRoom”containingworksheetsandotherteachingresourcesIntroductiontoProgrammingwithGreenfootThispageintentionallyleftblankIntroductiontoProgrammingwithGreenfootObjectOrientedProgramminginJavawithGamesandSimulationsMichaelKöllingPrenticeHallUpperSaddleRiver•Boston•Columbus•SanFrancisco•NewYorkIndianapolis•London•Toronto•Sydney•Singapore•Tokyo•Montreal•DubaiMadrid•HongKong•MexicoCity•Munich•Paris•Amsterdam•CapeTownVicePresidentandEditorialDirector,ECS:MarciaJHortonEditorinChief,CS:MichaelHirschExecutiveEditor:TracyDunkelbergerAssistantEditor:MelindaHaggertyEditorialAssistant:AllisonMichaelDirectorofTeamBasedProjectManagement:VinceO’BrienSeniorManagingEditor:ScottDisannoProductionLiaison:IrwinZuckerProductionEditor:ShinyRajesh,IntegraSeniorOperationsSpecialist:AlanFischerOperationSpecialist:LisaMcDowellMarketingManager:ErinDavisMarketingCoordinator:KathrynFerrantiArtDirector:JayneConteCoverDesigner:BruceKenselaarArtEditor:GregDullesMediaEditor:DanielSandinCompositionFullServiceProjectManagement:IntegraCopyrightbyPearsonHigherEducationUpperSaddleRiver,NewJersey,AllrightsreservedManufacturedintheUnitedStatesofAmericaThispublicationisprotectedbyCopyrightandpermissionshouldbeobtainedfromthepublisherpriortoanyprohibitedreproduction,storageinaretrievalsystem,ortransmissioninanyformorbyanymeans,electronic,mechanical,photocopying,recording,orlikewiseToobtainpermission(s)tousematerialsfromthiswork,pleasesubmitawrittenrequesttoPearsonHigherEducation,PermissionsDepartment,LakeStreet,UpperSaddleRiver,NJTheauthorandpublisherofthisbookhaveusedtheirbesteffortsinpreparingthisbookTheseeffortsincludethedevelopment,research,andtestingofthetheoriesandprogramstodeterminetheireffectivenessTheauthorandpublishermakenowarrantyofanykind,expressedorimplied,withregardtotheseprogramsorthedocumentationcontainedinthisbookTheauthorandpublishershallnotbeliableinanyeventforincidentalorconsequentialdamagesinconnectionwith,orarisingoutof,thefurnishing,performance,oruseoftheseprogramsLibraryofCongressCataloginginPublicationDataonFileISBN:ISBN:ToKrümelandCrackermaytheirimaginationneverfademkEducationisnotthefillingofapail,butthelightingofafireWilliamButlerYeatsThispageintentionallyleftblankListofscenariosdiscussedinthisbookxiAcknowledgmentsxvIntroductionChapterGettingtoknowGreenfootGettingstartedObjectsandclassesInteractingwithobjectsReturntypesParametersGreenfootexecutionAsecondexampleUnderstandingtheclassdiagramPlayingwithAsteroidsSourcecodeSummaryChapterThefirstprogram:LittleCrabTheLittleCrabscenarioMakingthecrabmoveTurningDealingwithscreenedgesSummaryofprogrammingtechniquesChapterImprovingtheCrabmoresophisticatedprogrammingAddingrandombehaviorAddingwormsEatingwormsContentsCreatingnewmethodsAddingaLobsterKeyboardcontrolEndingthegameAddingsoundSummaryofprogrammingtechniquesChapterFinishingthecrabgameAddingobjectsautomaticallyCreatingnewobjectsAnimatingimagesGreenfootimagesInstancevariables(fields)AssignmentUsingactorconstructorsAlternatingtheimagesTheifelsestatementCountingwormsMoreideasSummaryofprogrammingtechniquesInterludeSharingyourscenariosIExportingyourscenarioIExporttoapplicationIExporttoawebpageIPublishingontheGreenfootGalleryChapterMakingmusic:AnonscreenpianoAnimatingthekeyProducingthesoundAbstraction:CreatingmultiplekeysBuildingthepianoUsingloops:ThewhileloopUsingarraysSummaryofprogrammingtechniquesChapterInteractingobjects:Newton’sLabThestartingpoint:Newton’sLabHelperclasses:SmoothMoverandVectorviii|ContentsTheexistingBodyclassFirstextension:CreatingmovementUsingJavalibraryclassesAddinggravitationalforceTheListtypeTheforeachloopApplyinggravityTryingitoutGravityandmusicSummaryofprogrammingtechniquesChapterCollisiondetection:AsteroidsInvestigation:WhatistherePaintingstarsTurningFlyingforwardCollidingwithasteroidsCastingAddingfirepower:TheprotonwaveGrowingthewaveInteractingwithobjectsinrangeFurtherdevelopmentSummaryofprogrammingtechniquesInterludeTheGreepscompetitionIHowtogetstartedIProgrammingyourGreepsIRunningthecompetitionITechnicalitiesChapterCreatingimagesandsoundPreparationWorkingwithsoundSoundrecordingandeditingSoundfileformatsandfilesizesWorkingwithimagesImagefilesandfileformatsDrawingimagesCombiningimagesfilesanddynamicdrawingSummaryContents|ixChapterSimulationsFoxesandrabbitsAntsCollectingfoodSettinguptheworldAddingpheromonesPathformingSummaryChapterAdditionalscenarioideasMarblesLiftsBoidsCirclesExplosionBreakoutPlatformjumperWaveSummaryAppendixAInstallingGreenfootBGreenfootAPICCollisiondetectionDSomeJavadetailsIndexx|ContentsLeavesandwombats(Chapter)Thisisasimpleexampleshowingwombatsmovingaroundonscreen,occasionallyeatingleavesThescenariohasnospecificpurposeotherthanillustratingsomeimportantobjectorientedconceptsandGreenfootinteractionsAsteroids(Chapter)ThisisasimpleversionofaclassicarcadegameYouflyaspaceshipthroughspaceandtrytoavoidbeinghitbyasteroidsAtthisstage,weonlyusethescenariotomakesomesmallchangesandillustratesomebasicconceptsLittleCrab(Chapter)ThisisourfirstfulldevelopmentStartingfromalmostnothing,wedevelopasimplegameslowly,addingmaythingssuchasmovement,keyboardcontrol,sound,andmanyotherelementsoftypicalgamesPiano(Chapter)AnonscreenpianothatyoucanreallyplayNewton’sLab(Chapter)Newton’sLabisasimulationofthemotionofstarsandplanetsinspaceGravityplaysacentralrolehereWealsomakeavariantofthisthatcombinesgravitywithmakingmusic,endingupwithmusicaloutputtriggeredbyobjectsundergravitationalmovementAsteroids(Chapter)WecomebacktotheasteroidsexamplefromChapterThistime,weinvestigatemorefullyhowtoimplementitAnts(Chapter)Asimulationofantcoloniessearchingforfood,communicatingviadropsofpheromonesleftonthegroundThefollowingscenariosarepresentedinChapterandselectedaspectsofthembrieflydiscussedTheyareintendedasinspirationforfurtherprojectsMarblesAsimulationofamarbleboardgameMarbleshavetobeclearedoftheboardwithinalimitednumberofmovesContainssimplephysicsListofscenariosdiscussedinthisbookxii|ListofscenariosdiscussedinthisbookLiftsAstartofaliftsimulationIncompleteatthisstagecanbeusedasastartofaprojectBoidsAdemoshowingflockingbehavior:Aflockofbirdsfliesacrossthescreen,aimingtosticktogetherwhileavoidingobstaclesCirclesMakepatternsindifferentcolorsonthescreenwithmovingcirclesExplosionAdemoofamoresophisticatedexplosioneffectBreakoutThisisthestartofanimplementationoftheclassicBreakoutgameVeryincomplete,butwithaninterestingvisualeffectPlatformjumperAdemoofapartialimplementationofaneverpopulargenreofgames:platformjumpersWaveThisscenarioisasimpledemonstrationofaphysicaleffect:thepropagationofawaveonastringPrefaceGreenfootisaprogrammingenvironmentthatcanbeusedbyindividuals,inschoolsorinintroductoryuniversitycoursestolearnandteachtheprinciplesofprogrammingItisflexibleenoughtobesuitableforteenagersaswellasolderstudentsGreenfootsupportstheJavaProgrammingLanguage,sostudentslearnstandardobjectorientedprogramminginJavaTheenvironmentisdesignedspecificallytoconveyobjectorientedconceptsandprinciplesinaclean,easilyaccessiblemannerTheGreenfootenvironmentmakescreationofgraphicsandinteractioneasyStudentscanconcentrateonmodifyingtheapplicationlogic,andengageandexperimentwithobjectsDevelopingsimulationsandinteractivegamesbecomeseasy,andfeedbackisimmediateTheenvironmentisdesignedtoquicklyengagestudentswhomayhavenopriorinterestorexperienceinprogrammingAchievingsimpleanimationresultsisquick,sophisticated,professionallookingscenariosarepossibleAccessingSupplementaryMaterialsThelearningaidsandsupplementarymaterialsthatarenotedinthebookcanbeaccessedthroughtheGreenfootCompanionWebsiteorthroughthepublisher’sWebsite:CompanionWebsite:http:wwwgreenfootorgbookPublisher’sWebsite:http:wwwprenhallcomkollingSupplementaryMaterialsAvailableforStudentsThefollowingsupplementsareavailableforstudents:TheGreenfootsoftwareThescenariosdiscussedinthisbookTheGreenfootGalleryascenarioshowcaseTutorialvideosAdiscussionforumTechnicalsupportSupplementaryMaterialsAvailableforInstructorsThefollowingsupplementsareavailableforinstructors:AteacherdiscussionforumAdditionalexercisesrelatedtothebookThe“GreenRoom”containingworksheetsandotherteachingresourcesFormoredetailsaboutGreenfootandthisbook,pleasealsoseetheIntroductionfollowingtheAcknowledgmentsPreface|xiiiThispageintentionallyleftblankThisbookistheresultofmorethanfiveyearsofworkbyagroupofpeopleFirstandforemostinvolvedarethepeoplewhocontributedtothedevelopmentoftheGreenfootenvironment,whichmakesthisentireeducationalapproachpossiblePoulHenriksenstartedtheimplementationofGreenfootashisMastersprojectandbuiltthefirstprototypeHealsotookonthedevelopmentofthisprototypeintoaproductionsystemForthefirstyearorso,wewereatwomanproject,andPoul’sworkledtothequalityandrobustnessofthecurrentsystemBruceQuigandDavinMcCallwerethenextdeveloperstojointheproject,andPoul,Bruce,andDavinjointlybuiltmostofGreenfootasitistodayAllthreeareexceptionalsoftwaredevelopers,andtheircontributiontotheprojectcannotbeoverstatedItisajoyworkingwiththemEventually,thewhole“BlueJGroup”gotinvolvedintheGreenfootproject,includingJohnRosenbergandIanUtting,andthisbookbuildsoncontributionsandjointworkofallgroupmembersColleaguesintheComputingLaboratoryattheUniversityofKentalsohelpedmeagreatdeal,especiallyourHeadofDepartment,SimonThompson,whosawthevalueofGreenfootearlyonandsupportedandencourageditsfurtherdevelopmentAnotherimportantcontribution,withoutwhichthedevelopmentofGreenfoot(andultimately,thisbook)wouldnothavebeenpossible,isthegeneroussupportofSunMicrosystemsEmilSarpa,KatherineHartsell,JessicaOrquina,SarahHammond,andmanyotherswithinSunbelievedinthevalueofoursystemandprovidedimportantsupportEveryoneatPearsonEducationworkedveryhardtogetthisbookpublishedontime,withaverytightschedule,andinsometimesdifficultcircumstancesTracyDunkelbergerworkedwithmeonthisbookfromthebeginningShemanagedamazinglywelltostaypositiveandexcitedwhileputtingupwithmyrepeatedmisseddeadlines,andshestillencouragedmetocontinuewritingMelindaHaggertydidawholelotofdifferentthings,includingmanagingthereviewsAspecialthankyouneedstogotothereviewersofthisbook,whohaveprovidedverydetailed,thoughtful,andusefulfeedbackTheyareCarolynOates,DamiannePresident,DetlefRick,GunnarJohannesmeyer,JoshFishburn,MarkHayes,MarlaParker,MattJadud,ToddO’Bryan,LaelGrant,JasonGreen,MarkLewis,RodneyHoffman,andMichaelKadriTheyhelpedspottingmanyerrorsandpointedoutmanyopportunitiesforimprovementMygoodfriendMichaelCaspersenalsodeservesthanksforprovidingearlyfeedbackandencouragementthatwasveryimportanttome,partlybecauseithelpedimprovethebook,andmoreimportantlybecauseitencouragedmetobelievethatthisworkmightbeinterestingtoteachersandworthwhilecompletingAcknowledgmentsThispageintentionallyleftblankWelcometoGreenfoot!Inthisbook,wewilldiscusshowtoprogramgraphicalcomputerprograms,suchassimulationsandgames,usingtheJavaProgrammingLanguageandtheGreenfootenvironmentThereareseveralgoalsindoingthis:Oneistolearnprogramming,anotheristohavefunalongthewayWhiletheexampleswediscussinthisbookarespecifictotheGreenfootenvironment,theconceptsaregeneral:workingthroughthisbookwillteachyougeneralprogrammingprinciplesinamodern,objectorientedprogramminglanguageHowever,itwillalsoshowyouhowtomakeyourowncomputergame,abiologysimulation,oranonscreenpianoThisbookisverypracticallyorientedChaptersandexercisesarestructuredaroundreal,handsondevelopmenttasksFirst,thereisaproblemthatweneedtosolve,thenwelookatlanguageconstructsandstrategiesthathelpussolvetheproblemThisisquitedifferentfrommanyintroductoryprogrammingtextbookswhichareoftenstructuredaroundprogramminglanguageconstructsAsaresult,thisbookstartswithlesstheoryandmorepracticalactivitythanmostprogrammingbooksThisisalsothereasonweuseGreenfoot:ItistheGreenfootenvironmentthatmakesthispossibleGreenfootallowsustoplayAndthatdoesnotonlymeanplayingcomputergamesitmeansplayingwithprogramming:Wecancreateobjects,movethemaroundonscreen,calltheirmethods,andobservewhattheydo,allinteractivelyandeasilyThisleadstoamorehandsonapproachtoprogrammingthanwhatwouldbepossiblewithoutsuchanenvironmentAmorepracticalapproachdoesnotmeanthatthebookdoesnotcoverthenecessarytheoryandprinciplesaswellIt’sjustthattheorderischangedInsteadofintroducingaconcepttheoreticallyfirst,andthendoingsomeexerciseswithit,weoftenjumprightinanduseaconstruct,initiallyexplainingonlyasmuchasnecessarytosolvethetaskathand,thencomebacktothetheoreticalbackgroundlaterWetypicallyfollowaspiralapproach:Weintroducesomeaspectsofaconceptwhenwefirstencounterit,thenrevisititlaterinanothercontext,andgraduallydeepenourunderstandingTheemphasisthroughoutistomaketheworkwedointeresting,relevant,andenjoyableThereisnoreasonwhycomputerprogramminghastobedry,formal,orboringHavingfunalongthewayisokayWethinkwecanmanagemakingtheexperienceinterestingandpedagogicallysoundatthesametimeThisisanapproachthathasbeencalledseriousfunwedosomethinginteresting,andlearnsomethingusefulalongthewayThisbookcanbeusedbothasaselfstudybookandasatextbookinaprogrammingcourseExercisesareworkedintothetextthroughoutthebookifyoudothemall,youwillcomeoutofthisasafairlycompetentprogrammerIntroductionTheprojectsdiscussedinthisbookareeasyenoughthattheycanbemanagedbyhighschoolstudents,buttheyarealsoopenandextendableenoughthatevenseasonedprogrammerscanfindinterestingandchallengingaspectstodoWhileGreenfootisaneducationalenvironment,JavaisnotatoylanguageSinceJavaisourlanguageofchoiceforthisbook,theprojectsdiscussedhere(andothersyoumaywanttocreateinGreenfoot)canbemadeascomplexandchallengingasyoulikeWhileitispossibletocreatesimplegamesquicklyandeasilyinGreenfoot,itisequallypossibletobuildhighlysophisticatedsimulationsofcomplexsystems,possiblyusingartificialintelligencealgorithms,agenttechnology,databaseconnectivity,oranythingelseyoucanthinkofJavaisaveryrichlanguagethatopensthewholeworldofprogramming,andGreenfootimposesnorestrictionsastowhichaspectsofthelanguageyoucanuseInotherwords,GreenfootscaleswellItallowseasyentryforyoungbeginners,butexperiencedprogrammerscanalsoimplementinteresting,sophisticatedscenariosYouarelimitedonlybyyourimagination|IntroductionThisbookwillshowyouhowtodevelopcomputergamesandsimulationswithGreenfoot,adevelopmentenvironmentInthischapter,weshalltakealookatGreenfootitself,seewhatitcandoandhowtouseitWedothisbytryingoutsomeexistingprogramsOncewearecomfortablewithusingGreenfoot,weshalljumprightintowritingagameourselvesThebestwaytoreadthischapter(andindeedthewholebook)isbysittingatyourcomputerwithGreenfootopenonyourscreenandthebookopenonyourdeskWewillregularlyaskyoutodothingsinGreenfootwhileyoureadSomeofthetasksyoucanskiphowever,youwillhavetodosomeinordertoprogressinthechapterInanycase,youwilllearnmostifyoufollowalonganddothemAtthisstage,weassumethatyouhavealreadyinstalledtheGreenfootsoftwareandthebookscenarios(describedinAppendixA)Ifnot,readthroughthatappendixfirstGettingstartedStartGreenfootandopenthescenarioleavesandwombatsfromtheGreenfootbookscenariosfolderCHAPTERtopics:theGreenfootinterface,interactingwithobjects,invokingmethods,runningascenarioconcepts:object,class,methodcall,parameter,returnvalueNoteIfyouarestartingGreenfootforthefirsttime,youwillseeadialogaskingwhatyouwanttodoClickChooseascenarioOtherwise,useScenario–OpenfromthemenuWeusethisnotationtotellyoutoselectfunctionsfromthemenuScenario–OpenreferstotheOpenitemintheScenariomenuGettingtoknowGreenfoot|ChapterGettingtoknowGreenfootMakesuretoopentheleavesandwombatsscenariothatyoufindinthebookscenariosfolder,notthesomewhatsimilarwombatsscenariofromthestandardGreenfootinstallationYouwillnowseetheGreenfootmainwindow,withthescenarioopen,lookingsimilartoFigureThemainwindowconsistsofthreemainareasandacoupleofextrabuttons

职业精品

精彩专题

上传我的资料

热门资料

资料评价:

/ 207
所需积分:0 立即下载

意见
反馈

返回
顶部

Q