Discussion:
Keyboard Configuration Tab Big Problem
asherbaig
2008-12-05 19:02:52 UTC
Permalink
Hi Developers,

As in earlier days you people help me a lots for that i am really
thankful to you by heart.Now i have biggest problem facing hopefully
you will help me in this matter.

The problem is About configuration of Keyboard for My Robot for
single player.

I will explain in step by step

At first in PreferencesDialog.java
i have created object

private PreferencesKeyConfigurationOptionsTab KeyConfigurationOptionsTab;



Under wizard i added tab



tabbedPane.insertTab("Key Configuration", null,
getKeyConfigurationnOptionsTab(), null, 5);
tabbedPane.setMnemonicAt(5, KeyEvent.VK_K);
tabbedPane.setDisplayedMnemonicIndexAt(5,0);



Now i created seperate calls for KeyConfigurationOptionsTab,java
Also i created seperated project for my Robot by the name Uniteam and
added pakcage single player and class Sprobot.java ( which is my robot).

Robots work fine Here is the code detail as follows:

package singleplayer;

import robocode.AdvancedRobot;

import java.awt.*;
import java.awt.event.KeyEvent;
import static java.awt.event.KeyEvent.*;

public class Sprobot extends AdvancedRobot {


// Move direction: 1 = move forward, 0 = stand still, -1 = move backward
int moveDirection;

// Turn direction: 1 = turn right, 0 = no turning, -1 = turn left
int turnDirection;

// Amount of pixels/units to move
double moveAmount;

// The coordinate of the aim (x,y)
int aimX, aimY;

// Fire power, where 0 = don't fire
int firePower;

//Returns the direction that the robot's radar is facing, in degrees.
//The value returned will be between 0 and 360 (is excluded).
//Note that the heading in Robocode is like a compass, where 0 means
North,
//90 means East, 180 means South, and 270 means West.
double getRadarHeading;

// Called when the robot must run
public void run() {

// Sets the colors of the robot
// body = black, gun = white, radar = red
setColors(Color.BLACK, Color.BLACK, Color.YELLOW);

// Loop forever
for (;;) {
// Sets the robot to move forward, backward or stop moving depending
// on the move direction and amount of pixels to move
setAhead(moveAmount * moveDirection);

// Decrement the amount of pixels to move until we reach 0 pixels
// This way the robot will automatically stop if the mouse wheel
// has stopped it's rotation
moveAmount = Math.max(0, moveAmount - 1);

// Sets the robot to turn right or turn left (at maximum speed) or
// stop turning depending on the turn direction
setTurnRight(45 * turnDirection); // degrees

// Turns the gun toward the current aim coordinate (x,y) controlled by
// the current mouse coordinate
// double angle = normalAbsoluteAngle(Math.atan2(aimX - getX(), aimY
- getY()));



// setTurnGunRightRadians(normalRelativeAngle(angle -
getGunHeadingRadians()));

// Fire the gun with the specified fire power, unless the fire
power = 0
if (firePower > 0) {
setFire(firePower);
}

// Execute all pending set-statements
execute();

// Next turn is processed in this loop..
}
}

// Called when a key has been pressed
public void onKeyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
case VK_W:
// Arrow up key: move direction = forward (infinitely)
moveDirection = 1;
moveAmount = Double.POSITIVE_INFINITY;
break;

case VK_S:
// Arrow down key: move direction = backward (infinitely)
moveDirection = -1;
moveAmount = Double.POSITIVE_INFINITY;
break;

case VK_D:
// Arrow right key: turn direction = right
turnDirection = 1;
break;


case VK_A:
// Arrow left key: turn direction = left
turnDirection = -1;
break;

// Button 3 : return fire
case VK_G:
firePower = 3;
setBulletColor(Color.RED);
break;

// Button 2 : return fire
case VK_H:
firePower = 2;
setBulletColor(Color.YELLOW);
break;

// Button 1 : return fire
case VK_J:
firePower = 1;
setBulletColor(Color.WHITE);
break;

// Move Gun : In Direction 180 to fire using buttons
case VK_U:
char c = e.getKeyChar();
if (c == 'u') {
setTurnGunLeft(180);
} else if (c == 'i') {
setTurnGunRight(180);
}


}

}

// Called when a key has been released (after being pressed)
public void onKeyReleased(KeyEvent e) {
switch (e.getKeyCode()) {
case VK_W:
case VK_S:
// Arrow up and down keys: move direction = stand still
moveDirection = 0;
break;

case VK_D:
case VK_A:
// Arrow right and left keys: turn direction = stop turning
turnDirection = 0;
break;

// Button 3 : Stop firing
case VK_G:
firePower = 0;
break;

// Button 2 : Stop firing
case VK_H:
firePower = 0;
break;

// Button 1 : Stop firing
case VK_J:
firePower = 0;
break;


}
}



}


And Here is the code for PreferencesKeyConfigurationOptionsTab

package robocode.dialog;



import robocode.manager.RobocodeManager;
import robocode.manager.RobocodeProperties;
//import robocode.manager.RobocodeProperties;


import javax.swing.*;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;



public class PreferencesKeyConfigurationOptionsTab extends WizardPanel {

private RobocodeManager manager;

private JPanel specificSettingsPanel;

private JPanel fireSettingsPanel;
private JPanel RadarSettingsPanel;

private JComboBox optionsKeyboardComboBox;
private JComboBox optionsKeyboard2ComboBox;
private JComboBox optionsKeyboard3ComboBox;
private JComboBox optionsKeyboard4ComboBox;
// for firesettingsPanel
private JComboBox optionsKeyboard5ComboBox;
private JComboBox optionsKeyboard6ComboBox;
private JComboBox optionsKeyboard7ComboBox;
private JComboBox optionsKeyboard8ComboBox;
private JComboBox optionsKeyboard9ComboBox;
private JCheckBox optionsRenderingBufferImagesCheckBox;


private JButton predefinedPlaformDefaultButton;
private JButton predefinedSpeedButton;
private JButton predefinedQualityButton;


private EventHandler eventHandler;

public PreferencesKeyConfigurationOptionsTab(RobocodeManager manager) {
super();
this.manager = manager;
initialize();
}

private void initialize() {
eventHandler = new EventHandler();

setLayout(new GridLayout(1, 3));

add(getDirectionSettingsPanel());
add(getFireSettingsPanel());
add(getRadarSettingsPanel());


loadPreferences(manager.getProperties());
}

private JPanel getDirectionSettingsPanel() {

if (specificSettingsPanel == null) {
specificSettingsPanel = new JPanel();
specificSettingsPanel.setBorder(

BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
"Direction settings"));
specificSettingsPanel.setLayout(new GridBagLayout());

GridBagConstraints c = new GridBagConstraints();

c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(6,8,6,8);
c.anchor = GridBagConstraints.PAGE_START;

c.weightx = 2;

c.gridwidth = 4;

c.gridx = 0;
c.gridy = 0;
specificSettingsPanel.add(new JLabel("Set Direction of Robot:"), c);

c.gridwidth = 1;

c.gridy = 1;
specificSettingsPanel.add(new JLabel("RIGHT",
SwingConstants.RIGHT), c);
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboardComboBox(), c);

c.gridx = 0;
c.gridy = 2;
specificSettingsPanel.add(new JLabel("LEFT", SwingConstants.RIGHT), c);
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboard2ComboBox(), c);

c.gridx = 0;
c.gridy = 3;
specificSettingsPanel.add(new JLabel("UP", SwingConstants.RIGHT), c);
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboard3ComboBox(), c);

c.gridx = 0;
c.gridy = 4;
specificSettingsPanel.add(new JLabel("DOWN", SwingConstants.RIGHT), c);
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboard4ComboBox(), c);


}
return specificSettingsPanel;
}

private JPanel getFireSettingsPanel() {
if (fireSettingsPanel == null) {
fireSettingsPanel = new JPanel();
fireSettingsPanel.setBorder(

BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
"Power settings"));
fireSettingsPanel.setLayout(new GridBagLayout());

GridBagConstraints c = new GridBagConstraints();

c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(6,8,6,8);
c.anchor = GridBagConstraints.PAGE_START;

c.weightx = 2;

c.gridwidth = 8;

c.gridx = 0;
c.gridy = 0;
fireSettingsPanel.add(new JLabel("Power Setting:"), c);

c.gridwidth = 1;

c.gridy = 1;
fireSettingsPanel.add(new JLabel("PowerKey 1",
SwingConstants.RIGHT), c);
c.gridx = 1;
fireSettingsPanel.add(getOptionsKeyboard5ComboBox(), c);

c.gridx = 0;
c.gridy = 2;
fireSettingsPanel.add(new JLabel("PowerKey 2",
SwingConstants.RIGHT), c);
c.gridx = 1;
fireSettingsPanel.add(getOptionsKeyboard6ComboBox(), c);

c.gridx = 0;
c.gridy = 3;
fireSettingsPanel.add(new JLabel("PowerKey 3",
SwingConstants.RIGHT), c);
c.gridx = 1;
fireSettingsPanel.add(getOptionsKeyboard7ComboBox(), c);

}
return fireSettingsPanel;
}

private JPanel getRadarSettingsPanel() {
if (RadarSettingsPanel == null) {
RadarSettingsPanel = new JPanel();
RadarSettingsPanel.setBorder(

BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
"Radar Settings"));
RadarSettingsPanel.setLayout(new GridBagLayout());

GridBagConstraints c = new GridBagConstraints();

c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(6,8,6,8);
c.anchor = GridBagConstraints.PAGE_START;

c.weightx = 2;

c.gridwidth = 5;

c.gridx = 0;
c.gridy = 0;
RadarSettingsPanel.add(new JLabel("Set Radar Button Key:"), c);

c.gridwidth = 1;

c.gridx = 0;
c.gridy = 4;
RadarSettingsPanel.add(new JLabel("RadarKey 1",
SwingConstants.RIGHT), c);
c.gridx = 1;
RadarSettingsPanel.add(getOptionsKeyboard8ComboBox(), c);

c.gridx = 0;
c.gridy = 5;
RadarSettingsPanel.add(new JLabel("RadarKey 2",
SwingConstants.RIGHT), c);
c.gridx = 1;
RadarSettingsPanel.add(getOptionsKeyboard9ComboBox(), c);


}
return RadarSettingsPanel;
}



private JComboBox getOptionsKeyboardComboBox() {
if (optionsKeyboardComboBox == null) {
optionsKeyboardComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboardComboBox.addActionListener(eventHandler);

}
return optionsKeyboardComboBox;
}

private JComboBox getOptionsKeyboard2ComboBox() {
if (optionsKeyboard2ComboBox == null) {
optionsKeyboard2ComboBox = new JComboBox(new String[] { "S", "
","A", "D", "X"});
optionsKeyboard2ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard2ComboBox;
}

private JComboBox getOptionsKeyboard3ComboBox() {
if (optionsKeyboard3ComboBox == null) {
optionsKeyboard3ComboBox = new JComboBox(new String[] { "D", "S",
"D", "X"});
optionsKeyboard3ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard3ComboBox;
}

private JComboBox getOptionsKeyboard4ComboBox() {
if (optionsKeyboard4ComboBox == null) {
optionsKeyboard4ComboBox = new JComboBox(new String[] { "X", "S",
"D", "X"});
optionsKeyboard4ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard4ComboBox;
}

private JComboBox getOptionsKeyboard5ComboBox() {
if (optionsKeyboard5ComboBox == null) {
optionsKeyboard5ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard5ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard5ComboBox;
}

private JComboBox getOptionsKeyboard6ComboBox() {
if (optionsKeyboard6ComboBox == null) {
optionsKeyboard6ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard6ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard6ComboBox;
}
private JComboBox getOptionsKeyboard7ComboBox() {
if (optionsKeyboard7ComboBox == null) {
optionsKeyboard7ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard7ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard7ComboBox;
}


private JComboBox getOptionsKeyboard8ComboBox() {
if (optionsKeyboard8ComboBox == null) {
optionsKeyboard8ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard8ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard8ComboBox;
}

private JComboBox getOptionsKeyboard9ComboBox() {
if (optionsKeyboard9ComboBox == null) {
optionsKeyboard9ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard9ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard9ComboBox;
}





private void loadPreferences(RobocodeProperties props) {

getOptionsKeyboardComboBox().setSelectedIndex(props.getOptionsRenderingAntialiasing());

getOptionsKeyboard2ComboBox().setSelectedIndex(props.getOptionsRenderingTextAntialiasing());

getOptionsKeyboard3ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());

getOptionsKeyboard4ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());

getOptionsKeyboard5ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());

getOptionsKeyboard6ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());

getOptionsKeyboard7ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());

getOptionsKeyboard8ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());

getOptionsKeyboard9ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
}


public void storePreferences() {
RobocodeProperties props = manager.getProperties();


props.setOptionsRenderingAntialiasing(optionsKeyboardComboBox.getSelectedIndex());

props.setOptionsRenderingTextAntialiasing(optionsKeyboard2ComboBox.getSelectedIndex());

props.setOptionsRenderingMethod(optionsKeyboard3ComboBox.getSelectedIndex());

props.setOptionsRenderingMethod(optionsKeyboard4ComboBox.getSelectedIndex());

props.setOptionsRenderingMethod(optionsKeyboard5ComboBox.getSelectedIndex());

props.setOptionsRenderingMethod(optionsKeyboard6ComboBox.getSelectedIndex());

props.setOptionsRenderingMethod(optionsKeyboard7ComboBox.getSelectedIndex());

props.setOptionsRenderingMethod(optionsKeyboard8ComboBox.getSelectedIndex());

props.setOptionsRenderingMethod(optionsKeyboard9ComboBox.getSelectedIndex());
manager.saveProperties();
}

@Override
public boolean isReady() {
return true;
}

private void setPredefinedSettings(int index) {
optionsKeyboardComboBox.setSelectedIndex(index);
optionsKeyboard2ComboBox.setSelectedIndex(index);
optionsKeyboard3ComboBox.setSelectedIndex(index);
}

private class EventHandler implements ActionListener {

public void actionPerformed(ActionEvent e) {
Object src = e.getSource();

if (src == predefinedPlaformDefaultButton) {
setPredefinedSettings(0);

} else if (src == predefinedQualityButton) {
setPredefinedSettings(1);
} else if (src == predefinedSpeedButton) {
setPredefinedSettings(2);
} else if (src == optionsRenderingBufferImagesCheckBox) {
// Reset images so they are reloaded and gets buffered or unbuffered
new Thread() {
@Override
public void run() {
storePreferences();
manager.getImageManager().initialize();
}
}.start();
return;
}

manager.getWindowManager().getRobocodeFrame().getBattleView().setInitialized(false);
}
}
}


NOW I WANT USER TO GET KEY CONFIGURA FROM
PreferencesKeyConfigurationOptionsTab.JAVA

I HOPE U UNDERSTAND THIS PROBLEM.

I MEAN WHEN USER LEFT KEY FROM COMBOBOX.It will directly assigned to
Left in Sprobot.java ( which is my robot).

Also i want to send These three java files.here is the link
1.PreferencesDialog.java
http://www.sendspace.com/file/6kgbv4
2.PreferencesKeyConfigurationOptionsTab.java
http://www.sendspace.com/file/rkzn2d
3.Uniteam3a SEPERATE PROJECT FOR Robot full package in rar format
http://www.sendspace.com/file/zkrv1m









------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/Robocode/

<*> Your email settings:
Individual Email | Traditional

<*> To change settings online go to:
http://groups.yahoo.com/group/Robocode/join
(Yahoo! ID required)

<*> To change settings via email:
mailto:Robocode-***@yahoogroups.com
mailto:Robocode-***@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
Robocode-***@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
Mike Purvis
2008-12-06 03:57:07 UTC
Permalink
Maybe its just me, but I thought by definition a robot is not controlled
from the keyboard that would be cheating.

Mike
Post by asherbaig
Hi Developers,
As in earlier days you people help me a lots for that i am really
thankful to you by heart.Now i have biggest problem facing hopefully
you will help me in this matter.
The problem is About configuration of Keyboard for My Robot for
single player.
I will explain in step by step
At first in PreferencesDialog.java
i have created object
private PreferencesKeyConfigurationOptionsTab KeyConfigurationOptionsTab;
Under wizard i added tab
tabbedPane.insertTab("Key Configuration", null,
getKeyConfigurationnOptionsTab(), null, 5);
tabbedPane.setMnemonicAt(5, KeyEvent.VK_K);
tabbedPane.setDisplayedMnemonicIndexAt(5,0);
Now i created seperate calls for KeyConfigurationOptionsTab,java
Also i created seperated project for my Robot by the name Uniteam and
added pakcage single player and class Sprobot.java ( which is my robot).
package singleplayer;
import robocode.AdvancedRobot;
import java.awt.*;
import java.awt.event.KeyEvent;
import static java.awt.event.KeyEvent.*;
public class Sprobot extends AdvancedRobot {
// Move direction: 1 = move forward, 0 = stand still, -1 = move backward
int moveDirection;
// Turn direction: 1 = turn right, 0 = no turning, -1 = turn left
int turnDirection;
// Amount of pixels/units to move
double moveAmount;
// The coordinate of the aim (x,y)
int aimX, aimY;
// Fire power, where 0 = don't fire
int firePower;
//Returns the direction that the robot's radar is facing, in degrees.
//The value returned will be between 0 and 360 (is excluded).
//Note that the heading in Robocode is like a compass, where 0 means
North,
//90 means East, 180 means South, and 270 means West.
double getRadarHeading;
// Called when the robot must run
public void run() {
// Sets the colors of the robot
// body = black, gun = white, radar = red
setColors(Color.BLACK, Color.BLACK, Color.YELLOW);
// Loop forever
for (;;) {
// Sets the robot to move forward, backward or stop moving depending
// on the move direction and amount of pixels to move
setAhead(moveAmount * moveDirection);
// Decrement the amount of pixels to move until we reach 0 pixels
// This way the robot will automatically stop if the mouse wheel
// has stopped it's rotation
moveAmount = Math.max(0, moveAmount - 1);
// Sets the robot to turn right or turn left (at maximum speed) or
// stop turning depending on the turn direction
setTurnRight(45 * turnDirection); // degrees
// Turns the gun toward the current aim coordinate (x,y) controlled by
// the current mouse coordinate
// double angle = normalAbsoluteAngle(Math.atan2(aimX - getX(), aimY
- getY()));
// setTurnGunRightRadians(normalRelativeAngle(angle -
getGunHeadingRadians()));
// Fire the gun with the specified fire power, unless the fire
power = 0
if (firePower > 0) {
setFire(firePower);
}
// Execute all pending set-statements
execute();
// Next turn is processed in this loop..
}
}
// Called when a key has been pressed
public void onKeyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
// Arrow up key: move direction = forward (infinitely)
moveDirection = 1;
moveAmount = Double.POSITIVE_INFINITY;
break;
// Arrow down key: move direction = backward (infinitely)
moveDirection = -1;
moveAmount = Double.POSITIVE_INFINITY;
break;
// Arrow right key: turn direction = right
turnDirection = 1;
break;
// Arrow left key: turn direction = left
turnDirection = -1;
break;
// Button 3 : return fire
firePower = 3;
setBulletColor(Color.RED);
break;
// Button 2 : return fire
firePower = 2;
setBulletColor(Color.YELLOW);
break;
// Button 1 : return fire
firePower = 1;
setBulletColor(Color.WHITE);
break;
// Move Gun : In Direction 180 to fire using buttons
char c = e.getKeyChar();
if (c == 'u') {
setTurnGunLeft(180);
} else if (c == 'i') {
setTurnGunRight(180);
}
}
}
// Called when a key has been released (after being pressed)
public void onKeyReleased(KeyEvent e) {
switch (e.getKeyCode()) {
// Arrow up and down keys: move direction = stand still
moveDirection = 0;
break;
// Arrow right and left keys: turn direction = stop turning
turnDirection = 0;
break;
// Button 3 : Stop firing
firePower = 0;
break;
// Button 2 : Stop firing
firePower = 0;
break;
// Button 1 : Stop firing
firePower = 0;
break;
}
}
}
And Here is the code for PreferencesKeyConfigurationOptionsTab
package robocode.dialog;
import robocode.manager.RobocodeManager;
import robocode.manager.RobocodeProperties;
//import robocode.manager.RobocodeProperties;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class PreferencesKeyConfigurationOptionsTab extends WizardPanel {
private RobocodeManager manager;
private JPanel specificSettingsPanel;
private JPanel fireSettingsPanel;
private JPanel RadarSettingsPanel;
private JComboBox optionsKeyboardComboBox;
private JComboBox optionsKeyboard2ComboBox;
private JComboBox optionsKeyboard3ComboBox;
private JComboBox optionsKeyboard4ComboBox;
// for firesettingsPanel
private JComboBox optionsKeyboard5ComboBox;
private JComboBox optionsKeyboard6ComboBox;
private JComboBox optionsKeyboard7ComboBox;
private JComboBox optionsKeyboard8ComboBox;
private JComboBox optionsKeyboard9ComboBox;
private JCheckBox optionsRenderingBufferImagesCheckBox;
private JButton predefinedPlaformDefaultButton;
private JButton predefinedSpeedButton;
private JButton predefinedQualityButton;
private EventHandler eventHandler;
public PreferencesKeyConfigurationOptionsTab(RobocodeManager manager) {
super();
this.manager = manager;
initialize();
}
private void initialize() {
eventHandler = new EventHandler();
setLayout(new GridLayout(1, 3));
add(getDirectionSettingsPanel());
add(getFireSettingsPanel());
add(getRadarSettingsPanel());
loadPreferences(manager.getProperties());
}
private JPanel getDirectionSettingsPanel() {
if (specificSettingsPanel == null) {
specificSettingsPanel = new JPanel();
specificSettingsPanel.setBorder(
BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
"Direction settings"));
specificSettingsPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(6,8,6,8);
c.anchor = GridBagConstraints.PAGE_START;
c.weightx = 2;
c.gridwidth = 4;
c.gridx = 0;
c.gridy = 0;
specificSettingsPanel.add(new JLabel("Set Direction of Robot:"), c);
c.gridwidth = 1;
c.gridy = 1;
specificSettingsPanel.add(new JLabel("RIGHT",
SwingConstants.RIGHT), c);
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboardComboBox(), c);
c.gridx = 0;
c.gridy = 2;
specificSettingsPanel.add(new JLabel("LEFT", SwingConstants.RIGHT), c);
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboard2ComboBox(), c);
c.gridx = 0;
c.gridy = 3;
specificSettingsPanel.add(new JLabel("UP", SwingConstants.RIGHT), c);
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboard3ComboBox(), c);
c.gridx = 0;
c.gridy = 4;
specificSettingsPanel.add(new JLabel("DOWN", SwingConstants.RIGHT), c);
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboard4ComboBox(), c);
}
return specificSettingsPanel;
}
private JPanel getFireSettingsPanel() {
if (fireSettingsPanel == null) {
fireSettingsPanel = new JPanel();
fireSettingsPanel.setBorder(
BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
"Power settings"));
fireSettingsPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(6,8,6,8);
c.anchor = GridBagConstraints.PAGE_START;
c.weightx = 2;
c.gridwidth = 8;
c.gridx = 0;
c.gridy = 0;
fireSettingsPanel.add(new JLabel("Power Setting:"), c);
c.gridwidth = 1;
c.gridy = 1;
fireSettingsPanel.add(new JLabel("PowerKey 1",
SwingConstants.RIGHT), c);
c.gridx = 1;
fireSettingsPanel.add(getOptionsKeyboard5ComboBox(), c);
c.gridx = 0;
c.gridy = 2;
fireSettingsPanel.add(new JLabel("PowerKey 2",
SwingConstants.RIGHT), c);
c.gridx = 1;
fireSettingsPanel.add(getOptionsKeyboard6ComboBox(), c);
c.gridx = 0;
c.gridy = 3;
fireSettingsPanel.add(new JLabel("PowerKey 3",
SwingConstants.RIGHT), c);
c.gridx = 1;
fireSettingsPanel.add(getOptionsKeyboard7ComboBox(), c);
}
return fireSettingsPanel;
}
private JPanel getRadarSettingsPanel() {
if (RadarSettingsPanel == null) {
RadarSettingsPanel = new JPanel();
RadarSettingsPanel.setBorder(
BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
"Radar Settings"));
RadarSettingsPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(6,8,6,8);
c.anchor = GridBagConstraints.PAGE_START;
c.weightx = 2;
c.gridwidth = 5;
c.gridx = 0;
c.gridy = 0;
RadarSettingsPanel.add(new JLabel("Set Radar Button Key:"), c);
c.gridwidth = 1;
c.gridx = 0;
c.gridy = 4;
RadarSettingsPanel.add(new JLabel("RadarKey 1",
SwingConstants.RIGHT), c);
c.gridx = 1;
RadarSettingsPanel.add(getOptionsKeyboard8ComboBox(), c);
c.gridx = 0;
c.gridy = 5;
RadarSettingsPanel.add(new JLabel("RadarKey 2",
SwingConstants.RIGHT), c);
c.gridx = 1;
RadarSettingsPanel.add(getOptionsKeyboard9ComboBox(), c);
}
return RadarSettingsPanel;
}
private JComboBox getOptionsKeyboardComboBox() {
if (optionsKeyboardComboBox == null) {
optionsKeyboardComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboardComboBox.addActionListener(eventHandler);
}
return optionsKeyboardComboBox;
}
private JComboBox getOptionsKeyboard2ComboBox() {
if (optionsKeyboard2ComboBox == null) {
optionsKeyboard2ComboBox = new JComboBox(new String[] { "S", "
","A", "D", "X"});
optionsKeyboard2ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard2ComboBox;
}
private JComboBox getOptionsKeyboard3ComboBox() {
if (optionsKeyboard3ComboBox == null) {
optionsKeyboard3ComboBox = new JComboBox(new String[] { "D", "S",
"D", "X"});
optionsKeyboard3ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard3ComboBox;
}
private JComboBox getOptionsKeyboard4ComboBox() {
if (optionsKeyboard4ComboBox == null) {
optionsKeyboard4ComboBox = new JComboBox(new String[] { "X", "S",
"D", "X"});
optionsKeyboard4ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard4ComboBox;
}
private JComboBox getOptionsKeyboard5ComboBox() {
if (optionsKeyboard5ComboBox == null) {
optionsKeyboard5ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard5ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard5ComboBox;
}
private JComboBox getOptionsKeyboard6ComboBox() {
if (optionsKeyboard6ComboBox == null) {
optionsKeyboard6ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard6ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard6ComboBox;
}
private JComboBox getOptionsKeyboard7ComboBox() {
if (optionsKeyboard7ComboBox == null) {
optionsKeyboard7ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard7ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard7ComboBox;
}
private JComboBox getOptionsKeyboard8ComboBox() {
if (optionsKeyboard8ComboBox == null) {
optionsKeyboard8ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard8ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard8ComboBox;
}
private JComboBox getOptionsKeyboard9ComboBox() {
if (optionsKeyboard9ComboBox == null) {
optionsKeyboard9ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard9ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard9ComboBox;
}
private void loadPreferences(RobocodeProperties props) {
getOptionsKeyboardComboBox().setSelectedIndex(props.getOptionsRenderingAntialiasing());
getOptionsKeyboard2ComboBox().setSelectedIndex(props.getOptionsRenderingTextAntialiasing());
getOptionsKeyboard3ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard4ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard5ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard6ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard7ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard8ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard9ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
}
public void storePreferences() {
RobocodeProperties props = manager.getProperties();
props.setOptionsRenderingAntialiasing(optionsKeyboardComboBox.getSelectedIndex());
props.setOptionsRenderingTextAntialiasing(optionsKeyboard2ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard3ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard4ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard5ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard6ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard7ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard8ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard9ComboBox.getSelectedIndex());
manager.saveProperties();
}
@Override
public boolean isReady() {
return true;
}
private void setPredefinedSettings(int index) {
optionsKeyboardComboBox.setSelectedIndex(index);
optionsKeyboard2ComboBox.setSelectedIndex(index);
optionsKeyboard3ComboBox.setSelectedIndex(index);
}
private class EventHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
Object src = e.getSource();
if (src == predefinedPlaformDefaultButton) {
setPredefinedSettings(0);
} else if (src == predefinedQualityButton) {
setPredefinedSettings(1);
} else if (src == predefinedSpeedButton) {
setPredefinedSettings(2);
} else if (src == optionsRenderingBufferImagesCheckBox) {
// Reset images so they are reloaded and gets buffered or unbuffered
new Thread() {
@Override
public void run() {
storePreferences();
manager.getImageManager().initialize();
}
}.start();
return;
}
manager.getWindowManager().getRobocodeFrame().getBattleView().setInitialized(false);
}
}
}
NOW I WANT USER TO GET KEY CONFIGURA FROM
PreferencesKeyConfigurationOptionsTab.JAVA
I HOPE U UNDERSTAND THIS PROBLEM.
I MEAN WHEN USER LEFT KEY FROM COMBOBOX.It will directly assigned to
Left in Sprobot.java ( which is my robot).
Also i want to send These three java files.here is the link
1.PreferencesDialog.java
http://www.sendspace.com/file/6kgbv4
2.PreferencesKeyConfigurationOptionsTab.java
http://www.sendspace.com/file/rkzn2d
3.Uniteam3a SEPERATE PROJECT FOR Robot full package in rar format
http://www.sendspace.com/file/zkrv1m
flemmingnlarsen
2008-12-06 22:55:28 UTC
Permalink
This feature was built-in many versions ago, since version 1.3.4. See
the sample.Interactive robot.

Regarding cheating:

1) You will never be able to beat a good robot runs 100% by itself
using the keyboard and mouse alone. So far, I have never seen such robot.

2) In competitions like e.g. RoboRumble, the author of the robot is
not able to control the robot using his/her keyboard. I you make a
robot that can be controlled by keyboard and mouse, and I run it on my
computer. Why should I try to control your robot in order to beat my
own robot? I would not do that of course in order to let your robot
loose. The point is. In competitions your robot need to run 100% by
itself.

3) The interactive feature was made to make debugging easier in some
cases, but also to make it possible to try to beat the other robots
yourself, or compete agaist friends by sharing the keyboard (coding
two individual robots using different keys).

So, no. In practise it's not possible to cheat. But you could prove me
wrong. ;-)

Best regards,
- Flemming
Post by Mike Purvis
Maybe its just me, but I thought by definition a robot is not controlled
from the keyboard that would be cheating.
Mike
Post by asherbaig
Hi Developers,
As in earlier days you people help me a lots for that i am really
thankful to you by heart.Now i have biggest problem facing hopefully
you will help me in this matter.
The problem is About configuration of Keyboard for My Robot for
single player.
I will explain in step by step
At first in PreferencesDialog.java
i have created object
private PreferencesKeyConfigurationOptionsTab
KeyConfigurationOptionsTab;
Post by Mike Purvis
Post by asherbaig
Under wizard i added tab
tabbedPane.insertTab("Key Configuration", null,
getKeyConfigurationnOptionsTab(), null, 5);
tabbedPane.setMnemonicAt(5, KeyEvent.VK_K);
tabbedPane.setDisplayedMnemonicIndexAt(5,0);
Now i created seperate calls for KeyConfigurationOptionsTab,java
Also i created seperated project for my Robot by the name Uniteam and
added pakcage single player and class Sprobot.java ( which is my robot).
package singleplayer;
import robocode.AdvancedRobot;
import java.awt.*;
import java.awt.event.KeyEvent;
import static java.awt.event.KeyEvent.*;
public class Sprobot extends AdvancedRobot {
// Move direction: 1 = move forward, 0 = stand still, -1 = move backward
int moveDirection;
// Turn direction: 1 = turn right, 0 = no turning, -1 = turn left
int turnDirection;
// Amount of pixels/units to move
double moveAmount;
// The coordinate of the aim (x,y)
int aimX, aimY;
// Fire power, where 0 = don't fire
int firePower;
//Returns the direction that the robot's radar is facing, in degrees.
//The value returned will be between 0 and 360 (is excluded).
//Note that the heading in Robocode is like a compass, where 0 means
North,
//90 means East, 180 means South, and 270 means West.
double getRadarHeading;
// Called when the robot must run
public void run() {
// Sets the colors of the robot
// body = black, gun = white, radar = red
setColors(Color.BLACK, Color.BLACK, Color.YELLOW);
// Loop forever
for (;;) {
// Sets the robot to move forward, backward or stop moving depending
// on the move direction and amount of pixels to move
setAhead(moveAmount * moveDirection);
// Decrement the amount of pixels to move until we reach 0 pixels
// This way the robot will automatically stop if the mouse wheel
// has stopped it's rotation
moveAmount = Math.max(0, moveAmount - 1);
// Sets the robot to turn right or turn left (at maximum speed) or
// stop turning depending on the turn direction
setTurnRight(45 * turnDirection); // degrees
// Turns the gun toward the current aim coordinate (x,y) controlled by
// the current mouse coordinate
// double angle = normalAbsoluteAngle(Math.atan2(aimX - getX(), aimY
- getY()));
// setTurnGunRightRadians(normalRelativeAngle(angle -
getGunHeadingRadians()));
// Fire the gun with the specified fire power, unless the fire
power = 0
if (firePower > 0) {
setFire(firePower);
}
// Execute all pending set-statements
execute();
// Next turn is processed in this loop..
}
}
// Called when a key has been pressed
public void onKeyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
// Arrow up key: move direction = forward (infinitely)
moveDirection = 1;
moveAmount = Double.POSITIVE_INFINITY;
break;
// Arrow down key: move direction = backward (infinitely)
moveDirection = -1;
moveAmount = Double.POSITIVE_INFINITY;
break;
// Arrow right key: turn direction = right
turnDirection = 1;
break;
// Arrow left key: turn direction = left
turnDirection = -1;
break;
// Button 3 : return fire
firePower = 3;
setBulletColor(Color.RED);
break;
// Button 2 : return fire
firePower = 2;
setBulletColor(Color.YELLOW);
break;
// Button 1 : return fire
firePower = 1;
setBulletColor(Color.WHITE);
break;
// Move Gun : In Direction 180 to fire using buttons
char c = e.getKeyChar();
if (c == 'u') {
setTurnGunLeft(180);
} else if (c == 'i') {
setTurnGunRight(180);
}
}
}
// Called when a key has been released (after being pressed)
public void onKeyReleased(KeyEvent e) {
switch (e.getKeyCode()) {
// Arrow up and down keys: move direction = stand still
moveDirection = 0;
break;
// Arrow right and left keys: turn direction = stop turning
turnDirection = 0;
break;
// Button 3 : Stop firing
firePower = 0;
break;
// Button 2 : Stop firing
firePower = 0;
break;
// Button 1 : Stop firing
firePower = 0;
break;
}
}
}
And Here is the code for PreferencesKeyConfigurationOptionsTab
package robocode.dialog;
import robocode.manager.RobocodeManager;
import robocode.manager.RobocodeProperties;
//import robocode.manager.RobocodeProperties;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class PreferencesKeyConfigurationOptionsTab extends
WizardPanel {
Post by Mike Purvis
Post by asherbaig
private RobocodeManager manager;
private JPanel specificSettingsPanel;
private JPanel fireSettingsPanel;
private JPanel RadarSettingsPanel;
private JComboBox optionsKeyboardComboBox;
private JComboBox optionsKeyboard2ComboBox;
private JComboBox optionsKeyboard3ComboBox;
private JComboBox optionsKeyboard4ComboBox;
// for firesettingsPanel
private JComboBox optionsKeyboard5ComboBox;
private JComboBox optionsKeyboard6ComboBox;
private JComboBox optionsKeyboard7ComboBox;
private JComboBox optionsKeyboard8ComboBox;
private JComboBox optionsKeyboard9ComboBox;
private JCheckBox optionsRenderingBufferImagesCheckBox;
private JButton predefinedPlaformDefaultButton;
private JButton predefinedSpeedButton;
private JButton predefinedQualityButton;
private EventHandler eventHandler;
public PreferencesKeyConfigurationOptionsTab(RobocodeManager
manager) {
Post by Mike Purvis
Post by asherbaig
super();
this.manager = manager;
initialize();
}
private void initialize() {
eventHandler = new EventHandler();
setLayout(new GridLayout(1, 3));
add(getDirectionSettingsPanel());
add(getFireSettingsPanel());
add(getRadarSettingsPanel());
loadPreferences(manager.getProperties());
}
private JPanel getDirectionSettingsPanel() {
if (specificSettingsPanel == null) {
specificSettingsPanel = new JPanel();
specificSettingsPanel.setBorder(
BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
"Direction settings"));
specificSettingsPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(6,8,6,8);
c.anchor = GridBagConstraints.PAGE_START;
c.weightx = 2;
c.gridwidth = 4;
c.gridx = 0;
c.gridy = 0;
specificSettingsPanel.add(new JLabel("Set Direction of Robot:"), c);
c.gridwidth = 1;
c.gridy = 1;
specificSettingsPanel.add(new JLabel("RIGHT",
SwingConstants.RIGHT), c);
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboardComboBox(), c);
c.gridx = 0;
c.gridy = 2;
specificSettingsPanel.add(new JLabel("LEFT",
SwingConstants.RIGHT), c);
Post by Mike Purvis
Post by asherbaig
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboard2ComboBox(), c);
c.gridx = 0;
c.gridy = 3;
specificSettingsPanel.add(new JLabel("UP", SwingConstants.RIGHT), c);
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboard3ComboBox(), c);
c.gridx = 0;
c.gridy = 4;
specificSettingsPanel.add(new JLabel("DOWN",
SwingConstants.RIGHT), c);
Post by Mike Purvis
Post by asherbaig
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboard4ComboBox(), c);
}
return specificSettingsPanel;
}
private JPanel getFireSettingsPanel() {
if (fireSettingsPanel == null) {
fireSettingsPanel = new JPanel();
fireSettingsPanel.setBorder(
BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
"Power settings"));
fireSettingsPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(6,8,6,8);
c.anchor = GridBagConstraints.PAGE_START;
c.weightx = 2;
c.gridwidth = 8;
c.gridx = 0;
c.gridy = 0;
fireSettingsPanel.add(new JLabel("Power Setting:"), c);
c.gridwidth = 1;
c.gridy = 1;
fireSettingsPanel.add(new JLabel("PowerKey 1",
SwingConstants.RIGHT), c);
c.gridx = 1;
fireSettingsPanel.add(getOptionsKeyboard5ComboBox(), c);
c.gridx = 0;
c.gridy = 2;
fireSettingsPanel.add(new JLabel("PowerKey 2",
SwingConstants.RIGHT), c);
c.gridx = 1;
fireSettingsPanel.add(getOptionsKeyboard6ComboBox(), c);
c.gridx = 0;
c.gridy = 3;
fireSettingsPanel.add(new JLabel("PowerKey 3",
SwingConstants.RIGHT), c);
c.gridx = 1;
fireSettingsPanel.add(getOptionsKeyboard7ComboBox(), c);
}
return fireSettingsPanel;
}
private JPanel getRadarSettingsPanel() {
if (RadarSettingsPanel == null) {
RadarSettingsPanel = new JPanel();
RadarSettingsPanel.setBorder(
BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
"Radar Settings"));
RadarSettingsPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(6,8,6,8);
c.anchor = GridBagConstraints.PAGE_START;
c.weightx = 2;
c.gridwidth = 5;
c.gridx = 0;
c.gridy = 0;
RadarSettingsPanel.add(new JLabel("Set Radar Button Key:"), c);
c.gridwidth = 1;
c.gridx = 0;
c.gridy = 4;
RadarSettingsPanel.add(new JLabel("RadarKey 1",
SwingConstants.RIGHT), c);
c.gridx = 1;
RadarSettingsPanel.add(getOptionsKeyboard8ComboBox(), c);
c.gridx = 0;
c.gridy = 5;
RadarSettingsPanel.add(new JLabel("RadarKey 2",
SwingConstants.RIGHT), c);
c.gridx = 1;
RadarSettingsPanel.add(getOptionsKeyboard9ComboBox(), c);
}
return RadarSettingsPanel;
}
private JComboBox getOptionsKeyboardComboBox() {
if (optionsKeyboardComboBox == null) {
optionsKeyboardComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboardComboBox.addActionListener(eventHandler);
}
return optionsKeyboardComboBox;
}
private JComboBox getOptionsKeyboard2ComboBox() {
if (optionsKeyboard2ComboBox == null) {
optionsKeyboard2ComboBox = new JComboBox(new String[] { "S", "
","A", "D", "X"});
optionsKeyboard2ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard2ComboBox;
}
private JComboBox getOptionsKeyboard3ComboBox() {
if (optionsKeyboard3ComboBox == null) {
optionsKeyboard3ComboBox = new JComboBox(new String[] { "D", "S",
"D", "X"});
optionsKeyboard3ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard3ComboBox;
}
private JComboBox getOptionsKeyboard4ComboBox() {
if (optionsKeyboard4ComboBox == null) {
optionsKeyboard4ComboBox = new JComboBox(new String[] { "X", "S",
"D", "X"});
optionsKeyboard4ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard4ComboBox;
}
private JComboBox getOptionsKeyboard5ComboBox() {
if (optionsKeyboard5ComboBox == null) {
optionsKeyboard5ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard5ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard5ComboBox;
}
private JComboBox getOptionsKeyboard6ComboBox() {
if (optionsKeyboard6ComboBox == null) {
optionsKeyboard6ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard6ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard6ComboBox;
}
private JComboBox getOptionsKeyboard7ComboBox() {
if (optionsKeyboard7ComboBox == null) {
optionsKeyboard7ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard7ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard7ComboBox;
}
private JComboBox getOptionsKeyboard8ComboBox() {
if (optionsKeyboard8ComboBox == null) {
optionsKeyboard8ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard8ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard8ComboBox;
}
private JComboBox getOptionsKeyboard9ComboBox() {
if (optionsKeyboard9ComboBox == null) {
optionsKeyboard9ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard9ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard9ComboBox;
}
private void loadPreferences(RobocodeProperties props) {
getOptionsKeyboardComboBox().setSelectedIndex(props.getOptionsRenderingAntialiasing());
getOptionsKeyboard2ComboBox().setSelectedIndex(props.getOptionsRenderingTextAntialiasing());
getOptionsKeyboard3ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard4ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard5ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard6ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard7ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard8ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard9ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
Post by Mike Purvis
Post by asherbaig
}
public void storePreferences() {
RobocodeProperties props = manager.getProperties();
props.setOptionsRenderingAntialiasing(optionsKeyboardComboBox.getSelectedIndex());
props.setOptionsRenderingTextAntialiasing(optionsKeyboard2ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard3ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard4ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard5ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard6ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard7ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard8ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard9ComboBox.getSelectedIndex());
Post by Mike Purvis
Post by asherbaig
manager.saveProperties();
}
@Override
public boolean isReady() {
return true;
}
private void setPredefinedSettings(int index) {
optionsKeyboardComboBox.setSelectedIndex(index);
optionsKeyboard2ComboBox.setSelectedIndex(index);
optionsKeyboard3ComboBox.setSelectedIndex(index);
}
private class EventHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
Object src = e.getSource();
if (src == predefinedPlaformDefaultButton) {
setPredefinedSettings(0);
} else if (src == predefinedQualityButton) {
setPredefinedSettings(1);
} else if (src == predefinedSpeedButton) {
setPredefinedSettings(2);
} else if (src == optionsRenderingBufferImagesCheckBox) {
// Reset images so they are reloaded and gets buffered or unbuffered
new Thread() {
@Override
public void run() {
storePreferences();
manager.getImageManager().initialize();
}
}.start();
return;
}
manager.getWindowManager().getRobocodeFrame().getBattleView().setInitialized(false);
Post by Mike Purvis
Post by asherbaig
}
}
}
NOW I WANT USER TO GET KEY CONFIGURA FROM
PreferencesKeyConfigurationOptionsTab.JAVA
I HOPE U UNDERSTAND THIS PROBLEM.
I MEAN WHEN USER LEFT KEY FROM COMBOBOX.It will directly assigned to
Left in Sprobot.java ( which is my robot).
Also i want to send These three java files.here is the link
1.PreferencesDialog.java
http://www.sendspace.com/file/6kgbv4
2.PreferencesKeyConfigurationOptionsTab.java
http://www.sendspace.com/file/rkzn2d
3.Uniteam3a SEPERATE PROJECT FOR Robot full package in rar format
http://www.sendspace.com/file/zkrv1m
------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/Robocode/

<*> Your email settings:
Individual Email | Traditional

<*> To change settings online go to:
http://groups.yahoo.com/group/Robocode/join
(Yahoo! ID required)

<*> To change settings via email:
mailto:Robocode-***@yahoogroups.com
mailto:Robocode-***@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
Robocode-***@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
asherbaig
2008-12-07 12:12:07 UTC
Permalink
May be you didn't understand my question.See the link below for snapshot.

Actually what i want that User can select any string from "A" upto "Z"
to define any keys to handle robot in battle to play.For example for
Sprobot


How to assign those key to Sprobot.

snapshot
Loading Image...


Also plzz let me know how to download old version 1.3.4? i couldn't
find it.

Thanks,
Asher
Post by flemmingnlarsen
This feature was built-in many versions ago, since version 1.3.4. See
the sample.Interactive robot.
1) You will never be able to beat a good robot runs 100% by itself
using the keyboard and mouse alone. So far, I have never seen such robot.
2) In competitions like e.g. RoboRumble, the author of the robot is
not able to control the robot using his/her keyboard. I you make a
robot that can be controlled by keyboard and mouse, and I run it on my
computer. Why should I try to control your robot in order to beat my
own robot? I would not do that of course in order to let your robot
loose. The point is. In competitions your robot need to run 100% by
itself.
3) The interactive feature was made to make debugging easier in some
cases, but also to make it possible to try to beat the other robots
yourself, or compete agaist friends by sharing the keyboard (coding
two individual robots using different keys).
So, no. In practise it's not possible to cheat. But you could prove me
wrong. ;-)
Best regards,
- Flemming
Post by Mike Purvis
Maybe its just me, but I thought by definition a robot is not controlled
from the keyboard that would be cheating.
Mike
Post by asherbaig
Hi Developers,
As in earlier days you people help me a lots for that i am really
thankful to you by heart.Now i have biggest problem facing hopefully
you will help me in this matter.
The problem is About configuration of Keyboard for My Robot for
single player.
I will explain in step by step
At first in PreferencesDialog.java
i have created object
private PreferencesKeyConfigurationOptionsTab
KeyConfigurationOptionsTab;
Post by Mike Purvis
Post by asherbaig
Under wizard i added tab
tabbedPane.insertTab("Key Configuration", null,
getKeyConfigurationnOptionsTab(), null, 5);
tabbedPane.setMnemonicAt(5, KeyEvent.VK_K);
tabbedPane.setDisplayedMnemonicIndexAt(5,0);
Now i created seperate calls for KeyConfigurationOptionsTab,java
Also i created seperated project for my Robot by the name
Uniteam and
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
added pakcage single player and class Sprobot.java ( which is my
robot).
Post by Mike Purvis
Post by asherbaig
package singleplayer;
import robocode.AdvancedRobot;
import java.awt.*;
import java.awt.event.KeyEvent;
import static java.awt.event.KeyEvent.*;
public class Sprobot extends AdvancedRobot {
// Move direction: 1 = move forward, 0 = stand still, -1 = move
backward
Post by Mike Purvis
Post by asherbaig
int moveDirection;
// Turn direction: 1 = turn right, 0 = no turning, -1 = turn left
int turnDirection;
// Amount of pixels/units to move
double moveAmount;
// The coordinate of the aim (x,y)
int aimX, aimY;
// Fire power, where 0 = don't fire
int firePower;
//Returns the direction that the robot's radar is facing, in degrees.
//The value returned will be between 0 and 360 (is excluded).
//Note that the heading in Robocode is like a compass, where 0 means
North,
//90 means East, 180 means South, and 270 means West.
double getRadarHeading;
// Called when the robot must run
public void run() {
// Sets the colors of the robot
// body = black, gun = white, radar = red
setColors(Color.BLACK, Color.BLACK, Color.YELLOW);
// Loop forever
for (;;) {
// Sets the robot to move forward, backward or stop moving depending
// on the move direction and amount of pixels to move
setAhead(moveAmount * moveDirection);
// Decrement the amount of pixels to move until we reach 0 pixels
// This way the robot will automatically stop if the mouse wheel
// has stopped it's rotation
moveAmount = Math.max(0, moveAmount - 1);
// Sets the robot to turn right or turn left (at maximum speed) or
// stop turning depending on the turn direction
setTurnRight(45 * turnDirection); // degrees
// Turns the gun toward the current aim coordinate (x,y)
controlled by
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
// the current mouse coordinate
// double angle = normalAbsoluteAngle(Math.atan2(aimX - getX(), aimY
- getY()));
// setTurnGunRightRadians(normalRelativeAngle(angle -
getGunHeadingRadians()));
// Fire the gun with the specified fire power, unless the fire
power = 0
if (firePower > 0) {
setFire(firePower);
}
// Execute all pending set-statements
execute();
// Next turn is processed in this loop..
}
}
// Called when a key has been pressed
public void onKeyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
// Arrow up key: move direction = forward (infinitely)
moveDirection = 1;
moveAmount = Double.POSITIVE_INFINITY;
break;
// Arrow down key: move direction = backward (infinitely)
moveDirection = -1;
moveAmount = Double.POSITIVE_INFINITY;
break;
// Arrow right key: turn direction = right
turnDirection = 1;
break;
// Arrow left key: turn direction = left
turnDirection = -1;
break;
// Button 3 : return fire
firePower = 3;
setBulletColor(Color.RED);
break;
// Button 2 : return fire
firePower = 2;
setBulletColor(Color.YELLOW);
break;
// Button 1 : return fire
firePower = 1;
setBulletColor(Color.WHITE);
break;
// Move Gun : In Direction 180 to fire using buttons
char c = e.getKeyChar();
if (c == 'u') {
setTurnGunLeft(180);
} else if (c == 'i') {
setTurnGunRight(180);
}
}
}
// Called when a key has been released (after being pressed)
public void onKeyReleased(KeyEvent e) {
switch (e.getKeyCode()) {
// Arrow up and down keys: move direction = stand still
moveDirection = 0;
break;
// Arrow right and left keys: turn direction = stop turning
turnDirection = 0;
break;
// Button 3 : Stop firing
firePower = 0;
break;
// Button 2 : Stop firing
firePower = 0;
break;
// Button 1 : Stop firing
firePower = 0;
break;
}
}
}
And Here is the code for PreferencesKeyConfigurationOptionsTab
package robocode.dialog;
import robocode.manager.RobocodeManager;
import robocode.manager.RobocodeProperties;
//import robocode.manager.RobocodeProperties;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class PreferencesKeyConfigurationOptionsTab extends
WizardPanel {
Post by Mike Purvis
Post by asherbaig
private RobocodeManager manager;
private JPanel specificSettingsPanel;
private JPanel fireSettingsPanel;
private JPanel RadarSettingsPanel;
private JComboBox optionsKeyboardComboBox;
private JComboBox optionsKeyboard2ComboBox;
private JComboBox optionsKeyboard3ComboBox;
private JComboBox optionsKeyboard4ComboBox;
// for firesettingsPanel
private JComboBox optionsKeyboard5ComboBox;
private JComboBox optionsKeyboard6ComboBox;
private JComboBox optionsKeyboard7ComboBox;
private JComboBox optionsKeyboard8ComboBox;
private JComboBox optionsKeyboard9ComboBox;
private JCheckBox optionsRenderingBufferImagesCheckBox;
private JButton predefinedPlaformDefaultButton;
private JButton predefinedSpeedButton;
private JButton predefinedQualityButton;
private EventHandler eventHandler;
public PreferencesKeyConfigurationOptionsTab(RobocodeManager
manager) {
Post by Mike Purvis
Post by asherbaig
super();
this.manager = manager;
initialize();
}
private void initialize() {
eventHandler = new EventHandler();
setLayout(new GridLayout(1, 3));
add(getDirectionSettingsPanel());
add(getFireSettingsPanel());
add(getRadarSettingsPanel());
loadPreferences(manager.getProperties());
}
private JPanel getDirectionSettingsPanel() {
if (specificSettingsPanel == null) {
specificSettingsPanel = new JPanel();
specificSettingsPanel.setBorder(
BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
"Direction settings"));
specificSettingsPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(6,8,6,8);
c.anchor = GridBagConstraints.PAGE_START;
c.weightx = 2;
c.gridwidth = 4;
c.gridx = 0;
c.gridy = 0;
specificSettingsPanel.add(new JLabel("Set Direction of Robot:"), c);
c.gridwidth = 1;
c.gridy = 1;
specificSettingsPanel.add(new JLabel("RIGHT",
SwingConstants.RIGHT), c);
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboardComboBox(), c);
c.gridx = 0;
c.gridy = 2;
specificSettingsPanel.add(new JLabel("LEFT",
SwingConstants.RIGHT), c);
Post by Mike Purvis
Post by asherbaig
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboard2ComboBox(), c);
c.gridx = 0;
c.gridy = 3;
specificSettingsPanel.add(new JLabel("UP",
SwingConstants.RIGHT), c);
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboard3ComboBox(), c);
c.gridx = 0;
c.gridy = 4;
specificSettingsPanel.add(new JLabel("DOWN",
SwingConstants.RIGHT), c);
Post by Mike Purvis
Post by asherbaig
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboard4ComboBox(), c);
}
return specificSettingsPanel;
}
private JPanel getFireSettingsPanel() {
if (fireSettingsPanel == null) {
fireSettingsPanel = new JPanel();
fireSettingsPanel.setBorder(
BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
"Power settings"));
fireSettingsPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(6,8,6,8);
c.anchor = GridBagConstraints.PAGE_START;
c.weightx = 2;
c.gridwidth = 8;
c.gridx = 0;
c.gridy = 0;
fireSettingsPanel.add(new JLabel("Power Setting:"), c);
c.gridwidth = 1;
c.gridy = 1;
fireSettingsPanel.add(new JLabel("PowerKey 1",
SwingConstants.RIGHT), c);
c.gridx = 1;
fireSettingsPanel.add(getOptionsKeyboard5ComboBox(), c);
c.gridx = 0;
c.gridy = 2;
fireSettingsPanel.add(new JLabel("PowerKey 2",
SwingConstants.RIGHT), c);
c.gridx = 1;
fireSettingsPanel.add(getOptionsKeyboard6ComboBox(), c);
c.gridx = 0;
c.gridy = 3;
fireSettingsPanel.add(new JLabel("PowerKey 3",
SwingConstants.RIGHT), c);
c.gridx = 1;
fireSettingsPanel.add(getOptionsKeyboard7ComboBox(), c);
}
return fireSettingsPanel;
}
private JPanel getRadarSettingsPanel() {
if (RadarSettingsPanel == null) {
RadarSettingsPanel = new JPanel();
RadarSettingsPanel.setBorder(
BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
"Radar Settings"));
RadarSettingsPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(6,8,6,8);
c.anchor = GridBagConstraints.PAGE_START;
c.weightx = 2;
c.gridwidth = 5;
c.gridx = 0;
c.gridy = 0;
RadarSettingsPanel.add(new JLabel("Set Radar Button Key:"), c);
c.gridwidth = 1;
c.gridx = 0;
c.gridy = 4;
RadarSettingsPanel.add(new JLabel("RadarKey 1",
SwingConstants.RIGHT), c);
c.gridx = 1;
RadarSettingsPanel.add(getOptionsKeyboard8ComboBox(), c);
c.gridx = 0;
c.gridy = 5;
RadarSettingsPanel.add(new JLabel("RadarKey 2",
SwingConstants.RIGHT), c);
c.gridx = 1;
RadarSettingsPanel.add(getOptionsKeyboard9ComboBox(), c);
}
return RadarSettingsPanel;
}
private JComboBox getOptionsKeyboardComboBox() {
if (optionsKeyboardComboBox == null) {
optionsKeyboardComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboardComboBox.addActionListener(eventHandler);
}
return optionsKeyboardComboBox;
}
private JComboBox getOptionsKeyboard2ComboBox() {
if (optionsKeyboard2ComboBox == null) {
optionsKeyboard2ComboBox = new JComboBox(new String[] { "S", "
","A", "D", "X"});
optionsKeyboard2ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard2ComboBox;
}
private JComboBox getOptionsKeyboard3ComboBox() {
if (optionsKeyboard3ComboBox == null) {
optionsKeyboard3ComboBox = new JComboBox(new String[] { "D", "S",
"D", "X"});
optionsKeyboard3ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard3ComboBox;
}
private JComboBox getOptionsKeyboard4ComboBox() {
if (optionsKeyboard4ComboBox == null) {
optionsKeyboard4ComboBox = new JComboBox(new String[] { "X", "S",
"D", "X"});
optionsKeyboard4ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard4ComboBox;
}
private JComboBox getOptionsKeyboard5ComboBox() {
if (optionsKeyboard5ComboBox == null) {
optionsKeyboard5ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard5ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard5ComboBox;
}
private JComboBox getOptionsKeyboard6ComboBox() {
if (optionsKeyboard6ComboBox == null) {
optionsKeyboard6ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard6ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard6ComboBox;
}
private JComboBox getOptionsKeyboard7ComboBox() {
if (optionsKeyboard7ComboBox == null) {
optionsKeyboard7ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard7ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard7ComboBox;
}
private JComboBox getOptionsKeyboard8ComboBox() {
if (optionsKeyboard8ComboBox == null) {
optionsKeyboard8ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard8ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard8ComboBox;
}
private JComboBox getOptionsKeyboard9ComboBox() {
if (optionsKeyboard9ComboBox == null) {
optionsKeyboard9ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard9ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard9ComboBox;
}
private void loadPreferences(RobocodeProperties props) {
getOptionsKeyboardComboBox().setSelectedIndex(props.getOptionsRenderingAntialiasing());
getOptionsKeyboard2ComboBox().setSelectedIndex(props.getOptionsRenderingTextAntialiasing());
getOptionsKeyboard3ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard4ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard5ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard6ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard7ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard8ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard9ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
}
public void storePreferences() {
RobocodeProperties props = manager.getProperties();
props.setOptionsRenderingAntialiasing(optionsKeyboardComboBox.getSelectedIndex());
props.setOptionsRenderingTextAntialiasing(optionsKeyboard2ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard3ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard4ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard5ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard6ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard7ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard8ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard9ComboBox.getSelectedIndex());
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
manager.saveProperties();
}
@Override
public boolean isReady() {
return true;
}
private void setPredefinedSettings(int index) {
optionsKeyboardComboBox.setSelectedIndex(index);
optionsKeyboard2ComboBox.setSelectedIndex(index);
optionsKeyboard3ComboBox.setSelectedIndex(index);
}
private class EventHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
Object src = e.getSource();
if (src == predefinedPlaformDefaultButton) {
setPredefinedSettings(0);
} else if (src == predefinedQualityButton) {
setPredefinedSettings(1);
} else if (src == predefinedSpeedButton) {
setPredefinedSettings(2);
} else if (src == optionsRenderingBufferImagesCheckBox) {
// Reset images so they are reloaded and gets buffered or unbuffered
new Thread() {
@Override
public void run() {
storePreferences();
manager.getImageManager().initialize();
}
}.start();
return;
}
manager.getWindowManager().getRobocodeFrame().getBattleView().setInitialized(false);
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
}
}
}
NOW I WANT USER TO GET KEY CONFIGURA FROM
PreferencesKeyConfigurationOptionsTab.JAVA
I HOPE U UNDERSTAND THIS PROBLEM.
I MEAN WHEN USER LEFT KEY FROM COMBOBOX.It will directly assigned to
Left in Sprobot.java ( which is my robot).
Also i want to send These three java files.here is the link
1.PreferencesDialog.java
http://www.sendspace.com/file/6kgbv4
2.PreferencesKeyConfigurationOptionsTab.java
http://www.sendspace.com/file/rkzn2d
3.Uniteam3a SEPERATE PROJECT FOR Robot full package in rar format
http://www.sendspace.com/file/zkrv1m
------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/Robocode/

<*> Your email settings:
Individual Email | Traditional

<*> To change settings online go to:
http://groups.yahoo.com/group/Robocode/join
(Yahoo! ID required)

<*> To change settings via email:
mailto:Robocode-***@yahoogroups.com
mailto:Robocode-***@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
Robocode-***@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
flemmingnlarsen
2008-12-07 22:19:33 UTC
Permalink
I fully understand your question.
However, there is not quick and good answer to your question. That is,
you want to tweak the game for a very specific purpose of changing the
keyboard mappings for your robot. This is not a typical question, and
I don't expect other people on this group will be able to answer your
question. I requires a lot of inside knowledge about the game.

I am sorry, but you'll have to study and make these kind of
experiments yourself by making the tweaks in the game, you need.
Otherwise you should add these as a feature request for Robocode.

Please asks questions here that other people will be able to answer,
and not just the developers of the game itself.

Best regards,
- Flemming
Post by asherbaig
May be you didn't understand my question.See the link below for snapshot.
Actually what i want that User can select any string from "A" upto "Z"
to define any keys to handle robot in battle to play.For example for
Sprobot
How to assign those key to Sprobot.
snapshot
http://i35.tinypic.com/2cdcnsl.jpg
Also plzz let me know how to download old version 1.3.4? i couldn't
find it.
Thanks,
Asher
Post by flemmingnlarsen
This feature was built-in many versions ago, since version 1.3.4. See
the sample.Interactive robot.
1) You will never be able to beat a good robot runs 100% by itself
using the keyboard and mouse alone. So far, I have never seen such
robot.
Post by flemmingnlarsen
2) In competitions like e.g. RoboRumble, the author of the robot is
not able to control the robot using his/her keyboard. I you make a
robot that can be controlled by keyboard and mouse, and I run it on my
computer. Why should I try to control your robot in order to beat my
own robot? I would not do that of course in order to let your robot
loose. The point is. In competitions your robot need to run 100% by
itself.
3) The interactive feature was made to make debugging easier in some
cases, but also to make it possible to try to beat the other robots
yourself, or compete agaist friends by sharing the keyboard (coding
two individual robots using different keys).
So, no. In practise it's not possible to cheat. But you could prove me
wrong. ;-)
Best regards,
- Flemming
Post by Mike Purvis
Maybe its just me, but I thought by definition a robot is not
controlled
Post by flemmingnlarsen
Post by Mike Purvis
from the keyboard that would be cheating.
Mike
Post by asherbaig
Hi Developers,
As in earlier days you people help me a lots for that i am really
thankful to you by heart.Now i have biggest problem facing hopefully
you will help me in this matter.
The problem is About configuration of Keyboard for My Robot for
single player.
I will explain in step by step
At first in PreferencesDialog.java
i have created object
private PreferencesKeyConfigurationOptionsTab
KeyConfigurationOptionsTab;
Post by Mike Purvis
Post by asherbaig
Under wizard i added tab
tabbedPane.insertTab("Key Configuration", null,
getKeyConfigurationnOptionsTab(), null, 5);
tabbedPane.setMnemonicAt(5, KeyEvent.VK_K);
tabbedPane.setDisplayedMnemonicIndexAt(5,0);
Now i created seperate calls for KeyConfigurationOptionsTab,java
Also i created seperated project for my Robot by the name
Uniteam and
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
added pakcage single player and class Sprobot.java ( which is my
robot).
Post by Mike Purvis
Post by asherbaig
package singleplayer;
import robocode.AdvancedRobot;
import java.awt.*;
import java.awt.event.KeyEvent;
import static java.awt.event.KeyEvent.*;
public class Sprobot extends AdvancedRobot {
// Move direction: 1 = move forward, 0 = stand still, -1 = move
backward
Post by Mike Purvis
Post by asherbaig
int moveDirection;
// Turn direction: 1 = turn right, 0 = no turning, -1 = turn left
int turnDirection;
// Amount of pixels/units to move
double moveAmount;
// The coordinate of the aim (x,y)
int aimX, aimY;
// Fire power, where 0 = don't fire
int firePower;
//Returns the direction that the robot's radar is facing, in
degrees.
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
//The value returned will be between 0 and 360 (is excluded).
//Note that the heading in Robocode is like a compass, where 0 means
North,
//90 means East, 180 means South, and 270 means West.
double getRadarHeading;
// Called when the robot must run
public void run() {
// Sets the colors of the robot
// body = black, gun = white, radar = red
setColors(Color.BLACK, Color.BLACK, Color.YELLOW);
// Loop forever
for (;;) {
// Sets the robot to move forward, backward or stop moving depending
// on the move direction and amount of pixels to move
setAhead(moveAmount * moveDirection);
// Decrement the amount of pixels to move until we reach 0 pixels
// This way the robot will automatically stop if the mouse wheel
// has stopped it's rotation
moveAmount = Math.max(0, moveAmount - 1);
// Sets the robot to turn right or turn left (at maximum speed) or
// stop turning depending on the turn direction
setTurnRight(45 * turnDirection); // degrees
// Turns the gun toward the current aim coordinate (x,y)
controlled by
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
// the current mouse coordinate
// double angle = normalAbsoluteAngle(Math.atan2(aimX -
getX(), aimY
Post by asherbaig
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
- getY()));
// setTurnGunRightRadians(normalRelativeAngle(angle -
getGunHeadingRadians()));
// Fire the gun with the specified fire power, unless the fire
power = 0
if (firePower > 0) {
setFire(firePower);
}
// Execute all pending set-statements
execute();
// Next turn is processed in this loop..
}
}
// Called when a key has been pressed
public void onKeyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
// Arrow up key: move direction = forward (infinitely)
moveDirection = 1;
moveAmount = Double.POSITIVE_INFINITY;
break;
// Arrow down key: move direction = backward (infinitely)
moveDirection = -1;
moveAmount = Double.POSITIVE_INFINITY;
break;
// Arrow right key: turn direction = right
turnDirection = 1;
break;
// Arrow left key: turn direction = left
turnDirection = -1;
break;
// Button 3 : return fire
firePower = 3;
setBulletColor(Color.RED);
break;
// Button 2 : return fire
firePower = 2;
setBulletColor(Color.YELLOW);
break;
// Button 1 : return fire
firePower = 1;
setBulletColor(Color.WHITE);
break;
// Move Gun : In Direction 180 to fire using buttons
char c = e.getKeyChar();
if (c == 'u') {
setTurnGunLeft(180);
} else if (c == 'i') {
setTurnGunRight(180);
}
}
}
// Called when a key has been released (after being pressed)
public void onKeyReleased(KeyEvent e) {
switch (e.getKeyCode()) {
// Arrow up and down keys: move direction = stand still
moveDirection = 0;
break;
// Arrow right and left keys: turn direction = stop turning
turnDirection = 0;
break;
// Button 3 : Stop firing
firePower = 0;
break;
// Button 2 : Stop firing
firePower = 0;
break;
// Button 1 : Stop firing
firePower = 0;
break;
}
}
}
And Here is the code for PreferencesKeyConfigurationOptionsTab
package robocode.dialog;
import robocode.manager.RobocodeManager;
import robocode.manager.RobocodeProperties;
//import robocode.manager.RobocodeProperties;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class PreferencesKeyConfigurationOptionsTab extends
WizardPanel {
Post by Mike Purvis
Post by asherbaig
private RobocodeManager manager;
private JPanel specificSettingsPanel;
private JPanel fireSettingsPanel;
private JPanel RadarSettingsPanel;
private JComboBox optionsKeyboardComboBox;
private JComboBox optionsKeyboard2ComboBox;
private JComboBox optionsKeyboard3ComboBox;
private JComboBox optionsKeyboard4ComboBox;
// for firesettingsPanel
private JComboBox optionsKeyboard5ComboBox;
private JComboBox optionsKeyboard6ComboBox;
private JComboBox optionsKeyboard7ComboBox;
private JComboBox optionsKeyboard8ComboBox;
private JComboBox optionsKeyboard9ComboBox;
private JCheckBox optionsRenderingBufferImagesCheckBox;
private JButton predefinedPlaformDefaultButton;
private JButton predefinedSpeedButton;
private JButton predefinedQualityButton;
private EventHandler eventHandler;
public PreferencesKeyConfigurationOptionsTab(RobocodeManager
manager) {
Post by Mike Purvis
Post by asherbaig
super();
this.manager = manager;
initialize();
}
private void initialize() {
eventHandler = new EventHandler();
setLayout(new GridLayout(1, 3));
add(getDirectionSettingsPanel());
add(getFireSettingsPanel());
add(getRadarSettingsPanel());
loadPreferences(manager.getProperties());
}
private JPanel getDirectionSettingsPanel() {
if (specificSettingsPanel == null) {
specificSettingsPanel = new JPanel();
specificSettingsPanel.setBorder(
BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
Post by asherbaig
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
"Direction settings"));
specificSettingsPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(6,8,6,8);
c.anchor = GridBagConstraints.PAGE_START;
c.weightx = 2;
c.gridwidth = 4;
c.gridx = 0;
c.gridy = 0;
specificSettingsPanel.add(new JLabel("Set Direction of
Robot:"), c);
Post by asherbaig
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
c.gridwidth = 1;
c.gridy = 1;
specificSettingsPanel.add(new JLabel("RIGHT",
SwingConstants.RIGHT), c);
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboardComboBox(), c);
c.gridx = 0;
c.gridy = 2;
specificSettingsPanel.add(new JLabel("LEFT",
SwingConstants.RIGHT), c);
Post by Mike Purvis
Post by asherbaig
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboard2ComboBox(), c);
c.gridx = 0;
c.gridy = 3;
specificSettingsPanel.add(new JLabel("UP",
SwingConstants.RIGHT), c);
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboard3ComboBox(), c);
c.gridx = 0;
c.gridy = 4;
specificSettingsPanel.add(new JLabel("DOWN",
SwingConstants.RIGHT), c);
Post by Mike Purvis
Post by asherbaig
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboard4ComboBox(), c);
}
return specificSettingsPanel;
}
private JPanel getFireSettingsPanel() {
if (fireSettingsPanel == null) {
fireSettingsPanel = new JPanel();
fireSettingsPanel.setBorder(
BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
Post by asherbaig
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
"Power settings"));
fireSettingsPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(6,8,6,8);
c.anchor = GridBagConstraints.PAGE_START;
c.weightx = 2;
c.gridwidth = 8;
c.gridx = 0;
c.gridy = 0;
fireSettingsPanel.add(new JLabel("Power Setting:"), c);
c.gridwidth = 1;
c.gridy = 1;
fireSettingsPanel.add(new JLabel("PowerKey 1",
SwingConstants.RIGHT), c);
c.gridx = 1;
fireSettingsPanel.add(getOptionsKeyboard5ComboBox(), c);
c.gridx = 0;
c.gridy = 2;
fireSettingsPanel.add(new JLabel("PowerKey 2",
SwingConstants.RIGHT), c);
c.gridx = 1;
fireSettingsPanel.add(getOptionsKeyboard6ComboBox(), c);
c.gridx = 0;
c.gridy = 3;
fireSettingsPanel.add(new JLabel("PowerKey 3",
SwingConstants.RIGHT), c);
c.gridx = 1;
fireSettingsPanel.add(getOptionsKeyboard7ComboBox(), c);
}
return fireSettingsPanel;
}
private JPanel getRadarSettingsPanel() {
if (RadarSettingsPanel == null) {
RadarSettingsPanel = new JPanel();
RadarSettingsPanel.setBorder(
BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
Post by asherbaig
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
"Radar Settings"));
RadarSettingsPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(6,8,6,8);
c.anchor = GridBagConstraints.PAGE_START;
c.weightx = 2;
c.gridwidth = 5;
c.gridx = 0;
c.gridy = 0;
RadarSettingsPanel.add(new JLabel("Set Radar Button Key:"), c);
c.gridwidth = 1;
c.gridx = 0;
c.gridy = 4;
RadarSettingsPanel.add(new JLabel("RadarKey 1",
SwingConstants.RIGHT), c);
c.gridx = 1;
RadarSettingsPanel.add(getOptionsKeyboard8ComboBox(), c);
c.gridx = 0;
c.gridy = 5;
RadarSettingsPanel.add(new JLabel("RadarKey 2",
SwingConstants.RIGHT), c);
c.gridx = 1;
RadarSettingsPanel.add(getOptionsKeyboard9ComboBox(), c);
}
return RadarSettingsPanel;
}
private JComboBox getOptionsKeyboardComboBox() {
if (optionsKeyboardComboBox == null) {
optionsKeyboardComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboardComboBox.addActionListener(eventHandler);
}
return optionsKeyboardComboBox;
}
private JComboBox getOptionsKeyboard2ComboBox() {
if (optionsKeyboard2ComboBox == null) {
optionsKeyboard2ComboBox = new JComboBox(new String[] { "S", "
","A", "D", "X"});
optionsKeyboard2ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard2ComboBox;
}
private JComboBox getOptionsKeyboard3ComboBox() {
if (optionsKeyboard3ComboBox == null) {
optionsKeyboard3ComboBox = new JComboBox(new String[] { "D", "S",
"D", "X"});
optionsKeyboard3ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard3ComboBox;
}
private JComboBox getOptionsKeyboard4ComboBox() {
if (optionsKeyboard4ComboBox == null) {
optionsKeyboard4ComboBox = new JComboBox(new String[] { "X", "S",
"D", "X"});
optionsKeyboard4ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard4ComboBox;
}
private JComboBox getOptionsKeyboard5ComboBox() {
if (optionsKeyboard5ComboBox == null) {
optionsKeyboard5ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard5ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard5ComboBox;
}
private JComboBox getOptionsKeyboard6ComboBox() {
if (optionsKeyboard6ComboBox == null) {
optionsKeyboard6ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard6ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard6ComboBox;
}
private JComboBox getOptionsKeyboard7ComboBox() {
if (optionsKeyboard7ComboBox == null) {
optionsKeyboard7ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard7ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard7ComboBox;
}
private JComboBox getOptionsKeyboard8ComboBox() {
if (optionsKeyboard8ComboBox == null) {
optionsKeyboard8ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard8ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard8ComboBox;
}
private JComboBox getOptionsKeyboard9ComboBox() {
if (optionsKeyboard9ComboBox == null) {
optionsKeyboard9ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard9ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard9ComboBox;
}
private void loadPreferences(RobocodeProperties props) {
getOptionsKeyboardComboBox().setSelectedIndex(props.getOptionsRenderingAntialiasing());
getOptionsKeyboard2ComboBox().setSelectedIndex(props.getOptionsRenderingTextAntialiasing());
getOptionsKeyboard3ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard4ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard5ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard6ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard7ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard8ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard9ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
Post by asherbaig
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
}
public void storePreferences() {
RobocodeProperties props = manager.getProperties();
props.setOptionsRenderingAntialiasing(optionsKeyboardComboBox.getSelectedIndex());
props.setOptionsRenderingTextAntialiasing(optionsKeyboard2ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard3ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard4ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard5ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard6ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard7ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard8ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard9ComboBox.getSelectedIndex());
Post by asherbaig
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
manager.saveProperties();
}
@Override
public boolean isReady() {
return true;
}
private void setPredefinedSettings(int index) {
optionsKeyboardComboBox.setSelectedIndex(index);
optionsKeyboard2ComboBox.setSelectedIndex(index);
optionsKeyboard3ComboBox.setSelectedIndex(index);
}
private class EventHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
Object src = e.getSource();
if (src == predefinedPlaformDefaultButton) {
setPredefinedSettings(0);
} else if (src == predefinedQualityButton) {
setPredefinedSettings(1);
} else if (src == predefinedSpeedButton) {
setPredefinedSettings(2);
} else if (src == optionsRenderingBufferImagesCheckBox) {
// Reset images so they are reloaded and gets buffered or unbuffered
new Thread() {
@Override
public void run() {
storePreferences();
manager.getImageManager().initialize();
}
}.start();
return;
}
manager.getWindowManager().getRobocodeFrame().getBattleView().setInitialized(false);
Post by asherbaig
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
}
}
}
NOW I WANT USER TO GET KEY CONFIGURA FROM
PreferencesKeyConfigurationOptionsTab.JAVA
I HOPE U UNDERSTAND THIS PROBLEM.
I MEAN WHEN USER LEFT KEY FROM COMBOBOX.It will directly
assigned to
Post by asherbaig
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
Left in Sprobot.java ( which is my robot).
Also i want to send These three java files.here is the link
1.PreferencesDialog.java
http://www.sendspace.com/file/6kgbv4
2.PreferencesKeyConfigurationOptionsTab.java
http://www.sendspace.com/file/rkzn2d
3.Uniteam3a SEPERATE PROJECT FOR Robot full package in rar format
http://www.sendspace.com/file/zkrv1m
------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/Robocode/

<*> Your email settings:
Individual Email | Traditional

<*> To change settings online go to:
http://groups.yahoo.com/group/Robocode/join
(Yahoo! ID required)

<*> To change settings via email:
mailto:Robocode-***@yahoogroups.com
mailto:Robocode-***@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
Robocode-***@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
asherbaig
2008-12-09 15:20:17 UTC
Permalink
I agree with you.But i need little hint to proceed as i am stuck on
assigning key values.
Post by flemmingnlarsen
I fully understand your question.
However, there is not quick and good answer to your question. That is,
you want to tweak the game for a very specific purpose of changing the
keyboard mappings for your robot. This is not a typical question, and
I don't expect other people on this group will be able to answer your
question. I requires a lot of inside knowledge about the game.
I am sorry, but you'll have to study and make these kind of
experiments yourself by making the tweaks in the game, you need.
Otherwise you should add these as a feature request for Robocode.
Please asks questions here that other people will be able to answer,
and not just the developers of the game itself.
Best regards,
- Flemming
Post by asherbaig
May be you didn't understand my question.See the link below for
snapshot.
Post by asherbaig
Actually what i want that User can select any string from "A" upto "Z"
to define any keys to handle robot in battle to play.For example for
Sprobot
How to assign those key to Sprobot.
snapshot
http://i35.tinypic.com/2cdcnsl.jpg
Also plzz let me know how to download old version 1.3.4? i couldn't
find it.
Thanks,
Asher
Post by flemmingnlarsen
This feature was built-in many versions ago, since version
1.3.4. See
Post by flemmingnlarsen
Post by asherbaig
Post by flemmingnlarsen
the sample.Interactive robot.
1) You will never be able to beat a good robot runs 100% by itself
using the keyboard and mouse alone. So far, I have never seen such
robot.
Post by flemmingnlarsen
2) In competitions like e.g. RoboRumble, the author of the robot is
not able to control the robot using his/her keyboard. I you make a
robot that can be controlled by keyboard and mouse, and I run it on my
computer. Why should I try to control your robot in order to beat my
own robot? I would not do that of course in order to let your robot
loose. The point is. In competitions your robot need to run 100% by
itself.
3) The interactive feature was made to make debugging easier in some
cases, but also to make it possible to try to beat the other robots
yourself, or compete agaist friends by sharing the keyboard (coding
two individual robots using different keys).
So, no. In practise it's not possible to cheat. But you could prove me
wrong. ;-)
Best regards,
- Flemming
Post by Mike Purvis
Maybe its just me, but I thought by definition a robot is not
controlled
Post by flemmingnlarsen
Post by Mike Purvis
from the keyboard that would be cheating.
Mike
Post by asherbaig
Hi Developers,
As in earlier days you people help me a lots for that i am really
thankful to you by heart.Now i have biggest problem facing
hopefully
Post by asherbaig
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
you will help me in this matter.
The problem is About configuration of Keyboard for My Robot for
single player.
I will explain in step by step
At first in PreferencesDialog.java
i have created object
private PreferencesKeyConfigurationOptionsTab
KeyConfigurationOptionsTab;
Post by Mike Purvis
Post by asherbaig
Under wizard i added tab
tabbedPane.insertTab("Key Configuration", null,
getKeyConfigurationnOptionsTab(), null, 5);
tabbedPane.setMnemonicAt(5, KeyEvent.VK_K);
tabbedPane.setDisplayedMnemonicIndexAt(5,0);
Now i created seperate calls for KeyConfigurationOptionsTab,java
Also i created seperated project for my Robot by the name
Uniteam and
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
added pakcage single player and class Sprobot.java ( which is my
robot).
Post by Mike Purvis
Post by asherbaig
package singleplayer;
import robocode.AdvancedRobot;
import java.awt.*;
import java.awt.event.KeyEvent;
import static java.awt.event.KeyEvent.*;
public class Sprobot extends AdvancedRobot {
// Move direction: 1 = move forward, 0 = stand still, -1 = move
backward
Post by Mike Purvis
Post by asherbaig
int moveDirection;
// Turn direction: 1 = turn right, 0 = no turning, -1 = turn left
int turnDirection;
// Amount of pixels/units to move
double moveAmount;
// The coordinate of the aim (x,y)
int aimX, aimY;
// Fire power, where 0 = don't fire
int firePower;
//Returns the direction that the robot's radar is facing, in
degrees.
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
//The value returned will be between 0 and 360 (is excluded).
//Note that the heading in Robocode is like a compass, where 0
means
Post by asherbaig
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
North,
//90 means East, 180 means South, and 270 means West.
double getRadarHeading;
// Called when the robot must run
public void run() {
// Sets the colors of the robot
// body = black, gun = white, radar = red
setColors(Color.BLACK, Color.BLACK, Color.YELLOW);
// Loop forever
for (;;) {
// Sets the robot to move forward, backward or stop moving
depending
Post by asherbaig
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
// on the move direction and amount of pixels to move
setAhead(moveAmount * moveDirection);
// Decrement the amount of pixels to move until we reach 0 pixels
// This way the robot will automatically stop if the mouse wheel
// has stopped it's rotation
moveAmount = Math.max(0, moveAmount - 1);
// Sets the robot to turn right or turn left (at maximum speed) or
// stop turning depending on the turn direction
setTurnRight(45 * turnDirection); // degrees
// Turns the gun toward the current aim coordinate (x,y)
controlled by
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
// the current mouse coordinate
// double angle = normalAbsoluteAngle(Math.atan2(aimX -
getX(), aimY
Post by asherbaig
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
- getY()));
// setTurnGunRightRadians(normalRelativeAngle(angle -
getGunHeadingRadians()));
// Fire the gun with the specified fire power, unless the fire
power = 0
if (firePower > 0) {
setFire(firePower);
}
// Execute all pending set-statements
execute();
// Next turn is processed in this loop..
}
}
// Called when a key has been pressed
public void onKeyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
// Arrow up key: move direction = forward (infinitely)
moveDirection = 1;
moveAmount = Double.POSITIVE_INFINITY;
break;
// Arrow down key: move direction = backward (infinitely)
moveDirection = -1;
moveAmount = Double.POSITIVE_INFINITY;
break;
// Arrow right key: turn direction = right
turnDirection = 1;
break;
// Arrow left key: turn direction = left
turnDirection = -1;
break;
// Button 3 : return fire
firePower = 3;
setBulletColor(Color.RED);
break;
// Button 2 : return fire
firePower = 2;
setBulletColor(Color.YELLOW);
break;
// Button 1 : return fire
firePower = 1;
setBulletColor(Color.WHITE);
break;
// Move Gun : In Direction 180 to fire using buttons
char c = e.getKeyChar();
if (c == 'u') {
setTurnGunLeft(180);
} else if (c == 'i') {
setTurnGunRight(180);
}
}
}
// Called when a key has been released (after being pressed)
public void onKeyReleased(KeyEvent e) {
switch (e.getKeyCode()) {
// Arrow up and down keys: move direction = stand still
moveDirection = 0;
break;
// Arrow right and left keys: turn direction = stop turning
turnDirection = 0;
break;
// Button 3 : Stop firing
firePower = 0;
break;
// Button 2 : Stop firing
firePower = 0;
break;
// Button 1 : Stop firing
firePower = 0;
break;
}
}
}
And Here is the code for PreferencesKeyConfigurationOptionsTab
package robocode.dialog;
import robocode.manager.RobocodeManager;
import robocode.manager.RobocodeProperties;
//import robocode.manager.RobocodeProperties;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class PreferencesKeyConfigurationOptionsTab extends
WizardPanel {
Post by Mike Purvis
Post by asherbaig
private RobocodeManager manager;
private JPanel specificSettingsPanel;
private JPanel fireSettingsPanel;
private JPanel RadarSettingsPanel;
private JComboBox optionsKeyboardComboBox;
private JComboBox optionsKeyboard2ComboBox;
private JComboBox optionsKeyboard3ComboBox;
private JComboBox optionsKeyboard4ComboBox;
// for firesettingsPanel
private JComboBox optionsKeyboard5ComboBox;
private JComboBox optionsKeyboard6ComboBox;
private JComboBox optionsKeyboard7ComboBox;
private JComboBox optionsKeyboard8ComboBox;
private JComboBox optionsKeyboard9ComboBox;
private JCheckBox optionsRenderingBufferImagesCheckBox;
private JButton predefinedPlaformDefaultButton;
private JButton predefinedSpeedButton;
private JButton predefinedQualityButton;
private EventHandler eventHandler;
public PreferencesKeyConfigurationOptionsTab(RobocodeManager
manager) {
Post by Mike Purvis
Post by asherbaig
super();
this.manager = manager;
initialize();
}
private void initialize() {
eventHandler = new EventHandler();
setLayout(new GridLayout(1, 3));
add(getDirectionSettingsPanel());
add(getFireSettingsPanel());
add(getRadarSettingsPanel());
loadPreferences(manager.getProperties());
}
private JPanel getDirectionSettingsPanel() {
if (specificSettingsPanel == null) {
specificSettingsPanel = new JPanel();
specificSettingsPanel.setBorder(
BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
Post by asherbaig
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
"Direction settings"));
specificSettingsPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(6,8,6,8);
c.anchor = GridBagConstraints.PAGE_START;
c.weightx = 2;
c.gridwidth = 4;
c.gridx = 0;
c.gridy = 0;
specificSettingsPanel.add(new JLabel("Set Direction of
Robot:"), c);
Post by asherbaig
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
c.gridwidth = 1;
c.gridy = 1;
specificSettingsPanel.add(new JLabel("RIGHT",
SwingConstants.RIGHT), c);
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboardComboBox(), c);
c.gridx = 0;
c.gridy = 2;
specificSettingsPanel.add(new JLabel("LEFT",
SwingConstants.RIGHT), c);
Post by Mike Purvis
Post by asherbaig
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboard2ComboBox(), c);
c.gridx = 0;
c.gridy = 3;
specificSettingsPanel.add(new JLabel("UP",
SwingConstants.RIGHT), c);
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboard3ComboBox(), c);
c.gridx = 0;
c.gridy = 4;
specificSettingsPanel.add(new JLabel("DOWN",
SwingConstants.RIGHT), c);
Post by Mike Purvis
Post by asherbaig
c.gridx = 1;
specificSettingsPanel.add(getOptionsKeyboard4ComboBox(), c);
}
return specificSettingsPanel;
}
private JPanel getFireSettingsPanel() {
if (fireSettingsPanel == null) {
fireSettingsPanel = new JPanel();
fireSettingsPanel.setBorder(
BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
Post by asherbaig
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
"Power settings"));
fireSettingsPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(6,8,6,8);
c.anchor = GridBagConstraints.PAGE_START;
c.weightx = 2;
c.gridwidth = 8;
c.gridx = 0;
c.gridy = 0;
fireSettingsPanel.add(new JLabel("Power Setting:"), c);
c.gridwidth = 1;
c.gridy = 1;
fireSettingsPanel.add(new JLabel("PowerKey 1",
SwingConstants.RIGHT), c);
c.gridx = 1;
fireSettingsPanel.add(getOptionsKeyboard5ComboBox(), c);
c.gridx = 0;
c.gridy = 2;
fireSettingsPanel.add(new JLabel("PowerKey 2",
SwingConstants.RIGHT), c);
c.gridx = 1;
fireSettingsPanel.add(getOptionsKeyboard6ComboBox(), c);
c.gridx = 0;
c.gridy = 3;
fireSettingsPanel.add(new JLabel("PowerKey 3",
SwingConstants.RIGHT), c);
c.gridx = 1;
fireSettingsPanel.add(getOptionsKeyboard7ComboBox(), c);
}
return fireSettingsPanel;
}
private JPanel getRadarSettingsPanel() {
if (RadarSettingsPanel == null) {
RadarSettingsPanel = new JPanel();
RadarSettingsPanel.setBorder(
BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
Post by asherbaig
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
"Radar Settings"));
RadarSettingsPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(6,8,6,8);
c.anchor = GridBagConstraints.PAGE_START;
c.weightx = 2;
c.gridwidth = 5;
c.gridx = 0;
c.gridy = 0;
RadarSettingsPanel.add(new JLabel("Set Radar Button Key:"), c);
c.gridwidth = 1;
c.gridx = 0;
c.gridy = 4;
RadarSettingsPanel.add(new JLabel("RadarKey 1",
SwingConstants.RIGHT), c);
c.gridx = 1;
RadarSettingsPanel.add(getOptionsKeyboard8ComboBox(), c);
c.gridx = 0;
c.gridy = 5;
RadarSettingsPanel.add(new JLabel("RadarKey 2",
SwingConstants.RIGHT), c);
c.gridx = 1;
RadarSettingsPanel.add(getOptionsKeyboard9ComboBox(), c);
}
return RadarSettingsPanel;
}
private JComboBox getOptionsKeyboardComboBox() {
if (optionsKeyboardComboBox == null) {
optionsKeyboardComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboardComboBox.addActionListener(eventHandler);
}
return optionsKeyboardComboBox;
}
private JComboBox getOptionsKeyboard2ComboBox() {
if (optionsKeyboard2ComboBox == null) {
optionsKeyboard2ComboBox = new JComboBox(new String[] { "S", "
","A", "D", "X"});
optionsKeyboard2ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard2ComboBox;
}
private JComboBox getOptionsKeyboard3ComboBox() {
if (optionsKeyboard3ComboBox == null) {
optionsKeyboard3ComboBox = new JComboBox(new String[] { "D", "S",
"D", "X"});
optionsKeyboard3ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard3ComboBox;
}
private JComboBox getOptionsKeyboard4ComboBox() {
if (optionsKeyboard4ComboBox == null) {
optionsKeyboard4ComboBox = new JComboBox(new String[] { "X", "S",
"D", "X"});
optionsKeyboard4ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard4ComboBox;
}
private JComboBox getOptionsKeyboard5ComboBox() {
if (optionsKeyboard5ComboBox == null) {
optionsKeyboard5ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard5ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard5ComboBox;
}
private JComboBox getOptionsKeyboard6ComboBox() {
if (optionsKeyboard6ComboBox == null) {
optionsKeyboard6ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard6ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard6ComboBox;
}
private JComboBox getOptionsKeyboard7ComboBox() {
if (optionsKeyboard7ComboBox == null) {
optionsKeyboard7ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard7ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard7ComboBox;
}
private JComboBox getOptionsKeyboard8ComboBox() {
if (optionsKeyboard8ComboBox == null) {
optionsKeyboard8ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard8ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard8ComboBox;
}
private JComboBox getOptionsKeyboard9ComboBox() {
if (optionsKeyboard9ComboBox == null) {
optionsKeyboard9ComboBox = new JComboBox(new String[] { " ","A",
"S", "D", "X"});
optionsKeyboard9ComboBox.addActionListener(eventHandler);
}
return optionsKeyboard9ComboBox;
}
private void loadPreferences(RobocodeProperties props) {
getOptionsKeyboardComboBox().setSelectedIndex(props.getOptionsRenderingAntialiasing());
getOptionsKeyboard2ComboBox().setSelectedIndex(props.getOptionsRenderingTextAntialiasing());
getOptionsKeyboard3ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard4ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard5ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard6ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard7ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard8ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
getOptionsKeyboard9ComboBox().setSelectedIndex(props.getOptionsRenderingMethod());
Post by flemmingnlarsen
Post by asherbaig
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
}
public void storePreferences() {
RobocodeProperties props = manager.getProperties();
props.setOptionsRenderingAntialiasing(optionsKeyboardComboBox.getSelectedIndex());
props.setOptionsRenderingTextAntialiasing(optionsKeyboard2ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard3ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard4ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard5ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard6ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard7ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard8ComboBox.getSelectedIndex());
props.setOptionsRenderingMethod(optionsKeyboard9ComboBox.getSelectedIndex());
Post by flemmingnlarsen
Post by asherbaig
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
manager.saveProperties();
}
@Override
public boolean isReady() {
return true;
}
private void setPredefinedSettings(int index) {
optionsKeyboardComboBox.setSelectedIndex(index);
optionsKeyboard2ComboBox.setSelectedIndex(index);
optionsKeyboard3ComboBox.setSelectedIndex(index);
}
private class EventHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
Object src = e.getSource();
if (src == predefinedPlaformDefaultButton) {
setPredefinedSettings(0);
} else if (src == predefinedQualityButton) {
setPredefinedSettings(1);
} else if (src == predefinedSpeedButton) {
setPredefinedSettings(2);
} else if (src == optionsRenderingBufferImagesCheckBox) {
// Reset images so they are reloaded and gets buffered or
unbuffered
Post by asherbaig
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
new Thread() {
@Override
public void run() {
storePreferences();
manager.getImageManager().initialize();
}
}.start();
return;
}
manager.getWindowManager().getRobocodeFrame().getBattleView().setInitialized(false);
Post by flemmingnlarsen
Post by asherbaig
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
}
}
}
NOW I WANT USER TO GET KEY CONFIGURA FROM
PreferencesKeyConfigurationOptionsTab.JAVA
I HOPE U UNDERSTAND THIS PROBLEM.
I MEAN WHEN USER LEFT KEY FROM COMBOBOX.It will directly
assigned to
Post by asherbaig
Post by flemmingnlarsen
Post by Mike Purvis
Post by asherbaig
Left in Sprobot.java ( which is my robot).
Also i want to send These three java files.here is the link
1.PreferencesDialog.java
http://www.sendspace.com/file/6kgbv4
2.PreferencesKeyConfigurationOptionsTab.java
http://www.sendspace.com/file/rkzn2d
3.Uniteam3a SEPERATE PROJECT FOR Robot full package in rar format
http://www.sendspace.com/file/zkrv1m
------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/Robocode/

<*> Your email settings:
Individual Email | Traditional

<*> To change settings online go to:
http://groups.yahoo.com/group/Robocode/join
(Yahoo! ID required)

<*> To change settings via email:
mailto:Robocode-***@yahoogroups.com
mailto:Robocode-***@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
Robocode-***@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/

Continue reading on narkive:
Loading...