Trying to write Connect Four

I'm fairly new to java. Actually, I'm not that new but I forgot everything I ever learned about applets. I'm trying to write Connect Four but I'm having trouble figuring out what parts of my code are supposed to do. From what I understand, start(), starts the execution of my applet. I'm not sure what code I should put in there. I basically want it to say IF the game is not over, keep playing. I'm not entirely sure what playing is. I think I need a thread somewhere thats constantly checking if the game is over but I'm not sure how to code that. Thanks for any help.
Here's what I have so far:
import java.applet.*;
import java.awt.*;
import java.util.*;
public class GameDisplay extends Applet implements MouseListener
                 ArrayList pieces;
     Image board;
     Toolkit tool;
     Player red,blue;
     Game connect;
     String turn;
     boolean gameOver;
     public void init()
          pieces = new ArrayList();
          tool = Toolkit.getDefaultToolkit();
          board = tool.getImage(fileName);
          red = new Player("red");
          blue = new Player("blue");
          gameOver = false;
          turn = "red";
          connect = new Game();
          addMouseListener(this);
     public void start()
          while(!gameOver)
               //Do something
                stop()
     public void stop()
     public void destroy()
     public void mouseClicked (MouseEvent me)
          Location loc = new Location(me.getX(),me.getY());
          if(loc.isValid())
               if(turn.equals("red"))
                    Piece p = new Piece("red",me.getX(),me.getY());
                    pieces.add(p);
               else if(turn.equals("blue"))
                    Piece p = new Piece("blue",me.getX(),me.getY());
                    pieces.add(p);
                 public void mouseEntered (MouseEvent me) {}
                 public void mousePressed (MouseEvent me) {}
                 public void mouseReleased (MouseEvent me) {}
                 public void mouseExited (MouseEvent me) {}
     public void update()
          paint(g);
     public void paint(Graphics g)
          for(int i=0;i<pieces.size();i++)
               Piece p = pieces.get(i)
               g.drawImage(p.getName(), p.getX(), p.getY(),null);
               g.drawImage(board, 0, 0, null);
}

Ok, I added a couple more things. I'm planning on having a board object which will be a matrix of Piece objects. I think the reason that this was confusing me, was a couple of years ago I tried to right a Monopoly game and I don't remember how I did it, I know I used applets but I also had a thread going and I don't remember why I needed it.
import java.applet.*;
import java.awt.*;
import java.util.*;
public class GameDisplay extends Applet implements MouseListener
                 ArrayList pieces;
     Image board;
     Toolkit tool;
     Player red,blue;
     Game connect;
     String turn,message;
     public void init()
          pieces = new ArrayList();
          tool = Toolkit.getDefaultToolkit();
          board = tool.getImage(fileName);
          red = new Player("red");
          blue = new Player("blue");
          turn = "red";
          message = "";
          connect = new Game();
          addMouseListener(this);
     public void mouseClicked (MouseEvent me)
          Location loc = new Location(me.getX(),me.getY());
          if(loc.isValid())
               if(turn.equals("red"))
                    Piece p = new Piece("red",me.getX(),me.getY());
                    pieces.add(p);
                    update();
               else if(turn.equals("blue"))
                    Piece p = new Piece("blue",me.getX(),me.getY());
                    pieces.add(p);
                    update();
          if(connect.gameOver())//Some recursive check or something to see if game is over.
               message = "Game Over!";
               update();
                 public void mouseEntered (MouseEvent me) {}
                 public void mousePressed (MouseEvent me) {}
                 public void mouseReleased (MouseEvent me) {}
                 public void mouseExited (MouseEvent me) {}
     public void update()
          paint(g);
     public void paint(Graphics g)
          for(int i=0;i<pieces.size();i++)
               Piece p = pieces.get(i)
               g.drawImage(p.getName(), p.getX(), p.getY(),null);
               g.drawImage(board, 0, 0, null);
          if(connect.gameOver())
               g.drawString(message,0,0);
               //Wait a certain amount of time
               init(); //Reset game
}

Similar Messages

  • Help with connect four

    im trying to write a connect four project but im having a little trouble.
    import java.util.Scanner;
    public class Main{
              Scanner scan = new Scanner(System.in);
         int grid[][];
         int currentPlayer;
         int rows = 6;
         int columns = 7;
         public Main(){
              grid = new int[7][6];
              for(int i = 0; i <7; i++){
                   for(int k = 0; k <6; k++){
                        grid[i][k] = 0;
              currentPlayer = 1;
         for(int j = 0; j <=7; j++){
              for(int n = 0; n < 6; n++){
                   if(grid[j][n] == 0){
                        getNextMove();
                        showBoard();
         public void showBoard(){
              System.out.print("+-");
                for ( int j = 0; j < 7; j++ )
                    System.out.print((j+1) + "-");
                System.out.println("+");
                for (int i = 6-1; i >= 0; i-- )
                    System.out.print("| ");
                    for ( int j = 0; j < 7; j++ )
                        char c = ' ';
                        switch ( grid[j] )
    case 0 : c = ' '; break;
    case 1 : c = 'x'; break;
    case 2 : c = 'o'; break;
    System.out.print(c + " ");
    System.out.println("|");
    System.out.print("+-");
    for ( int j = 0; j < 7; j++ )
    System.out.print("--");
    System.out.println("+");
         public void getNextMove(){
         System.out.println("Player " + currentPlayer + " Enter the column to place checker in.");
         int column = scan.nextInt()-1;
         int row =0;     
    if(grid[column][row] == 0){
         if(currentPlayer ==1 && grid[column][row] == 0){
              if(row > 1){
                   if(grid[column][row-1] == 0){
                        grid[column][row-1] = 1;
                   grid[column][row] = 1 ;
                   currentPlayer = 2;
              else{
                   if(currentPlayer ==2 && grid[column][row] == 0){
                   grid[column][row] = 2;
                   currentPlayer = 1;
         else{
              if(row > 6){
                   System.out.println("That column is full, enter another column");
                   column = scan.nextInt()-1;
                   row = 0;
         else{
              if(grid[column][row] != 0){
                   grid[column][row + 1] = currentPlayer;
                   if(currentPlayer ==1){
                        currentPlayer =2;
                        else{
                             if(currentPlayer ==2){
                                  currentPlayer = 1;                     }
    public static void main(String[] args) {
    Main game = new Main();
    so far this program creates the grid or play chart and it allows the user to add checkers only up to the first two rows, it can fill in all the columns but never gets past 2 rows up and i cant figure out why, ive tried a few different ways to try to get it to work but im having trouble figuring it out, if anyone can give me a hint or some help that would be great.
    (and i kno the porgram isnt the nicest but thats the way it has to be so if you can comment then just comment on the code i have and not what you would do to write this program cuz i kno there are plenty of easier ways) thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    The problem lies in your getNextMove method, as I'm sure you've guessed. Let's take a step back and look at the task. You want to drop a checker into the board. It should occupy the first open slot, yes? But to find out which one is the first open slot, you will need to look at each slot in turn to see if it's full. That sounds to me like a loop:
    * Start with a current row of zero.
    * As long as the current row has a checker in it, increment the row number.
    * Put a checker in the current row at the specified column.
    Does that make sense? I would suggest you write a method called "findFirstRowInColumn(int columnNumber)" that returns the row number of the row where the next checker would go. Then you can call that method whenever you need to figure out where to put a checker. Feel free to post your implementation of that method here if you want us to look at it. :)

  • NotSerializable error while trying to write arraylist

    I am getting a NotSerializable error while trying to write an arraylist to a file.
    Here's the part of the code causing problem
    File temp = fileOpenerAndSaver.getSelectedFile(); // fileOpenerAndSaver is a JFileChooser object which has been created and initialized and was already used to select a file with
    currentWorkingFile = new File (temp.getAbsolutePath() + ".gd");      // currentWorking file is a file object
    try
         ObjectOutput output = new ObjectOutputStream (new BufferedOutputStream(new FileOutputStream(currentWorkingFile)));
         output.writeObject(nodeList); // <-- This is the line causing problem (it is line 1475 on which exception is thrown)
         output.writeObject(edgeList);
         output.writeObject(nodesWithSelfLoop);
         output.writeObject(nextId);
         output.writeUTF(currentMessage);
         output.close();
    catch (Exception e2)
         JOptionPane.showMessageDialog (graphDrawer, "Unknown error writing.", "Error", JOptionPane.ERROR_MESSAGE);
         e2.printStackTrace();
    } As far as what nodeList is -- it's an arraylist of my own class Node which has been serialized and any object used inside the class has been serialized as well.
    Here is the declaration of nodeList:
         private ArrayList <Node> nodeList; // ArrayList to hold a list all the nodesLet me show you whats inside the node class:
    private class Node implements Serializable
         private static final long serialVersionUID = -4625153386839971250L;
         /*  edgeForThisNodeList holds all the edges that are between this node and another node
          *  nodesConnected holds all the nodes that are connected (adjacent) to this node
          *  p holds the top left corner coordinate of this node.  The centre. of this node is at (p.x + 5, p.y + 5)
          *  hasSelfLoop holds whether this node has a self loop.
          *  **NOTE**: ONLY ONE SELF LOOP IS ALLOWED FOR A NODE.
         ArrayList <Edge> edgeForThisNodeList = new ArrayList <Edge> ();
         ArrayList <Node> nodesConnected = new ArrayList <Node> ();
         Point p;
         boolean hasSelfLoop = false;
         int index = -1;
         BigInteger id;
                     ... some methods following this....
    }Here is the edge class
    private class Edge implements Serializable
         private static final long serialVersionUID = -72868914829743947L;
         Node p1, p2; // The two nodes
         Line2D line;
          * Constructor:
          * Assigns nodes provided as appropriate.
          * Also calls the addEdge method on each of the two nodes, and passes
          * "this" edge and the other node to the nodes, so that
          * this edge and the other node can be added to the
          * data of the node.
         public Edge (Node p1, Node p2)
              this.p1 = p1;
              this.p2 = p2;
              line = new Line2D.Float(p1.p.x+5,p1.p.y+5,p2.p.x+5,p2.p.y+5);
              p1.addEdge(this, p2, true);
              p2.addEdge(this, p1, false);
         }Here is the error I am getting:
    java.io.NotSerializableException: javax.swing.plaf.metal.MetalFileChooserUI
         at java.io.ObjectOutputStream.writeObject0(Unknown Source)
         at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
         at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
         at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
         at java.io.ObjectOutputStream.writeObject0(Unknown Source)
         at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
         at java.io.ObjectOutputStream.writeObject0(Unknown Source)
         at java.io.ObjectOutputStream.writeObject(Unknown Source)
         at MyPanel.save(MyPanel.java:1475)
         at GraphDrawer.actionPerformed(GraphDrawer.java:243)
         I inentionally did not write the whole error stack because it was way too long and I ran out of characters. But line 1475 is where I do the writeObject call. I also goet some weird not serialized exceptions before on some other classes that are not being written to the file or are not part of the object that I am writing. I serialized those classes and now it's this unknown object that's causing problems.
    Edit: The problem may be due to the JFileChooser I am using to select the file as it is a non-serializable object. But I am not trying to write it to the file and in fact am just writing the arrayLists and BigInteger as objects to the file.
    Edited by: Cricket_struck on Dec 21, 2009 1:25 PM
    Edited by: Cricket_struck on Dec 21, 2009 1:32 PM
    Edited by: Cricket_struck on Dec 21, 2009 2:16 PM

    java.io.NotSerializableException: javax.swing.plaf.metal.MetalFileChooserUIThat's a Swing component and it is clearly related to the JFileChooser.
    I also get some weird not serialized exceptions before on some other classes that are not being written to the file or are not part of the object that I am writing.That's a contradiction in terms. If you get NotSerialzableException it means the objects are being written. So they are reachable from the objects you're writing.
    Edit: The problem may be due to the JFileChooser I am using to select the file as it is a non-serializable object.JFileChooser implements Serializable, but you're right, you shouldn't try to serialize it. But clearly this is the current problem. Somewhere you have a reference to it reachable via the object(s) you are serializing.
    I suspect that Node and Edge inner classes and that you aren't aware that inner classes contain a hidden reference to their containing class. The solution for serializaition purposes is to make them static nested classes, or outer classes.

  • TS1424 my i phone write connect with itunes

    i write my password wrong more times and write connect with itunes

    What happens when you try to pair the devices?
    Are you able to put the headset into pairing mode?
    Does the iPhone not detect the headset at all?
    Have you tried turning bluetooth off and back on for the iPhone?
    Have you tried resetting or restarting the iPhone?

  • Trying to write an SQL import script

    Hello All,
    I am trying to write a bulk importer for data for my clients and I am just about there. However I am running into a problem updating records in a second table.
    I want to do all this through the SQL Server for resource purposes.
    The SQL statement will go through the entire temp table (users to be added or updated) and compare it to the main existing table. First it will compare records and determine who are exactly the same (no changes) and then delete those records out of the temp table. Now it will find the records that are in the table (by employee ID), but have changes in their profiles (name, number, etc.).
    This is my problem:
    When I compare the phonenumbers in a separate table, which are connected by a sub_id. Example
    Main Table: (Fields) sub_id, fname, lname, address, groups, subgroups, etc.
    Phonenumbers Table: sub_id, account_id, sub_user_number, active
    Right now, I am performing update statements:
    -- Update sub_user_number
    print('Update sub_user_number');
    print('  -sub_user_number3');
    UPDATE WENS..SUBSCRIPTION
    SET sub_user_number = i.sub_user_number3
      FROM WENS_IMPORT..IMPORT_INSPIRON i INNER JOIN WENS..SUBSCRIPTION s
       ON i.misc1 = s.misc1
      LEFT JOIN WENS..ACCOUNT_USER_GROUPS g
       ON g.sub_id = s.sub_id
      WHERE s.account_id = @account_id
      AND isnull(i.sub_user_number, '') <> isnull(s.sub_user_number, '')
      AND g.group_id IN (@group_id)
    The problem is that if I have three numbers, it updates all three numbers with the same number.
    Ideally what I would like to do is completely delete the numbers and then re-enter them. For example:
    Perform a DELETE of all numbers out of PHONENUMBERS table where maintable.sub_id = temptable.sub_id
    LOOP through numbers found in temptable
    INSERT new number into PHONENUMBERS (sub_id, account_id, active, sub_user_number)
    END LOOP
    Therefore at the end of the loop, we will have entered three numbers (two that were originally in there and one that is new)
    Could someone help me with the SQL syntax that will work in SQL Server Query analyzer?
    Thank you VERY much for anything you all can do.

    LOOP through numbers found in temptable
    I have only skimmed this thread, but I would say do not loop unless it is truly needed.  Databases are designed to work best with "sets" of information. So it is usually more efficient to process a group of records than one record at a time.
    What I usually do with imports is run a series of bulk updates on my #temp table(s) to identify which items are "new" which ones are "changed". When finished I can easily JOIN to the base tables and do a single UPDATE for changed records and INSERT for new records.  Usually a lot more efficient than looping one record at a time.
    I want to do all this through the SQL Server for resource
    purposes.
    BTW: Not to ignore your question, but database questions are usually best answered in a database forum (in your case MS SQL).  Because once you get the information into the #temp table, it is strictly sql from there and any database guru could assist. They do not have to know anything about CF ;-)
    Message was edited by: -==cfSearching==-

  • I had an iPhone 4 and recently upgraded to iphone5 now iCloud will not back up new phone.  Under iCloud it shows 2 iPhones and my iPad. Is it trying to write new phone over the old one?  What should I do?  I a, afraid I might lose everything messing with

    I had an iPhone 4 and recently upgraded to iphone5 now iCloud will not back up new phone.  Under iCloud it shows 2 iPhones and my iPad. Is it trying to write new phone over the old one?  What should I do?  I am afraid I might lose everything messing with

    I see.  If you go to Settings>General>About>Name, that is the current name of your phone.  The backup bearing that name should be the more recent one, and therefore the one you want to keep.  I would delete the other one (presumably the one set up by Best Buy under your real name, assuming you changed it later), then see if that gives you enough space to back up again.
    If it still reporting insufficient storage, use this guide: http://support.apple.com/kb/HT4847 to try to determine what's taking up all your room.  In them meantime, you can perform a manual backup on your computer so your have a current one while you're troubleshooting this.  To do so, connect your phone to iTunes, then right-click on the name of your phone on the left side and select Back Up.

  • My iPhone 4 no longer connects to my car or alarm clock after a recent sync to my computer.  The message at I get when trying to. Connect is "this accessory is not optimized for the device" or something like that.  Anyone know how to fix this?

    My iPhone 4 no longer connects to my car or alarm clock after a recent sync to my computer.  The message at I get when trying to. Connect is "this accessory is not optimized for the device" or something like that.  Anyone know how to fix this?

    Hello there philp_69,
    If I understand correctly it sounds like your phone hasnt been recognized in iTunes on your PC since the last couple of updates. I would use the troubleshooting in the following article which will walk you through the steps one by one. 
    iPhone, iPad, or iPod touch not recognized in iTunes for Windows
    Thank you for using Apple Support Communities.
    All the very best,
    Sterling

  • Urgent Help Required for Connect Four Game

    Hi all,
    I am a student and I have a project due 20th of this month, I mean May 20, 2007 after 8 days. The project is about creating a Connect Four Game. I have found some code examples on the internet which helped me little bit. But there are lot of problems I am facing developing the whole game. I have drawn the Board and the two players can play. The players numbers can fill the board, but I have problem implementing the winner for the game. I need to implement the hasWon() method for Horizontal win, Vertical win and Diagonal win. I also found some code examples on the net but I was unable to make it working. I have 5 classes and one interface which I m implementing. The main problem is how to implement the hasWon() method in the PlayGame class below with Horizontal, vertical and diagonal moves.
    Sorry there is so much code.
    This the interface I must implement, but now I am only implementing the int move() of this interface. I will implement the rest later after solving the winner problem with your help.
    Interface code..............
    interface Player {
    void init (Boolean color);
    String name ();
    int move ();
    void inform (int i);
    Player1 class......................
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    public class Player1 implements Player
    public Player1()
    public int move()
    Scanner scan = new Scanner(System.in);
    // BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in));
    int player1;
    System.out.println ("What is your Number, player 1?");
    player1 = scan.nextInt();
    System.out.println ("Hey number"+player1+" are you prepared to CONNECT FOUR");
    System.out.println();
    return player1;
    //Player.move();
    //return player1;
    }//end move method
    public void init (Boolean color)
    public void inform (int i)
    public String name()
    return "Koonda";
    }//end player1 class
    Player2 class...........................
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    public class Player2 implements Player
    public int move()
    //int cup0,cup1,cup2,cup3,cup4,cup5,cup6;
    // cup0=5;cup1=5;cup2=5;cup3=5;cup4=5;cup5=5;cup6=5;
    //int num1, num2;
    Scanner scan = new Scanner(System.in);
    // BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in));
    int player2;
    System.out.println ("What is your Number, player 2?");
    player2 = scan.nextInt();
    System.out.println ("Hey "+player2+" are you prepared to CONNECT FOUR");
    System.out.println();
    //return player1;
    return player2;
    }//end move method
    public void init (Boolean color)
    public void inform (int i)
    public String name()
    return "malook";
    }//end player1 class
    PlayGame class which contains all the functionality.........................................................
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    public class PlayGame
    //Player player1;
    //Player player2;
    int [][]ConnectFourArray;
    boolean status;
    int winner;
         int player1;
         int player2;
         public PlayGame()
              //this.player1 = player1;
              //this.player2 = player2;
         public void StartGame()
         try{
         // int X = 0, Y = 0;
         //int value;
         int cup0,cup1,cup2,cup3,cup4,cup5,cup6;
    cup0=5;cup1=5;cup2=5;cup3=5;cup4=5;cup5=5;cup6=5;
         int[][] ConnectFourArray = new int[6][7];
         int num1, num2;
         for(int limit=21;limit!=0;limit--)
    BufferedReader selecter = new BufferedReader (new InputStreamReader(System.in));
    String column1;
    System.out.println();
    for ( int row=0; row < ConnectFourArray.length; row++ ){
    System.out.print("Row " + row + ": ");
    for ( int col=0; col < ConnectFourArray[row].length; col++ )
    System.out.print( ConnectFourArray[row][col] + " ");
    System.out.println();
    System.out.println();
    System.out.println ("Please Select a column of 0 through 6 ");
    column1 = selecter.readLine();
    num1= Integer.parseInt(column1);
    System.out.println();
    if (num1==0){
    ConnectFourArray[cup0][0]=1;
    cup0=cup0-1;
    else if (num1==1){
    ConnectFourArray[cup1][1]=1;
    cup1=cup1-1;
    else if (num1==2){
    ConnectFourArray[cup2][2]=1;
    cup2=cup2-1;
    else if (num1==3){
    ConnectFourArray[cup3][3]=1;
    cup3=cup3-1;
    else if (num1==4){
    ConnectFourArray[cup4][4]=1;
    cup4=cup4-1;
    else if (num1==5){
    ConnectFourArray[cup5][5]=1;
    cup5=cup5-1;
    else if (num1==6){
    ConnectFourArray[cup6][6]=1;
    cup6=cup6-1;
    System.out.println();
    BufferedReader selecter2 = new BufferedReader (new InputStreamReader(System.in));
    String column2;
    System.out.println();
    for ( int row=0; row < ConnectFourArray.length; row++ ){
    System.out.print("Row " + row + ": ");
    for ( int col=0; col < ConnectFourArray[row].length; col++ )
    System.out.print( ConnectFourArray[row][col] + " ");
    System.out.println();
    System.out.println();
    System.out.println ("Please Select a column of 0 through 6 ");
    column1 = selecter.readLine();
    num1= Integer.parseInt(column1);
    System.out.println();
    if (num1==0){
    ConnectFourArray[cup0][0]=2;
    cup0=cup0-1;
    else if (num1==1){
    ConnectFourArray[cup1][1]=2;
    cup1=cup1-1;
    else if (num1==2){
    ConnectFourArray[cup2][2]=2;
    cup2=cup2-1;
    else if (num1==3){
    ConnectFourArray[cup3][3]=2;
    cup3=cup3-1;
    else if (num1==4){
    ConnectFourArray[cup4][4]=2;
    cup4=cup4-1;
    else if (num1==5){
    ConnectFourArray[cup5][5]=2;
    cup5=cup5-1;
    else if (num1==6){
    ConnectFourArray[cup6][6]=2;
    cup6=cup6-1;
    System.out.println();
    System.out.println();
    catch (Exception E){
    System.out.println("Error with input");
    System.out.println("Would you like to play again");
    try{
    String value;
    BufferedReader reader = new BufferedReader (new InputStreamReader(System.in));
    // Scanner scan = new Scanner(System.in);
    System.out.println("Enter yes to play or no to quit");
    // value = scan.nextLine();
    // String value2;
    value = reader.readLine();
    //value2 = reader.readLine();
    if (value.equals("yes"))
    System.out.println("Start again");
    StartGame(); // calling the StartGame method to play a game once more
    else if (value.equals("no"))
    System.out.println("No more games to play");
    // System.exit(0);
    else
    System.exit(0);
    System.out.println();
    catch (Exception e){
    System.out.println("Error with input");
    finally
    System.out.println(" playing done");
    //StartGame();
    //check for horizontal win
    public int hasWon()
    int status = 0;
    for (int row=0; row<6; row++)
    for (int col=0; col<4; col++)
    if (ConnectFourArray[col][row] != 0 &&
    ConnectFourArray[col][row] == ConnectFourArray[col+1][row] &&
    ConnectFourArray[col][row] == ConnectFourArray[col+2][row] &&
    ConnectFourArray[col][row] == ConnectFourArray[col+3][row])
    //status = true;//int winner;
    if(status == player1)
    System.out.println("Player 1 is the winner");
    else if(status == player2)
    System.out.println("Player 2 is the winner" );
    }//end inner for loop
    }// end outer for loop
    } // end method Winner
    return status;
    }//end class
    ClassConnectFour which designs the board........................
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    public class ClassConnectFour
         //Player player1;
         //Player player2;
         public ClassConnectFour()
              //this.player1 = player1;
    public void DrawBoard()
    int[][] ConnectFourArray = new int[6][7] ;
    for ( int row=0; row < ConnectFourArray.length; row++ ){
    System.out.print("Row " + row + ": ");
    for ( int col=0; col < ConnectFourArray[row].length; col++ )
    System.out.print( ConnectFourArray[row][col] + " ");
    System.out.println();
    System.out.println();
    }//end class
    TestConnetFour class which uses most of the above class..................
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    public class TestConnectFour
    public static void main(String[] args)
    ClassConnectFour cf = new ClassConnectFour();
    cf.DrawBoard();
    Player1 player1 = new Player1();
    Player2 player2 = new Player2();
    player1.move();
    player2.move();
    System.out.println("Number 1 belongs to player " + player1.name());
    System.out.println("Number 2 belongs to player " + player2.name());
    PlayGame pg = new PlayGame();
    pg.StartGame();
    pg.hasWon();
    //pg.Play();
    //System.out.println(player.name());
    //System.out.println(player2.name());
    }// end main
    }//end class
    I am sorry for all this junk code but I only understand it this way. Your urgent help is required. Looking forward to your reply.
    Thanks in advance.
    Koonda
    //

    Hi,
    Thanks for your help but I really don't understand the table lookup algorithm. Could you please send me some code to implement that.
    I will send you the formatted code as well
    Thanks for your help.
    looking forward to your reply.
    Koonda
    Hi all,
    I am a student and I have a project due 20th of this month, I mean May 20, 2007 after 8 days. The project is about creating a Connect Four Game. I have found some code examples on the internet which helped me little bit. But there are lot of problems I am facing developing the whole game. I have drawn the Board and the two players can play. The players numbers can fill the board, but I have problem implementing the winner for the game. I need to implement the hasWon() method for Horizontal win, Vertical win and Diagonal win. I also found some code examples on the net but I was unable to make it working. I have 5 classes and one interface which I m implementing. The main problem is how to implement the hasWon() method in the PlayGame class below with Horizontal, vertical and diagonal moves.
    Sorry there is so much code.
    This the interface I must implement, but now I am only implementing the int move() of this interface. I will implement the rest later after solving the winner problem with your help.
    Interface code..............
    interface Player {
    void init (Boolean color);
    String name ();
    int move ();
    void inform (int i);
    Player1 class......................
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    public class Player1 implements Player
    public Player1()
    public int move()
    Scanner scan = new Scanner(System.in);
    // BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in));
    int player1;
    System.out.println ("What is your Number, player 1?");
    player1 = scan.nextInt();
    System.out.println ("Hey number"+player1+" are you prepared to CONNECT FOUR");
    System.out.println();
    return player1;
    //Player.move();
    //return player1;
    }//end move method
    public void init (Boolean color)
    public void inform (int i)
    public String name()
    return "Koonda";
    }//end player1 class
    Player2 class...........................
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    public class Player2 implements Player
    public int move()
    //int cup0,cup1,cup2,cup3,cup4,cup5,cup6;
    // cup0=5;cup1=5;cup2=5;cup3=5;cup4=5;cup5=5;cup6=5;
    //int num1, num2;
    Scanner scan = new Scanner(System.in);
    // BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in));
    int player2;
    System.out.println ("What is your Number, player 2?");
    player2 = scan.nextInt();
    System.out.println ("Hey "+player2+" are you prepared to CONNECT FOUR");
    System.out.println();
    //return player1;
    return player2;
    }//end move method
    public void init (Boolean color)
    public void inform (int i)
    public String name()
    return "malook";
    }//end player1 class
    PlayGame class which contains all the functionality.........................................................
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    public class PlayGame
    //Player player1;
    //Player player2;
    int [][]ConnectFourArray;
    boolean status;
    int winner;
    int player1;
    int player2;
    public PlayGame()
    //this.player1 = player1;
    //this.player2 = player2;
    public void StartGame()
    try{
    // int X = 0, Y = 0;
    //int value;
    int cup0,cup1,cup2,cup3,cup4,cup5,cup6;
    cup0=5;cup1=5;cup2=5;cup3=5;cup4=5;cup5=5;cup6=5;
    int[][] ConnectFourArray = new int[6][7];
    int num1, num2;
    for(int limit=21;limit!=0;limit--)
    BufferedReader selecter = new BufferedReader (new InputStreamReader(System.in));
    String column1;
    System.out.println();
    for ( int row=0; row < ConnectFourArray.length; row++ ){
    System.out.print("Row " + row + ": ");
    for ( int col=0; col < ConnectFourArray[row].length; col++ )
    System.out.print( ConnectFourArray[row][col] + " ");
    System.out.println();
    System.out.println();
    System.out.println ("Please Select a column of 0 through 6 ");
    column1 = selecter.readLine();
    num1= Integer.parseInt(column1);
    System.out.println();
    if (num1==0){
    ConnectFourArray[cup0][0]=1;
    cup0=cup0-1;
    else if (num1==1){
    ConnectFourArray[cup1][1]=1;
    cup1=cup1-1;
    else if (num1==2){
    ConnectFourArray[cup2][2]=1;
    cup2=cup2-1;
    else if (num1==3){
    ConnectFourArray[cup3][3]=1;
    cup3=cup3-1;
    else if (num1==4){
    ConnectFourArray[cup4][4]=1;
    cup4=cup4-1;
    else if (num1==5){
    ConnectFourArray[cup5][5]=1;
    cup5=cup5-1;
    else if (num1==6){
    ConnectFourArray[cup6][6]=1;
    cup6=cup6-1;
    System.out.println();
    BufferedReader selecter2 = new BufferedReader (new InputStreamReader(System.in));
    String column2;
    System.out.println();
    for ( int row=0; row < ConnectFourArray.length; row++ ){
    System.out.print("Row " + row + ": ");
    for ( int col=0; col < ConnectFourArray[row].length; col++ )
    System.out.print( ConnectFourArray[row][col] + " ");
    System.out.println();
    System.out.println();
    System.out.println ("Please Select a column of 0 through 6 ");
    column1 = selecter.readLine();
    num1= Integer.parseInt(column1);
    System.out.println();
    if (num1==0){
    ConnectFourArray[cup0][0]=2;
    cup0=cup0-1;
    else if (num1==1){
    ConnectFourArray[cup1][1]=2;
    cup1=cup1-1;
    else if (num1==2){
    ConnectFourArray[cup2][2]=2;
    cup2=cup2-1;
    else if (num1==3){
    ConnectFourArray[cup3][3]=2;
    cup3=cup3-1;
    else if (num1==4){
    ConnectFourArray[cup4][4]=2;
    cup4=cup4-1;
    else if (num1==5){
    ConnectFourArray[cup5][5]=2;
    cup5=cup5-1;
    else if (num1==6){
    ConnectFourArray[cup6][6]=2;
    cup6=cup6-1;
    System.out.println();
    System.out.println();
    catch (Exception E){
    System.out.println("Error with input");
    System.out.println("Would you like to play again");
    try{
    String value;
    BufferedReader reader = new BufferedReader (new InputStreamReader(System.in));
    // Scanner scan = new Scanner(System.in);
    System.out.println("Enter yes to play or no to quit");
    // value = scan.nextLine();
    // String value2;
    value = reader.readLine();
    //value2 = reader.readLine();
    if (value.equals("yes"))
    System.out.println("Start again");
    StartGame(); // calling the StartGame method to play a game once more
    else if (value.equals("no"))
    System.out.println("No more games to play");
    // System.exit(0);
    else
    System.exit(0);
    System.out.println();
    catch (Exception e){
    System.out.println("Error with input");
    finally
    System.out.println(" playing done");
    //StartGame();
    //check for horizontal win
    public int hasWon()
    int status = 0;
    for (int row=0; row<6; row++)
    for (int col=0; col<4; col++)
    if (ConnectFourArray[col][row] != 0 &&
    ConnectFourArray[col][row] == ConnectFourArray[col+1][row] &&
    ConnectFourArray[col][row] == ConnectFourArray[col+2][row] &&
    ConnectFourArray[col][row] == ConnectFourArray[col+3][row])
    //status = true;//int winner;
    if(status == player1)
    System.out.println("Player 1 is the winner");
    else if(status == player2)
    System.out.println("Player 2 is the winner" );
    }//end inner for loop
    }// end outer for loop
    } // end method Winner
    return status;
    }//end class
    ClassConnectFour which designs the board........................
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    public class ClassConnectFour
    //Player player1;
    //Player player2;
    public ClassConnectFour()
    //this.player1 = player1;
    public void DrawBoard()
    int[][] ConnectFourArray = new int[6][7] ;
    for ( int row=0; row < ConnectFourArray.length; row++ ){
    System.out.print("Row " + row + ": ");
    for ( int col=0; col < ConnectFourArray[row].length; col++ )
    System.out.print( ConnectFourArray[row][col] + " ");
    System.out.println();
    System.out.println();
    }//end class
    TestConnetFour class which uses most of the above class..................
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    public class TestConnectFour
    public static void main(String[] args)
    ClassConnectFour cf = new ClassConnectFour();
    cf.DrawBoard();
    Player1 player1 = new Player1();
    Player2 player2 = new Player2();
    player1.move();
    player2.move();
    System.out.println("Number 1 belongs to player " + player1.name());
    System.out.println("Number 2 belongs to player " + player2.name());
    PlayGame pg = new PlayGame();
    pg.StartGame();
    pg.hasWon();
    //pg.Play();
    //System.out.println(player.name());
    //System.out.println(player2.name());
    }// end main
    }//end classI am sorry for all this junk code but I only understand it this way. Your urgent help is required. Looking forward to your reply.
    Thanks in advance.
    Koonda

  • Trying to write a Listener on a CheckBox to change the Model of a ComboBox

    I am trying to change the list that appears in a ComboBox dynamically based on if a CheckBox is selected or not. I have multiple CheckBoxes and ComboBoxes being created in a loop based on a variable assigned at creation. Every tutorial i have seen writes out a listener that explicitly defines the checkbox instance but in my case i don't acctually know. My checkboxes are in an array of checkboxes as are the comboboxes as they are being created at runtime. Any help would be much apreciated this issue has been with me for two days now.

    here is a snippit of my code in how i was implementing this:
    int numButton = 17; //this is for testing only, this variable is set from another class normally
    // these variables are defined private elsewhere in the class
    JCheckBox PlayerByeCheck[] = new JCheckBox[numButton + 1];
    JCheckBox PlayerHomeCheck[] = new JCheckBox[numButton + 1];
    boolean PlayerOnBye[] = new boolean[numButton + 1];
    for (int i = 1; i <= numButton; i++) {
             PlayerByeCheck[i] = new JCheckBox();
         PlayerHomeCheck[i] = new JCheckBox();
         PlayerOnBye[i] = false;
    // more code here for building the gui it is not important for this problem
    // code to build the list starts here
    for (int i = 1; i <= numButton; i++) {
         ((TableLayout)PlayerRosterPanel.getLayout()).insertRow(1, TableLayout.PREFERRED);
             PlayerByeCheck.setOpaque(false);
         PlayerByeCheck[i].addItemListener(this);
         PlayerByeCheck[i].setName("PlayerByeCheck" + i);
         PlayerRosterPanel.add(PlayerByeCheck[i], new TableLayoutConstraints(2, 1, 2, 1, TableLayoutConstraints.CENTER, TableLayoutConstraints.FULL));
    //the comboox that i want to change
    //---- PlayerTeamSelect1 ----
         if (PlayerOnBye[i] = true) {
              PlayerTeamSelect[i].setModel(new DefaultComboBoxModel(new String[] {
                   "ARI",
                   "ATL",
                   "BAL",
              "BUF",
         "BYE"
              PlayerTeamSelect[i].setSelectedItem("BYE");
         } else {
              PlayerTeamSelect[i].setModel(new DefaultComboBoxModel(new String[] {
                   "ARI",
                   "ATL",
                   "BAL",
                   "BUF",
                   "CAR",
              "BYE"
         PlayerTeamSelect[i].setOpaque(false);
         PlayerRosterPanel.add(PlayerTeamSelect[i], new TableLayoutConstraints(4, 1, 4, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL));
    //more gui code here method gets closed
    //Item Action Listener starts here this is where i am having the problem                         
    public void itemStateChanged(ItemEvent e) {
         Object source = e.getItem();
         if (source == PlayerByeCheck[1])
         int select = e.getStateChange();
              if (select == ItemEvent.SELECTED)
              PlayerOnBye[1] = true;
    PlayerRosterPanel.repaint();
    //repaint the window i think can't get the listener to work to see if this is the right way to do this
    //i doubt it is
    I have tried several different ways to write the listener, the example in the code above is following the java swing tutorial by explicitly defining the checkbox. I have tried to write the listener as i am creating the checkbox, which doesn't seem to work or i am wrting it wrong, which is entirely possible. Once the listener sets the value i think it should repaint the screen but i am sure that that is wrong right now as well. As my hunch is the repaint will reset the checkbox to DESELCTED the default value. I will come to that issue once i figure out how to get the listener working. Ideally i want to be able to set the listener for the checkboxes regardless as to how many there are. As stated above i am generating a list of checkboxes, comboboxes and other fields based on a variable that is defined in one of my objects. If the user selects checkbox 3 than combobox 3 should be changed, and the others should not. if the user selects all the checkboxes than all the comboboxes change.
    thanks for any help. Still plugging along on it trying to figure this one out.

  • WIN7 x64 Home Basic, 0x80070013 when trying to write or delete files. Disk is write protected.

    Hi,
    My SD card reader is not able to write or delete and format sd cards.
    WIN7 x64 Home Basic, 0x80070013 when I trying to write or delete files. When I trying to format I can see a message that disk is write protected. 
    The card is not locked, it's work in Lenovo Idea Pad s10 without any problem, It's also work in my Pentax camera.
    I'm almost sure that the problem is software, but can't find solution.
    Could Any one help me please?
    Laptop is new, 8 days in use. 

    I have network shutdown 2.0.1 installed and the pcns process normally would be abend in 1 or 2 minute's time. What could be the problem ? Consider to upgrade the network shutdown to 2.2.1 version. Could the problem be resolved in new version ? Any precaution needs to be taken when installing the new version ?
    Terence.

  • Same here, 4s working perfectly, downloaded update 8.0.1 Now no wifi or bluetooth or hotspot. Control on/off icons are muted in colour and don't respond. Tried resetting network connections then total restore, didn't work so still have the same probl

    Same here, 4s working perfectly, downloaded update 8.0.1 Now no wifi or bluetooth or hotspot. Control on/off icons are muted in colour and don't respond. Tried resetting network connections then total restore, didn't work so still have the same problems as before.

    Satellite L505D-S5983
    I would try another restore of the hard disk to its original out-of-the-box contents using Toshiba recovery media. Maybe something went wrong in the process. Make sure everything works before applying any updates and adding any hardware or software.
    Then add things carefully, rebooting Windows and testing the USB and audio at each step.
    Please note this.
    The only info windows gives me for the sound card is that it from Microsoft... with a driver version of 6.1.7601.17514....which naturally doesn't really help me since I have no idea what card or mobo I have . Is there any way for me to find out what I need other than opening up my laptop?
    Every one of them lists my mobo simply as a Toshiba motherboard, with no audio card information. Which I'm assuming that is because it has an internal sound processor. My problem is that none of the properties, or ANYTHING I try, will give me information on what I need to fix this...
    All of the latest drivers for your model are easily found here. This one is for the sound.
       Realtek Audio Driver for Windows 7 (32/64)
    -Jerry

  • I have an Airport Express that I am trying to use connected by ethernet to my iMac G4 running Mac OS 10.4.11.  I need to update the Airport software in order to use security option WPA2 Personal.  I currently have Airport software v. 5.6.1.

    I have an Airport Express that I am trying to use connected by ethernet to my iMac G4 running Mac OS 10.4.11.  I need to update the Airport Express softwart in order to use security option WPA2 Personal to connect to the internet through my Airport Extreme.  I currently have Airport Express software version 5.6.1.  How can I update this software? (I can connect directly to my Airport Extreme by ethernet and download the update that way).  Is a later version of A E software available for download anywhere?   Any suggestions would be greatly appreciated.
    Thanks.

    Download and install AirPort Utility 5.4.2 for Mac OS X 10.4.11 "Tiger" here:
    AirPort Utility 5.4.2
    Once installed, launch AirPort Utility. It will tell you if a firmware upgrade is available for your Express.

  • I switched my keyboard to french and now it won't change back to english. Quite the hassle when trying to write in english. Why would it be stuck?

    I switched my keyboard to french and now it won't change back to english. Quite the hassle when trying to write in english. Why would it be stuck?

    When the keyboard pops up, tab the Globe icon, and select the English keyboard.

  • My ipod 4G won't connect to my wifi at home with new router. Says "unable to connect" and won't give me any other options. Have tried resetting network connections. Help.

    My ipod 4G won't connect to my wifi at home with new router. Says "unable to connect" and won't give me any other options. Have tried resetting network connections. I don't want to lose anything. I have tried turning everything off and back on again. Desktop and laptop are working fine. Sometimes it turns on suddenly and I can use it for like 20 mins but then shuts off again. Same thing is happening with my dad's iphone, Help.

    Does the iOS device connect to other networks?
    Does the iOS device see the network?
    Any error messages?
    Do other devices now connect?
    Did the iOS device connect before?
    Try the following to rule out a software problem:                 
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Power off and then back on your router
    .- Reset network settings: Settings>General>Reset>Reset Network Settings
    - iOS: Troubleshooting Wi-Fi networks and connections
    - Wi-Fi: Unable to connect to an 802.11n Wi-Fi network       
    - iOS: Recommended settings for Wi-Fi routers and access points
    - Restore from backup. See:
    iOS: How to back up
    - Restore to factory settings/new iOS device.
    If still problem and it does not connect to any networks make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar

  • I'm trying to write an Applescript: when I add a file to a folder, I want finder to name it "1" and increment the other files in the folder by 1. i.e. once I drop a new file into the folder, the file originally called "1" will be renamed "2" etc

    I'm trying to write an Applescript. I have never used Applescript but my boss has just asked me to write a script so I dutifully nodded and said "Yes Boss"...
    The funtionality I need is that I want finder to rename the files in folder when I drop a new file in. When I add the new file (file neame: "1") to a folder, I want to increment the other file names in the folder by 1.
    So when I drop a my new "1" file into the folder, the file original file called "1" will be renamed "2", the original file named "2" will be renamed "3" etc
    I'm creating a 'stream' of images. When I add a new image i want it to nudge the other images in the folder along.
    Thanks guys!

    Maybe this will help. If you monitor the "More Like This" box (top right), other threads appear. Opening them usually displays other threads.
    https://discussions.apple.com/message/1986834#1986834

Maybe you are looking for

  • AIR 3.8: BASELINE_EXTENDED failing to initialize on a Nexus 7.

    We're using BaseLine extended profile, which works fine on iPad, iPhone, Desktop and Android Nexus 10. However when trying to initialize Starling on a Nexus 7, I get the error: "Context3D is not available! Possible reasons: wrongRenderMode or missing

  • Disc Burner Not Found Windows Vista

    Im getting disc burner not found or burning software not found with iTunes 7.2 using Windows Vista x64 It worked fine in Windows XP! I use a Sony DRU-810A with latest 1.0f firmware. Please fix this Apple this is annoying, it worked in XP!

  • Used HandBrake to rip video off of my dvd..now I want to edit it in i-movie

    the program put the 'rip' to itunes in one or another into movie. neither will open in i-movie. how do I convert this so that I can open it in imovie and edit it to put on to youtube?

  • Organizer crashes when moving photos to another directory

    Shortly after upgrading (?) from PSE 7 to PSE 8, i discovered that my catalog had become corrupted.  When viewing photos by folder location, many photos are shown as being in an incorrect folder in the directory tree on the left.  The correct locatio

  • How can I sent a parameter into Having sentence.

    I want to create a VO by the below sentence. SELECT fte.employee_id, fte.salary, fte.position_code FROM fwk_tbx_employees fte GROUP BY fte.employee_id, fte.salary, fte.position_code HAVING COUNT(fte.salary) >= :1 But I have no idea to set the paramet