您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 咨询培训 > robocode-API中文参考(java)
robocode部分API中文参考ahead向前publicvoidahead(doubledistance)Immediatelymovesyourrobotahead(forward)bydistancemeasuredinpixels.马上将你的机器人向前移动以distance指定的多少个像素Thiscallexecutesimmediately,anddoesnotreturnuntilitiscomplete,i.e.whentheremainingdistancetomoveis0.这个函数会马上执行,并且直到完成了任务才返回,比如,当距离已前进完时。Iftherobotcollideswithawall,themoveiscomplete,meaningthattherobotwillnotmoveanyfurther.Iftherobotcollideswithanotherrobot,themoveiscompleteifyouareheadingtowardtheotherrobot.当机器人撞到墙时,动作也是完成了,意味着此时机器人将不再向前进。当你的机器人撞到其它的机器人时,如果你是头部撞到其它的机器人时动作也就完成。Notethatbothpositiveandnegativevaluescanbegivenasinput,wherenegativevaluesmeansthattherobotissettomovebackwardinsteadofforward.记住正数和负数都可以作为距离的值,当距离为负值时表示机器人向后退距离的绝对值个像素。Example:比如://Movetherobot100pixelsforward将机器人向前移动100个像素ahead(100);//Afterwards,movetherobot50pixelsbackward然后,向后移动50个像素ahead(-50);Parameters:参数:distance-thedistancetomoveaheadmeasuredinpixels.Ifthisvalueisnegative,therobotwillmovebackinsteadofaheaddistanse-向前移动的距离,单位是像素。如果其值是负数,机器人会用向后来代替向前。SeeAlso:可以参考:back(double),onHitWall(HitWallEvent),onHitRobot(HitRobotEvent)back向后publicvoidback(doubledistance)Immediatelymovesyourrobotbackwardbydistancemeasuredinpixels.马上将你的机器人向后移动以distance指定的多少个像素Thiscallexecutesimmediately,anddoesnotreturnuntilitiscomplete,i.e.whentheremainingdistancetomoveis0.这个函数会马上执行,并且直到完成了任务才返回,比如,当距离已前进完时。Iftherobotcollideswithawall,themoveiscomplete,meaningthattherobotwillnotmoveanyfurther.Iftherobotcollideswithanotherrobot,themoveiscompleteifyouareheadingtowardtheotherrobot.当机器人撞到墙时,动作也是完成了,意味着此时机器人将不再向前进。当你的机器人撞到其它的机器人时,如果你是头部撞到其它的机器人时动作也就完成。Notethatbothpositiveandnegativevaluescanbegivenasinput,wherenegativevaluesmeansthattherobotissettomoveforwardinsteadofbackward.记住正数和负数都可以作为距离的值,当距离为负值时表示机器人向前进距离的绝对值个像素。Example:比如://Movetherobot100pixelsbackward将机器人向后移动100个像素back(100);//Afterwards,movetherobot50pixelsforward然后,向前移动50个像素ahead(-50);back(-50);Parameters:参数:distance-thedistancetomovebackmeasuredinpixels.Ifthisvalueisnegative,therobotwillmoveaheadinsteadofback.distanse-向后移动的距离,单位是像素。如果其值是负数,机器人会用向前来代替向后。SeeAlso:可以参考:ahead(double),onHitWall(HitWallEvent),onHitRobot(HitRobotEvent)getBattleFieldWidth得到战场宽度publicdoublegetBattleFieldWidth()Returnsthewidthofthecurrentbattlefieldmeasuredinpixels.返回值为以像素为单位表示的当前战场的宽度Returns:thewidthofthecurrentbattlefieldmeasuredinpixels.--------------------------------------------------------------------------------getBattleFieldHeight得到战场高度publicdoublegetBattleFieldHeight()Returnstheheightofthecurrentbattlefieldmeasuredinpixels.返回值为能像素为单位的当前战场的高度Returns:theheightofthecurrentbattlefieldmeasuredinpixels.getHeading得到自己的方向publicdoublegetHeading()Returnsthedirectionthattherobot'sbodyisfacing,indegrees.Thevaluereturnedwillbebetween0and360(isexcluded).返回机器人面对的方向,用角度表示。返回值的范围是0到360之间(不含360)。NotethattheheadinginRobocodeislikeacompass,where0meansNorth,90meansEast,180meansSouth,and270meansWest.记住在机器人软件中的坐标系就像一个罗盘,0表示正北,90表示正东,180表示正南,270表示正西。Returns:thedirectionthattherobot'sbodyisfacing,indegrees.返回机器人面对的方向,用角度表示SeeAlso:getGunHeading(),getRadarHeading()getHeightpublicdoublegetHeight()Returnstheheightoftherobotmeasuredinpixels.返回机器人自己的高度,单位为像素。Returns:theheightoftherobotmeasuredinpixels.SeeAlso:getWidth()--------------------------------------------------------------------------------getWidthpublicdoublegetWidth()Returnsthewidthoftherobotmeasuredinpixels.返回机器人自己的宽度,单位为像素。Returns:thewidthoftherobotmeasuredinpixels.SeeAlso:getHeight()getName返回自己的名字publicStringgetName()Returnstherobot'sname.返回机器人自己的名字Returns:therobot'sname.--------------------------------------------------------------------------------getX得到X坐标publicdoublegetX()ReturnstheXpositionoftherobot.(0,0)isatthebottomleftofthebattlefield.返回值为机器人的X坐标,(0,0)坐标在战场的左下角。(译者注:向右为X正向,向上为Y正向)。Returns:theXpositionoftherobot.SeeAlso:getY()--------------------------------------------------------------------------------getY得到Y坐标publicdoublegetY()ReturnstheYpositionoftherobot.(0,0)isatthebottomleftofthebattlefield.返回值为机器人的Y坐标,(0,0)坐标在战场的左下角。(译者注:向右为X正向,向上为Y正向)。Returns:theYpositionoftherobot.SeeAlso:getX()runpublicvoidrun()Themainmethodineveryrobot.Youmustoverridethistosetupyourrobot'sbasicbehavior.在每个机器人中的主方法。为了你的机器人有一些基本行为,你必须重写这个方法。Example:例如://Abasicrobotthatmovesaroundinasquare一个在一个正方形里反复行走的基本的机器人publicvoidrun(){while(true){ahead(100);turnRight(90);}}Specifiedby:runininterfaceRunnable可以行走的时候才会行走。--------------------------------------------------------------------------------turnLeftpublicvoidturnLeft(doubledegrees)Immediatelyturnstherobot'sbodytotheleftbydegrees.马上将机器人向左转以degrees指写的度数Thiscallexecutesimmediately,anddoesnotreturnuntilitiscomplete,i.e.whentheangleremainingintherobot'sturnis0.这个指令马上被调用,直到做完才会返回。比如,当角度已经转完时就会返回。Notethatbothpositiveandnegativevaluescanbegivenasinput,wherenegativevaluesmeansthattherobot'sbodyissettoturnrightinsteadofleft.正数和负数都可以作为参数,是负数意味着会向右转,转动角度的大小是一样的。Example://Turntherobot180degreestotheleft将机器人向左转180度。turnLeft(180);//Afterwards,turntherobot90degreestotheright然后,向右转90度。turnLeft(-90);Parameters:degrees-theamountofd
本文标题:robocode-API中文参考(java)
链接地址:https://www.777doc.com/doc-5113450 .html