DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Page 2 of 2 FirstFirst 1 2
Results 16 to 22 of 22
  1. #16
    Join Date
    Dec 2005
    Location
    New Jersey
    Posts
    290
    I haven't even looked at what you're doing but I already know it's wayyy simpler than that. You don't even need to create a method to check for a tie. Use the turn variable.

    Code:
    if (turn == 9 && winner().equals(EMPTY)) {
        System.out.println("Tie!");
    }

  2. #17
    Join Date
    Jan 2006
    Posts
    9
    Quote Originally Posted by destin
    I haven't even looked at what you're doing but I already know it's wayyy simpler than that. You don't even need to create a method to check for a tie. Use the turn variable.

    Code:
    if (turn == 9 && winner().equals(EMPTY)) {
        System.out.println("Tie!");
    }
    This code saves so much space and really makes sense but System.out.println("Tie!"); doesnt work, it doesnt outprint the actual word "Tie", may be i put it in the place where its not supposed to be, but i think i should be in the last Public Static...
    Im sorry for such dumb things, but i really appreciate your help
    Thank You

  3. #18
    Join Date
    Dec 2005
    Location
    New Jersey
    Posts
    290
    Code:
    static public void main(String[] args) {
        boolean tie = false;
        init();
        
        System.out.println("Welcome to Tic-Tac-Toe.");
        
        do {
            int row = Integer.parseInt(JOptionPane.showInputDialog(
                "Enter the row you wish to move in."));
            int column = Integer.parseInt(JOptionPane.showInputDialog(
                "Enter the column you wish to move in."));
            getMove(row, column);
            printBoard();
            
            if (turn == 9 && winner().equals(EMPTY)) {
                tie = true;
                break;
            }
        } while(winner().equals(EMPTY));
            
        if (tie) {
            System.out.println("TIE!");
        } else {
            System.out.println("PLAYER " + ((turn - 1) % 2 + 1) + " WINS!");
        }
    }

  4. #19
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Isn't a tie the situation when the board is full but has no winner lines ?

    Anyway rupa, you said my solution was too complicated, and I agree that it may be so if you need to resort GUI-less and (nearly) sequantial programming (non-oop) methods.

    My method is a combination of oop/tabledriven programming and a GUI. The whole game is controlled by the winLine matrix and the fact that player1 & 2 are awarded different scores for the placements (1 & 4).

    As a java program, its not complicated at all, but hey, its your game.
    eschew obfuscation

  5. #20
    Join Date
    Dec 2005
    Location
    New Jersey
    Posts
    290
    Quote Originally Posted by sjalle
    Isn't a tie the situation when the board is full but has no winner lines ?
    Well, if turn == 9, the board is full, and if winner().equals(EMPTY), then there's no winner.

  6. #21
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560

    Yes, but...

    ...I will still argue that my tabledriven approach is more 'generic'; if I wanted to make a bigger gameboard and more complicated win patterns, and allow more players, I would only have to plot in these patterns into the win matrix and allocated a wider spectre of awards (so that no player sum could be equal).

    As for problem analysis, my solution has dealt with the general concept of a game where players place dices in turn, and the object it to get some pattern first. Expanding the games complexity craves no programming effort and if it is supplied with a GUI for plotting in the win matrix, the player can make his 'own' game. And thats rather cool.
    eschew obfuscation

  7. #22
    Join Date
    Jan 2006
    Posts
    9
    I just want to THANK everyone for helping me, especially Destin!

    Thank U Guys!

Similar Threads

  1. Tic Tac Toe
    By shadow in forum Java
    Replies: 3
    Last Post: 11-14-2005, 10:21 PM
  2. Simple tic tac toe applet
    By Ant_Magma in forum Java
    Replies: 5
    Last Post: 09-26-2005, 03:41 AM
  3. Replies: 1
    Last Post: 08-20-2001, 07:17 AM
  4. Replies: 1
    Last Post: 02-10-2001, 12:20 AM

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