Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. tic toe game not working as expected,please help?

tic toe game not working as expected,please help?

Scheduled Pinned Locked Moved C#
csharplinqcomgame-devhelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 9432280
    wrote on last edited by
    #1

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Threading;

    namespace tictoegame
    {

    public class gamestart
    {
        int functionalcount, computernumber,usernumber;
        char\[\] box = new char\[9\];
        static int j=6;
        public gamestart()
        {
    
            
            for(int k=0;k<9;k++)
            {
                box\[k\] = ' ';
            }
            functionalcount = 0;
            Random rd = new Random();
    
          while(true)
          {
                computernumber = rd.Next(0, 8);
                if (box\[computernumber\]!='x'&& box\[computernumber\]!='X'&&box\[computernumber\]!='o'&& box\[computernumber\]!='O')
                {
                    insertvalue(computernumber,Program.computersymbol);
                    break;
                    
                }
          }
            
            functionalcount++;
            userturn();
        }
        public void position()
        {
            int i=1;
            Console.CursorLeft=i;
            Console.CursorTop=j;
            j++;
        }
        public void userturn()
        {
    
            if (functionalcount != 9)
            {
                bool flag1 = checkwin(Program.usersymbol);
                if (flag1)
                {
                    position();
                    Console.WriteLine("you won");
                    Thread.Sleep(3000);
                    Environment.Exit(0);
                }
                else
                {
                    while (true)
                    {
                        position();
                        Console.WriteLine("enter the number for symbol");
                        usernumber = Convert.ToInt32(Console.ReadLine());
                        if (box\[usernumber\] != 'x' || box\[usernumber\] != 'X' && box\[usernumber\] != 'o' || box\[usernumber\] != 'O')
                        {
                            insertvalue(usernumber, Program.usersymbol);
                            functionalcount++;
                            break;
                        }
                    }
                    computerturn();
    
                }
    
            }
        }
        public void computerturn()
        {
            int count=0,i;
            if (functionalcount == 2)
            {
                Random rd = new Random();
                while (true)
                {
                    com
    
    P J 2 Replies Last reply
    0
    • U User 9432280

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using System.IO;
      using System.Threading;

      namespace tictoegame
      {

      public class gamestart
      {
          int functionalcount, computernumber,usernumber;
          char\[\] box = new char\[9\];
          static int j=6;
          public gamestart()
          {
      
              
              for(int k=0;k<9;k++)
              {
                  box\[k\] = ' ';
              }
              functionalcount = 0;
              Random rd = new Random();
      
            while(true)
            {
                  computernumber = rd.Next(0, 8);
                  if (box\[computernumber\]!='x'&& box\[computernumber\]!='X'&&box\[computernumber\]!='o'&& box\[computernumber\]!='O')
                  {
                      insertvalue(computernumber,Program.computersymbol);
                      break;
                      
                  }
            }
              
              functionalcount++;
              userturn();
          }
          public void position()
          {
              int i=1;
              Console.CursorLeft=i;
              Console.CursorTop=j;
              j++;
          }
          public void userturn()
          {
      
              if (functionalcount != 9)
              {
                  bool flag1 = checkwin(Program.usersymbol);
                  if (flag1)
                  {
                      position();
                      Console.WriteLine("you won");
                      Thread.Sleep(3000);
                      Environment.Exit(0);
                  }
                  else
                  {
                      while (true)
                      {
                          position();
                          Console.WriteLine("enter the number for symbol");
                          usernumber = Convert.ToInt32(Console.ReadLine());
                          if (box\[usernumber\] != 'x' || box\[usernumber\] != 'X' && box\[usernumber\] != 'o' || box\[usernumber\] != 'O')
                          {
                              insertvalue(usernumber, Program.usersymbol);
                              functionalcount++;
                              break;
                          }
                      }
                      computerturn();
      
                  }
      
              }
          }
          public void computerturn()
          {
              int count=0,i;
              if (functionalcount == 2)
              {
                  Random rd = new Random();
                  while (true)
                  {
                      com
      
      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      You haven't said what the problem really is, so how do you think we can help? You need to debug your application and try to narrow down what is happening yourself.

      *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

      "Mind bleach! Send me mind bleach!" - Nagy Vilmos

      CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

      1 Reply Last reply
      0
      • U User 9432280

        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;
        using System.IO;
        using System.Threading;

        namespace tictoegame
        {

        public class gamestart
        {
            int functionalcount, computernumber,usernumber;
            char\[\] box = new char\[9\];
            static int j=6;
            public gamestart()
            {
        
                
                for(int k=0;k<9;k++)
                {
                    box\[k\] = ' ';
                }
                functionalcount = 0;
                Random rd = new Random();
        
              while(true)
              {
                    computernumber = rd.Next(0, 8);
                    if (box\[computernumber\]!='x'&& box\[computernumber\]!='X'&&box\[computernumber\]!='o'&& box\[computernumber\]!='O')
                    {
                        insertvalue(computernumber,Program.computersymbol);
                        break;
                        
                    }
              }
                
                functionalcount++;
                userturn();
            }
            public void position()
            {
                int i=1;
                Console.CursorLeft=i;
                Console.CursorTop=j;
                j++;
            }
            public void userturn()
            {
        
                if (functionalcount != 9)
                {
                    bool flag1 = checkwin(Program.usersymbol);
                    if (flag1)
                    {
                        position();
                        Console.WriteLine("you won");
                        Thread.Sleep(3000);
                        Environment.Exit(0);
                    }
                    else
                    {
                        while (true)
                        {
                            position();
                            Console.WriteLine("enter the number for symbol");
                            usernumber = Convert.ToInt32(Console.ReadLine());
                            if (box\[usernumber\] != 'x' || box\[usernumber\] != 'X' && box\[usernumber\] != 'o' || box\[usernumber\] != 'O')
                            {
                                insertvalue(usernumber, Program.usersymbol);
                                functionalcount++;
                                break;
                            }
                        }
                        computerturn();
        
                    }
        
                }
            }
            public void computerturn()
            {
                int count=0,i;
                if (functionalcount == 2)
                {
                    Random rd = new Random();
                    while (true)
                    {
                        com
        
        J Offline
        J Offline
        John Orendt
        wrote on last edited by
        #3

        For comparision you can look at http://www.hugetiger.com/FSetup/Tic2D-Detail.aspx[^]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups