Repository navigation
Expand file tree
/
Copy pathplayer.cpp
More file actions
91 lines (76 loc) · 2.17 KB
/
Copy pathplayer.cpp
File metadata and controls
91 lines (76 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "player.h"
#include <QDebug>
Player::Player() {}
void Player::setHand(const std::vector<Card>& cards) {
hand = cards;
}
void Player::removeCard(const Card& card) {
// 在這裡實現移除手牌的邏輯
// 你可以使用向量的相關函數,如erase(),來移除手牌中的特定卡片
}
void Player::displayHand() const
{
QString remainingText = QString::number(hand.size());
if (playerNumber == 1) {
mainwindow->remainingCardsLabel1->setText(remainingText);
} else if (playerNumber == 2) {
mainwindow->remainingCardsLabel2->setText(remainingText);
} else if (playerNumber == 3) {
mainwindow->remainingCardsLabel3->setText(remainingText);
} else if (playerNumber == 4) {
mainwindow->remainingCardsLabel4->setText(remainingText);
}
}
void Player::setPlayerNumber(int number) {
playerNumber = number;
// 根据编号设置对应的图片路径
if (playerNumber == 1) {
if (!avatar.load("./dataset/images/player.png")) {
qDebug() << "Failed to load player.png";
}
} else if (playerNumber == 2) {
if (!avatar.load("./dataset/images/friend_1.png")) {
qDebug() << "Failed to load friend_1.png";
}
} else if (playerNumber == 3) {
if (!avatar.load("./dataset/images/friend_2.png")) {
qDebug() << "Failed to load friend_2.png";
}
} else if (playerNumber == 4) {
if (!avatar.load("./dataset/images/friend_3.png")) {
qDebug() << "Failed to load friend_3.png";
}
}
}
void Player::addCard(const Card& card) {
hand.push_back(card);
}
void Player::setMainWindow(Mainwindow* window) {
mainwindow = window;
}
int Player::getHandSize() {
return hand.size();
}
int Player::getScore() {
return score;
}
QString Player::getName() {
return name;
}
void Player::setName(const QString& newName) {
name = newName;
}
int Player::getNum() {
return playerNumber;
}
void Player::addScore(int number){
score += number;
}
bool Player::hasCardTwo(){
for (int i = 0; i < hand.size(); i++)
{
if (hand[i].getRank() == 12)
return true;
}
return false;
}