Thread: Tic Tac Toe

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    84

    Tic Tac Toe

    hey..im creating a simple tic tac toe game in c# but im having a small problem. i want the input to be only be accepted if it is between 0 and 8..otherwise ask the user for input again..but i cant seem to get it..here is what i have

    Code:
     static int getInput()
            {
               int input;
                Console.WriteLine("Please Make Your Move!");
                input = Convert.ToInt32(Console.ReadLine());
                if(input < 0 || input > 8)
                {
                   Console.WriteLine("Invalid Input!");
                    getInput();
                  } 
               return input;
            }
    
    while(!player1.isEmpty(value=getInput())) // check if spot has already been filled
                    {
                       Console.WriteLine("Sorry,Alredy Filled!");
                    }
                    
                    player1.makeMove(value);
    my code does the check fine..but after that if i return a value between 0 and 8..it crashes ??

  2. #2
    Registered User
    Join Date
    Jan 2008
    Posts
    290
    You're not doing anything with the return value from the recursive call to getInput().

    Code:
    if(input < 0 || input > 8)
    {
       Console.WriteLine("Invalid Input!");
       return getInput();
    }

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    84
    oh!..i forgot about that!..thanks..it worked !

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help me with my simple Tic tac toe prog
    By maybnxtseasn in forum C Programming
    Replies: 2
    Last Post: 04-04-2009, 06:25 PM
  2. tic tac toe crashes :(
    By stien in forum Game Programming
    Replies: 4
    Last Post: 05-13-2007, 06:25 PM
  3. Help with Tic Tac Toe game
    By snef73 in forum C++ Programming
    Replies: 1
    Last Post: 04-25-2003, 08:33 AM
  4. Need some help with a basic tic tac toe game
    By darkshadow in forum C Programming
    Replies: 1
    Last Post: 05-12-2002, 04:21 PM
  5. Tic Tac Toe Help
    By aresashura in forum C++ Programming
    Replies: 1
    Last Post: 11-21-2001, 12:52 PM