Here is the code after Editing it i made an array of lines initializing it with 48 divided into , 24 lines Colored with yellow that will user click on , and other 24 lines colored with red that will be drawn after user click .
so its the same problems plus it breaks when i try to draw the red line !!
Code :
#include <SFML/Graphics.hpp>
#include <string>
#include <iostream>
#include <algorithm>
#include <SFML/Graphics/Vertex.hpp>
using namespace std;
using namespace sf;
//Consts
const int Num_Rects = 48 ;
const int Num_Yellow = 24 , Num_Red = 48 ;
const Color Rect_Colors [Num_Rects] ;
bool Key_Flag[Num_Red] = {false};
void Intialize_Colors ( RectangleShape Rect_Colors[] )
{
for (int i=0 ; i<Num_Yellow ; i++)
Rect_Colors[i].setFillColor(Color::Yellow);
for (int i=Num_Yellow ; i<Num_Red ; i++)
Rect_Colors[i].setFillColor(Color::Red);
}
void Intialize_Position ( RectangleShape rects[] )
{
const Vector2f Rect_Positions [Num_Rects] = {
Vector2f(55,50) , Vector2f(155,50) , Vector2f(255,50)
, Vector2f(50,55) , Vector2f(150,55) , Vector2f(250,55) , Vector2f(350,55)
, Vector2f(55,150) , Vector2f(155,150) , Vector2f(255,150)
, Vector2f(50,155) , Vector2f(150,155) , Vector2f(250,155) , Vector2f(350,155)
, Vector2f(55,250) , Vector2f(155,250) , Vector2f(255,250)
, Vector2f(50,255) , Vector2f(150,255) , Vector2f(250,255) , Vector2f(350,255)
, Vector2f(55,350) , Vector2f(155,350) , Vector2f(255,350)
, Vector2f(55,50) , Vector2f(155,50) , Vector2f(255,50)
, Vector2f(50,55) , Vector2f(150,55) , Vector2f(250,55) , Vector2f(350,55)
, Vector2f(55,150) , Vector2f(155,150) , Vector2f(255,150)
, Vector2f(50,155) , Vector2f(150,155) , Vector2f(250,155) , Vector2f(350,155)
, Vector2f(55,250) , Vector2f(155,250) , Vector2f(255,250)
, Vector2f(50,255) , Vector2f(150,255) , Vector2f(250,255) , Vector2f(350,255)
, Vector2f(55,350) , Vector2f(155,350) , Vector2f(255,350)
};
for (int i=0 ; i<Num_Rects ; i++)
rects[i].setPosition(Rect_Positions[i]);
}
void Intialize_Size ( RectangleShape rects[] )
{
const Vector2f Lines_Size [Num_Rects] = {
Vector2f(100,10) , Vector2f(100,10) , Vector2f(100,10)
, Vector2f(10,100) , Vector2f(10,100) , Vector2f(10,100) , Vector2f(10,100)
, Vector2f(100,10) , Vector2f(100,10) , Vector2f(100,10)
, Vector2f(10,100) , Vector2f(10,100) , Vector2f(10,100) , Vector2f(10,100)
, Vector2f(100,10) , Vector2f(100,10) , Vector2f(100,10)
, Vector2f(10,100) , Vector2f(10,100) , Vector2f(10,100) , Vector2f(10,100)
, Vector2f(100,10) , Vector2f(100,10) , Vector2f(100,10)
, Vector2f(100,10) , Vector2f(100,10) , Vector2f(100,10)
, Vector2f(10,100) , Vector2f(10,100) , Vector2f(10,100) , Vector2f(10,100)
, Vector2f(100,10) , Vector2f(100,10) , Vector2f(100,10)
, Vector2f(10,100) , Vector2f(10,100) , Vector2f(10,100) , Vector2f(10,100)
, Vector2f(100,10) , Vector2f(100,10) , Vector2f(100,10)
, Vector2f(10,100) , Vector2f(10,100) , Vector2f(10,100) , Vector2f(10,100)
, Vector2f(100,10) , Vector2f(100,10) , Vector2f(100,10)
};
for (int i=0 ; i<Num_Rects ; i++)
rects[i].setSize(Lines_Size[i]);
}
void Set_Position(CircleShape circles[][Num_Rects])
{
int pos_x=50,pos_y=50;
for ( int i=0;i<Num_Rects;i++)
for (int j=0;j<Num_Rects;j++)
{
circles[i][j].setPosition(pos_x,pos_y);
circles[i][j].setRadius(5);
pos_x+=100;
if (j==Num_Rects-1)
{
pos_x=50;
pos_y+=100;
}
}
}
int main ()
{
bool r1_key=false,r2_key=false,r3_key=false,r4_key=false;
bool turn=true;
int player1_score=0,player2_score=0;
Vector2i screenDimensions(400,400);
sf::RenderWindow Window;
Window.create(sf::VideoMode(screenDimensions.x,screenDimensions.y),"The Fuckin DOTS Game");
CircleShape circles[Num_Rects][Num_Rects];
Set_Position(circles);
//Lines
RectangleShape rects [Num_Rects];
//INTIALIZING colors , positions and Sizes
Intialize_Colors(rects);
Intialize_Position(rects);
Intialize_Size(rects);
while (Window. isOpen())
{
sf::Event event;
while (Window.pollEvent(event))
{
if ( (event.type==Event::KeyPressed && event.key.code==Keyboard::Escape) || event.type == Event::Closed)
Window.close();
if (event.type==Event::MouseButtonPressed && event.mouseButton.button==sf::Mouse::Left)
{
for (int i=0 ; i<Num_Rects ; i++)
{
if (rects[i].getGlobalBounds().contains(event.mouseButton.x,event.mouseButton.y))
{
Key_Flag[i]=true;
turn=false;
Window.draw(rects[23+i]);
}
}
}
}
for (int i=0 ; i<Num_Rects ; i++)
{
if (Key_Flag[i] && Key_Flag[i+3] && Key_Flag[i+7] && Key_Flag[i+4])
if (turn)
player1_score++;
else if (!turn)
player2_score++;
}
//Drawing Lines
for (int i=0 ; i<Num_Rects/2 ; i++)
Window.draw(rects[i]);
//Drawing Dots
for (int i=0;i<Num_Rects;i++)
for (int j=0;j<Num_Rects;j++)
Window.draw(circles[i][j]);
Window.display();
Window.clear();
}
return 0;
}