Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 29ed12f

Browse files
author
charlie-lutaud
committed
demo robot added
main.sh added death image added
1 parent 841ebec commit 29ed12f

File tree

8 files changed

+107
-0
lines changed

8 files changed

+107
-0
lines changed

Python-Robocode/GUI/window.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ def addRobotInfo(self, robot):
112112
rb.robot = robot
113113
robot.info = rb
114114
robot.progressBar = rb.progressBar
115+
robot.icon = rb.toolButton
116+
robot.icon2 = rb.toolButton_2
115117
p = self.sceneMenu.addWidget(rb)
116118
l = (len(self.scene.aliveBots) )
117119
self.sceneMenu.setSceneRect(0, 0, 170, l*80)

Python-Robocode/Objects/robot.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,10 @@ def removeMyProtectedItem(self, item):
549549
self.__items.remove(item)
550550

551551
def __death(self):
552+
552553
try:
554+
self.icon.setIcon(QtGui.QIcon(os.getcwd() + "/robotImages/dead.png"))
555+
self.icon2.setIcon(QtGui.QIcon(os.getcwd() + "/robotImages/dead.png"))
553556
self.progressBar.setValue(0)
554557
except :
555558
pass

Python-Robocode/Robots/demo.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#! /usr/bin/python
2+
#-*- coding: utf-8 -*-
3+
4+
from robot import Robot #Import a base Robot
5+
6+
7+
class Demo(Robot): #Create a Robot
8+
9+
def init(self):# NECESARY FOR THE GAME To initialyse your robot
10+
11+
12+
#Set the bot color in RGB
13+
self.setColor(0, 200, 100)
14+
self.setGunColor(200, 200, 0)
15+
self.setRadarColor(255, 60, 0)
16+
self.setBulletsColor(0, 200, 100)
17+
18+
#get the map size
19+
size = self.getMapSize() #get the map size
20+
self.radarVisible(True) # show the radarField
21+
22+
23+
def run(self): #NECESARY FOR THE GAME main loop to command the bot
24+
25+
26+
self.move(90) # for moving (negative values go back)
27+
self.turn(360) #for turning (negative values turn counter-clockwise)
28+
self.stop()
29+
"""
30+
the stop command is used to make moving sequences: here the robot will move 90steps and turn 360° at the same time
31+
and next, fire
32+
"""
33+
34+
35+
self.fire(3) # To Fire (power between 1 and 10)
36+
37+
self.move(100)
38+
self.turn(50)
39+
self.stop()
40+
bulletId = self.fire(2) #to let you you manage if the bullet hit or fail
41+
self.move(180)
42+
self.turn(180)
43+
self.gunTurn(90) #to turn the gun (negative values turn counter-clockwise)
44+
self.stop()
45+
self.fire(1) # To Fire (power between 1 and 10)
46+
self.radarTurn(180) #to turn the radar (negative values turn counter-clockwise)
47+
self.stop()
48+
49+
def sensors(self): #NECESARY FOR THE GAME
50+
"""Tick each frame to have datas about the game"""
51+
52+
pos = self.getPosition() #return the center of the bot
53+
x = pos.x() #get the x coordinate
54+
y = pos.y() #get the y coordinate
55+
56+
angle = self.getGunHeading() #Returns the direction that the robot's gun is facing
57+
angle = self.getHeading() #Returns the direction that the robot is facing
58+
angle = self.getRadarHeading() #Returns the direction that the robot's radar is facing
59+
list = self.getEnemiesLeft() #return a list of the enemies alive in the battle
60+
for robot in list:
61+
id = robot["id"]
62+
name = robot["name"]
63+
# each element of the list is a dictionnary with the bot's id and the bot's name
64+
65+
def onHitByRobot(self, robotId, robotName):
66+
self.rPrint("damn a bot collided me!")
67+
68+
def onHitWall(self):
69+
self.reset() #To reset the run fonction to the begining (auomatically called on hitWall, and robotHit event)
70+
self.pause(100)
71+
self.move(-100)
72+
self.rPrint('ouch! a wall !')
73+
self.setRadarField("large") #Change the radar field form
74+
75+
def onRobotHit(self, robotId, robotName): # when My bot hit another
76+
self.rPrint('collision with:' + str(robotName)) #Print information in the robotMenu (click on the righ panel to see it)
77+
78+
def onHitByBullet(self, bulletBotId, bulletBotName, bulletPower): #NECESARY FOR THE GAME
79+
""" When i'm hit by a bullet"""
80+
self.reset() #To reset the run fonction to the begining (auomatically called on hitWall, and robotHit event)
81+
self.rPrint ("hit by " + str(bulletBotName) + "with power:" +str( bulletPower))
82+
83+
def onBulletHit(self, botId, bulletId):#NECESARY FOR THE GAME
84+
"""when my bullet hit a bot"""
85+
self.rPrint ("fire done on " +str( botId))
86+
87+
88+
def onBulletMiss(self, bulletId):#NECESARY FOR THE GAME
89+
"""when my bullet hit a wall"""
90+
self.rPrint ("the bullet "+ str(bulletId) + " fail")
91+
self.pause(10) #wait 10 frames
92+
93+
def onRobotDeath(self):#NECESARY FOR THE GAME
94+
"""When my bot die"""
95+
self.rPrint ("damn I'm Dead")
96+
97+
def onTargetSpotted(self, botId, botName, botPos):#NECESARY FOR THE GAME
98+
"when the bot see another one"
99+
self.fire(5)
100+
self.rPrint("I see the bot:" + str(botId) + "on position: x:" + str(botPos.x()) + " , y:" + str(botPos.y()))
101+

Python-Robocode/main.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python main.py
-4.26 KB
Binary file not shown.
-1019 Bytes
Binary file not shown.
-971 Bytes
Binary file not shown.
-928 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)