Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 68 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7  Next
Author Message
 Post subject: Re: Simon Says Game
 Post Posted: July 5th, 2017, 4:15 pm 
User avatar

Joined: February 14th, 2017, 7:32 pm
Posts: 170
I got it to work! https://github.com/Zedtho/Simon-Says
Now for the actual program, Im having a problem with it not actually responding when I click on a square.
Here's what the game should look like at the end http://www.freesimon.org/welcome/
I do not endorse or am affiliated with the website or the people working on it and will not be blamed if you get a virus or something along those lines.

EDIT: It added the sln file as a text document again. Why isnt it working this time? :(


Top 
 Profile  
Reply with quote  
 Post subject: Re: Simon Says Game
 Post Posted: July 6th, 2017, 12:59 am 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2711
Location: Oklahoma, United States
This isn't a good way to handle things

Code:
while( duration < 1 )
{
   BLRed = 255;
   BLGreen = 255;
   BLBlue = 0;
   end = std::chrono::steady_clock::now();
   runtime = end - start;
   duration = runtime.count();
   gfx.BeginFrame();
   ComposeFrame();
   gfx.EndFrame();
}


The game locks up on me, because it gets stuck in one of these while loops.

The game is already in a loop, so the BeginFrame, ComposeFrame and EndFrame are being called once per frame already. You need to make iterations last an entire frame and not try to draw and present in a while loop like that.

Try making some functions to separate the code. This will make it easier to find what where problems are and depending on how you write your functions, there could be some code reuse. For instance, a lot of the code you have is very similar, to other sections, try putting that code in a function. Use function parameters to change how the function behaves.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post subject: Re: Simon Says Game
 Post Posted: July 6th, 2017, 4:38 pm 
User avatar

Joined: February 14th, 2017, 7:32 pm
Posts: 170
I'll make a more object-oriented version right now! Thanks for the feedback :D


Top 
 Profile  
Reply with quote  
 Post subject: Re: Simon Says Game
 Post Posted: July 6th, 2017, 9:21 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2711
Location: Oklahoma, United States
Doesn't have to be OO, but the biggest concern is the begin, compose, end frames being in while loops inside of a loop that already calls those functions.

You should at least figure out how to use enums as a way of implementing a state machine. While in a specified state, the current color pattern is lit, then after a period of time and frames, change states and the color will dim and advance to the next pattern. You can have two states for the computer and player based on turn, and each one of those states can have their own state based on time. This will allow you to control flow of the game across multiple frames.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post subject: Re: Simon Says Game
 Post Posted: July 8th, 2017, 1:01 pm 
User avatar

Joined: February 14th, 2017, 7:32 pm
Posts: 170
I'll note that Papa!

I've got a rather odd error this time:

Squares.h file
Code:
class Square
{
public:
   int RedV;
   int GreenV;
   int BlueV;
    int HorizontalLeft;
    int HorizontalRight;
    int VerticalBottom;
    int VerticalTop;   
   Square(int GivenRedV, int GivenGreenV, int GivenBlueV, int GivenHorizontalLeft, int GivenHorizontalRight, int GivenVerticalBottom, int GivenVerticalTop)
   {
      RedV = GivenRedV;
      GreenV = GivenGreenV;
      BlueV = GivenBlueV;
      HorizontalLeft = GivenHorizontalLeft;
      HorizontalRight = GivenHorizontalRight;
      VerticalBottom = GivenVerticalBottom;
      VerticalTop = GivenVerticalTop;
   }
};



I can't figure out how to initialize my 4 squares, RedTopLeft, BlueTopRight, YellowBottomLeft and GreenBottomRight:

Top Part in game.cpp
Code:
Game::Game( MainWindow& wnd )
   :
   wnd( wnd ),
   gfx( wnd )
{
   Square RedTopLeft (50, 0, 0, +100, +5, -5, -100);
   Square BlueTopRight (0, 0, 50, -5, -100, -5, -100);
   Square YellowBottomLeft (50, 50, 0, +100, +5, +5, +100);
   Square GreenBottomRight (0, 50, 0, -100, -5, +5, +100);
}


I also tried to put these initializations in game.h, but that didnt change anything
game.h
Code:
   Square RedTopLeft;
   Square BlueTopRight;
   Square YellowBottomLeft;
   Square GreenBottomRight;


The Debug Output
1>------ Build started: Project: Engine, Configuration: Release Win32 ------
1> Game.cpp
1> Main.cpp
1> MainWindow.cpp
1>Game.cpp(29): error C2512: 'Square': no appropriate default constructor available
1> c:\users\gebruiker\downloads\simon says v3\chili framework 2016\engine\Squares.h(4): note: see declaration of 'Square' (compiling source file Game.cpp)
1>Game.cpp(48): warning C4244: 'argument': conversion from 'time_t' to 'unsigned int', possible loss of data
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Top 
 Profile  
Reply with quote  
 Post subject: Re: Simon Says Game
 Post Posted: July 8th, 2017, 1:50 pm 
 

Joined: April 19th, 2017, 12:49 pm
Posts: 33
Location: Germany
Hi,
the problem is like the error message says those member variables in game.h cant be constructed by default. You defined a specific constructor for the Square class:

Code:
Square(int GivenRedV, int GivenGreenV, int GivenBlueV, int GivenHorizontalLeft, int GivenHorizontalRight, int GivenVerticalBottom, int GivenVerticalTop)


The default constructor is usually a constructor with no parameters:
like classname(){}

I guess you tried to initialize those members in the game constructor here:

Code:
Game::Game( MainWindow& wnd )
   :
   wnd( wnd ),
   gfx( wnd )
{
   Square RedTopLeft (50, 0, 0, +100, +5, -5, -100); //declaring local variables initialized with your specified constructor in Square.h
   Square BlueTopRight (0, 0, 50, -5, -100, -5, -100);
   Square YellowBottomLeft (50, 50, 0, +100, +5, +5, +100);
   Square GreenBottomRight (0, 50, 0, -100, -5, +5, +100);
}


But you re actual creating new local variables cause you placed the type Square in front of those.
And thatswhy the members in game.h are not initialized with these lines.
And so the compiler bitches that those members cant be constructed properly.

You could put those lines in the initializer list of the game.cpp constructor like:

Code:
Game::Game( MainWindow& wnd )
   :
   wnd( wnd ),
   gfx( wnd ),

   RedTopLeft (50, 0, 0, +100, +5, -5, -100), //initializing members stored in game.h with your specific constructor
   BlueTopRight (0, 0, 50, -5, -100, -5, -100),
   YellowBottomLeft (50, 50, 0, +100, +5, +5, +100),
   GreenBottomRight (0, 50, 0, -100, -5, +5, +100)
{
}


Hope that helps. I couldnt test it myself, but it should point you at least in the right direction.


Top 
 Profile  
Reply with quote  
 Post subject: Re: Simon Says Game
 Post Posted: July 8th, 2017, 6:03 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2711
Location: Oklahoma, United States
xu2201g wrote:
You could put those lines in the initializer list of the game.cpp constructor...


Kudos on the solution and explanation with example. The only thing I'd like to point out is if Square doesn't have a default constructor, you must ( not could ) use the initializer list of any class you have a Square object, just like xu2201g's example. To have the option of delaying initialization, you must at the very least add Square() = default; as the default constructor of class Square.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post subject: Re: Simon Says Game
 Post Posted: July 8th, 2017, 6:33 pm 
User avatar

Joined: February 14th, 2017, 7:32 pm
Posts: 170
Thanks a lot for the help! The programming is currently going very smoothly by the way,
it's a lot nicer with a bunch of functions & stuff.


Top 
 Profile  
Reply with quote  
 Post subject: Re: Simon Says Game
 Post Posted: July 8th, 2017, 6:38 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2711
Location: Oklahoma, United States
sweet

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post subject: Re: Simon Says Game
 Post Posted: July 12th, 2017, 5:39 pm 
User avatar

Joined: February 14th, 2017, 7:32 pm
Posts: 170
https://github.com/Zedtho/Simon-Says I uploaded my 3rd version of the game. I can't find the bug in it, which is causing the game to stop.

Edit 1: Found one bug, it should be
Code:
 if(TimeOutForSetColor != 0)TimeOutForSetColor--;
instead of just
Code:
TimeOutForSetColor--;


Edit 2: All functions except for UpdateModel are fully operational and have no bugs. If anything, I would probably be calling those functions wrongly.

Edit 3:

Code:
if (wnd.mouse.GetPosX() > AxisX && wnd.mouse.GetPosX() < AxisX + GreenBottomRight.HorizontalRight && wnd.mouse.GetPosY() > AxisY && wnd.mouse.GetPosY() < AxisY + GreenBottomRight.VerticalBottom && wnd.mouse.LeftIsPressed() && TimeOutForSetColor == 0)
            {
               UserInput.push_back(4);
               SetColor(GreenBottomRight, 0, 30, 0);
               TimeOutForSetColor = 30;
               if (UserInput[UserInput.size() - 1] != ColorPattern[UserInput.size() - 1])
               {
                  GameOver = true;
               }
            }

and its YellowBottomLeft equivalent used to say SetColor(BlueTopLeft). Fixed.

Edit 4: With that I fixed the last bug I could easily find. Now come the huge logic problems :(

Edit 5: Used to say if(IndexForColorPattern == ColorPattern.size()-1) , fixed, should be without -1.
Will keep posting bugs I find. Game no longer crashes in Debug mode.


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 68 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7  Next

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: