Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - samm3

Pages: [1]
1
General / Re: New to SFML, creating my own game and guidelines needed!
« on: December 16, 2015, 12:49:38 am »
I have to ask you... does the cards show up on different locations for you every time you start it or is it only the order that they're shown in that's randomized?

EDIT: My fault, removed and changed some old code. Solved it =)

2
General / Re: New to SFML, creating my own game and guidelines needed!
« on: December 15, 2015, 10:08:18 pm »
congart,  :)
it looks really awesome

Thanks! Regarding the seed generator, is it really necessary to implement that in my small game for a perfect "random"? Because I doubt it'll matter when I turn it in to my teacher. I probably won't be able to explain it in detail if I'm questioned, as I lack "general" knowledge in C++, and the game itself is enough for an A :)

Also, mind explaining what std::transform does? I read that it has something to do with lambas but can't really find the real mening behind its purpose when I use it ;/

3
General / Re: New to SFML, creating my own game and guidelines needed!
« on: December 15, 2015, 09:44:02 pm »
After a bit of coding, I'm finally done! The game is working perfectly and exactly as it should.
I'd like to thank everyone who helped me, I learned a lot and the new randomizer noticeably improved the performance .

Here's the final product, https://www.dropbox.com/s/kmrf5b90b9wwjjf/Nostalgitripp.rar?dl=0

4
General / Re: New to SFML, creating my own game and guidelines needed!
« on: December 12, 2015, 10:03:07 pm »
hello Ladies and Guys

I tried to run Samm's app i downloaded, and after having it asked me for MSVCP140D.dll and MSVCP140.dll and i have downloaded and put them with the exe file, the dialogbox i attached was shown.

Another thing i would appreciate if someone could tell me is how to start C++ IDE. I already downloaded C++ .Net and could not start the environment. There is no shortcut anywhere. I would like to try to run the app from the IDE and perhaps i find what's failing.

Thanks
Pablo

I also had the same problem when trying to run it on the computers in school, which had Visual Studio 2010 C++. Try downloading Visual Studio 2015, might solve the problem :)

Also, I've made some changes. In this link https://www.dropbox.com/s/hmqhj89dih6p5wu/Nostalgitripp.help.rar?dl=0 you'll find my progress so far. I've implemented a new "randomizer" + a new logic when clicking on the cards and displaying the clicked cards, so there's some new problems now. If you want to look at the logic I used before they're in the previous links :)

5
General / Re: New to SFML, creating my own game and guidelines needed!
« on: December 12, 2015, 06:39:43 pm »
Quote
yes
mostly this function is called utility function so, it is better to make a new .h .cpp files for it like this:

Utility.hpp
#include <random>

namespace utility
{
        std::mt19937 random();
}

and in Utility.cpp
#include "Utility.hpp"

std::mt19937 utility::random()
{
        std::mt19937 r{ std::random_device{}() };
        return r;
}

usage is simply like this
std::shuffle(cardOrder.begin(), cardOrder.end(), utility::random());

Ah, I tried to do it that way actually but I only used a header file, which might explain the errors I got :D Figured out, instead of creating a utility function for the std::mt19937 I created one for shuffling vectors instead. Less code so it doesn't look so messy :)

6
General / Re: New to SFML, creating my own game and guidelines needed!
« on: December 12, 2015, 04:29:56 pm »
it looks cool game, good job

there are few things need to clarify a bit regarding your source code

Randomness
no need to call std::srand every time when you called std::random_shuffle, unless you want to generate a new seed sequence every time which is not necessary here.
better you declared std::srand at first of your project right after the main().

or if you're interesting on c++11 you can use <random> which is better in seeding and generating randomness.
the easiest  implementation is to define free function for it like this
std::mt19937 rnd()
{
        static std::mt19937 r{ std::random_device{}() };
        return r;
}
and then you can use it else where like so,

std::vector<int> cardOrder(16);
int i = 0;
std::transform(cardOrder.begin(), cardOrder.end(), cardOrder.begin(), [&i](int j) { return j = i++;});
std::shuffle(cardOrder.begin(), cardOrder.end(), rnd());

I implemented the mt19937 code but need some things clarified. What's the benefits of using it, specially compared to this http://www.cplusplus.com/reference/algorithm/shuffle/? Here's the recent changes https://www.dropbox.com/s/7s7d7s2la0pp0ci/Nostalgitripp.mt19937.rar?dl=0. I'm using the function in both main.cpp and Cards.cpp (void Cards::shuffleDeck). Do you know of a better way to implement it in my code so there's no need to write the function twice?

@Jesper Juhl, awesome, thanks for sharing! =)

Does anyone of you know how to improve my game logic? It "works" but is pretty shitty right now ;/

7
General / Re: New to SFML, creating my own game and guidelines needed!
« on: December 12, 2015, 02:11:55 am »
Hey man, sorry for not answering! ;/ I totally forgot about the thread as I went straight to action, creating the game on my own after the first reply :) Here's the result so far, https://www.dropbox.com/s/kmrf5b90b9wwjjf/Nostalgitripp.rar?dl=0

I'm almost done with the game, there's still some left.

This is what's left:
  • Show all cards clicked on while playing. Right now they're disappearing one after another.
  • Add a text that displays which round it is.
  • Add an end, so if you manage to beat all levels, you have to possibility to start over.
  • Fix a start delay of each round so the first card isn't shown instantly.
  • Make a "flawless" gameplay with no bugs and logic errors.

You'll get the "what's left" list and how the game is supposed to be when you run my game. Right now there's a pretty big bug that gets you stuck while playing the game if you click the cards too fast (I think?) or if you're just unlucky clicking in the wrong "cycle"? I don't really know what's causing it as I've tried to play through the rounds slowly but even that doesn't help if you click the cards irregurarly. I'm pretty sure it's a logic error as I'm still pretty new to coding and even if it works partually it's not the most optimal way to do it in :D

To finish off, thanks for helping me, appreciate it a lot!

EDIT: Fixed a text which displays which round it is and an end so you can start over + a little bit of clean up in the project.

8
General / New to SFML, creating my own game and guidelines needed!
« on: December 04, 2015, 10:29:41 pm »
Hey,

as the title says I'm new to SFML and fairly new to C++ aswell. I'm making Memory card game as my final project in the C++ course I'm studying  but are currently stuck on the "game" part. What I need is some guidelines to continue :)

The game should be like this:
Create a game where you draw out 16 cards. When the game starts, 2 cards should be randomized and displayed. The cards are shown for one second, one after another. The player should click on which cards he saw, in order, and if he's correct the next round is started with 3 cards and so on. The total amount of cards that the player has found should be displayed.

Here's my project so far:
#include "SFML/Graphics.hpp"
#include <iostream>
#include "Meny.h";

int main() {
        const int bredd = 640;
        const int höjd = 480;
        sf::RenderWindow fönster(sf::VideoMode(bredd, höjd), "Kortspel!");

        Meny meny(bredd, höjd);

        bool gameStart = false;

        while (fönster.isOpen()) {
                sf::Event event;
                fönster.clear();

                while (fönster.pollEvent(event)) {
                        if (gameStart) {
                                std::cout << "It works!";
                        }

                        else {
                                switch (event.type) {
                                case sf::Event::KeyPressed:
                                        switch (event.key.code) {
                                        case sf::Keyboard::Return:
                                                gameStart = true;
                                                break;

                                        case sf::Keyboard::Escape:
                                                fönster.close();
                                                break;
                                        }
                                        break;

                                case sf::Event::Closed:
                                        fönster.close();
                                        break;
                                }
                        }
                }
               
                meny.Rita(fönster);
                fönster.display();
        }
}

#pragma once
#include "SFML/Graphics.hpp"

class Meny {

private:
        sf::Font typsnitt;
        sf::Text meny1, meny2;

public:
        Meny(float bredd, float höjd);
        ~Meny();

        void Rita(sf::RenderWindow &fönster);
};

#include "Meny.h"


Meny::Meny(float bredd, float höjd) {
        if (!typsnitt.loadFromFile("resurser/ARCADECLASSIC.TTF")) {
                // ta hand om error
        }

        meny1.setFont(typsnitt);
        meny1.setCharacterSize(80);
        meny1.setColor(sf::Color::Green);
        meny1.setString("Memory");
        meny1.setPosition(bredd / 2 - meny1.getGlobalBounds().width / 2, 100);

        meny2.setFont(typsnitt);
        meny2.setCharacterSize(30);
        meny2.setColor(sf::Color::Green);
        meny2.setString("Press ENTER to play");
        meny2.setPosition(bredd / 2 - meny2.getGlobalBounds().width / 2, 275);

}

Meny::~Meny() {}

void Meny::Rita(sf::RenderWindow &fönster) {
                fönster.draw(meny1);
                fönster.draw(meny2);
}

My questions/wonderings are:
I will create a class for the cards that can be used for both the backside of the cards and showing the front. How do I create that in a simple way for my project? Do I need to keep track of the x and y coordinates of every card? I plan to use vectors and random_shuffle in some sort of way to randomize the cards. I came across this https://github.com/SFML/SFML/wiki/Tutorial:-Image-Manager image manager but it feels like it's a bit too complicated for my project.

Also, how do I keep track of which card I've clicked on?

Well, as you can see the questions just build up, there's no end. How would you create my game? I appreciate all help!





Pages: [1]