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 <[email protected]>
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 <[email protected]>
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