Help with Uno game

I'm trying to make the game UNO for my school assigment, i'm quite new to visual programming, we haven't really taken it yet at school (lol) but i have to make the game in about an month and so far i've made a deck that suffles the random cards and a hand, which contains 7 cards from said deck. But i can't seem to move the cards in hand to the lower end of the "playfield". I've tried setPos, moveBy with no succes. I'll post the code bellow

UnoCard.h:

#ifndef UNOCARD_H
#define UNOCARD_H

#include<QGraphicsItem>
#include <QString>
#include <QObject>

class UnoCard: public QObject, public QGraphicsRectItem
{ Q_OBJECT
public:
QString number;
QString color;


UnoCard(QString num, QString c);
};


#endif // UNOCARD_H

UnoDeck.h:

#ifndef UNODECK_H
#define UNODECK_H

#include "unocard.h"
#include <QList>

class UnoDeck
{public:
QList<UnoCard *> deck;
UnoDeck();
void init_deck();
void izpis();
void shuffle();
void kolikokrat();
void polni(QList <UnoCard> &yeah, int hand);
};

#endif // UNODECK_H

UnoCard.cpp:

#include "unocard.h"
#include <Qbrush>
#include <QGraphicsTextItem>
#include <QTextEdit>
#include <QGraphicsEllipseItem>
#include <QObject>

UnoCard::UnoCard(QString number, QString color)
{

this->setRect(0,0,220,300);
this->setBrush(QBrush(QColor(color)));

QGraphicsEllipseItem *ecl = new QGraphicsEllipseItem(this);
ecl->setRect(80,-40,170,270);
ecl->setBrush(Qt::white);
ecl->setRotation(25);
QGraphicsTextItem *txt =new QGraphicsTextItem(this);
txt->setDefaultTextColor(color);
txt->setPlainText(number);
txt->setPos(35,35);
txt->setScale(10.5);



}

UnoDeck.cpp:

#include "unodeck.h"
#include "unocard.h"
#include <ctime>
#include <cstdlib>


UnoDeck::UnoDeck()
{QString color;
int st=0;

for(int i=0; i < 20; i++)
{if(i%10==0)st=0;

for(int j=0; j < 4;j++)
{
switch(j){
case 0: color="blue"; break;
case 1: color="green"; break;
case 2: color="yellow"; break;
case 3: color="red"; break;
default: color="black";
}
UnoCard *card = new UnoCard(QString::number(st),color);
UnoDeck::deck.append(card);
}st++;
}
}
void UnoDeck::shuffle()
{
srand(time(0));
std::random_shuffle(deck.begin(), deck.end());
}

main.cpp:

#include <QApplication>
#include <QGraphicsScene>
#include "unocard.h"
#include "unodeck.h"
#include <QGraphicsView>
#include <QTextEdit>
#include <QList>
#include <QString>
#include <QObject>
#include <ctime>
#include <cstdlib>
#include <QList>






int main(int argc, char *argv[])
{

QApplication a(argc, argv);
//ustvari sceno
QGraphicsScene *scene = new QGraphicsScene();
//ustvari deck
UnoDeck *ez = new UnoDeck();
ez->shuffle();
//doda deck na sceno


QList <UnoCard *> hand;
for(int i=0;i<7;i++)
{
hand.append(ez->deck.last());
ez->deck.pop_back();

}
hand.first()->moveBy(100,100);
scene->addItem(hand.first());

Topic archived. No new replies allowed.