Tictactoe in colour help

This is a discussion on Tictactoe in colour help within the Game Programming forums, part of the General Programming Boards category; Hello I'm doing an assignment making a tictactoe game. My teacher said not to use arrays and he'd give extra ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    4

    Tictactoe in colour help

    Hello I'm doing an assignment making a tictactoe game. My teacher said not to use arrays and he'd give extra marks if we can do it in colour.

    So I think I've got the game right but no idea how to do it in colour.

    MY teacher gave me a program with its supporting files to help me. Currently I can only do it if my tictactoe program and the file is in the same directory. Oh I'm using MinGW.
    To get the colour I'd type g++ conio_yp.cpp tictactoe.cpp -o tictactoe.exe, but my teacher wants me to get it just by compiling my tictactoe.cpp.

    He said something about compiling while compiling which I didn't really understand quite well. I've been reading the FAQ and read about using colours here but my teacher said don't use it because it's more complicated.

    Should I post my tictactoe code? I'm not asking bout it I need help on the colour part.
    I'd like to put an attachment to the colour code but I don't know how. The attachment menu gives me a blank box? I'm sorry I don't post much I just read a lot here it helps me quite a bit

    This is the code he wants me to use

    Code:
    *
      conio_yp.cpp
      
      version : ver060806
    
      Copyright (C) 2006 Ya-Ping Wong <ypwong@mmu.edu.my>
    
      Purpose : Program files for functions for low level I/O under Microsoft Windows
                and mingw environment which allow you to display text in colors
                amd on specified locations
                These functions are NOT part of the standard library of C++. 
      
    */
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <windows.h>
    #include <string.h>
    #include "conio_yp.hpp"
    
    void setcolor(int backgroundcolor, int foregroundcolor)
    {
     textbackground(backgroundcolor);
     textcolor(foregroundcolor);
    }
    
    void _setcursortype (int type)
    {
        CONSOLE_CURSOR_INFO Info;
    
        Info.bVisible = type;
    
        SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE),
          &Info);
    }
    
    void hidecursor()
    {
     _setcursortype(FALSE); /* temporary hide the cursor */
    }
    
    void showcursor()
    {
     _setcursortype(TRUE);
    }
    
    void gotoxy(int x, int y) 
    {
      COORD c;
    
      c.X = x - 1;
      c.Y = y - 1;
      SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);
    }
    
    static int __BACKGROUND = BLACK;
    static int __FOREGROUND = LIGHTGRAY;
    
    void textattr (int _attr)
    {
        SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), _attr);
    }
    
    void textbackground (int color)
    {
        __BACKGROUND = color;
        SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
          __FOREGROUND + (color << 4));
    }
    
    void textcolor (int color)
    {
        __FOREGROUND = color;
        SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
          color + (__BACKGROUND << 4));
    }
    
    void clrscr()
    {
        DWORD written;
    
        FillConsoleOutputAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
          __FOREGROUND + (__BACKGROUND << 4), 2000, (COORD) {0, 0},
          &written);
          FillConsoleOutputCharacter (GetStdHandle
          (STD_OUTPUT_HANDLE), ' ',
          2000, (COORD) {0, 0}, &written);
        gotoxy (1, 1);
    }
    
    void clreol()
    {
        COORD coord;
        DWORD written;
        CONSOLE_SCREEN_BUFFER_INFO info;
    
        GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE),
          &info);
        coord.X = info.dwCursorPosition.X;
        coord.Y = info.dwCursorPosition.Y;
    
        FillConsoleOutputCharacter (GetStdHandle (STD_OUTPUT_HANDLE),
          ' ', info.dwSize.X - info.dwCursorPosition.X, coord, &written);
        gotoxy (coord.X, coord.Y);
    }
    
    void delline()
    {
        COORD coord;
        DWORD written;
        CONSOLE_SCREEN_BUFFER_INFO info;
    
        GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE),
          &info);
        coord.X = info.dwCursorPosition.X;
        coord.Y = info.dwCursorPosition.Y;
    
        FillConsoleOutputCharacter (GetStdHandle (STD_OUTPUT_HANDLE),
          ' ', info.dwSize.X * info.dwCursorPosition.Y, coord, &written);
        gotoxy (info.dwCursorPosition.X + 1,
        info.dwCursorPosition.Y + 1);
    }
    Code:
    /*
      conio_yp.hpp
      
      version : ver060806
    
      Copyright (C) 2006 Ya-Ping Wong <ypwong@mmu.edu.my>
    
      Purpose : Header files for functions for low level I/O under Microsoft Windows
                and mingw environment which allow you to display text in colors
                amd on specified locations
                These functions are NOT part of the standard library of C++. 
      
    */
    
    #ifndef	_CONIO_YP_HPP_
    #define	_CONIO_YP_HPP_
    
    #include <_mingw.h>
    
    void setcolor(int backgroundcolor, int foregroundcolor);
    void hidecursor();
    void showcursor();
    void gotoxy(int x, int y);
    
    #ifdef	__cplusplus
    extern "C" {
    #endif
    
    typedef enum
    {
        BLACK,
        BLUE,
        GREEN,
        CYAN,
        RED,
        MAGENTA,
        BROWN,
        LIGHTGRAY,
        DARKGRAY,
        LIGHTBLUE,
        LIGHTGREEN,
        LIGHTCYAN,
        LIGHTRED,
        LIGHTMAGENTA,
        YELLOW,
        WHITE
    } COLORS;
    
    void textattr (int _attr);
    void textbackground (int color);
    void textcolor (int color);
    
    void clrscr ();
    void clreol ();
    void delline();
    
    int	getch (void);
    int	getche (void);
    int	kbhit (void);
    
    #ifdef	__cplusplus
    }
    #endif
    
    #endif	//_CONIO_YP_HPP_
    So I should put this code in my tictactoe program? Can someone help me how I should do it?

    I've never done this sort of stuff before. It's not shown in any examples in my book.

    Edit: Oh the colour thing doesnt give me any extra marks. He wants us to do it in colour because he says tictactoe in black and white is boring. And that he wants to see who can pull it off. Sortof like telling which ones a genius and which ones are just robots who memorize the whole book and have no sense of imagination. oO
    Last edited by g1bber; 09-08-2006 at 12:12 AM.

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    To get the colour I'd type g++ conio_yp.cpp tictactoe.cpp -o tictactoe.exe, but my teacher wants me to get it just by compiling my tictactoe.cpp.
    I don't get this... he's saying you can't include the implementation file provided? That doesn't make any sense. Unless you physically copy the implementation to your tictactoe.cpp, then you won't be able to get it to link without including the implementation in the project. Not as far as I can see.
    Sent from my iPadŽ

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    No arrays eh? Sheesh.

    So what does he want?

    I want you to open a file but you cannot use any file I/O functions.

    Well this solution is ugly, but use a string of 9 characters to represent the cells. It's much easier than using 9 separate values.

    You could also use one integer and use bitwise comparisons but that's also a stupid solution.

    In fact every solution that does not employ an array is stupid.
    Last edited by VirtualAce; 09-08-2006 at 01:52 AM.

  4. #4
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Quote Originally Posted by Bubba
    Well this solution is ugly, but use a string of 9 characters to represent the cells. It's much easier than using 9 separate values.
    I believe that is called a character array.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Not if he's talking about the C++ string class it isn't.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Boy that would really tick the teacher off eh.

  7. #7
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Can't you just use ANSI color codes in your program?

  8. #8
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Quote Originally Posted by Bubba
    Boy that would really tick the teacher off eh.
    Well as long as we're using C++, why not use the vector class? It isn't an array.

  9. #9
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    It's a good thing I'm not taking any C++ classes. I'd probably get kicked out for not doing the assignments the teacher's way. But man could I come up with some interesting ways to get around their stupid requirements.

  10. #10
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Use std::list then. Or std::map.

    If the teacher wants color, go ahead and do a full Win32 app. Instead of lounging around with obsolete, copyrighted, unlicensed DOS maggots.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  11. #11
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Quote Originally Posted by jafet
    If the teacher wants color, go ahead and do a full Win32 app. Instead of lounging around with obsolete, copyrighted, unlicensed DOS maggots.
    Actually he is doing Win32 in case you hadn't noticed that windows.h is included. In fact everything he needs to do color is already present in the code he's posted.

    Edit: After looking a second time at it, it does seem to be obsolete DOS. But in reality its merely a variant of conio modified to make use of Win32 instead. I've seen other teachers do similar - but with different file names.
    Last edited by Frobozz; 09-09-2006 at 02:42 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-24-2006, 07:36 PM
  2. Curses-- colour pairs
    By sufthingol in forum C++ Programming
    Replies: 0
    Last Post: 03-21-2005, 07:26 PM
  3. Replies: 5
    Last Post: 03-01-2003, 03:52 PM
  4. DirectDraw colour matching
    By Hunter2 in forum Game Programming
    Replies: 2
    Last Post: 12-10-2002, 01:17 PM
  5. Colour theory... (weird title)
    By Magos in forum C++ Programming
    Replies: 5
    Last Post: 11-25-2001, 03:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21