开心农场代码

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

packagesrc.plant{importflash.display.MovieClip;publicclassPlantextendsMovieClip{publicvartypePlant:int=0;publicfunctionPlant(){}publicfunctionsetStatus(s:int):void{//每帧一种植物,例如第1帧苹果(1)gotoAndStop(s);}publicfunctiongetStatus():int{returncurrentFrame;}}}packagesrc.plant{publicclassAppleextendsPlant{publicfunctionApple(){typePlant=1;}}}packagesrc.plant{publicclassGrapeextendsPlant{publicfunctionGrape(){typePlant=2;}}}packagesrc.field{importflash.display.MovieClip;importflash.events.MouseEvent;importsrc.plant.*;//几种状态0:未开垦;1:正常;2:干旱;3:长草;4:生虫publicclassFieldextendsMovieClip{publicvarindex:int=-1;publicvarstatusField:int=0;publicvarweed:Weed=newWeed;publicvarworm:Worm=newWorm;publicvarp=null;publicfunctionField(){addEventListener(MouseEvent.CLICK,onClickField);}//status:0:未开垦;1:正常;2:干旱;3:长草;4:生虫publicfunctionsetStatus(statusField:int):void{this.statusField=statusField;switch(statusField){case0:this.gotoAndStop(1);//未开垦if(contains(weed))removeChild(weed);if(contains(worm))removeChild(worm);break;case1:this.gotoAndStop(2);//正常break;case2:this.gotoAndStop(3);//干旱break;case3://长草this.gotoAndStop(2);addChild(weed);weed.x=40;weed.y=20;weed.width=this.width/2;weed.height=this.height/2;break;case4://生虫this.gotoAndStop(2);addChild(worm);worm.x=20;worm.y=20;worm.width=this.width/2;worm.height=this.height/2;break;}}publicfunctionsetPlant(typePlant:int,statusPlant:int):void{if(p!=null&&contains(p))removeChild(p);switch(typePlant){case1:p=newApple();//苹果addChild(p);break;case2:p=newGrape();//葡萄addChild(p);break;}if(typePlant!=0){p.setStatus(statusPlant);//播放相应帧图形}}privatefunctiononClickField(e:MouseEvent):void{switch(HappyFarmMgr.mouseType){//不同的工具鼠标按钮,被文档类赋值的case2://hoeingMouseif(p!=null&&contains(p)&&p.getStatus()==7&&HappyFarmMgr.myName==HappyFarmMgr.fieldMgr.ownerName){removeChild(p);gotoAndStop(2);HappyFarmMgr.commMgr.setPlantType(index,0);}break;case3://wateringMouseif(statusField==2){gotoAndStop(2);HappyFarmMgr.commMgr.setFieldStatus(index,1);//跟新数据库数据}break;case4://killWeedMouseif(statusField==3&&contains(weed)){this.removeChild(weed);HappyFarmMgr.commMgr.setFieldStatus(index,1);}break;case5://killWormMouseif(statusField==4&&contains(worm)){this.removeChild(worm);HappyFarmMgr.commMgr.setFieldStatus(index,1);}break;case6://reapMouseif(p!=null&&contains(p)&&p.getStatus()==6){p.gotoAndStop(7);HappyFarmMgr.commMgr.setPlantStatus(index,7);HappyFarmMgr.commMgr.setWarehouseSum(Warehouse,p.typePlant,6);//HappyFarmMgr.wareHouse.addPlant(p.toString(),3);}break;case7://种苹果if((p==null||!contains(p))&&HappyFarmMgr.myName==HappyFarmMgr.fieldMgr.ownerName){HappyFarmMgr.commMgr.setPlantType(index,1);setPlant(1,1);HappyFarmMgr.tool.main.SwitchMouse(1);}break;case8://种葡萄if((p==null||!contains(p))&&HappyFarmMgr.myName==HappyFarmMgr.fieldMgr.ownerName){HappyFarmMgr.commMgr.setPlantType(index,2);setPlant(2,1);HappyFarmMgr.tool.main.SwitchMouse(1);}break;}}}}

1 / 4
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功