Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - omarking05

Pages: [1]
1
Graphics / Re: questions about Dots game project
« on: May 20, 2013, 01:30:56 pm »
Okay ,I really appreciated thanks Dr ^^

2
Graphics / Re: questions about Dots game project
« on: May 19, 2013, 01:38:16 pm »
sorry Dr im kinda confused with all of this functions , i think the problems are getting bigger and bigger .
yes I know that i should break up event from drawing but what if i need to mix them like if he closed the square set BOOL = true and if BOOL == true , then Draw(something) and Do event like score++ !!
the score here will getting bigger and bigger cuz BOOL will always be true !

what i understood from your reply :

if (gameState==NOT_PLAYING){
        // change the game state
        gameState = PLAYER_ONE_TURN;
      }

it will change game state to PLAYER_ONE_TURN and else it will Deal with the logic inside game

and here :
if (gameState==NOT_PLAYING){
    // draw the menu, and a message that says "click to start"
  }
  else {
     drawTheGrid();
     if (gameState==PLAYER_ONE_TURN){
        // draw the text "player one's turn"
     }
     else if (gameState==PLAYER_TWO_TURN){
        // draw the text "player two's turn"
     }

If it was player1 turn can I add 1 to his score HERE if he closed the square ?

what i don't understand bout bool GridHasHLine(Grid& grid, int x, int y) Function is why we are checking if there is a line or not !? , if the user himself MUST click on the line or nothing would happen ?!

in bool clickedOnHLine = GridHLineAtMouse(grid, event.mouse.x, event.mouse.y, hx, hy);

hx an hy are the position of the line ,right ?

i don't understand this function :(
 bool isSet = GridHasHLine(grid, hx, hy);
      if (isSet){
         // then line is already set, so don't do anything
      }
      else {
         // line is not set, so we set it and update the score etc..
         GridSetHLine(grid,hx,hy,true);
         updateScore()...
      }

Thanks for your time Dr.

3
Graphics / Re: questions about Dots game project
« on: May 18, 2013, 07:34:51 am »
Thanks Dr i really appreciate your time and help :)) .
although your reply was very helpful but im really confused , and got more questions

First
i think im rolling in circle without or like im taking a lot of time in this project although its easy except some bugs ,and im kinda approaching dead line so i need to build a working game as quickly as i can and then improve it if there is a time ,so i hope if there is any simple solution for this instead of lost into hard codes and reaching deadline .
but i can't deny the benefits i gained and gaining here ,and im making really use of it.

Second
questions about code (in comments) :

enum GameState {NOT_PLAYING, PLAYER_ONE_TURN, PLAYER_TWO_TURN};
...
GameState gameState;
while(window.isOpen()){
  ...
  if (event.type==Event::MouseButtonPressed && event.mouseButton.button==sf::Mouse::Left){
    if (gameState==NOT_PLAYING){
      start the game ...
          drawing grid and Displaying texts and menu right?
    }    
    else {
      detect which line we have clicked in
                  i will do that with 2 functions :
                        void GridSetHLine(Grid& grid, int x, int y, bool b);
                        void GridSetVLine(Grid& grid, int x, int y, bool b);
                        right?

      then update the lines
                Draw the line with another color that shows to the user that he has clicked on right?

      numLoops= calculate all the loops we've just closed
      if (gameState==PLAYER_ONE_TURN) playerOneScore += numLoops;
      else if (gameState==PLAYER_TWO_TURN) playerTwoScore += numLoops;  
      detect if the grid is full, and if so go into GAME_FINISHED mode and show who won      
    }
  }
  ...
  draw everything
  to draw anything i will set bool variable and using if and else i will draw it
}

so am i getting it right till now?

for the other code :

i got that Grid is kinda grid of bool beside the grid it drawn to the user ,and we use it to determine which line the user has clicked on.

void GridSetEmpty(Grid& grid);

so this function set all the grid to False till user click on any line it comes the turn of this two functions :

bool GridHasHLine(Grid& grid, int x, int y);
bool GridHasVLine(Grid& grid, int x, int y);

im really confusing at this ,but i think its a mouse position (x,y) ,but i can't understand why checking if the mouse position is in the range of the grid ? ,and also returning x and y as here :
else {
    return grid.hlines[x][y];
  }
confusing me cuz it cant be mouse position or it will be returning a huge integer for a grid.

any way this 2 functions will return some values that this two functions will take :
void GridSetHLine(Grid& grid, int x, int y, bool b);
void GridSetVLine(Grid& grid, int x, int y, bool b);

so this 2 functions will set the clicked line to True till it comes to the logic of GAME_FINISHED mode

so i hope i get most of it right :D ,and thanks for your time agian Dr :)

4
Graphics / Re: questions about Dots game project
« on: May 17, 2013, 07:28:42 pm »
Also thanks for your advices , and any help to improve my code i will be grateful :)

5
Graphics / Re: questions about Dots game project
« on: May 17, 2013, 07:23:08 pm »
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;
}

6
Graphics / Re: questions about Dots game project
« on: May 17, 2013, 03:31:33 am »
Any help !

I set all the Keys (  r1_key, r2_key, r3_key and r4_key ) to false till the player click on the any of the 4 lines then it set one of the keys to true as in the code :

if (event.type==Event::MouseButtonPressed)
                        {
                                if (event.key.code== Mouse::Left && r1_copy.getGlobalBounds().contains(mouse_x,mouse_y))
                                {
                                        r1_key=true;
                                        turn=false;
                                }
                                else if (event.key.code== Mouse::Left && r2_copy.getGlobalBounds().contains(mouse_x,mouse_y))
                                {
                                        r2_key=true;
                                        turn=false;
                                }
                                else if (event.key.code== Mouse::Left && r3_copy.getGlobalBounds().contains(mouse_x,mouse_y))
                                {
                                        r3_key=true;
                                        turn=false;
                                }
                                else if (event.key.code== Mouse::Left && r4_copy.getGlobalBounds().contains(mouse_x,mouse_y))
                                {
                                        r4_key=true;
                                        turn=false;
                                }
                        }

and if all Keys are true so it is a full closed square , and i initialized bool variable turn where :
Turn = true >> First player turn
Turn = false >> second player turn
So if its closed square check if its player 1 turn or not as here :

if (r1_key && r2_key && r3_key && r4_key)
                        if (turn)
                                player1_score++;
                        else if (!turn)
                                player2_score++;

and here is a problem that makes the score is always increasing without stopping that i connected the drawing of the lines with the Turn variable to make it True again to let the player play .
as here :

if (r1_key)
                {
                        Window.draw(r1);
                        turn=true;
                }
                if (r2_key)
                {
                        Window.draw(r2);
                        turn=true;
                }
                if (r3_key)
                {
                        Window.draw(r3);
                        turn=true;
                }
                if (r4_key)
                {
                        Window.draw(r4);
                        turn=true;
                }

Im really confused with a big pressure on , so any help i will be grateful .

7
Graphics / Re: questions about Dots game project
« on: May 16, 2013, 04:34:15 pm »
aha , it is True all the game I see .
but if i set to False the lines would gone !!

8
Graphics / Re: questions about Dots game project
« on: May 16, 2013, 01:41:22 am »
okay , i did it but for 1 square till now but i encountered a prob , I ( cout ) the score but it keep increasing and increasing
here is my code :
#include <SFML/Graphics.hpp>
#include <string>
#include <iostream>
#include <SFML/Graphics/Vertex.hpp>
using namespace std;
using namespace sf;

const int SIZE=4;

void Set_Position(CircleShape circles[][SIZE])
{      
        int pos_x=50,pos_y=50;

        for ( int i=0;i<SIZE;i++)
                for (int j=0;j<SIZE;j++)
                {
                        circles[i][j].setPosition(pos_x,pos_y);
                        circles[i][j].setRadius(5);
                        pos_x+=100;
                        if (j==SIZE-1)
                        {
                                pos_x=50;
                                pos_y+=100;
                        }
                }
}


int main ()
{
        Vector2i screenDimensions(400,400);
        sf::RenderWindow Window;
        Window.create(sf::VideoMode(screenDimensions.x,screenDimensions.y),"My First Sfml Game");
       
        CircleShape circles[SIZE][SIZE];
        Set_Position(circles);
       
        //Lines
        //Y
        RectangleShape r1;
        r1.setSize(Vector2f(10,100));
        r1.setFillColor(Color::Blue);
        r1.setPosition(50,55);

        RectangleShape r1_copy;
        r1_copy.setSize(Vector2f(10,100));
        r1_copy.setFillColor(Color::Yellow);
        r1_copy.setPosition(50,55);

        RectangleShape r2;
        r2.setSize(Vector2f(10,100));
        r2.setFillColor(Color::Blue);
        r2.setPosition(150,55);

        RectangleShape r2_copy;
        r2_copy.setSize(Vector2f(10,100));
        r2_copy.setFillColor(Color::Yellow);
        r2_copy.setPosition(150,55);
       
        //X
        RectangleShape r3;
        r3.setSize(Vector2f(100,10));
        r3.setFillColor(Color::Blue);
        r3.setPosition(50,50);

        RectangleShape r3_copy;
        r3_copy.setSize(Vector2f(100,10));
        r3_copy.setFillColor(Color::Yellow);
        r3_copy.setPosition(55,50);

        RectangleShape r4;
        r4.setSize(Vector2f(100,10));
        r4.setFillColor(Color::Blue);
        r4.setPosition(50,150);

        RectangleShape r4_copy;
        r4_copy.setSize(Vector2f(100,10));
        r4_copy.setFillColor(Color::Yellow);
        r4_copy.setPosition(55,150);

        bool r1_key=false,r2_key=false,r3_key=false,r4_key=false;
        bool turn=true;

        int mouse_x,mouse_y,player1_score=0,player2_score=0;
       

        while (Window. isOpen())
        {
                sf::Event event;
                while (Window.pollEvent(event))
                {
                        switch(event.type)
                        {
                                case sf::Event::Closed:
                                Window.close();
                                break;
                        }
                        if (event.type==Event::MouseMoved)
                        {
                                mouse_x=event.mouseMove.x;
                                mouse_y=event.mouseMove.y;
                        }

                        if (event.type==Event::MouseButtonPressed)
                        {
                                if (event.key.code== Mouse::Left && r1_copy.getGlobalBounds().contains(mouse_x,mouse_y))
                                {
                                        r1_key=true;
                                        turn=false;
                                }
                                else if (event.key.code== Mouse::Left && r2_copy.getGlobalBounds().contains(mouse_x,mouse_y))
                                {
                                        r2_key=true;
                                        turn=false;
                                }
                                else if (event.key.code== Mouse::Left && r3_copy.getGlobalBounds().contains(mouse_x,mouse_y))
                                {
                                        r3_key=true;
                                        turn=false;
                                }
                                else if (event.key.code== Mouse::Left && r4_copy.getGlobalBounds().contains(mouse_x,mouse_y))
                                {
                                        r4_key=true;
                                        turn=false;
                                }
                        }
                }

                if (r1_key && r2_key && r3_key && r4_key)
                        if (turn)
                                player1_score++;
                        else if (!turn)
                                player2_score++;

                cout<<player1_score<<" "<<player2_score<<endl;
               
                Window.draw(r1_copy);
                Window.draw(r2_copy);
                Window.draw(r3_copy);
                Window.draw(r4_copy);
               
               
                if (r1_key)
                {
                        Window.draw(r1);
                        turn=true;
                }
                if (r2_key)
                {
                        Window.draw(r2);
                        turn=true;
                }
                if (r3_key)
                {
                        Window.draw(r3);
                        turn=true;
                }
                if (r4_key)
                {
                        Window.draw(r4);
                        turn=true;
                }

                //Drawing Dots
                for (int i=0;i<SIZE;i++)
                        for (int j=0;j<SIZE;j++)
                                Window.draw(circles[i][j]);
               
                Window.display();
                Window.clear();
        }

        return 0;
}
 

Also here ( for more comfortable ) : http://www.ahmed-aly.com/f.jsp?i=XJtDLZVa

thanks for your time eXpl0it3r ^^

9
Graphics / Re: questions about Dots game project
« on: May 15, 2013, 03:35:05 am »
I actually did that but i still can't find the logic that add 1 to one of 2 players score , that is the thing that i miss

10
Graphics / Re: questions about Dots game project
« on: May 14, 2013, 10:14:02 am »
thanks for reply ^^ .

in fact , yes maybe be my knowledge isn't enough for that project i reached till STL in C++ till now but what can i do its a first year college project and i have to do it :D.

the problem in Multiplayer issue that i use mouse instead of keyboard and i don't know what line would any of the 2 players choose ! , so i can't increase the score due to clicking on special texture or thing cuz i don't know what this thing would be !

and to be clear i want to make user share mouse and also take turns between User1 and User2 .

thanks again :))

11
Graphics / questions about Dots game project
« on: May 14, 2013, 09:22:58 am »
Hey ,
im doing a dots game project and i have a lot of questions about using arrays and some logic of the game

1- how can i make an array of circles ? - to use it in drawing dots on the window -
i tried to use vertex array but i didn't find any solution !

rest of questions about the Dots project so anyone can Give me a help please don't stop it ^^

2- how can i do a multiplayer game logic ? in simple way

3- how can i write the logic code of making the score increases one if the one of the 2 users complete a full square ?

this is how i want my project to be like if you didn't understand because my bad English :D
http://www.addictinggames.com/puzzle-games/dots.jsp

thanks in advance

Pages: [1]