Problem with reseting game

closed account (10oTURfi)
Line 15 of Game.cpp gives me awkward error:
1>.\src\Game.cpp(14) : error C2059: syntax error : ']'
1>.\src\Game.cpp(14) : error C2143: syntax error : missing ';' before '{'
1>.\src\Game.cpp(14) : error C2143: syntax error : missing ';' before '}'


This is the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//Game.h
#include "SFML\Window.hpp"
#include "SFML\Graphics.hpp"
#include "SFML\Graphics\Drawable.hpp"

#ifndef GAME_H
#define GAME_H

class Game
{
    static bool IsExiting();
    static void GameLoop();
    static void GameReset();

    static void DrawX(float X, float Y, float _X, float _Y, int index);
    static void DrawO(float X, float Y, int index);

    static void ButtonPress(sf::Event& currentEvent);
    static char CheckWinCondition();

    static char board[11];
    static int counter;
	
    static void PrintFinalScreen(char WhoWon);

    enum GameState
    {
        Uninitialized, ShowingMenu, 
        Playing, Exiting, GameOver
    };

    enum Move
    {
        moveX,
        moveO
    };

    enum GameMode
    {
        SinglePlayer,
        MultiPlayer
    };

    static GameState _gameState;
    static sf::RenderWindow _mainWindow;
    static Move _move;

public:
    static void Start();
};

#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//Game.cpp
#include "Game.h"

sf::RenderWindow Game::_mainWindow;
Game::Move Game::_move = moveX;
Game::GameState Game::_gameState = Uninitialized;
char Game::board[] = { '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' };
int Game::counter = 0;

void Game::GameReset()
{
    _gameState = Uninitialized;
    _move = moveX;
    counter = 0;
    board[] = { '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' };//ERROR!
}

//Alot of code here... Removed cuz too long 


What am I doing wrong?
board[] = { '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' };//ERROR!

You can only use the = { } thing when arrays are constructed (ie: first created). Line 7 is where it's created, so it works there.

If you want to reset board, you'll have to use a loop and set each individual entry. Or you'll have to use a std function to do it (ie: std::fill).


Also -- why are you making everything static?
closed account (10oTURfi)
Thanks: it seem to work.

I'm making it static beacuse there are no objects of that class.
This is the main.cpp
1
2
3
4
5
6
7
8
9
#include "Game.h"

int main()
{
    //Start the game
    Game::Start();

	return 0;
}


Was it a bad idea?
Making everything static kind of defeats the point of putting it in a class. You're basically just making everything global.

I would recommend you do make an object:

1
2
3
4
5
int main()
{
  Game theGame;
  theGame.Start();
}
closed account (10oTURfi)
I lol'd IRL when I read that.
That sure is usefull to know.
Thanks again.
Topic archived. No new replies allowed.