Results 1 to 5 of 5
  1. #1
    kab84 is offline Member
    Join Date
    Apr 2009
    Posts
    2
    Rep Power
    0

    Exclamation Problem In Tic tac toe

    I have almost created the tic tac toe game buti am stuck in the game class. can anyone help me what to do now......
    public class ticktactoe

    {
    public static void main (String args[])
    {
    Game myGame = new Game();
    myGame.Start();



    }
    }





    public class Cell
    {
    private String szsymbol;
    private boolean bstatus;


    public Cell()
    {
    szsymbol= " ";
    bstatus= false;
    }

    public String getSymbol()
    {
    return szsymbol;
    }

    public boolean Move (String token)
    {
    if (!bstatus)
    {
    szsymbol=token;
    bstatus=true;
    return true; //success
    }
    else
    return false; //false
    }

    public boolean getstatus()
    {
    return bstatus;
    }
    }




    public class Board
    {
    private Cell cells[];

    public Board ()
    {
    cells =new Cell[9];
    for (int i=0; i <cells.length; i++)
    cells[i]= new Cell();

    }
    public boolean move (String token, int location)
    {
    if (location<cells.length)
    {
    if (cells[location].Move(token))
    return true;
    else
    return false;

    }
    else
    return false;
    }

    public String getCell(int loc)
    {
    if (loc <cells.length)
    return cells[loc].getSymbol();
    else
    return " ";
    }

    public String DisplayBoard()
    {
    String o;
    o=String.format("%s|%s|%s|\n",cells[0].getSymbol(),cells[1].getSymbol(),cells[2].getSymbol());
    o+=String.format("%s|%s|%s|\n",cells[3].getSymbol(),cells[4].getSymbol(),cells[5].getSymbol());
    o+=String.format("%s|%s|%s|\n",cells[6].getSymbol(),cells[7].getSymbol(),cells[8].getSymbol());
    return o;
    }
    }









    public class Player
    {
    private String szName;
    private String sztoken;

    public Player (String Name, String token)
    {
    szName=Name;
    sztoken=token;

    }
    public String getName()
    {
    return szName;
    }
    public String gettoken()
    {
    return sztoken;
    }


    }








    import java.util.Scanner;

    public class Game
    {
    Scanner input;
    private Board playingboard;
    private Player P1;
    private Player P2;

    public Game()
    {
    playingboard = new Board();
    input = new Scanner(System.in);
    set_Players();
    }

    private void set_Players()
    {
    String tmp;
    System.out.print ("P1 enter your name:");
    tmp= input.next();
    P1 = new Player (tmp, "O");
    System.out.print ("P2 Enter your Name:");
    tmp=input.next();
    P2 = new Player(tmp, "x");
    }

    public void Start()
    {


    //Play the game via the rules

    //Boolean Draw = true;
    }


    public boolean checkWinX()
    {
    Boolean win = false;

    if (playingboard.getCell(0) == "x" && playingboard.getCell(1) == "x" && playingboard.getCell(2) == "x")
    win = true;

    else if (playingboard.getCell(3) == "x" && playingboard.getCell(4) == "x" && playingboard.getCell(5) == "x")
    win = true;

    else if (playingboard.getCell(6) == "x" && playingboard.getCell(7) == "x" && playingboard.getCell(8) == "x")
    win = true;

    else if (playingboard.getCell(0) == "x" && playingboard.getCell(3) == "x" && playingboard.getCell(6) == "x")
    win = true;

    else if (playingboard.getCell(1) == "x" && playingboard.getCell(4) == "x" && playingboard.getCell(7) == "x")
    win = true;

    else if (playingboard.getCell(2) == "x" && playingboard.getCell(5) == "x" && playingboard.getCell(8) == "x")
    win = true;

    else if (playingboard.getCell(0) == "x" && playingboard.getCell(4) == "x" && playingboard.getCell(8) == "x")
    win = true;

    else if (playingboard.getCell(2) == "x" && playingboard.getCell(4) == "x" && playingboard.getCell(6) == "x")
    win = true;

    if (playingboard.getCell(0) == "O" && playingboard.getCell(1) == "O" && playingboard.getCell (2) == "O")
    win = true;

    else if (playingboard.getCell(3) == "O" && playingboard.getCell(4) == "O" && playingboard.getCell(5) == "O")
    win = true;

    else if (playingboard.getCell(6) == "O" && playingboard.getCell(7) == "O" && playingboard.getCell(8) == "O")
    win = true;

    else if (playingboard.getCell(0) == "O" && playingboard.getCell(3) == "O" && playingboard.getCell(6) == "O")
    win = true;

    else if (playingboard.getCell(1) == "O" && playingboard.getCell(4) == "O" && playingboard.getCell(7) == "O")
    win = true;

    else if (playingboard.getCell(2) == "O" && playingboard.getCell(5) == "O" && playingboard.getCell(8) == "O")
    win = true;

    else if (playingboard.getCell(0) == "O" && playingboard.getCell(4) == "O" && playingboard.getCell(8) == "O")
    win = true;

    else if (playingboard.getCell(2) == "O" && playingboard.getCell(4) == "O" && playingboard.getCell(6) == "O")
    win = true;

    else
    win = false;

    return false;
    }

    }



    the problem is with Start th game. am i missing some rulesss and if yes how.

    any help would be appreciated

    Regard
    Kab

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    What are the you've implemented here. Reading such a long code is not an easy task lol.

    Take a peace of paper and write down all the rules you have in that game first of all.

  3. #3
    kab84 is offline Member
    Join Date
    Apr 2009
    Posts
    2
    Rep Power
    0

    Default

    I did but i couldn't figure it out. i am new to Java thats why i posted all of them in here.
    the only problem is in the Start that i have to create some ruless..
    I hope you can do somthing

    Thanks

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Actually you should have the set of rules. Because you are the creater of this game. I can help you to implement those things if you have them.

  5. #5
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

Posting Permissions

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