Class JuniorRobot
เขียนโดย Administrator    วันอาทิตย์ที่ 31 มกราคม 2010 เวลา 10:30 น.   

          ความเรียบง่ายของชุดคำสั่ง Junior Robot จึงทำให้เป็นชุดคำสั่งที่เหมาะอย่างยิ่งกับการใช้ในการเรียนการสอนการเขียนโปรแกรม ด้วยรูปแบบคำสั่งที่เข้าใจง่าย แต่คงไว้ซึ่งประสิทธิภาพและแนวคิดพื้นฐานของการเขียนโปรแกรม จึงทำให้ชุดคำสั่ง Junior Robot เหมาะอย่างยิ่งสำหรับผู้เริ่มต้นฝึกเขียนโปรแกรม ต่อไปนี้เป็นตัวอย่างคำสั่งของ Robocode ในส่วนของ Class JuniorRobot ที่ควรรู้

เมธอดต่าง ๆ
 void ahead(int distance)
          เคลื่อนหุ่นยนต์ไปข้างหน้า( หน่วย พิกเซล)
 void back(int distance)
          เคลื่อนหุ่นยนต์ถอยหลัง (หน่วย พิกเซล)
 void bearGunTo(int angle)
          หมุนปืนไปยังมุมที่ระบุ (หน่วย องศา) เทียบกับตัวเอง
 void doNothing()
          ข้าม รอบการเล่น
 void doNothing(int turns)
          ข้าม รอบการเล่นตามค่าที่ระบุ
 void fire()
          ยิงกระสุน ด้วยกำลัง =1
 void fire(double power)
          ยิงกระสุน ด้วยกำลังตามระบุ ระหว่าง 0.1 ถึง 3 ซึ่งเป็นกำลังสูงสุด
 IBasicEvents getBasicEventListener()
          ห้ามใช้ (ระบบเป็นผู้เรียกใช้เอง)
 Runnable getRobotRunnable()
          ห้ามใช้ (ระบบเป็นผู้เรียกใช้เอง)
 void onHitByBullet()
          เป็นการรับค่าจากระบบ เมื่อมีกระสุนของหุ่นยนต์อื่นมากระทบ
 void onHitRobot()
          เป็นการรับค่าจากระบบ เมื่อกระสุนที่ยิง ไปปะทะหุ่นยนต์อื่น
 void onHitWall()
          เป็นการรับค่าจากระบบ เมื่อหุ่นยนต์ ไปปะทะขอบสนาม
 void onScannedRobot()
          เป็นการรับค่าจากระบบ เมื่อเรดาร์ตรวจพบหุ่นยนต์ตัวอื่น
 void run()
          เป็นกระบวนงานหลักของหุ่นยนต์ทุกตัว
 void setColors(int bodyColor, int gunColor, int radarColor)
          กำหนดสีของหุ่นยนต์ (ตัวถัง ,ปืน,เรดาร์)
 void setColors(int bodyColor, int gunColor, int radarColor, int bulletColor, int scanArcColor)
          กำหนดสีของหุ่นยนต์ (ตัวถัง ,ปืน,เรดาร์,กระสุน,ลำแสงตรวจ)
 void turnAheadLeft(int distance, int degrees)
          เคลื่อนไปด้านหน้า จำนวน พิกเซล แล้วเลี้ยวซ้ายจำนวนองศา
 void turnAheadRight(int distance, int degrees)
          เคลื่อนไปด้านหน้า จำนวน พิกเซล แล้วเลี้ยวขวาจำนวนองศา
 void turnBackLeft(int distance, int degrees)
          ถอยหลัง จำนวน พิกเซล แล้วเลี้ยวซ้ายจำนวนองศา
 void turnBackRight(int distance, int degrees)
          ถอยหลัง จำนวน พิกเซล แล้วเลี้ยวขวาจำนวนองศา
 void turnGunLeft(int degrees)
          หันปืนไปทางซ้าย ...องศา
 void turnGunRight(int degrees)
          หันปืนไปทางขวา ...องศา
 void turnGunTo(int angle)
          หันปืนไปยังมุมเทียบกับสนาม ที่ระบุ (หน่วย องศา)
 void turnLeft(int degrees)
          หันหุ่นยนต์ไปทางซ้าย ตามมุมที่ระบุ (หน่วย องศา)
 void turnRight(int degrees)
          หันหุ่นยนต์ไปทางขวา ตามมุมที่ระบุ (หน่วย องศา)
 void turnTo(int angle)
          หันหุ่นยนต์ไปยังมุมเทียบกับสนาม ตามระบุ (หน่วย องศา)

 

ฟิลด์ ต่าง ๆ
static int black
          สีดำ (0x000000)
static int blue
          สีน้ำเงิน (0x0000FF)
static int brown
          สัน้ำตาล (0x8B4513)
 int energy
          พลังของหุ่นยนต์,มากที่สุด 100 น้อยที่สุด 0 (ตาย).
 int fieldHeight
          ค่าความสูงของสนามรบ.
 int fieldWidth
          ค่าความกว้างของสนามรบ.
static int gray
          สีเทา (0x808080)
static int green
          สีเขียว (0x008000)
 int gunBearing
          ทิศของปืนเทียบกับตัวรถ (หน่วย องศา).
 int gunHeading
          ทิศของปืนเทียบกับสนาม (หน่วย องศา).
 boolean gunReady
          สัญญาณพร้อมยิง, เมื่อความร้อนของปืน <= 0
 int heading
          ทิศมุ่งหน้าของหุ่นยนต์ เทียบกับสนามรบ(หน่วย องศา).
 int hitByBulletAngle
          ทิศทางล่าสุดเทียบกับสนามรบซึ่งถูกยิง (หน่วย องศา).
 int hitByBulletBearing
          ทิศทางล่าสุดเทียบกับตัวเองซึ่งถูกยิง (หน่วย องศา)
 int hitRobotAngle
          ทิศทางล่าสุดเทียบกับสนามรบ ซึ่งหุ่นยนต์ชนตัวอื่น (หน่วย องศา)
 int hitRobotBearing
          ทิศทางล่าสุดเทียบกับตัวเอง ซึ่งหุ่นยนต์ชนตัวอื่น (หน่วย องศา)
 int hitWallAngle
          ทิศทางล่าสุดเทียบกับสนามรบ ซึ่งหุ่นยนต์ชนกำแพง (หน่วย องศา)
 int hitWallBearing
          ทิศทางล่าสุดเทียบกับตัวเอง ซึ่งหุ่นยนต์ชนกำแพง (หน่วย องศา)
static int orange
          สีส้ม (0xFFA500)
 int others
          จำนวนหุ่นยนต์อื่นที่อยู่ในสนามรบ
static int purple
          สีม่วง (0x800080)
static int red
          สีแดง (0xFF0000)
 int robotX
          ตำแหน่งของหุ่นยนต์ในแนวนอน (X) (หน่วย พิกเซล)
 int robotY
          ตำแหน่งของหุ่นยนต์ ในแนวตั้ง (Y) (หน่วย พิกเซล)
 int scannedAngle
          ทิศทางเทียบกับสนามรบของหุ่นยนต์อื่นซึ่งอยู่ใกล้ (หน่วย องศา)
 int scannedBearing
          ทิศทางเทียบกับตัวเองของหุ่นยนต์อื่นซึ่งอยู่ใกล้ (หน่วย องศา)
 int scannedDistance
          ระยะทางถึงหุ่นนยต์ตัวที่อยู่ใกล้สุด (หน่วย พิกเซล)
 int scannedEnergy
          พลังของหุ่นยนต์ตัวอื่นซึ่งอยู่ใกล้สุด
 int scannedHeading
          ทิศมุ่งหน้า ของหุ่นยนต์อื่นซึ่งอยู่ใกล้สุด (หน่วย องศา)
 int scannedVelocity
          ความเร็วของหุ่นยนต์อื่น ซึ่งอยู่ใกล้สุด
static int white
          สีขาว (0xFFFFFF)
static int yellow
          สีเหลือง (0xFFFF00)
 

Your are currently browsing this site with Internet Explorer 6 (IE6).

Your current web browser must be updated to version 7 of Internet Explorer (IE7) to take advantage of all of template's capabilities.

Why should I upgrade to Internet Explorer 7? Microsoft has redesigned Internet Explorer from the ground up, with better security, new capabilities, and a whole new interface. Many changes resulted from the feedback of millions of users who tested prerelease versions of the new browser. The most compelling reason to upgrade is the improved security. The Internet of today is not the Internet of five years ago. There are dangers that simply didn't exist back in 2001, when Internet Explorer 6 was released to the world. Internet Explorer 7 makes surfing the web fundamentally safer by offering greater protection against viruses, spyware, and other online risks.

Get free downloads for Internet Explorer 7, including recommended updates as they become available. To download Internet Explorer 7 in the language of your choice, please visit the Internet Explorer 7 worldwide page.