[HELP] Checkers (Droughts) game.

I hope everyone is fine,
I want to make a checkers game by java that allows two players to play against each other.
But I am beginner in programing.
So if anybody could post some codes for the game or even some outlines , I would be thankful.

Khalid.S wrote:
I want to make a checkers game by java that allows two players to play against each other.
But I am beginner in programing.Then I'd suggest starting with something simpler. Mastermind perhaps?
Checkers has a lot of components to it - board, pieces, allowable moves, piece taking and conversion - that make it a big project to take on board at this stage.
Winston

Similar Messages

  • The game "horn" does'nt open and shows installing but nothing happens. it was transferred from the computer to the ipad. help!, The game horn does'nt open and shows installing but nothing happens. it was transferred from the computer to the ipad. help!

    The game "horn" does'nt open and shows installing but nothing happens. it was transferred from the computer to the ipad. help!, The game horn does'nt open and shows installing but nothing happens. it was transferred from the computer to the ipad. help!

    Try this  - Reset the iPad by holding down on the Sleep and Home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons. (This is equivalent to rebooting your computer.) No data/files will be erased. http://support.apple.com/kb/ht1430
    iOS 7: Help with how to fix a crashing app on iPhone, iPad (Mini), and iPod Touch
    http://teachmeios.com/help-with-how-to-fix-a-crashing-app-on-iphone-ipad-mini-an d-ipod-touch/
    Troubleshooting apps purchased from the App Store
    http://support.apple.com/kb/TS1702
    Delete the app and redownload.
    Downloading Past Purchases from the iTunes Store, App Store and iBooks Store
    http://support.apple.com/kb/ht2519
     Cheers, Tom 

  • Guys need help is regarding games. I want to install games like commandos, gta vice city, counter strike etc I mean action games in which we do levels, like games in playsatation and xbox ?

    Guys need help is regarding games. I want to install games like commandos, gta vice city, counter strike etc I mean action games in which we do levels, like games in playsatation and xbox ?

    You can only install games that are in the iTunes app store on your computer and the App Store app directly on the iPad - if there are games like those that you mention in your country's store then you can buy and install them. Have you had a look in your country's store ?

  • Help with rhythm game

    So i am starting university in late september (to learn 3d character animation) and need to get the grades to get in, sadly we have a flash programming unit in the college course im in now and we didnt get taught anything at all and i mean nothing, we were given printed sheets and told to copy the code word for word. so i really need help with my game. how would i make the movement of something my cursor? so when i move the cursor it follows it? also how do i play an animation on click?
    My  idea for the game is to have a rhythm style game where the player moves the net and catches the bee's, something i thought would be simple to figure out how to do
    This is my game at the minute, ive used the code we were told to copy from sheets and just changed the sprites :\ any help would be amazing!
    https://www.dropbox.com/s/1pjbv2mavycsi3q/sopaceship%20rev7%20%20moving%20bullet.fla

    http://orangesplotch.com/blog/flash-tutorial-elastic-object-follower/
    var distx:Number;
    var disty:Number;
    var momentumx:Number;
    var momentumy:Number;
    follower.addEventListener(Event.ENTER_FRAME, FollowMouse)
    function FollowMouse(event:Event):void {
         // follow the mouse in a more elastic way
         // by using momentum
         distx = follower.x - mouseX;
         disty = follower.y - mouseY;
         momentumx -= distx / 3;
         momentumy -= disty / 3;
         // dampen the momentum a little
         momentumx *= 0.75;
         momentumy *= 0.75;
         // go get that mouse!
         follower.x += momentumx;
         follower.y += momentumy;

  • -anyone can help me with my program?"Checkers"   a game java gode.

    the problem always in my program is the main.. sorry if im not perfectly good in programming, but i always try my best to understand.. so please help me..thanks
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.ArrayList;
    public class Checkers extends JApplet {
    JButton newGameButton;
    JButton resignButton;
    JLabel message;
    public void init() {
    Container content = getContentPane();
    content.setLayout(null);
    content.setBackground(new Color(0,150,0));
    Board board = new Board();
    content.add(board);
    content.add(newGameButton);
    content.add(resignButton);
    content.add(message);
    board.setBounds(20,20,164,164); // Note: size MUST be 164-by-164 !
    newGameButton.setBounds(210, 60, 120, 30);
    resignButton.setBounds(210, 120, 120, 30);
    message.setBounds(0, 200, 350, 30);
    // -------------------- Nested Classes -------------------------------
    static class CheckersMove {
    int fromRow, fromCol;
    int toRow, toCol;
    CheckersMove(int r1, int c1, int r2, int c2) {
    fromRow = r1;
    fromCol = c1;
    toRow = r2;
    toCol = c2;
    boolean isJump() {
    return (fromRow - toRow == 2 || fromRow - toRow == -2);
    class Board extends JPanel implements ActionListener, MouseListener {
    CheckersData board;
    boolean gameInProgress;
    int currentPlayer;
    int selectedRow, selectedCol;
    CheckersMove[] legalMoves;
    public Board() {
    setBackground(Color.black);
    addMouseListener(this);
    resignButton = new JButton("Resign");
    resignButton.addActionListener(this);
    newGameButton = new JButton("New Game");
    newGameButton.addActionListener(this);
    message = new JLabel("",JLabel.CENTER);
    message.setFont(new Font("Serif", Font.BOLD, 14));
    message.setForeground(Color.green);
    board = new CheckersData();
    doNewGame();
    public void actionPerformed(ActionEvent evt) {
    // Respond to user's click on one of the two buttons.
    Object src = evt.getSource();
    if (src == newGameButton)
    doNewGame();
    else if (src == resignButton)
    doResign();
    void doNewGame() {
    // Begin a new game.
    if (gameInProgress == true) {
    // This should not be possible, but it doens't
    // hurt to check.
    message.setText("Finish the current game first!");
    return;
    board.setUpGame();
    currentPlayer = CheckersData.RED;
    legalMoves = board.getLegalMoves(CheckersData.RED);
    selectedRow = -1;
    message.setText("Red: Make your move.");
    gameInProgress = true;
    newGameButton.setEnabled(false);
    resignButton.setEnabled(true);
    repaint();
    void doResign() {
    if (gameInProgress == false) {
    message.setText("There is no game in progress!");
    return;
    if (currentPlayer == CheckersData.RED)
    gameOver("RED resigns. BLACK wins.");
    else
    gameOver("BLACK resigns. RED wins.");
    void gameOver(String str) {
    message.setText(str);
    newGameButton.setEnabled(true);
    resignButton.setEnabled(false);
    gameInProgress = false;
    void doClickSquare(int row, int col) {
    for (int i = 0; i < legalMoves.length; i++)
    if (legalMoves.fromRow == row && legalMoves[i].fromCol == col) {
    selectedRow = row;
    selectedCol = col;
    if (currentPlayer == CheckersData.RED)
    message.setText("RED: Make your move.");
    else
    message.setText("BLACK: Make your move.");
    repaint();
    return;
    if (selectedRow < 0) {
    message.setText("Click the piece you want to move.");
    return;
    for (int i = 0; i < legalMoves.length; i++)
    if (legalMoves[i].fromRow == selectedRow && legalMoves[i].fromCol == selectedCol
    && legalMoves[i].toRow == row && legalMoves[i].toCol == col) {
    doMakeMove(legalMoves[i]);
    return;
    message.setText("Click the square you want to move to.");
    void doMakeMove(CheckersMove move) {
    board.makeMove(move);
    if (move.isJump()) {
    legalMoves = board.getLegalJumpsFrom(currentPlayer,move.toRow,move.toCol);
    if (legalMoves != null) {
    if (currentPlayer == CheckersData.RED)
    message.setText("RED: You must continue jumping.");
    else
    message.setText("BLACK: You must continue jumping.");
    selectedRow = move.toRow;
    selectedCol = move.toCol;
    repaint();
    return;
    if (currentPlayer == CheckersData.RED) {
    currentPlayer = CheckersData.BLACK;
    legalMoves = board.getLegalMoves(currentPlayer);
    if (legalMoves == null)
    gameOver("BLACK has no moves. RED wins.");
    else if (legalMoves[0].isJump())
    message.setText("BLACK: Make your move. You must jump.");
    else
    message.setText("BLACK: Make your move.");
    else {
    currentPlayer = CheckersData.RED;
    legalMoves = board.getLegalMoves(currentPlayer);
    if (legalMoves == null)
    gameOver("RED has no moves. BLACK wins.");
    else if (legalMoves[0].isJump())
    message.setText("RED: Make your move. You must jump.");
    else
    message.setText("RED: Make your move.");
    selectedRow = -1;
    if (legalMoves != null) {
    boolean sameStartSquare = true;
    for (int i = 1; i < legalMoves.length; i++)
    if (legalMoves[i].fromRow != legalMoves[0].fromRow
    || legalMoves[i].fromCol != legalMoves[0].fromCol) {
    sameStartSquare = false;
    break;
    if (sameStartSquare) {
    selectedRow = legalMoves[0].fromRow;
    selectedCol = legalMoves[0].fromCol;
    repaint();
    public void paintComponent(Graphics g) {
    g.setColor(Color.black);
    g.drawRect(0,0,getSize().width-1,getSize().height-1);
    g.drawRect(1,1,getSize().width-3,getSize().height-3);
    for (int row = 0; row < 8; row++) {
    for (int col = 0; col < 8; col++) {
    if ( row % 2 == col % 2 )
    g.setColor(Color.lightGray);
    else
    g.setColor(Color.gray);
    g.fillRect(2 + col*20, 2 + row*20, 20, 20);
    switch (board.pieceAt(row,col)) {
    case CheckersData.RED:
    g.setColor(Color.red);
    g.fillOval(4 + col*20, 4 + row*20, 16, 16);
    break;
    case CheckersData.BLACK:
    g.setColor(Color.black);
    g.fillOval(4 + col*20, 4 + row*20, 16, 16);
    break;
    case CheckersData.RED_KING:
    g.setColor(Color.red);
    g.fillOval(4 + col*20, 4 + row*20, 16, 16);
    g.setColor(Color.white);
    g.drawString("K", 7 + col*20, 16 + row*20);
    break;
    case CheckersData.BLACK_KING:
    g.setColor(Color.black);
    g.fillOval(4 + col*20, 4 + row*20, 16, 16);
    g.setColor(Color.white);
    g.drawString("K", 7 + col*20, 16 + row*20);
    break;
    if (gameInProgress) {
    // First, draw a cyan border around the pieces that can be moved.
    g.setColor(Color.cyan);
    for (int i = 0; i < legalMoves.length; i++) {
    g.drawRect(2 + legalMoves[i].fromCol*20, 2 + legalMoves[i].fromRow*20, 19, 19);
    if (selectedRow >= 0) {
    g.setColor(Color.white);
    g.drawRect(2 + selectedCol*20, 2 + selectedRow*20, 19, 19);
    g.drawRect(3 + selectedCol*20, 3 + selectedRow*20, 17, 17);
    g.setColor(Color.green);
    for (int i = 0; i < legalMoves.length; i++) {
    if (legalMoves[i].fromCol == selectedCol && legalMoves[i].fromRow ==
    selectedRow)
    g.drawRect(2 + legalMoves[i].toCol*20, 2 + legalMoves[i].toRow*20, 19, 19);
    public Dimension getPreferredSize() {
    return new Dimension(164, 164);
    public Dimension getMinimumSize() {
    return new Dimension(164, 164);
    public Dimension getMaximumSize() {
    return new Dimension(164, 164);
    public void mousePressed(MouseEvent evt) {
    if (gameInProgress == false)
    message.setText("Click \"New Game\" to start a new game.");
    else {
    int col = (evt.getX() - 2) / 20;
    int row = (evt.getY() - 2) / 20;
    if (col >= 0 && col < 8 && row >= 0 && row < 8)
    doClickSquare(row,col);
    public void mouseReleased(MouseEvent evt) { }
    public void mouseClicked(MouseEvent evt) { }
    public void mouseEntered(MouseEvent evt) { }
    public void mouseExited(MouseEvent evt) { }
    static class CheckersData {
    public static final int
    EMPTY = 0,
    RED = 1,
    RED_KING = 2,
    BLACK = 3,
    BLACK_KING = 4;
    private int[][] board;
    public CheckersData() {
    board = new int[8][8];
    setUpGame();
    public void setUpGame() {
    for (int row = 0; row < 8; row++) {
    for (int col = 0; col < 8; col++) {
    if ( row % 2 == col % 2 ) {
    if (row < 3)
    board[row][col] = BLACK;
    else if (row > 4)
    board[row][col] = RED;
    else
    board[row][col] = EMPTY;
    else {
    board[row][col] = EMPTY;
    public int pieceAt(int row, int col) {
    return board[row][col];
    public void setPieceAt(int row, int col, int piece) {
    board[row][col] = piece;
    public void makeMove(CheckersMove move) {
    makeMove(move.fromRow, move.fromCol, move.toRow, move.toCol);
    public void makeMove(int fromRow, int fromCol, int toRow, int toCol) {
    board[toRow][toCol] = board[fromRow][fromCol];
    board[fromRow][fromCol] = EMPTY;
    if (fromRow - toRow == 2 || fromRow - toRow == -2) {
    int jumpRow = (fromRow + toRow) / 2;
    int jumpCol = (fromCol + toCol) / 2;
    board[jumpRow][jumpCol] = EMPTY;
    if (toRow == 0 && board[toRow][toCol] == RED)
    board[toRow][toCol] = RED_KING;
    if (toRow == 7 && board[toRow][toCol] == BLACK)
    board[toRow][toCol] = BLACK_KING;
    public CheckersMove[] getLegalMoves(int player) {
    if (player != RED && player != BLACK)
    return null;
    int playerKing;
    if (player == RED)
    playerKing = RED_KING;
    else
    playerKing = BLACK_KING;
    ArrayList moves = new ArrayList();
    for (int row = 0; row < 8; row++) {
    for (int col = 0; col < 8; col++) {
    if (board[row][col] == player || board[row][col] == playerKing) {
    if (canJump(player, row, col, row+1, col+1, row+2, col+2))
    moves.add(new CheckersMove(row, col, row+2, col+2));
    if (canJump(player, row, col, row-1, col+1, row-2, col+2))
    moves.add(new CheckersMove(row, col, row-2, col+2));
    if (canJump(player, row, col, row+1, col-1, row+2, col-2))
    moves.add(new CheckersMove(row, col, row+2, col-2));
    if (canJump(player, row, col, row-1, col-1, row-2, col-2))
    moves.add(new CheckersMove(row, col, row-2, col-2));
    if (moves.size() == 0) {
    for (int row = 0; row < 8; row++) {
    for (int col = 0; col < 8; col++) {
    if (board[row][col] == player || board[row][col] == playerKing) {
    if (canMove(player,row,col,row+1,col+1))
    moves.add(new CheckersMove(row,col,row+1,col+1));
    if (canMove(player,row,col,row-1,col+1))
    moves.add(new CheckersMove(row,col,row-1,col+1));
    if (canMove(player,row,col,row+1,col-1))
    moves.add(new CheckersMove(row,col,row+1,col-1));
    if (canMove(player,row,col,row-1,col-1))
    moves.add(new CheckersMove(row,col,row-1,col-1));
    if (moves.size() == 0)
    return null;
    else {
    CheckersMove[] moveArray = new CheckersMove[moves.size()];
    for (int i = 0; i < moves.size(); i++)
    moveArray[i] = (CheckersMove)moves.get(i);
    return moveArray;
    public CheckersMove[] getLegalJumpsFrom(int player, int row, int col) {
    if (player != RED && player != BLACK)
    return null;
    int playerKing;
    if (player == RED)
    playerKing = RED_KING;
    else
    playerKing = BLACK_KING;
    ArrayList moves = new ArrayList();
    if (board[row][col] == player || board[row][col] == playerKing) {
    if (canJump(player, row, col, row+1, col+1, row+2, col+2))
    moves.add(new CheckersMove(row, col, row+2, col+2));
    if (canJump(player, row, col, row-1, col+1, row-2, col+2))
    moves.add(new CheckersMove(row, col, row-2, col+2));
    if (canJump(player, row, col, row+1, col-1, row+2, col-2))
    moves.add(new CheckersMove(row, col, row+2, col-2));
    if (canJump(player, row, col, row-1, col-1, row-2, col-2))
    moves.add(new CheckersMove(row, col, row-2, col-2));
    if (moves.size() == 0)
    return null;
    else {
    CheckersMove[] moveArray = new CheckersMove[moves.size()];
    for (int i = 0; i < moves.size(); i++)
    moveArray[i] = (CheckersMove)moves.get(i);
    return moveArray;
    } // end getLegalMovesFrom()
    private boolean canJump(int player, int r1, int c1, int r2, int c2, int r3, int c3) {
    if (r3 < 0 || r3 >= 8 || c3 < 0 || c3 >= 8)
    return false;
    if (board[r3][c3] != EMPTY)
    return false;
    if (player == RED) {
    if (board[r1][c1] == RED && r3 > r1)
    return false;
    if (board[r2][c2] != BLACK && board[r2][c2] != BLACK_KING)
    return false;
    return true; // The jump is legal.
    else {
    if (board[r1][c1] == BLACK && r3 < r1)
    return false;
    if (board[r2][c2] != RED && board[r2][c2] != RED_KING)
    return false;
    return true;
    private boolean canMove(int player, int r1, int c1, int r2, int c2) {
    if (r2 < 0 || r2 >= 8 || c2 < 0 || c2 >= 8)
    return false;
    if (board[r2][c2] != EMPTY)
    return false;
    if (player == RED) {
    if (board[r1][c1] == RED && r2 > r1)
    return false;
    return true;
    else {
    if (board[r1][c1] == BLACK && r2 < r1)
    return false;
    return true;
    *..please ... thanks!!*

    Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the tags that appear.
    db

  • I am having problems being able to sign out of everything that requires a sign in and password can you help and some games only show have the page

    I have been doing online banking with this bank for 7 months with no problems. About 2 weeks ago I started having problems with certain things within the account. I called the support team with the bank and told them the problem and they suggested to uninstall firefox and reinstall so I did. Now I can move around within the account but can not sign off. Also all my accounts that require a sign in I have the same problem and some games I play only load up part of the game. I play goldminer and now I can not see the little miner to play the game. Can you help????????

    That issue can be caused by corrupted cookies.
    *https://support.mozilla.org/kb/Cannot+log+in+to+websites
    Clear the cache and the cookies from sites that cause problems.
    "Clear the Cache":
    *Tools > Options > Advanced > Network > Offline Storage (Cache): "Clear Now"
    "Remove Cookies" from sites causing problems:
    *Tools > Options > Privacy > Cookies: "Show Cookies"
    If clearing the cookies doesn't help then it is possible that the file <i>cookies.sqlite</i> that stores the cookies is corrupted.<br />
    Rename (or delete) <b>cookies.sqlite</b> (cookies.sqlite.old) and delete other present cookie files like <b>cookies.sqlite-journal</b> in the Firefox Profile Folder in case the file cookies.sqlite got corrupted.
    *http://kb.mozillazine.org/Cookies

  • Please! I need someone help with a game

    I got this Error everytime the scene is reseted. I have no clue where mistake is made. Please help!
    TypeError: Error #1010: A term is undefined and has no properties.
        at golfer_fla::MainTimeline/resetScene()
        at golfer_fla::MainTimeline/golfer_fla::frame1()
    TypeError: Error #1010: A term is undefined and has no properties.
        at golfer_fla::MainTimeline/resetScene()
        at golfer_fla::MainTimeline/countDown()
        at flash.utils::Timer/flash.utils:Timer::_timerDispatch()
        at flash.utils::Timer/flash.utils:Timer::tick()
    If that helps I could send my game by mail so someone could check the error which constantly pop out when the golfer hit the ball, ball stops and the scene resets.
    Here is the code:
    //Variables
    var myHead = new head();
    var myArms = new arms();
    var myBody = new body();
    var myStick = new stick();
    var myGround = new ground();
    var myFlag = new flag();
    var myCapsel = new capsel();
    var grassMask:Number;
    var speedUp:int = 2;
    var speedDown:int = speedUp * 8;
    var checker:int;
    var minPower:int;
    var maxPower:int = 110;
    var strength:Number;
    var capselPower:Number;
    var distance:Number;
    var target:int;
    var tryShot:int = 0;
    var myTimer = new Timer(2000, 1);
    //EventListeners
    stage.addEventListener(KeyboardEvent.KEY_DOWN, onDown);
    stage.addEventListener(KeyboardEvent.KEY_UP, onUp);
    stage.addEventListener(Event.ENTER_FRAME, hit);
    myTimer.addEventListener(TimerEvent.TIMER, countDown);
    //Functions
    function resetScene():void {   
        addChild(myBody);
        addChild(myArms);
        addChild(myHead);
        addChild(myStick);
        addChild(myGround);
        addChild(myFlag);
        addChild(myCapsel);
        grassMask = (320 + Math.random()*260);
        myBody.x = 70;
        myBody.y = 296;
        myArms.x = 68;
        myArms.y = 276;
        myArms.rotation = 0;
        myHead.x = 70;
        myHead.y = 215;   
        myStick.x = 68;
        myStick.y = 276;   
        myStick.rotation = 0;
        myCapsel.x = 90;
        myCapsel.y = 331;
        myGround.x = 0;
        myGround.y = 375;
        myGround.grassMask.x = grassMask - 610;
        myFlag.x = grassMask;
        myFlag.y = 375;
        checker = 0;
        minPower = 0;
        target = 0;
        tryShot ++;
        myCapsel.capselFall.gotoAndStop(1);
        myMessage.text = "Press any key!";
    resetScene();
    function invisibleCapsels():void {   
        a1.visible = false;
        a2.visible = false;
        a3.visible = false;
        a4.visible = false;
        a5.visible = false;
        a6.visible = false;
        a1.gotoAndStop(1);
        a2.gotoAndStop(1);
        a3.gotoAndStop(1);
        a4.gotoAndStop(1);
        a5.gotoAndStop(1);
        a6.gotoAndStop(1);
    invisibleCapsels();
    function onDown(e:KeyboardEvent):void {
        checker = 1;
        minPower = -20;
    function onUp(e:KeyboardEvent):void {
        checker = 0;
        capselPower = (myCapsel.x + myStick.rotation) * 3.2;
    function hit(e:Event):void {
        if(tryShot < 7) {
            if((checker == 1) && (myStick.rotation < maxPower)) {
                myStick.rotation += speedUp;
                myArms.rotation += speedUp;
                } else {
                    if(myStick.rotation > minPower) {
                        myStick.rotation -= speedDown;
                        myArms.rotation -= speedDown;
                    if(myStick.hitTestObject(myCapsel)) {
                        stage.addEventListener(Event.ENTER_FRAME, shot);
                } else {
                    myMessage.text = "Game Over\nClick to play again";
                    stage.addEventListener(MouseEvent.MOUSE_DOWN, playAgain);
    function playAgain(e:MouseEvent):void {
        resetScene();
        invisibleCapsels();
        tryShot = 1;
        stage.removeEventListener(MouseEvent.MOUSE_DOWN, playAgain);
    function shot(e:Event):void {
        strength = (capselPower - myCapsel.x);
        distance = grassMask - myCapsel.x;
        if((Math.round(distance) <= 10) && (Math.round(distance) >= 3) && (strength <= 65)) {
            if(target == 0) {
                myCapsel.capselFall.play();
                myCapsel.rotation = 0;
                target = 1;
                this["a" + tryShot].visible = true;
                myMessage.text = "Cooool!";
                myTimer.start();
            } else {
                if(strength > 5) {
                    myCapsel.x += strength / 30;
                    myCapsel.rotation += strength / 4;
                    } else {
                        this["a" + tryShot].visible = true;
                        this["a" + tryShot].gotoAndStop(2);
                        myMessage.text = "Bad Luck!";
                        myTimer.start();
    function countDown(e:TimerEvent):void {
        resetScene();
        stage.removeEventListener(Event.ENTER_FRAME, shot);

    Try adding the following two lines before line 59:
    trace(myCapsel);
    trace(myCapsel.capselFall);
    If one of them traces undefined, it should isolate which object is the problem.  If you describe what is involved with that object.child, then it may help generate an idea of what might be wrong.

  • Help! Aspyr Games Not Loading After Updating To Mac OS X 10.4.11

    I can't seem to get my Sims 2 game to load after installing the latest update. It will bounce once in the dock then disappear.
    I called Aspyr and they said it was a problem with Apple's update, not their game(s) or company.
    I was told to see if I could update to 10.5.5 and that this should fix things. How would I do that, and first of all, would that be a good idea? Is it even possible? I'm (clearly) running Tiger.
    I'm very confused because I haven't been able to connect to the internet for about a month and finally installed the Apple updates and then I started having all these problems. I'm not sure what to do!
    Thanks in advance for your help!
    Message was edited by: papersky06

    Run Disk Utility and repair permissions on your drive. If that doesn't work, follow the more extensive instructions for repairing your drive.
    As you have observed, you are running Tiger and the company told you to upgrade to Leopard, which I agree isn't very helpful unless you want to upgrade (is it worth it?).
    [Resolve startup issues and perform disk maintenance with Disk Utility and fsck|http://docs.info.apple.com/article.html?artnum=106214]
    [Using Disk Utility in Mac OS X 10.4.3 or later|http://docs.info.apple.com/article.html?artnum=302672]
    [Disk Utility's Repair Disk Permissions|http://docs.info.apple.com/article.html?artnum=25751]
    [Post by japamac about using fsk|http://discussions.apple.com/thread.jspa?threadID=1649143&tstart=0]
    From BDaqua (couldn't have said it better):
    "Try Disk Utility
    1. Insert the Mac OS X Install disc that came with your computer (Edit: Do not use this disc if it is not the same general version as what you have currently on your computer, e.g. use a Tiger disc for a Tiger drive, not a Panther disc), then restart the computer while holding the C key.
    2. When your computer finishes starting up from the disc, choose Disk Utility from the Installer menu. (In Mac OS X 10.4 or later, you must select your language first.)
    Important: Do not click Continue in the first screen of the Installer. If you do, you must restart from the disc again to access Disk Utility.
    3. Click the First Aid tab.
    4. Click the disclosure triangle to the left of the hard drive icon to display the names of your hard disk volumes and partitions.
    5. Select your Mac OS X volume.
    6. Click Repair. Disk Utility checks and repairs the disk.
    Then Safe Boot, (holding Shift key down at bootup), run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions, reboot when it completes."

  • Help Making a Game Like Pokémon Trading Card Game.

    Hello! Im kinda new into making games in flash. And im trying hard to make a Game like the Pokemon TCG and i can't find anything on the internet that helps, so can't someone teach me how to do a game like that. Thanks!

    Well, it's not much. But i will studdy and become great!
    Thanks for your answer!

  • Help:checkered-like blocks

    Hi Expert .
    Please Help i dont know what is wrong with my MBP 13" mid 2010,
    parts of the display that are actively being scrolled will flash in big checkered-like blocks during the scrolling process.
    Thanks.

    Take it in for service either to the Apple Store or an AASP

  • Help with platform game

    I can't solve this for days already... When the hero object dies, the floorObject do not remove completely, such that one of them remains. And the hero object
    disappears. Thanks for all the help.
    package
              import flash.display.MovieClip;
              import flash.events.KeyboardEvent;
              import flash.events.*;
              import flash.utils.getTimer;
              public class Platform extends MovieClip
                        // movement constants
                        static const gravity:Number = .004;
                        // screen constants
                        static const edgeDistance:Number = 100;
                        // object arrays
                        private var fixedObjects:Array;
                        private var otherObjects:Array;
                        // hero and enemies
                        private var hero:Object;
                        private var enemies:Array;
                        // game state
                        private var playerObjects:Array;
                        private var gameScore:int;
                        private var gameMode:String = "start";
                        private var playerLives:int;
                        private var lastTime:Number = 0;
                        private var currentX:int = 0;
                        public function startPlatformGame()
                                  // constructor code
                                  gameMode = "play";
                        public function startGameLevel()
                                  createHero();
                                  addEnemies();
                                  // examine level and note all objects
                                  examineLevel();
                                  // add listeners
                                  this.addEventListener(Event.ENTER_FRAME,gameLoop);
                                  stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownFunction);
                                  stage.addEventListener(KeyboardEvent.KEY_UP,keyUpFunction);
                                  // set game state
                                  gameMode = "play";
                        public function createHero()
                                  hero = new Object();
                                  hero.mc = gamelevel.hero;
                                  hero.dx = 0.0;
                                  hero.dy = 0.0;
                                  hero.inAir = false;
                                  hero.direction = 1;
                                  hero.animstate = "stand";
                                  hero.walkAnimation = new Array(2,3,4,5,6,7,8);
                                  hero.animstep = 0;
                                  hero.jump = false;
                                  hero.moveLeft = false;
                                  hero.moveRight = true;
                                  hero.jumpSpeed = .8;
                                  hero.walkSpeed = .15;
                                  hero.width = 30.0;
                                  hero.height = 40.0;
                                  hero.startx = hero.mc.x;
                                  hero.starty = hero.mc.y;
                        public function addEnemies() {
                                  enemies = new Array();
                                  var i:int = 1;
                                  while (true) {
                                            if (gamelevel["enemy"+i] == null) break;
                                            var enemy = new Object();
                                            enemy.mc = gamelevel["enemy"+i];
                                            enemy.dx = 0.0;
                                            enemy.dy = 0.0;
                                            enemy.inAir = false;
                                            enemy.direction = 1;
                                            enemy.animstate = "stand"
                                            enemy.walkAnimation = new Array(2,3,4,5);
                                            enemy.animstep = 0;
                                            enemy.jump = false;
                                            enemy.moveRight = true;
                                            enemy.moveLeft = false;
                                            enemy.jumpSpeed = 1.0;
                                            enemy.walkSpeed = .08;
                                            enemy.width = 30.0;
                                            enemy.height = 30.0;
                                            enemies.push(enemy);
                                            i++;
                        public function examineLevel()
                                  fixedObjects = new Array();
                                  otherObjects = new Array();
                                  for (var i:int=0; i<this.gamelevel.numChildren; i++)
                                            var mc = this.gamelevel.getChildAt(i);
                                            // add floors and walls to fixedObjects
                                            if (mc is Floor)
                                                      var floorObject:Object = new Object();
                                                      floorObject.mc = mc;
                                                      floorObject.leftside = mc.x;
                                                      floorObject.rightside = mc.x + mc.width;
                                                      floorObject.topside = mc.y;
                                                      floorObject.bottomside = mc.y + mc.height;
                                                      fixedObjects.push(floorObject);
                                            else if ((mc is Treasure) )
                                                      otherObjects.push(mc);
                                  fixedObjects.sortOn("leftside" , Array.NUMERIC );
                                  for each (floorObject in fixedObjects)
                                            trace(floorObject.leftside);
                        // add treasure, key and door to otherOjects;
                        public function keyDownFunction(event:KeyboardEvent)
                                  if (gameMode != "play")
                                            return;
                                  }// don't move until in play mode
                                  if (event.keyCode == 37)
                                            hero.moveLeft = true;
                                  else if (event.keyCode == 39)
                                            hero.moveRight = true;
                                  else if (event.keyCode == 32)
                                            if (! hero.inAir)
                                                      hero.jump = true;
                        public function keyUpFunction(event:KeyboardEvent)
                                  if (event.keyCode == 37)
                                            hero.moveLeft = false;
                                  else if (event.keyCode == 39)
                                            hero.moveRight = false;
                        public function gameLoop(event:Event)
                                  // get time differentce
                                  if (lastTime == 0)
                                            lastTime = getTimer();
                                  var timeDiff:int = getTimer() - lastTime;
                                  lastTime +=  timeDiff;
                                  // only perform tasks if in play mode
                                  if (gameMode == "play")
                                            moveCharacter(hero,timeDiff);
                                            checkCollisions();
                                            scrollWithHero();
                                            death();
                        public function moveCharacter(char:Object,timeDiff:Number)
                                  if (timeDiff < 1)
                                            return;
                                  // assume character pulled down by gravity
                                  var verticalChange:Number = char.dy * timeDiff + timeDiff * gravity;
                                  if (verticalChange > 15.0)
                                            verticalChange = 15.0;
                                  char.dy +=  timeDiff * gravity;
                                  // react to changes from key presses
                                  var horizontalChange = 0;
                                  var newAnimState:String = "stand";
                                  var newDirection:int = char.direction;
                                  if (char.moveLeft)
                                            // walk left
                                            horizontalChange =  -  char.walkSpeed * timeDiff;
                                            newAnimState = "walk";
                                            newDirection = -1;
                                  else if (char.moveRight)
                                            // walk right
                                            horizontalChange = char.walkSpeed * timeDiff;
                                            newAnimState = "walk";
                                            newDirection = 1;
                                  if (char.jump)
                                            // start jump
                                            char.jump = false;
                                            char.dy =  -  char.jumpSpeed;
                                            verticalChange =  -  char.jumpSpeed;
                                            newAnimState = "jump";
                                  // assume no wall hit, and hanging in air
                                  char.hitWallRight = false;
                                  char.hitWallLeft = false;
                                  char.inAir = true;
                                  // find new vertical position
                                  var newY:Number = char.mc.y + verticalChange;
                                  // loop through all fixed objects to see if character has landed
                                  for (var i:int=0; i<fixedObjects.length; i++)
                                            if ((char.mc.x+char.width/2 > fixedObjects[i].leftside) && (char.mc.x-char.width/2 < fixedObjects[i].rightside))
                                                      if ((char.mc.y <= fixedObjects[i].topside) && (newY > fixedObjects[i].topside))
                                                                newY = fixedObjects[i].topside;
                                                                char.dy = 0;
                                                                char.inAir = false;
                                                                break;
                                  // find new horizontal position
                                  var newX:Number = char.mc.x + horizontalChange;
                                  // loop through all objects to see if character has bumped into a wall
                                  for (i=0; i<fixedObjects.length; i++)
                                            if ((newY > fixedObjects[i].topside) && (newY-char.height < fixedObjects[i].bottomside))
                                                      if ((char.mc.x-char.width/2 >= fixedObjects[i].rightside) && (newX-char.width/2 <= fixedObjects[i].rightside))
                                                                newX = fixedObjects[i].rightside + char.width / 2;
                                                                char.hitWallLeft = true;
                                                                break;
                                                      if ((char.mc.x+char.width/2 <= fixedObjects[i].leftside) && (newX+char.width/2 >= fixedObjects[i].leftside))
                                                                newX = fixedObjects[i].leftside - char.width / 2;
                                                                char.hitWallRight = true;
                                                                break;
                                  // set position of character
                                  char.mc.x = newX;
                                  char.mc.y = newY;
                                  // set animation state
                                  if (char.inAir)
                                            newAnimState = "jump";
                                  char.animstate = newAnimState;
                                  // move along walk cycle
                                  if (char.animstate == "walk")
                                            char.animstep +=  timeDiff / 60;
                                            if (char.animstep > char.walkAnimation.length)
                                                      char.animstep = 0;
                                            char.mc.gotoAndStop(char.walkAnimation[Math.floor(char.animstep)]);
                                            // not walking, show stand or jump state
                                  else
                                            char.mc.gotoAndStop(char.animstate);
                                  // changed directions
                                  if (newDirection != char.direction)
                                            char.direction = newDirection;
                                            char.mc.scaleX = char.direction;
                        public function checkCollisions()
                                  for (var i = otherObjects.length-1; i >= 0; i--)
                                            if (hero.mc.hitTestObject(otherObjects[i]))
                                                      getObject(i);
                                  for (var j:int = enemies.length-1; j>=0; j--)
                                            if (hero.mc.hitTestObject(enemies[j].mc))
                                                      currentX = hero.mc.x;
                                                      gameComplete();
                        public function scrollWithHero()
                                  var stagePosition:Number = gamelevel.x + hero.mc.x;
                                  var rightEdge:Number = stage.stageWidth - edgeDistance;
                                  var leftEdge:Number = edgeDistance;
                                  if (stagePosition > rightEdge)
                                            gamelevel.x -= (stagePosition-rightEdge);
                                            if (gamelevel.x < -(gamelevel.width-stage.stageWidth))
                                                      gamelevel.x = -(gamelevel.width-stage.stageWidth);
                                  if (stagePosition < leftEdge)
                                            gamelevel.x += (leftEdge-stagePosition);
                                            if (gamelevel.x > 0)
                                                      gamelevel.x = 0;
                        public function getObject(objectNum:int)
                                  if (otherObjects[objectNum] is Treasure)
                                            gamelevel.removeChild(otherObjects[objectNum]);
                                            otherObjects.splice(objectNum,1);
                        public function death()
                                  if (hero.mc.y > 300)
                                            currentX = gamelevel.hero.x;
                                            trace(currentX);
                                            gameComplete();
                        public function gameComplete()
                                  gameMode = "dead";
                                  var dialog:Dialog = new Dialog();
                                  dialog.x = 175;
                                  dialog.y = 100;
                                  addChild(dialog);
                                  dialog.message.text = "Gameover";
                        public function clickDialogButton(event:MouseEvent)
                                  removeChild(MovieClip(event.currentTarget.parent));
                                  // new life, restart, or go to next level
                                  if (gameMode == "dead")
                                            // reset hero
                                            hero.mc.x = currentX;
                                            hero.mc.y = 0;
                                            trace("dead");
                                            setReplay();
                                            gameMode = "play";
                                  // give stage back the keyboard focus
                                  stage.focus = stage;
                        public function setReplay()
                                  for (var i:int = fixedObjects.length-1; i>-1; i--)
                                            if (fixedObjects[i].leftside < currentX)
                                                      this.gamelevel.removeChildAt(fixedObjects[i]);
                                                      fixedObjects.splice(i,1);
                                                      trace("Splice?");
                                  for each (var floorObject in fixedObjects){
                                            trace(floorObject.leftside);
                        public function cleanUp()
                                  removeChild(gamelevel);
                                  this.removeEventListener(Event.ENTER_FRAME,gameLoop);
                                  stage.removeEventListener(KeyboardEvent.KEY_DOWN,keyDownFunction);
                                  stage.removeEventListener(KeyboardEvent.KEY_UP,keyUpFunction);

    Ok, I fiured it all out, the other way you mentioned. Just opened up the character MC, and named 2 frames. One LEFT and one RIGHT. Then I added a few simple lines of code, and turned out with this:
    if (Key.isDown(Key.RIGHT)) {
    _x += speed;
    this.gotoAndStop("right");
    if (Key.isDown(Key.LEFT)) {
    _x -= speed;
    this.gotoAndStop("left");
    Thanks for helping!!!

  • Need help in a game design.Cirles,lines intersections

    Hello,
    Im trying to create a board game (the go game) but i have problems with the design. Till now i have design a 19 * 19 table and what i want is when i click with the mouse on this table to display circles, but i want them exactly on the intersection. With my program i get circles everywhere i click and not on the intersection of the line.
    So if anyone can help me,i would like to tell me, how can i place the circle exactly on the intersection? Also i would like to eliminate the clicks just on the table and not outside of it.
    Please help if anyone knows, im not that expert in java
    My code is this till now.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class goGame extends JFrame {
    private int x1Value , y1Value ;
    boolean isWhitesTurn = true,first = true;
    public goGame()
    super( "Go game" );
    Color redbrown = new Color (75,17,17);
    setBackground(redbrown);
    addMouseListener(
    // anonymous inner class
    new MouseAdapter() {
    // store drag coordinates and repaint
    public void mouseClicked( MouseEvent event )
    x1Value = event.getX();
    y1Value = event.getY();
    repaint();
    } // end anonymous inner class
    ); // end call to addMouseMotionListener
    setSize( 700,550 );
    setVisible(true);
    public void paint( Graphics g )
    Graphics2D graphics2D = (Graphics2D ) g;
    Color redbrown = new Color (75,17,17);
    g.setColor(redbrown);
    Color lightbrown = new Color (192,148,119);
    g.setColor(lightbrown);
    if (first) {
    //paint yellow the big rectangle
    graphics2D.setPaint(new GradientPaint (600,100, Color.yellow,100, 10,Color.red,true));
    graphics2D.fillRect(60,60,450,450);
    graphics2D.setPaint(Color.black);
    graphics2D.setStroke(new BasicStroke(3.0f));
    //draw rows
    int y=60;
    for (int n=0; n<=18 ; n++)
    g.drawLine(60,y,510,y );
    y= y + 25;
    //draw columns
    int x = 60;
    for (int n=0; n<=18 ; n++)
    g.drawLine(x,510,x,60);
    x = x + 25;
    g.setColor(Color.green) ;
    //draw the 1st 3 vertical dots
    int z = 133;
    for (int n=0; n<=2; n++)
    g.fillOval(133,z,5,5);
    z = z + 150;
    //draw the 2 vertical dots of the 1st row-dot , the 1 already exists
    int w = 283;
    for (int n =0; n<=1; n++)
    g.fillOval(w,133,5,5);
    w = w + 150;
    //draw the 2 vertical dots of the 2nd row-dot
    int t = 283;
    for (int n=0; n<=2; n++)
    g.fillOval(283,t,5,5);
    t = t + 150;
    //draw the last dots
    g.fillOval(433,283,5,5);
    g.fillOval(433,433,5,5);
    first = false;
    if (isWhitesTurn) g.setColor(Color.white);
    else g.setColor(Color.black);
    g.fillOval( x1Value, y1Value,20,20 );
    isWhitesTurn = !isWhitesTurn ;
    // execute application
    public static void main( String args[] )
    goGame application = new goGame();
    application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    This will capture vertical and horizontal
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    public class GoGame extends JFrame
    public GoGame()
         getContentPane().setLayout(null);
         setBounds(10,10,510,520);
         getContentPane().add(new TheTable());
         setVisible(true);
    public class TheTable extends JPanel
         int[][]points  = new int[19][19];
         boolean black  = true;
    public TheTable()
         setBounds(20,20,453,453);
         addMouseListener(new MouseAdapter()
              public void mouseReleased(MouseEvent m)
                   Point p = clickOnIntersection(m.getPoint());
                   if (p != null && points[p.x/25][p.y/25] == 0)
                        int x = p.x/25;
                        int y = p.y/25;
                        if (black)
                             points[x][y] = 1;
                             black = false;
                        else
                             points[x][y] = 2;
                             black = true;
                        capture(x,y);
                        repaint();
    private Point clickOnIntersection(Point p)
         Rectangle rh = new Rectangle(0,0,getWidth(),4);
         Rectangle rv = new Rectangle(0,0,4,getHeight());
         for (int h=0; h < 19; h++)
              rh.setLocation(0,h*25-1);
              if (rh.contains(p))
                   for (int v=0; v < 19; v++)
                        rv.setLocation(v*25-1,0);
                        if (rv.contains(p)) return(new Point(v*25+1,h*25+1));
         return(null);
    private void capture(int x, int y)
         onTheY(x,y,points[x][y]);
         onTheX(x,y,points[x][y]);
    private void onTheY(int x, int y, int col)
         for (int j=x-1; j > -1; j--)
              if (points[j][y] == 0) break;
              if (points[j][y] == col)
                   outOnY(j,x,y);
                   break;
         for (int j=x+1; j < 19; j++)
              if (points[j][y] == 0) break;
              if (points[j][y] == col)
                   outOnY(x,j,y);
                   break;
    private void onTheX(int x, int y, int col)
         for (int j=y-1; j > -1; j--)
              if (points[x][j] == 0) break;
              if (points[x][j] == col)
                   outOnX(j,y,x);
                   break;
         for (int j=y+1; j < 19; j++)
              if (points[x][j] == 0) break;
              if (points[x][j] == col)
                   outOnX(y,j,x);
                    break;
    private void outOnY(int f, int t, int y)
         for (f=f+1; f < t; f++) points[f][y] = 0;
    private void outOnX(int f, int t, int x)
         for (f=f+1; f < t; f++) points[x][f] = 0;
    public void paintComponent(Graphics g)
         super.paintComponent(g);
         Graphics2D g2 = (Graphics2D)g;
         g2.setPaint(new GradientPaint(getWidth(),getHeight(),Color.yellow,0,0,Color.red,true));
         g2.fillRect(0,0,getWidth(),getHeight());
         g2.setColor(Color.black);
         for (int n=0; n < 19; n++)
              g2.fillRect(0,n*25,getWidth(),3);
              g2.fillRect(n*25,0,3,getHeight());
         g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);          
         g2.setColor(Color.green) ;
         for (int n=0; n < 3; n++)
              g2.fillOval(25*3-1,n*150+74,5,5);
              g2.fillOval(25*9-1,n*150+74,5,5);
              g2.fillOval(25*15-1,n*150+74,5,5);
         for (int x=0; x < 19; x++)
              for (int y=0; y < 19; y++)
                   if (points[x][y] != 0)
                        if (points[x][y] == 1) g.setColor(Color.black);     
                        if (points[x][y] == 2) g.setColor(Color.white);     
                        g2.fillOval(x*25-9,y*25-9,20,20);
    public static void main(String[] args)
         GoGame game = new GoGame();
         game.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }Noah

  • Help for Connect4 game java.

    Hello, I am attending Java in the university, previously worked in C++, for my first work on java to me to make the Game of Connect 4 with GUI, navigating the forums i found a code for this game, well this code has a few problems, first the methods checkDiagonalFromTopLeft or checkDiagonalFromBottomLeft dosnt work, especial checkDiagonalFromBottomLeft, second when the 1st game is played and second game is coming the circle is yellow , taht to be RED NOT YELLOW well I NEED YOUR help guys please help mee
    the code please see heckDiagonalFromTopLeft checkDiagonalFromTopLeft
    especially heckDiagonalFromTopLeft
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Tallers1
         static class Connect4
              extends JPanel
              private static final int SIZE= 30;
              private static final int GAP= 10;
              private static final int ROWS= 6;
              private static final int COLS= 7;
              private Color mColor;
              private Color[][] mCounters;
              public Connect4()
                   reset();
                   addMouseListener(new MouseAdapter() {
                        public void mousePressed(MouseEvent e) {
                             hitTest(e.getPoint());
              private void hitTest(Point point) {
    int row = Math.min((point.y / (SIZE+GAP)*ROWS) / ROWS, ROWS-1);
    int col = Math.min((point.x / (SIZE+GAP)*COLS) / COLS, COLS-1);
                   if (mCounters[col][row] == null) {
                        for (row= ROWS-1; row >= 0; row--) {
                             if (mCounters[col][row] == null) {
                                  mCounters[col][row]= mColor;
                                  repaint();
                                  check(col, row);
                                  mColor= mColor == Color.RED ?
                                       Color.YELLOW : Color.RED;
                                  return;
              private void check(int col, int row)
                   if (checkVertical(col) ||
                        checkHorizontal(row) ||
                        checkDiagonalFromTopLeft(col, row) ||
                        checkDiagonalFromBottomLeft(col, row))
                        alert();
              private boolean checkDiagonalFromTopLeft(int col, int row)
                   if (col >= row) {
                        col= col-row;
                        row= 0;
                   else {
                        row= row-col;
                        col= 0;
                   for (int cnt= 0; row < ROWS && col < COLS; row++, col++) {
                        if (mCounters[col][row] == mColor) {
                             if (++cnt >= 4)
                                  return true;
                        else
                             cnt= 0;
                   return false;
              private boolean checkDiagonalFromBottomLeft(int col, int row) {
    if(row >= ROWS-1) {
    // do nowt and move on to the checking.
    else {
    int delta= Math.min(3, col);
    col= Math.max(0, col-delta);
    row= Math.min(ROWS-1, row+delta);
    for (int tally= 0; row >= 0 && col < COLS; row--, col++) {
    if (mCounters[col][row] == mColor) {
    if (++tally >= 4)
    return true;
    } else
    tally= 0;
    return false;
              private boolean checkVertical(int col)
                   for (int cnt= 0, row= 0; row < ROWS; row++) {
                        if (mCounters[col][row] == mColor) {
                             if (++cnt >= 4)
                                  return true;
                        else
                             cnt= 0;
                   return false;
              private boolean checkHorizontal(int row)
                   for (int cnt= 0, col= 0; col < COLS; col++) {
                        if (mCounters[col][row] == mColor) {
                             if (++cnt >= 4)
                                  return true;
                        else
                             cnt= 0;
                   return false;
              private void alert()
                   int option= JOptionPane.showConfirmDialog(this,
                        (mColor == Color.RED ? "Red" : "Yellow") +
                             " wins! Want to go again?",
                        "Game Over",
                        JOptionPane.YES_NO_OPTION);
                   if (option == JOptionPane.YES_OPTION)
                        reset();
                   else
                        System.exit(0);
              private void reset()
                   mCounters= new Color[COLS][ROWS];
                   mColor= Color.RED;
                   repaint();
              public void paint(Graphics g)
                   g.setColor(Color.BLUE);
                   g.fillRect(0, 0, getSize().width, getSize().height);
                   for (int col= 0; col< COLS; col++) {
                        for (int row= 0; row< ROWS; row++) {
                             g.setColor(mCounters[col][row] == null ?
                                  Color.WHITE : mCounters[col][row]);
                             g.fillOval(
                                  GAP+((GAP+SIZE)*col),
                                  GAP+((GAP+SIZE)*row),
                                  SIZE, SIZE);
              public Dimension getPreferredSize()
                   return new Dimension(
                        ((SIZE+GAP)*COLS) +GAP,
                        ((SIZE+GAP)*ROWS) +GAP);
         public static void main(String[] argv)
              JFrame frame= new JFrame();
              frame.getContentPane().add(new Connect4());
              frame.pack();
              frame.setResizable(false);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setVisible(true);
    }

    hi, 2) the GUI is from the forums the algorhytm is made by me, so i need to now wy the diagonal dostn Work ON GUI please, sorry my bad english i m from argentina
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Tallers1
    static class Connect4
    extends JPanel
    private static final int SIZE= 30;
    private static final int GAP= 10;
    private static final int ROWS= 6;
    private static final int COLS= 7;
    private Color mColor;
    private Color[][] mCounters;
    public Connect4()
    reset();
    addMouseListener(new MouseAdapter() {
    public void mousePressed(MouseEvent e) {
    hitTest(e.getPoint());
    private void hitTest(Point point) {
    int row = Math.min((point.y / (SIZE+GAP)*ROWS) / ROWS, ROWS-1);
    int col = Math.min((point.x / (SIZE+GAP)*COLS) / COLS, COLS-1);
    if (mCounters[col][row] == null) {
    for (row= ROWS-1; row >= 0; row--) {
    if (mCounters[col][row] == null) {
    mCounters[col][row]= mColor;
    repaint();
    check(col, row);
    mColor= mColor == Color.RED ?
    Color.YELLOW : Color.RED;
    return;
    private void check(int col, int row)
    if (checkVertical(col) ||
    checkHorizontal(row) ||
    checkDiagonalFromTopLeft(col, row) ||
    checkDiagonalFromBottomLeft(col, row))
    alert();
    private boolean checkDiagonalFromTopLeft(int col, int row)
    if (col >= row) {
    col= col-row;
    row= 0;
    else {
    row= row-col;
    col= 0;
    for (int cnt= 0; row < ROWS && col < COLS; row++, col++) {
    if (mCounters[col][row] == mColor) {
    if (++cnt >= 4)
    return true;
    else
    cnt= 0;
    return false;
    private boolean checkDiagonalFromBottomLeft(int col, int row) {
    if(row >= ROWS-1) {
    // do nowt and move on to the checking.
    else {
    int delta= Math.min(3, col);
    col= Math.max(0, col-delta);
    row= Math.min(ROWS-1, row+delta);
    for (int tally= 0; row >= 0 && col < COLS; row--, col++) {
    if (mCounters[col][row] == mColor) {
    if (++tally >= 4)
    return true;
    } else
    tally= 0;
    return false;
    private boolean checkVertical(int col)
    for (int cnt= 0, row= 0; row < ROWS; row++) {
    if (mCounters[col][row] == mColor) {
    if (++cnt >= 4)
    return true;
    else
    cnt= 0;
    return false;
    private boolean checkHorizontal(int row)
    for (int cnt= 0, col= 0; col < COLS; col++) {
    if (mCounters[col][row] == mColor) {
    if (++cnt >= 4)
    return true;
    else
    cnt= 0;
    return false;
    private void alert()
    int option= JOptionPane.showConfirmDialog(this,
    (mColor == Color.RED ? "Red" : "Yellow") +
    " wins! Want to go again?",
    "Game Over",
    JOptionPane.YES_NO_OPTION);
    if (option == JOptionPane.YES_OPTION)
    reset();
    else
    System.exit(0);
    private void reset()
    mCounters= new Color[COLS][ROWS];
    mColor= Color.RED;
    repaint();
    public void paint(Graphics g)
    g.setColor(Color.BLUE);
    g.fillRect(0, 0, getSize().width, getSize().height);
    for (int col= 0; col< COLS; col++) {
    for (int row= 0; row< ROWS; row++) {
    g.setColor(mCounters[col][row] == null ?
    Color.WHITE : mCounters[col][row]);
    g.fillOval(
    GAP+((GAP+SIZE)*col),
    GAP+((GAP+SIZE)*row),
    SIZE, SIZE);
    public Dimension getPreferredSize()
    return new Dimension(
    ((SIZE+GAP)*COLS) +GAP,
    ((SIZE+GAP)*ROWS) +GAP);
    public static void main(String[] argv)
    JFrame frame= new JFrame();
    frame.getContentPane().add(new Connect4());
    frame.pack();
    frame.setResizable(false);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    }

  • Help writing RTS game

    I have been writing a RTS game, and need help. Can anyone tell me how to, when one of my units gets in range of a foe, to attack that foe and destroy it? It should attack the closest target in its weapons range. Here is my code so far...
    Main.java
    package rixor;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.Point;
    import java.awt.Rectangle;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseMotionListener;
    import java.net.URL;
    import javax.swing.ButtonGroup;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JRadioButton;
    import javax.swing.JViewport;
    public class Main extends JFrame implements ActionListener, KeyListener, Runnable, MouseListener,
            MouseMotionListener {
        Image map;
        int mouseX, mouseY;
        int counter = 0;
        Thread game = new Thread(this);
        int mode = 0;
        Point p = new Point(0,0);
        JViewport port = new JViewport();
        //Create my resources
        int resources = 10000;
        int aiResources = 10000;
        unit[] units = new unit[600];
        unit[] aiUnits = new unit[600];
        SoundClip music;
        SoundClip transferScreen;
        //Declare faction variables
        int playerFaction = 0;
        int computerFaction = 0;
        int mouseXa;
        int mouseYa;
        boolean enterGameSetupScreen = false;
        public Main() {
            super("Rixos");
            setSize(1024,768);
            setVisible(true);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            draw drawer = new draw();
            Container content = getContentPane();
            content.add(drawer);
            setContentPane(content);
            addKeyListener(this);
            addMouseListener(this);
            addMouseMotionListener(this);
            game.start();
            music = new SoundClip("music.wav");
            transferScreen = new SoundClip("0000.wav");
            music.setLooping(true);
            this.setResizable(false);
            this.setDefaultLookAndFeelDecorated(true);
            FlowLayout flow = new FlowLayout();
            content.setLayout(flow);
            music.play();
        public class draw extends JPanel {
            public void paintComponent(Graphics g) {
                Image image;
                //Draw the mouse
                if(mode == 0) {
                    g.setColor(Color.black);
                    g.fillRect(0,0,1024,768);
                    g.setColor(Color.white);
                    g.setFont(new Font("Axaxax",Font.PLAIN,40));
                    Toolkit tk = Toolkit.getDefaultToolkit();
                    image = tk.getImage(getURL("splash.png"));
                    g.drawImage(image,0,0,null);
                    g.drawString("Press B to Begin",100,100);
                    g.setColor(Color.GREEN);
                    g.fillRect(mouseX-10,mouseY-29,20,20);
                    repaint();
                if(mode == 1) {
                    g.setColor(Color.black);
                    g.fillRect(0,0,1024,768);
                    Toolkit tk = Toolkit.getDefaultToolkit();
                    image = tk.getImage(getURL("back.png"));
                    g.drawImage(image,0,0,null);
                    image = tk.getImage(getURL("earth.jpg"));
                    g.drawImage(image,700,200,null);
                    image = tk.getImage(getURL("planet.jpg"));
                    g.drawImage(image,690,450,null);
                    g.setFont(new Font("Axaxax",Font.PLAIN,80));
                    g.drawString("Operations Center Menu",40,80);
                    g.setColor(Color.RED);
                    g.fillRect(73,200,300,50);
                    g.fillRect(73,300,300,50);
                    g.setFont(new Font("Axaxax",Font.PLAIN,35));
                    g.setColor(Color.black);
                    g.drawString("About This Game",75,240);
                    g.setColor(Color.GREEN);
                    g.fillRect(70,170,20,20);
                    checkImage(70,270,20,20,mouseX-10,mouseY-29,20,20);
                    g.fillRect(70,270,20,20);
                    g.setColor(Color.black);
                    g.drawString("Start a Game",75,340);
                    g.setColor(Color.GREEN);
                    g.fillRect(mouseX-10,mouseY-29,20,20);
                    repaint();
                if(mode == 4) {
                    //The select map screen
                    g.setColor(Color.green);
                    g.fillRect(0,0,1024,768);
                if(mode == 2) {
                    //The game mode (Under construction)
                    Toolkit tk = Toolkit.getDefaultToolkit();
                    image = tk.getImage(getURL("back.png"));
                    g.drawImage(image,0,0,null);
                    Color transparency = null;
                    if(playerFaction == 0) {
                        //Each faction gets a different HUD Color
                        transparency = new Color(10,10,10,50);
                    g.setColor(transparency);
                    g.fillRect(900,50,100,680);
                    g.fillRect(10,20,990,25);
                    g.setColor(Color.BLACK);
                    g.setFont(new Font("Axaxax",Font.PLAIN,20));
                    if(playerFaction == 0) {
                        //Each faction gets a different TEXT Color
                        g.setColor(Color.BLUE);
                    g.drawString("Resources: "+resources,15,40);
                    if(playerFaction == 0) {
                        g.drawString("Faction: None",215,40);
                    g.setColor(transparency);
                    g.fillRect(mouseX-10,mouseY-29,20,20);
                    g.setColor(Color.RED);
                    g.fillRect(970,22,20,20);
                    g.setColor(transparency);
                    for(int i = 0; i < 600; i++) {
                        if(units.getHealth() > 0) units[i].drawUnit(g,Color.BLUE);
    if(aiUnits[i].getHealth() > 0) aiUnits[i].drawUnit(g,Color.RED);
    g.setColor(Color.RED);
    //Draw the tank option
    image = tk.getImage(getURL("0000.png"));
    g.drawImage(image,900,80,null);
    repaint();
    private URL getURL(String string) {
    URL url = null;
    try {
    url = this.getClass().getResource(string);
    } catch(Exception e) {}
    return url;
    public void checkImage(int i, int i0, int i1, int i2, int i3, int i4, int i5, int i6) {
    Rectangle b = new Rectangle(i,i0,i1,i2);
    Rectangle c = new Rectangle(i3,i4,i5,i6);
    if(b.intersects(c)) {
    enterGameSetupScreen = true;
    public static void main(String[] args) {
    Main i = new Main();
    public void actionPerformed(ActionEvent e) {
    public void keyTyped(KeyEvent e) {
    public void keyPressed(KeyEvent e) {
    if(mode == 0){
    if(e.getKeyCode() == KeyEvent.VK_B) {
    transferScreen.play();
    mode = 1;
    if(mode == 3) {
    if(e.getKeyCode() == KeyEvent.VK_B) {
    mode = 1;
    transferScreen.play();
    if(e.getKeyCode() == KeyEvent.VK_Y) {
    mode = 2;
    //Create player's construction vehicle
    for(int i = 0; i < 600; i++) {
    units[i] = new unit(0,0,0,0,0,0,0);
    aiUnits[i] = new unit(0,0,0,0,0,0,0);
    units[0].setController(1);
    units[0].setType(1);
    units[0].setX(500);
    units[0].setY(680);
    units[0].setHealth(80000);
    units[0].setSpeed(0);
    aiUnits[0].setController(2);
    aiUnits[0].setType(1);
    aiUnits[0].setX(500);
    aiUnits[0].setY(30);
    aiUnits[0].setHealth(80000);
    aiUnits[0].setSpeed(0);
    //TODO: ADD AI UNITS
    transferScreen.play();
    if(mode == 2) {
    for(int i = 0; i < 600; i++) {
    if(e.getKeyCode() == KeyEvent.VK_DELETE) {
    if(units[i].isSelected()) {
    if(units[i].getType() == 2) { resources = resources + 600; }
    units[i].setType(0);
    public void keyReleased(KeyEvent e) {
    public void run() {
    while(game == Thread.currentThread()) {
    if(mode == 2) {
    if(counter < 90) {
    //Count the time for a resource addition
    counter = counter + 1;
    if(counter == 90) {
    //Allot resources to the player
    resources = resources + 5;
    aiResources = resources + 5;
    counter = 0;
    moveCheck();
    if(mode == 1) {
    counter = 0;
    try {
    Thread.sleep(20);
    } catch(Exception e) {}
    repaint();
    public void mouseClicked(MouseEvent e) {
    public void mousePressed(MouseEvent e) {
    if(mode == 1) {
    if(e.getX() > 70) {
    if(e.getX() < 120) {
    if(e.getY() > 200) {
    if(e.getY() < 500) {
    mode = 3;
    transferScreen.play();
    if(enterGameSetupScreen) {
    mode = 4;
    enterGameSetupScreen = false;
    if(mode == 2) {
    //Does in-game mouse detection
    Rectangle Quit = new Rectangle(970,22,20,20);
    Rectangle mouseTest = new Rectangle(mouseX-10,mouseY-29,20,20);
    if(Quit.intersects(mouseTest)) {
    transferScreen.play();
    mode = 1;
    aiResources = 10000;
    resources = 10000;
    for(int i = 0; i < 600; i++) {
    //Deletes the units
    try {
    units[i].setController(0);
    units[i].setType(0);
    aiUnits[i].setController(0);
    aiUnits[i].setType(0);
    } catch(Exception ex) {}
    //Creates a new Human tank if player is human
    if(mouseTest.intersects((new Rectangle(900,80,50,50)))) {
    int offset = 0;
    boolean found = false;
    if(playerFaction == 0) {
    if(resources > 700) {
    resources = resources - 700;
    for(int i = 0; i < 600; i++) {
    if(found == false) {
    if(units[i].getType() == 0) {
    offset = offset - 10;
    found = true;
    units[i].setType(2);
    units[i].setFirepower(800);
    units[i].setX(550+offset);
    units[i].setY(650+offset);
    units[i].setSpeed(1);
    units[i].setHealth(800);
    units[i].setController(1);
    for(int i = 0; i < 600; i++) {
    if(mouseTest.intersects(units[i].getBounds())) {
    units[i].setSelected(true);
    if(!mouseTest.intersects(units[i].getBounds())) {
    units[i].setSelected(false);
    public void mouseReleased(MouseEvent e) {
    public void mouseEntered(MouseEvent e) {
    public void mouseExited(MouseEvent e) {
    public void mouseDragged(MouseEvent e) {
    for(int i = 0; i < units.length; i++) {
    if(units[i].isSelected()) {
    //The moving!
    if(units[i].getType() == 2) {
    units[i].setState(3);
    if(units[i].isSelected()) {
    //The moving!
    if(units[i].getType() == 2) {
    units[i].setState(0);
    units[i].setDistance(new Point(e.getX(),e.getY()));
    units[i].setTraveled(0);
    public void mouseMoved(MouseEvent e) {
    //Moves our mouse collision sensor accross screen
    mouseX = e.getX();
    mouseY = e.getY();
    private void moveCheck() {
    if(mode == 2) {
    for(int i = 0; i < units.length; i++) {
    if(units[i].getDistance() != new Point(units[i].getX(),units[i].getY())) {
    if(units[i].getX() > units[i].getDistance().getX()) {
    units[i].setX(units[i].getX() - units[i].getSpeed());
    if(units[i].getX() < units[i].getDistance().getX()) {
    units[i].setX(units[i].getX() + units[i].getSpeed());
    if(units[i].getY() > units[i].getDistance().getY()) {
    units[i].setY(units[i].getY() - units[i].getSpeed());
    if(units[i].getY() < units[i].getDistance().getY()) {
    units[i].setY(units[i].getY() + units[i].getSpeed());
    And here is my unit.java file...
    package rixor;
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.Point;
    import java.awt.Rectangle;
    import java.awt.Toolkit;
    import java.net.URL;
    public class unit {
        //This class controlls the units and structures and allows them to be declared.
        int type = 0;
        int controller = 0;
        //1 is player, 2 is computer
        int health = 0;
        int firepower = 0;
        int speed = 0;
        int x;
        int y;
        int traveled;
        Point distance = new Point(x,y);
        int sizeX;;
        int sizeY;
        int state = 0;
        //0 is being places, 1 is placed.
        boolean selected = false;
        public unit(int type, int controller, int health, int firepower, int speed, int x, int y) {
            this.type = type;
            this.controller = controller;
            this.health = health;
            this.firepower = firepower;
            this.speed = speed;
            this.x = x;
            this.y = y;
        public int getHealth() {
            return health;
        public int getType() {
            return type;
        public int getController() {
            return controller;
        public int getSpeed() {
            return speed;
        public int getFirepower() {
            return firepower;
        public int getX() {
            return x;
        public int getY() {
            return y;
        public void setX(int x) {
            this.x = x;
        public void setY(int y) {
            this.y = y;
        public void setHealth(int health) {
            this.health = health;
        public void setFirepower(int firepower) {
            this.firepower = firepower;
        public void setController(int controller) {
            this.controller = controller;
        public void setSpeed(int speed) {
            this.speed = speed;
        public void setType(int type) {
            this.type = type;
        public void setState(int state) {
            this.state = state;
        public int getState() {
            return state;
        public void drawUnit(Graphics g, Color color) {
            Image image;
            Toolkit tk = Toolkit.getDefaultToolkit();
            if(type == 1) {
                sizeX = 30;
                sizeY = 30;
                //Draw A Construction Vehicle
                g.setColor(color);
                g.fillRect(x,y,sizeX,sizeY);
                g.setFont(new Font("Axaxax",Font.PLAIN,36));
                g.setColor(Color.green);
                g.drawString("C",x+5,y+30);
                if(selected == true) {
                    g.setColor(Color.PINK);
                    g.drawRect(x,y,sizeX,sizeY);
            if(type == 2) {
                sizeX = 40;
                sizeY = 40;
                image = tk.getImage(getURL("0000.png"));
                g.drawImage(image,x,y,null);
                if(selected == true) {
                    g.setColor(Color.PINK);
                    g.drawRect(x,y,50,50);
        private URL getURL(String string) {
            URL url = null;
            try {
                url = this.getClass().getResource(string);
            } catch(Exception e) {}
            return url;
        public Rectangle getBounds() {
            Rectangle bounds = new Rectangle(x,y,sizeX,sizeY);
            return bounds;
        public void setSelected(boolean selected) {
            this.selected = selected;
        public boolean isSelected() {
            return selected;
        public void setTraveled(int traveled) {
            this.traveled = traveled;
        public void setDistance(Point distance) {
            this.distance = distance;
        public int getTraveled() {
            return traveled;
        public Point getDistance() {
            return distance;
    //TODO: Implement collision testing systemThat's all you should need to help. Thanks in advance.

    pardon me jwenting,
    But you cannot triangulate with 2 (x,y) pairs.
    TRI-angulation involves 3 coordinates.
    The method our peer needs is a simple distance formula:
    dist = sqrt( ( x1-x2 )^2 + ( y1-y2 )^2 )
    Now...
    All you need for range detection is a little "for-each loop"
    Place something like this in your unit class's update method:
    for ( each unit in unit list )
       if ( unit.isNotMine() && unit.isWithinMyRange() )
          this.attack( unit );
    }The attack( Unit u ) function should do as follows:
    double dx = this.getX()-u.getX(); //you may need to flip these i did not test
    double dy = this.getY()-u.getY();
    double angle = Math.atan2(dy,dx);
    // here define what "attacking" even means???
    if ( this.isMelee() )
       this.x += Math.cos(angle)*this.getSpeed(); //this will move your unit
       this.y += Math.sin(angle)*this.getSpeed();
       if ( this.getDistance( u ) <= this.meleeAttackRange() )
          this.causeDamage( u );
    else
       load++;
       if ( load>this.loadingTime() )
          this.shootToward( unit );
    }Ok, get started with that...
    If that doesn't help then we cant help you!!
    Show us what you're trying to do, then tell us what errors.
    Dont just post all your code and say "fix-me".
    Good luck though, hope this gave you some ideas.
    Message was edited by:
    ArikArikArik

  • Help retrieving a game file

    Hi it's me katzmac and I have recently gotten an old imac g3 i think? from my dad and it has a shanghai game on it My question is how do I take this game from one imac to load on a mac laptop? this is extremely important to me and I have windows knowledge aplenty but am mac illiterate so any help would be greatly appreciated? thanks sincerely,,,,,,katz

    Texas mac man thanks, I am currently waiting to get my imac back from my brother then I will tell you the exact model if I can figure it out as I looked at the link but its all confusing to me and without my imac here I cant get that info just yet. It's blueberry in color if that helps and has a drawer in the front and I believe its operating system is 09 it will be going on a mac laptop and thats all I know so far thanks again for any help that can be shed on this topic its greatly appreciated.......katzmac

Maybe you are looking for