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

Author Topic: Problem with tac tac toe  (Read 1213 times)

0 Members and 1 Guest are viewing this topic.

ltmtdz

  • Newbie
  • *
  • Posts: 1
    • View Profile
Problem with tac tac toe
« on: October 30, 2011, 07:13:10 pm »
I have a strange problem with my game.
I get this error when i debugg:

Quote
1>c:\program files (x86)\sfml-1.6\include\sfml\window\window.hpp(321): error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'
1>          c:\program files (x86)\sfml-1.6\include\sfml\system\noncopyable.hpp(57) : see declaration of 'sf::NonCopyable::NonCopyable'
1>          c:\program files (x86)\sfml-1.6\include\sfml\system\noncopyable.hpp(41) : see declaration of 'sf::NonCopyable'
1>          This diagnostic occurred in the compiler generated function 'sf::Window::Window(const sf::Window &)'


What is the problem?
Heres my code of the game Tic Tac Toe:

Code: [Select]
#include <iostream>
#include <SFML/Graphics.hpp>
#define X 3
#define Y 3
using namespace std;
bool ginit = true;
char field[3][3];
char eile = 'O';
char kitoeile = 'X';
char pergale = 0;
int pradzia()
{
pergale = 0;
for(int b=0;b<Y;b++)
{
for(int a=0;a<X;a++)
{
field[a][b] = ' ';
}
}
return 0;
}
int inputhandle(const sf::Input& Input)
{
bool LeftKeyDown = Input.IsKeyDown(sf::Key::Left);
unsigned int MouseX = Input.GetMouseX();
unsigned int MouseY = Input.GetMouseY();
int Xas;
int Yas;
if(LeftKeyDown)
{
if(MouseX < 100)
{
Xas = 0;
}else if(MouseX > 100 && MouseX < 200)
{
Xas = 1;
}else if(MouseX > 200)
{
Xas = 2;
}
if(MouseY < 100)
{
Yas = 0;
}else if(MouseY > 100 && MouseY < 200)
{
Yas = 1;
}else if(MouseY > 200)
{
Yas = 2;
}
if(field[Xas][Yas] == ' ')
{
field[Xas][Yas] = eile;
eile = kitoeile;
kitoeile = field[Xas][Yas];
}
if(field[0][0] != ' ' && field[0][1] != ' ' && field[0][2] != ' ' && field[1][0] != ' ' && field[1][1] != ' ' && field[1][2] != ' ' && field[2][0] != ' ' && field[2][1] != ' ' && field[2][2] != ' ')
{
pergale = 2;
}
}
return 0;
}
int collision()
{
if(field[0][0] == kitoeile && field[1][0] == kitoeile && field[2][0] == kitoeile)
{
pergale = 1;

}else if(field[0][1] == kitoeile && field[1][1] == kitoeile && field[2][1] == kitoeile)
{
pergale = 1;
}else if(field[0][2] == kitoeile && field[1][2] == kitoeile && field[2][2] == kitoeile)
{
pergale = 1;
}else if(field[0][0] == kitoeile && field[0][1] == kitoeile && field[0][2] == kitoeile)
{
pergale = 1;
}else if(field[1][0] == kitoeile && field[1][1] == kitoeile && field[1][2] == kitoeile)
{
pergale = 1;
}else if(field[2][0] == kitoeile && field[2][1] == kitoeile && field[2][2] == kitoeile)
{
pergale = 1;
}else if(field[0][0] == kitoeile && field[1][1] == kitoeile && field[2][2] == kitoeile)
{
pergale = 1;
}else if(field[2][0] == kitoeile && field[1][1] == kitoeile && field[0][2] == kitoeile)
{
pergale = 1;

}
return 0;
}
int paintfield(sf::RenderWindow App, sf::Sprite fieldsprite[3][3], sf::Image tuscia, sf::Image imageO, sf::Image imageX)
{
for(int b=0;b<Y;b++)
{
for(int a=0;a<X;a++)
{
if(field[a][b] == ' ')
{
fieldsprite[a][b].SetImage(tuscia);
fieldsprite[a][b].SetPosition(a*100.f, b*100.f);
App.Draw(fieldsprite[a][b]);
}
if(field[a][b] == 'X')
{
fieldsprite[a][b].SetImage(imageX);
fieldsprite[a][b].SetPosition(a*100.f, b*100.f);
App.Draw(fieldsprite[a][b]);
}
if(field[a][b] == 'O')
{
fieldsprite[a][b].SetImage(imageO);
fieldsprite[a][b].SetPosition(a*100.f, b*100.f);
App.Draw(fieldsprite[a][b]);
}
}
}
if(pergale == 1)
{
ginit = false;
}else if(pergale == 2)
{
ginit = false;
}
App.Clear();
//    App.Draw();
    App.Display();
return 0;
}
int main()
{
sf::RenderWindow App(sf::VideoMode(300, 300, 32), "Tic Tac Toe! made by Zilvinas");
const sf::Input& Input = App.GetInput();
sf::Image imageX;
sf::Image imageO;
sf::Image imagelenta;
sf::Image tuscia;
    if(!imageX.LoadFromFile("X.png"))
        return EXIT_FAILURE;
if(!imageO.LoadFromFile("O.png"))
        return EXIT_FAILURE;
if(!imagelenta.LoadFromFile("lenta.png"))
        return EXIT_FAILURE;
if(!tuscia.LoadFromFile("tuscia.png"))
        return EXIT_FAILURE;
sf::Sprite fieldsprite[3][3];
pradzia();
while (ginit)
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

inputhandle(Input);
collision();
paintfield(App, fieldsprite, tuscia, imageX, imageO);
    }
return 0;
}

Salepate

  • Newbie
  • *
  • Posts: 11
    • View Profile
Problem with tac tac toe
« Reply #1 on: October 31, 2011, 01:19:27 am »
you have a bad prototype
Code: [Select]

int paintfield(sf::RenderWindow App, sf::Sprite fieldsprite[3][3], sf::Image tuscia, sf::Image imageO, sf::Image imageX)


the first argument should be a reference, otherwise it would try copying your RenderWindow, which is unrequired

Code: [Select]

int paintfield(sf::RenderWindow &App, sf::Sprite fieldsprite[3][3], sf::Image tuscia, sf::Image imageO, sf::Image imageX)

even if it works, the way you pass arguments is quite wrong