File indexing completed on 2024-04-28 04:04:39
0001 /* 0002 This file is part of the game 'KTron' 0003 0004 SPDX-FileCopyrightText: 1998-2000 Matthias Kiefer <matthias.kiefer@gmx.de> 0005 SPDX-FileCopyrightText: 2005 Benjamin C. Meyer <ben at meyerhome dot net> 0006 SPDX-FileCopyrightText: 2008-2009 Stas Verberkt <legolas at legolasweb dot nl> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 0010 */ 0011 0012 #ifndef PLAYER_H 0013 #define PLAYER_H 0014 0015 #include "snakepart.h" 0016 #include "playfield.h" 0017 0018 #include <QObject> 0019 #include <QQueue> 0020 0021 namespace PlayerDirections 0022 { 0023 enum Direction { 0024 None, 0025 Up, 0026 Down, 0027 Left, 0028 Right 0029 }; 0030 } 0031 0032 /** 0033 * @short This class represents a player with current position and several flags 0034 */ 0035 class Player : public QObject 0036 { 0037 Q_OBJECT 0038 0039 public: 0040 Player(PlayField &pf, int playerNr); 0041 int getPlayerNumber(); 0042 void reset(); 0043 void setCoordinates(int x, int y); 0044 bool isComputer() const; 0045 void setComputer(bool computer); 0046 void setStartPosition(); 0047 void movePlayer(); 0048 bool crashed(int x, int y); 0049 int getX(); 0050 int getY(); 0051 int getScore(); 0052 void addScore(int increment); 0053 void resetScore(); 0054 void setEnlargement(int enlargement); 0055 PlayerDirections::Direction getDirection(); 0056 void setDirection(PlayerDirections::Direction direction); 0057 bool isAlive(); 0058 void die(); 0059 bool isAccelerated(); 0060 void setAccelerated(bool value); 0061 bool hasKeyPressed(); 0062 void setKeyPressed(bool value); 0063 QString getName() const; 0064 void setName(const QString &name); 0065 0066 private: 0067 int m_playerNumber; 0068 QQueue<SnakePart> m_snakeParts; 0069 PlayField *m_playField; 0070 int m_score; 0071 int m_enlarge; 0072 PlayerDirections::Direction m_dir; 0073 bool m_alive; 0074 bool m_computer; 0075 bool m_accelerated; 0076 bool m_keyPressed; 0077 QString m_name; 0078 bool m_blockSwitchDir; 0079 0080 Q_SIGNALS: 0081 void fetchedItem(int playerNumber, int x, int y); 0082 }; 0083 0084 #endif //PLAYER_H 0085