Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 14 posts ]  Go to page 1, 2  Next
Author Message
 Post Posted: June 15th, 2017, 7:34 pm 
 

Joined: February 14th, 2017, 7:32 pm
Posts: 71
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!


Top 
 Profile  
Reply with quote  
 Post Posted: June 15th, 2017, 9:15 pm 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 322
Location: Idiot from northern Europe
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=gB9zwetKOJk&index=39&list=PLqCJpWy5FohcehaXlCIt8sVBHBFFRVWsx


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


Top 
 Profile  
Reply with quote  
 Post Posted: June 16th, 2017, 1:06 am 
Site Admin
User avatar

Joined: December 31st, 2011, 4:53 pm
Posts: 3229
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 :lol:

_________________
Chili


Top 
 Profile  
Reply with quote  
 Post Posted: June 17th, 2017, 7:13 pm 
 

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


Top 
 Profile  
Reply with quote  
 Post Posted: June 18th, 2017, 5:03 pm 
 

Joined: February 14th, 2017, 7:32 pm
Posts: 71
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.


Top 
 Profile  
Reply with quote  
 Post Posted: June 20th, 2017, 3:42 pm 
 

Joined: February 14th, 2017, 7:32 pm
Posts: 71
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.


Top 
 Profile  
Reply with quote  
 Post Posted: June 20th, 2017, 4:02 pm 
 

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


Top 
 Profile  
Reply with quote  
 Post Posted: June 20th, 2017, 4:54 pm 
 

Joined: April 19th, 2017, 12:49 pm
Posts: 23
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).

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


Top 
 Profile  
Reply with quote  
 Post Posted: June 20th, 2017, 6:35 pm 
 

Joined: February 14th, 2017, 7:32 pm
Posts: 71
forgot to use chili's keyboard :P woops, will be in final patch obviously.
I'm currently making the game 'Simon says' and 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).


Top 
 Profile  
Reply with quote  
 Post Posted: June 20th, 2017, 7:17 pm 
 

Joined: April 19th, 2017, 12:49 pm
Posts: 23
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


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 14 posts ]  Go to page 1, 2  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:
cron