DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2006
    Posts
    1

    tic-tac-toe, 2d arrays and the console..

    Hi. I'm relatively new to Java Programming and have been experimenting with lots of code and using Eclipse to input my code. I was wondering if there is a way to program a 2 player tic-tac-toe game (without using a java applet) using 2-dimensional arrays to be played in the console.
    So for example, instead of a normal tic-tac-toe grid, i now have:
    1 2 3
    4 5 6
    7 8 9
    as my grid and now the players have to input a number which will replace the selected with a X or O.

    Eg:
    "Player X, please choose a number on the grid: "
    1

    X 2 3
    4 5 6
    7 8 9


    "Player O, please choose a number on the grid: "
    4

    X 2 3
    O 5 6
    7 8 9

    and so forth...

    I haven't gone as far as to writing validation methods because I can't get the 1st input to remain on the board after the 2nd input.
    So in the previous example when Player X enters 1 and then Player O enters 4, i get:
    1 2 3
    O 5 6
    7 8 9

    How do I store the state of the tic-tac-toe after someone has inputted a value???


    thanx...

  2. #2
    Join Date
    May 2006
    Posts
    23
    Have you considered using your 2D array like this

    index|Position|Player

    [ 0 | 1 | null ]
    [ 1 | 2 | X ]
    [ 2 | 3 | null ]
    [ 3 | 4 | O ]
    [ 4 | 5 | null ]
    [ 5 | 6 | null ]
    [ 6 | 7 | null ]
    [ 7 | 8 | null ]
    [ 8 | 9 | null ]

    if player is null populate with position else populate with player
    Last edited by smcneill; 05-02-2006 at 01:01 PM. Reason: clarification

  3. #3
    Join Date
    May 2006
    Posts
    1
    I'm a tutor at Monash Clayton teaching FIT1002, oh_my_java.
    Why this looks exactly like the task thats due.

  4. #4
    Join Date
    May 2006
    Posts
    1

    Lol

    So Busted!

  5. #5
    Join Date
    May 2006
    Posts
    23
    Dohhh! -- That's gonna' leave a mark.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links