Hi there,
i'm trying to create the checkers game that i'm sure most experts have done at some point in their programming life.
This is the code i have so far.
i only drawn the board and pieces and two boxes for new game and exit.
this program doesn't work at all yet.
i'd like some help on how to
1. make only 1 function to draw the board e.g void drawBoard()
2. make moves for the pieces (preferrably a valid move).
3. have the exit and new game buttons work.
**note i have different header files in this so it won't work if you copy and paste**
#include "ccc_win.h"
void initNewgame(int x, int y, int r, int g, int b, PenWidth pen1, PenColour blackPen)
{
BrushColour sBrush = BrushColour(r, g, b);
Point p(6.3, 3.5);
Point p1(x - 2, y + 1);
Point p2(x + 2, y - 1);
Rectangle square(p1, p2);
string s = "New Game";
Message newGame(p, s);
cwin << pen1 << blackPen << sBrush << square << newGame;
}
void initExit(int x, int y, int r, int g, int b, PenWidth pen1, PenColour blackPen)
{
BrushColour sBrush = BrushColour(r, g, b);
Point p(15.3, 3.5);
Point p1(x - 2, y + 1);
Point p2(x + 2, y - 1);
Rectangle square(p1, p2);
string s = "Exit";
Message exit(p, s);
cwin << pen1 << blackPen << sBrush << square << exit;
}
void initSquare(int x, int y, int r, int g, int b, PenWidth pen1, PenColour blackPen)
{
BrushColour sBrush = BrushColour(r, g, b);
Point p(x, y);
Point p1(x - 1, y - 1);
Point p2(x + 1, y + 1);
Rectangle square(p1, p2);
cwin << pen1 << blackPen << sBrush << square;
}
void initCircle(int x, int y, int r, int g, int b, PenWidth pen1, PenColour blackPen)
{
BrushColour sBrush = BrushColour(r, g, b);
Point p(x, y);
Circle smallCircle(p, 0.8);
cwin << pen1 << blackPen << sBrush << smallCircle;
}
int ccc_win_main()
{
cwin.coord(0, 24, 24, 0);
PenWidth pen1 = PenWidth(1);
PenColour blackPen = PenColour(0, 0, 0);
bool isDark = false;
initExit(16, 3, 240, 230, 70, pen1, blackPen);
initNewgame(8, 3, 240, 230, 70, pen1, blackPen);
for (int x = 5; x < 20; x = x + 2)
{
if (isDark == true)
{
isDark = false;
}
else
isDark = true;
for (int y = 7; y < 22; y = y + 2)
{
if (isDark == true)
{
initSquare(x, y, 55, 180, 15, pen1, PenColour(0, 0, 0));
isDark = false;
}
else{
initSquare(x, y, 240, 230, 70, pen1, PenColour(0, 0, 0));
isDark = true;
}
}
}
for (int x = 5; x < 20; x = x + 4)
{
for (int y = 7; y < 12; y = y + 4)
{
initCircle(x, y, 255, 0, 0, pen1, blackPen);
}
}
for (int x = 7; x < 20; x = x + 4)
{
int y = 9;
initCircle(x, y, 255, 0, 0, pen1, blackPen);
}
for (int x = 7; x < 20; x = x + 4)
{
for (int y = 17; y < 22; y = y + 4)
{
initCircle(x, y, 255, 255, 255, pen1, blackPen);
}
}
for (int x = 5; x < 20; x = x + 4)
{
int y = 19;
initCircle(x, y, 255, 255, 255, pen1, blackPen);
}
//This part does not work as i want it too. It is the exit button.
Point p = cwin.get_mouse("TEST TEST TEST");
double x = p.get_x();
double y = p.get_y();
if (x >= 8.3 && x <= 4.3 &&
y >= 4.5 && y <= 2.5)
{
return 1;
}
return 0;
}