Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 06-10-2007, 07:42 PM   #1
Fully Optimized
 
Join Date: Oct 2005
Location: 1
Posts: 2,525
Default check this for me?

hey guys i'm working on a tic tac toe final still and this is the code i made up so far

Quote:
/* Greg Thomase Tic Tac Toe Final*/

#include<lvp\gui_top.h>
#include<lvp\matrix.h>
#include<lvp\string.h>
#include<lvp\bool.h>
#include<lvp\random.h>

//------------------------
class GridClass{
public:
void Paint();
GridClass();
void MouseClick(int x, int y);
void InitGrid();
private:
const int GridDimension;
const int Empty, EmptyPicked, Treasure, TreasurePicked;
matrix<int>Board;
int TreasureRow, TreasureCol;
bool GameOver;
int NumClicks;
int BoxSize;
int LeftMargin;
int TopMargin;
void XYToRowCol(int x, int y, int &Row, int &Col);
void MarkBox(int Row, int Col, int BoxContents);

};
//--------------------------
GridClass::GridClass()
:GridDimension(3),
Empty(0),EmptyPicked(-1),Treasure(1),TreasurePicked(2),
Board(GridDimension,GridDimension,0),
NumClicks(0),GameOver(false),
BoxSize(GetMaxY()/2/GridDimension),
LeftMargin((GetMaxX()-BoxSize*GridDimension)/2),
TopMargin(GetMaxY()/4),

{
randomize();
Board[random(GridDimension)][random(GridDimension)]=Treasure;
}
//-------------------------
void GridClass::XYToRowCol(int x, int y, int &Row, int &Col)
{
int DistFromLeft=x-LeftMargin;
Col=(DistFromLeft+BoxSize)/BoxSize-1;
int DistFromTop=y-TopMargin;
Row=(DistFromTop+BoxSize)/BoxSize-1;
if(Col<0||Col>=GridDimension||
Row<0||Row>=GridDimension){
Row=-1;
Col=-1;
}
}
//-------------------------
void GridClass::MouseClick(int x, int y)
{
int Row, Col;
XYToRowCol(x, y, Row, Col);
if (Row !=-1 && Col !=-1&& Board[Row][Col] != EpmtyPicked) {
if(Board[Row][Col]==Empty)
Board[Row][Col]=EmptyPicked;
else if (Board[Row][Col]==Treasure) {
Board[Row][Col]=TreasurePicked;
GameOver=true;
}
NumClicks++;
}
}
//-------------------------

void GridClass::Paint()
{
QuitButton.Paint();
SetColor(BLACK);

int Row,Col;
for(Col=0; Col<=GridDimension; Col++)
Line(LeftMargin+Col*BoxSize, TopMargin,
LeftMargin+Col*BoxSize,
TopMargin+GridDimension*BoxSize);
for(Row=0; Row<=GridDimension; Row++)
Line(LeftMargin, TopMargin+Row*BoxSize,
LeftMargin+GridDimension*BoxSize,
TopMargin+Row*BoxSize);
for(Row=0; Row<GridDimension; Row++)
for(Col=0; Col<GridDimension; Col++)
MarkBox(Row,Col,Board[Row][Col]);
if(GameOver==true){
gotoxy(20,GetMaxY()-60);
DrawText("Game Over! Score =");
DrawText(NumClicks);
}
}
//------------------------
//------------------------
class GuiClass{
public:
GuiClass();
void GuiMouseClick(int x, int y);
void GuiPaint();
String Title();
private:
GridClass Game;
};
//------------------------
GuiClass::GuiClass()
{
}
//------------------------
String GuiClass::Title()
{
return("Soggy Biscuit");
}
//------------------------
void GuiClass::GuiMouseClick(int x, int y)
{
Game.MouseClick(x,y);
}
//------------------------
void GuiClass::GuiPaint()
{
Game.Paint();
}
//------------------------
#include <lvp\gui_bot.h>
now this is a modified case study i was working on to fit the needs of the tic tac toe board. now what this should do when i run it should give me a board of 3x3 boxes and let me click on them. problem is that it only finds one box hence the "treasure hunt" values in this code. now how would i go about changing it to a tic tac toe values?? thanks.
Ronco Rox is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 01:52 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0