#Battleship Issue

22 messages · Page 1 of 1 (latest)

wide ruin
#

Firstly I've created this C++ Console game with OOP in 1 file , then added 1 file with types and then separated each Class to a separate file(s) and there's appeared an issue :

Whatever value is set to Default of struct CellValue , the array in DataBoard fill with -858993460 instead of Default and the program can't work normally:
when it's time to randomly spawn a ship on board it check if there is already a ship to avoid spawn one over the other comparing a DataBoard array value (whitch is -858993460) with (eg ) -1, then again sellect random spawn coordinates ... there is infinite loop.

The only "fix" I found is to set Default of struct CellValue to the value that fills the DataBoard (-858993460).

https://github.com/Savvas200/BattleShip-Console-Game

GitHub

Battleship (C++ Console Project) – A console-based implementation of the classic Battleship game with OOP. - Savvas200/BattleShip-Console-Game

verbal pewterBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

unborn salmon
unborn salmon
#

it happens to be -858993460

#

you have to fill up the array in the DataBoard constructor

#

ah you call reset nooo

wide ruin
#

that is , I fill it

DataBoard::DataBoard()
{
ResetBoard();
boardSize = 10;
}

//Reset The Values of DataBoard
void DataBoard::ResetBoard()
{

for (int row = 0; row < boardSize; ++row)
{
    for (int cell = 0; cell < boardSize; ++cell)
    {
        board[row][cell] = CellValue::Default;
    }
}

}

unborn salmon
#

you really should use the member init list for this I struggled to find it xd

#

just a not dont use pragma once in cpp files

#

they are only needed in files you include

wide ruin
#

I found it ... just swap the

ResetBoard();  

and
boardSize = 10;

unborn salmon
#

i was just about to say i cloned your repo to debug because github is horrible with the colors...

unborn salmon
wide ruin
#

yes

unborn salmon
#

because ofc the board size happened to be 0

#

(or negative)

wide ruin
#

thanks

#

for help

#

!solved