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.


Topics - samm3

Pages: [1]
1
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]