Page 1 of 7 [ 68 posts ] Go to page 1, 2, 3, 4, 5 ... 7  Next

#### Simon Says Game

 Print view Previous topic | Next topic

#### Simon Says Game

Author Message
 Post subject: Simon Says Game  Posted: June 15th, 2017, 7:34 pm

Joined: February 14th, 2017, 7:32 pm
Posts: 170
Hi guys!

I'm back from about 2 months without programming, had a lot of exams in the meantime, sorry 'bout that.

To get back in to the groove I thought of making a Simon Says game (the one where you have to click on the colors in the right order every round and each round one step gets added)

Doesn't seem too hard. It would be nice to be able to use the cursor, but although Chili once told someone it on the forum, I must've forgotten. So I'll stick with WASD for now.
One thing I don't know how to do is the memory for the rounds every game, so I need an expandable "box", think they were called vectors, but again, I'm rusty. Accessing and manipulating it shouldn't be too hard, I hope.

But, this will probably be a hard project, since I had the same attitude when I made Pong .
Anyways, I'm looking forward to programming again!

// Future Zedtho here. I was completely wrong, this would not be an easy project. Atleast, not the way I handled it.

Last edited by Zedtho on July 15th, 2017, 2:14 pm, edited 2 times in total.

 Post subject: Re: Im back! Some questions...  Posted: June 15th, 2017, 9:15 pm

Joined: January 19th, 2017, 10:28 pm
Posts: 487
Location: Idiot from northern Europe
Fun idea for a poject, I might steal it

Pretty sure chili covers a little bit about the mouse in this video

Vectors seems like a good idea. One vector to store the pattern chosen by the computer and then compare users choices to the ones in the vector.

Code:
#include <vector>
#include <random>

int sequence = 1;
std::vector<int> choices;
std::random_device rd;
std::mt19937 rng(rd());
std::uniform_int_distribution<int>dist(1, 4);

void PickColors();

bool IsNotCorrect()
{
for (int i = 0; i < sequence; i++)
{
//get the user input
int userInput;
if (userInput != choices[sequence])
{
return false;
}
return true;
}
}

int main()
{
//when game starts
//function that stores the pattern
//and shows the colors flashing,
{
PickColors();
}

//now the user picks colors
{
if (IsNotCorrect())
{
//game ends and we start over

}
else
{
sequence++;
}
choices.clear();
}

}

void PickColors()
{
for (int i = 0; i < sequence; i++)
{
int color = dist(rng);

switch (color)
{
case 1:
//flash red
break;
case 2:
//etc
break;
}

choices.push_back(color);
}
}

Code above obv doesn't work, and you'd structure it better and use chili framework. I just wanted all variables etc to be inside this one post.
Just like an approx way of doing it

_________________
I just like to thumb my nose at millionaires.
If I was rolled I'd bust them heads up.

 Post subject: Re: Im back! Some questions...  Posted: June 16th, 2017, 1:06 am

Joined: December 31st, 2011, 4:53 pm
Posts: 3448
Location: Japan
Thanks yumtard for the link. zedtho, go to the wiki and search for mouse, and you will have all the info you need bro

As for how to accomplish your task, vector is great (I'll be covering it soon in the tutorials). I recommend having 1 vector store the answer, and then another vector to store the user input. When the user enters the correct number of inputs (or whatever other stopping condition you set), then you can just do answer == userInput to test for correctness.

Make sure you add sound as well. Simon says without sound is terribad

_________________
Chili

 Post subject: Re: Im back! Some questions...  Posted: June 17th, 2017, 7:13 pm

Joined: February 14th, 2017, 7:32 pm
Posts: 170
Thanks for the answers! Will continue this in a few days, got a lot of studying to do in the meantime .

 Post subject: Re: Im back! Some questions...  Posted: June 18th, 2017, 5:03 pm

Joined: February 14th, 2017, 7:32 pm
Posts: 170
I've been having problems with the game displaying the colors in 60 frame intervals. I can't get it to work, I'll finish the other functions and send the code.

 Post subject: Re: Im back! Some questions...  Posted: June 20th, 2017, 3:42 pm

Joined: February 14th, 2017, 7:32 pm
Posts: 170
https://github.com/Zedtho/Simon-Says
It's not ready at all yet, but if someone could tell me what I could do with those 3 bugs that would be nice.

 Post subject: Re: Im back! Some questions...  Posted: June 20th, 2017, 4:02 pm

Joined: February 14th, 2017, 7:32 pm
Posts: 170
Actually, any feedback is appreciated. This project seems like a mess right now. Might restart it.

 Post subject: Re: Im back! Some questions...  Posted: June 20th, 2017, 4:54 pm

Joined: April 19th, 2017, 12:49 pm
Posts: 33
Location: Germany
Not absolutely sure about this, but it seems that you try to get user inputs with std::cin using the console and the console subsystem is not active in your project so you may not get any input from that.

You could switch it on or use other ways of handling user input for your game like chilis Keyboard class provides (up, down, left right to match these colors for example).

 Post subject: Re: Im back! Some questions...  Posted: June 20th, 2017, 6:35 pm

Joined: February 14th, 2017, 7:32 pm
Posts: 170
forgot to use chili's keyboard woops, will be in final patch obviously.
I'm running into some errors when I run it in debug mode. As far as I know they aren't caused by std::cin (although I'll have to change that soon).

Last edited by Zedtho on July 15th, 2017, 2:16 pm, edited 1 time in total.

 Post subject: Re: Im back! Some questions...  Posted: June 20th, 2017, 7:17 pm

Joined: April 19th, 2017, 12:49 pm
Posts: 33
Location: Germany
I checked out your repo and got some errors like:

"function call must have a constant value in a constant expression" on

Code:
void Game::TakeInput(std::vector<int> &Input)
{
->const int l = Input.size;<-
for (int i = Input.size; i > 0; i--)
{
Input.pop_back;
}
for (int i = 0; i <= l; i++);
{
int temp;
std::cin >> temp;
Input.push_back(temp);
}
}

for example, if thats still a problem, then check out the container you re using there. Its a std::vector and look up its size "member"

like its described in here: http://en.cppreference.com/w/cpp/container/vector

Display posts from previous:  Sort by

 Page 1 of 7 [ 68 posts ] Go to page 1, 2, 3, 4, 5 ... 7  Next

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

 Search for: