Thread: Tic Tac Toe Help

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    66

    Angry Tic Tac Toe Help

    Alright I am writing tic tac toe for school project I was wondering if I am gonna get anywhere this I can't figure out a way to keep the old tic tac toe board and add X's and O's look at this please

    #include <iostream.h>
    #include <stdlib.h>
    #include <string.h>

    int gridchange();
    int begin(int fplayer);
    int selgrid(int gridnum);

    char one, two, three, four, five, six, seven, eight, nine;
    int fplayer, gridnum;
    char grid1[] = " || || \n || || \n_____||_____||_____\n";
    char grid2[] = "_____||_____||_____\n || || \n || || \n_____||_____||_____\n";
    char grid3[] = "_____||_____||_____\n || || \n || || \n || || \n";

    int gridchange()
    {
    if (fplayer == 1)
    {
    if (gridnum == 1)
    {
    strcpy(grid1," || || \n x || || \n_____||_____||_____\n");
    }

    else if (gridnum == 2)
    {
    strcpy(grid1," || || \n || x || \n_____||_____||_____\n");
    }

    else if (gridnum == 3)
    {
    strcpy(grid1," || || \n || || x \n_____||_____||_____\n");
    }

    else if (gridnum == 4)
    {
    strcpy(grid2,"_____||_____||_____\n || || \n x || || \n_____||_____||_____\n");
    }

    else if (gridnum == 5)
    {
    strcpy(grid2,"_____||_____||_____\n || || \n || x || \n_____||_____||_____\n");
    }

    else if (gridnum == 6)
    {
    strcpy(grid2,"_____||_____||_____\n || || \n || || x \n_____||_____||_____\n");
    }
    else if (gridnum == 7)
    {
    strcpy(grid3,"_____||_____||_____\n || || \n x || || \n || || \n");
    }

    else if (gridnum == 8)
    {
    strcpy(grid3,"_____||_____||_____\n || || \n || x || \n || || \n");
    }

    else if (gridnum == 9)
    {
    strcpy(grid3,"_____||_____||_____\n || || \n || || x \n || || \n");
    }
    }
    else if (fplayer == 2)
    {
    if (gridnum == 1)
    {
    strcpy(grid1," || || \n o || || \n_____||_____||_____\n");
    }

    else if (gridnum == 2)
    {
    strcpy(grid1," || || \n || o || \n_____||_____||_____\n");
    }

    else if (gridnum == 3)
    {
    strcpy(grid1," || || \n || || o \n_____||_____||_____\n");
    }

    else if (gridnum == 4)
    {
    strcpy(grid2,"_____||_____||_____\n || || \n o || || \n_____||_____||_____\n");
    }

    else if (gridnum == 5)
    {
    strcpy(grid2,"_____||_____||_____\n || || \n || o || \n_____||_____||_____\n");
    }

    else if (gridnum == 6)
    {
    strcpy(grid2,"_____||_____||_____\n || || \n || || o \n_____||_____||_____\n");
    }
    else if (gridnum == 7)
    {
    strcpy(grid3,"_____||_____||_____\n || || \n o || || \n || || \n");
    }

    else if (gridnum == 8)
    {
    strcpy(grid3,"_____||_____||_____\n || || \n || o || \n || || \n");
    }

    else if (gridnum == 9)
    {
    strcpy(grid3,"_____||_____||_____\n || || \n || || o \n || || \n");
    }

    }
    return 0;
    }

    int main()
    {
    do
    {
    cout << "Enter 1 for X first or 2 for O first: ";
    cin >> fplayer;
    }
    while (fplayer > 1 && fplayer < 2);

    do
    {
    cout << " 1 | 2 | 3 \n | | \n_____|_____|_____\n 4 | 5 | 6 \n | | \n_____|_____|_____\n 7 | 8 | 9 \n | | \n | | \n";
    cout << "Please enter the grid number you would like to place your character in: ";
    cin >> gridnum;
    }
    while (gridnum < 0 && gridnum > 9);
    gridchange();
    cout << grid1 << grid2 << grid3;

    return 0;

    }


    any help would be appreciated.

    Ryan

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    The most common way to depict the grid is to use a multidimensional char array with each char representing either an empty space or an X or an O. Searching the board using tic tac toe or naughts and crosses should give you some idea of how to get started. Once you can do it with a simple 2D array then you can add the "graphical representation" of the grid itself by having given char be | or _ or whkatever. Given the added complexity of actually showing the grid, I suggest coding gridless first, then add the grid later.

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
    By holden in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 05-09-2004, 09:59 AM
  3. Help with Tic Tac Toe game
    By snef73 in forum C++ Programming
    Replies: 1
    Last Post: 04-25-2003, 08:33 AM
  4. tic tac toe game
    By Leeman_s in forum Game Programming
    Replies: 9
    Last Post: 04-24-2002, 03:24 AM
  5. my tic tac toe game, please try it
    By Leeman_s in forum C++ Programming
    Replies: 2
    Last Post: 04-14-2002, 05:16 PM