Simon Says Game

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
User avatar
Zedtho
Posts: 189
Joined: February 14th, 2017, 7:32 pm

Simon Says Game

Post by Zedtho » June 15th, 2017, 7:34 pm

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 :P.
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.

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Im back! Some questions...

Post by Yumtard » June 15th, 2017, 9:15 pm

Fun idea for a poject, I might steal it :D

Pretty sure chili covers a little bit about the mouse in this video
https://www.youtube.com/watch?v=gB9zwet ... BHBFFRVWsx


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: Select all

#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

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Im back! Some questions...

Post by chili » June 16th, 2017, 1:06 am

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 :lol:
Chili

User avatar
Zedtho
Posts: 189
Joined: February 14th, 2017, 7:32 pm

Re: Im back! Some questions...

Post by Zedtho » June 17th, 2017, 7:13 pm

Thanks for the answers! Will continue this in a few days, got a lot of studying to do in the meantime :(.

User avatar
Zedtho
Posts: 189
Joined: February 14th, 2017, 7:32 pm

Re: Im back! Some questions...

Post by Zedtho » June 18th, 2017, 5:03 pm

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.

User avatar
Zedtho
Posts: 189
Joined: February 14th, 2017, 7:32 pm

Re: Im back! Some questions...

Post by Zedtho » June 20th, 2017, 3:42 pm

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.

User avatar
Zedtho
Posts: 189
Joined: February 14th, 2017, 7:32 pm

Re: Im back! Some questions...

Post by Zedtho » June 20th, 2017, 4:02 pm

Actually, any feedback is appreciated. This project seems like a mess right now. Might restart it.

xu2201g
Posts: 33
Joined: April 19th, 2017, 12:49 pm
Location: Germany

Re: Im back! Some questions...

Post by xu2201g » June 20th, 2017, 4:54 pm

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).

I need some more informations about what you wanted to do.

User avatar
Zedtho
Posts: 189
Joined: February 14th, 2017, 7:32 pm

Re: Im back! Some questions...

Post by Zedtho » June 20th, 2017, 6:35 pm

forgot to use chili's keyboard :P 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.

xu2201g
Posts: 33
Joined: April 19th, 2017, 12:49 pm
Location: Germany

Re: Im back! Some questions...

Post by xu2201g » June 20th, 2017, 7:17 pm

I checked out your repo and got some errors like:

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

Code: Select all

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

Post Reply