Results 1 to 2 of 2

Thread: Robot Game

  1. #1
    yanipao is offline Member
    Join Date
    Oct 2009
    Posts
    27
    Rep Power
    0

    Default Robot Game

    i am trying to make a robots game similar to the robots game played in ubuntu. i already have the borad and the game control class but i cannot run the game control. I cannot understand the error. May you please help. Thank you.

    Java Code:
    import java.lang.object.*;
    import java.util.Arrays;
    
    public class GameControl{
    
    	private Robot robot;		//maximum number of robots
    	private Boy boy;
    	private Board board; 			//the board is read row by column
    
    
    	public GameControl(){		//constructor
    		
    		int boardL;	//for the column
    		int boardW;	//for the row
    
    		int boyR;	//integer to store the row location of the boy
    		int boyC;	//integer to store the column location of the boy
    		
    		int robotR=0;	//integer to store the row location of one robot
    		int robotC=0;	//integer to store the column location of one robot
    		
    		int robotCtr=3;	//counter of the number of robots
    				//initially, there are three robots in the array
    		
    	}
    
    	public void intializeGame(){
    		int boardL = board.getLength();	//for the column
    		int boardW = board.getWidth();	//for the row
    	
    		int boyR = (board.getLength()/2);
    		int boyC = (board.getWidth()/2);
    
    		for (robotCtr = 0; robotCtr<4; robotCtr++){	//the counter gives the index of the array 
    			for(int i = 2 ; i<board.getLength(); i++){	//of the robot and its specified row
    				robot[robotCtr][robotC]=(board.getLength()/2+i);	//atleast two block separation
    			}
    
    		}
    
    		for (robotCtr = 0; robotCtr<4; robotCtr++){	//the counter gives the index of the array 
    			for (int j = 2; j<board.getWidth(); j++){	//of the robot and its specified column
    				robot[robotCtr][robotR]=(board.getWidth()/2+j);	//atleast two block separation
    			}					
    		}
    	}
    
    	public boolean isSafeLocation(int boyR, int boyC){	//gives the safelocation
    								//for the boy to teleport
    		switch(int num){
    
    			case (num==1){
    				if (boyR-1 < 0){		//breaks are not used
    				boyR = boyR + 2;		//for the continuous
    			}					//flow of the conditions
    			}			
    			case (num==2){
    			if (boyR-2 < 0){
    				boyR = boyR + 4;
    			}
    			}
    			case (num==3){
    			if (boyC-1 < 0){
    				boyC = boyC + 2;
    			}
    			}
    
    			case (num==4){
    			if (boyC-2 < 0){
    				boyC = boyC + 4;
    			}
    			}
    			
    			case (num==5){
    			if (boyR+1 > board.getWidth()){
    				boyR = boyR - 2;
    			}
    			}
    			
    			case (num=6){
    			if (boyR+2 > board.getWidth()){
    				boyR = boyR - 4;
    			}
    			}
    
    			case (num==7){
    			if (boyC+1 > board.getLength()){
    				boyC = boyC - 2;
    			}
    			}
    
    			case (num==8){ 
    			if (boyC+2 > board.getLength()){
    				boyC = boyC - 4;
    			}
    			}
    
    			case (num==9){
    			if (boyR == robotR && boyC == robotC){
    				boyR = boyR + 2;
    				boyC = boyC + 2;
    			}
    			}
    		
    			case (num==10){
    			if (boyR == robotR + 1 && boyC == robotC + 1){
    				boyR = boyR + 1;
    				boyC = boyC + 1;
    
    				return boyR;
    				return boyC;
    			}
    
    				return boyR;
    				return boyC;
    			}
    			
    		}
    
    	}
    	
    	public void moveRobots(){	//for the movement of the robot
    		robot[robotR][robotC]=robot[boyR.getLocationY()+2][boyC.getLocationX()+2];
    	}
    
    	public Array getRobots(){		//returns the list of robots
    		for(int k=1; k<robotCtr; k++){
    			return robot[k];
    		}
    	}
    	
    	public void addRobot() {		//add a new robot based from 
    		robot[robotCtr] = new Robot();	//the last value of the counter
    		robotCtr++;
    	}
    
    	public void removeRobot(robot n){	//remove two robots but not necessarily  
    						// the junkpile
    		for(int i=1; i<15; i++){	
    			if(robot[robotCtr][robotR]=robot[robotCtr+i][robotR] && robot[Ctr][robotC]=robot[robotCtr+i][robotC]){
    				robot.length()=robot.length()-2;
    			}
    		}
    			
    	}
    }
    that's my code for the game control. Thank you!=)

  2. #2
    yanipao is offline Member
    Join Date
    Oct 2009
    Posts
    27
    Rep Power
    0

    Default

    here is my Board class.

    Java Code:
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.*;
    //import java.util.List;
    import javax.swing.*;
    import static java.util.Collections.*;
    import java.util.Random;
    
    class Board extends JFrame implements ActionListener{
    
    	JPanel wholePanel, firstPanel, secondPanel;
    	JButton newButton, quitButton, scoreButton;			
    	JButton [][] matrixBoard = new JButton[10][10];
    	Boy boy;
    	
    	public Board() {
    		Container c = getContentPane();
    		panel();				
    		firstPanelButtons ();		
    		secondPanelButtons ();					
    		c.add(wholePanel);
    	}
    	public void panel(){
    		wholePanel = new JPanel();
    		firstPanel = new JPanel();
    		secondPanel = new JPanel();
    		
    		wholePanel.setLayout(new BorderLayout ());
    		firstPanel.setLayout(new FlowLayout());
    		secondPanel.setLayout(new GridLayout(10,10));
    		
    		wholePanel.add(firstPanel, BorderLayout.NORTH); //para sa taas
    		wholePanel.add(secondPanel, BorderLayout.CENTER); //center para i-fill up
    	}
    	public void firstPanelButtons (){
    		newButton = new JButton ("New Game");
    		newButton.addActionListener(this);		
    		quitButton = new JButton ("Quit Game");
    		quitButton.addActionListener(this);		
    		Boy boy = new Boy();
    		firstPanel.add(newButton);
    		firstPanel.add(quitButton);	
    		}
    		
    	public void secondPanelButtons(){
    		for(int i=0; i<10; i++){
    			for(int j=0; j<10; j++){
    			matrixBoard[i][j]=new JButton();
    			secondPanel.add(matrixBoard[i][j]);	
    			matrixBoard[i][j].addActionListener(this);
    			}		
    		}		
    	}	
    	
    	public static void main(String args[]){
    		Board application = new Board();
    		Boy boy = new Boy();
    		application.setTitle("RobotsGame");
    		application.setSize(800,800);
    		application.setVisible(true);		
    		application.setResizable(false); //para di nababago size
    	}
    	
    	public void actionPerformed(ActionEvent e){
    		for (int i=0; i<10; i++){
    			for(int j=0; j<10; j++){
    			if (matrixBoard[i][j] == e.getSource()){
    			matrixBoard[i][j].setEnabled(false);
    			}
    		}
    	}
    	}
    }

Similar Threads

  1. Robot Game
    By Galore in forum New To Java
    Replies: 7
    Last Post: 03-21-2010, 07:14 PM
  2. Help with Robot Class
    By protocos in forum Eclipse
    Replies: 11
    Last Post: 10-05-2009, 09:15 PM
  3. Karel the robot
    By vulerious in forum New To Java
    Replies: 0
    Last Post: 07-31-2009, 10:48 PM
  4. Robot Class
    By Jessie Madman in forum New To Java
    Replies: 3
    Last Post: 05-15-2008, 05:13 AM
  5. Robot Class
    By jfredrickson in forum New To Java
    Replies: 2
    Last Post: 07-11-2007, 10:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •