Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

##Bug

Bug

##Bug

Bug

removed bad advice on std::array
Source Link
Summer
  • 2.4k
  • 2
  • 16
  • 31
Block grid[GRID_WIDTH][GRID_HEIGHT];

Use standard library containers. Prefer std::array when you know the size at compile time to C style arrays. Standard containers are better for several reasons:

  • Iterator support
  • algorithm support
  • Access violation exception support

srand(static_cast<unsigned int>(time(0)));

youYou define and initialize these to false only to make them true before they can be used properly. Just initialize them to true to begin with. Also prefer brace initialization is more idiomatic.

Don't declare multiple variable on single lines. preferUse 1:1 lines to variables. Especially when some are assigned and some are not. This can get confusing to read. is frame_time assigned 0? I know the answer but its not obvious just by looking at it.

Block grid[GRID_WIDTH][GRID_HEIGHT];

Use standard library containers. Prefer std::array when you know the size at compile time to C style arrays. Standard containers are better for several reasons:

  • Iterator support
  • algorithm support
  • Access violation exception support

srand(static_cast<unsigned int>(time(0)));

you define and initialize these to false only to make them true before they can be used properly. Just initialize them to true to begin with. Also prefer brace initialization.

Don't declare multiple variable on single lines. prefer 1:1 lines to variables. Especially when some are assigned and some are not. This can get confusing to read. is frame_time assigned 0? I know the answer but its not obvious just by looking at it.

srand(static_cast<unsigned int>(time(0)));

You define and initialize these to false only to make them true before they can be used properly. Just initialize them to true to begin with. Also brace initialization is more idiomatic.

Don't declare multiple variable on single lines. Use 1:1 lines to variables. Especially when some are assigned and some are not. This can get confusing to read. is frame_time assigned 0? I know the answer but its not obvious just by looking at it.

added 1 character in body
Source Link
Summer
  • 2.4k
  • 2
  • 16
  • 31

Game().Run() calls the Game constructor and creates a second instance of Game and thethen calls Run() on that instance. Your postgame stats likely aren't working correctly. No?

struct Position
{
 float x;
 float y;
};
struct BlockPoint
{
 int x;
 int y;
};
BlockPoint PositionToBlockPositionToPoint(Position const& position)
{
 BlockPoint blockpoint{ static_cast<int>(position.x), static_cast<int>(position.y) };
 return block;point;
}
Position pos{ grid_width / 2, grid_height / 2 };

Game().Run() calls the Game constructor and creates a second instance of Game and the calls Run() on that instance. Your postgame stats likely aren't working correctly. No?

struct Position
{
 float x;
 float y;
};
struct Block
{
 int x;
 int y;
};
Block PositionToBlock(Position const& position)
{
 Block block{ static_cast<int>(position.x), static_cast<int>(position.y) };
 return block;
}
Position pos{ grid_width / 2, grid_height / 2 };

Game().Run() calls the Game constructor and creates a second instance of Game and then calls Run() on that instance. Your postgame stats likely aren't working correctly. No?

struct Position
{
 float x;
 float y;
};
struct Point
{
 int x;
 int y;
};
Point PositionToPoint(Position const& position)
{
 Point point{ static_cast<int>(position.x), static_cast<int>(position.y) };
 return point;
}
Position pos{ grid_width / 2, grid_height / 2 };
explained cast helper function
Source Link
Summer
  • 2.4k
  • 2
  • 16
  • 31
Loading
Minor edits. Removed excessive use of the word prefer. Added more context around std::array. explained cast function solution
Source Link
Summer
  • 2.4k
  • 2
  • 16
  • 31
Loading
added 19 characters in body
Source Link
Summer
  • 2.4k
  • 2
  • 16
  • 31
Loading
Source Link
Summer
  • 2.4k
  • 2
  • 16
  • 31
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /