diff --git a/蜘蛛纸牌/Card.cpp b/蜘蛛纸牌/Card.cpp new file mode 100644 index 0000000..8e2f17f --- /dev/null +++ b/蜘蛛纸牌/Card.cpp @@ -0,0 +1,2 @@ +#include "Card.h" + diff --git a/蜘蛛纸牌/Card.h b/蜘蛛纸牌/Card.h new file mode 100644 index 0000000..419eda0 --- /dev/null +++ b/蜘蛛纸牌/Card.h @@ -0,0 +1,37 @@ +#pragma once + +#include "CardType.h" + +class Card +{ +private: + CardValue _Value; + CardType _Type; +public: + Card() {} + Card(CardValue value, CardType type) + :_Value(value), _Type(type) {} + ~Card() {} + + CardValue GetValue() const + { + return _Value; + } + + CardType GetType() const + { + return _Type; + } + + bool operator<(const Card & card) const + { + return _Value < card._Value; + } + + bool operator<(const CardValue & value) const + { + return _Value < value; + } + +}; + diff --git a/蜘蛛纸牌/CardType.h b/蜘蛛纸牌/CardType.h new file mode 100644 index 0000000..a61797a --- /dev/null +++ b/蜘蛛纸牌/CardType.h @@ -0,0 +1,39 @@ +#pragma once + + + +// +enum CardType { + // + Spade, + + // + Heart, + + // ÷ + Club, + + // + Diamond +}; + +const int CardTypeNum = 4; + +// Ƶֵ +enum CardValue { + _A, + _2, + _3, + _4, + _5, + _6, + _7, + _8, + _9, + _10, + _J, + _Q, + _K, +}; + +const int CardValueNum = 13; \ No newline at end of file diff --git a/蜘蛛纸牌/CardsSlots.cpp b/蜘蛛纸牌/CardsSlots.cpp new file mode 100644 index 0000000..9171099 --- /dev/null +++ b/蜘蛛纸牌/CardsSlots.cpp @@ -0,0 +1,36 @@ +#include "CardsSlots.h" + + +CardsSlots::CardsSlots() +{ +} + + +CardsSlots::~CardsSlots() +{ +} + +void CardsSlots::Push(Card card) +{ + _Cards.push_back(card); +} + +void CardsSlots::MoveCardsTo(CardsSlots & targetSlots, int first) +{ + std::vector & targetCards = targetSlots.GetCards(); + targetCards.insert(targetCards.end(), _Cards.begin() + first, _Cards.end()); + _Cards.erase(_Cards.begin() + first, _Cards.end()); + UpdateHideLevel(); +} + +void CardsSlots::Pop(int num) +{ + _Cards.erase(_Cards.end() - num, _Cards.end()); + UpdateHideLevel(); +} + +void CardsSlots::UpdateHideLevel() +{ + if (HideLevel > 0 && HideLevel == _Cards.size()) + HideLevel--; +} diff --git a/蜘蛛纸牌/CardsSlots.h b/蜘蛛纸牌/CardsSlots.h new file mode 100644 index 0000000..6991fcf --- /dev/null +++ b/蜘蛛纸牌/CardsSlots.h @@ -0,0 +1,31 @@ +#pragma once +#include +#include "Card.h" + +class CardsSlots +{ +private: + std::vector _Cards; + int HideLevel; +public: + CardsSlots(); + ~CardsSlots(); + + int GetHideLevel() const { return HideLevel; } + void SetHideLevel(int level) { HideLevel = level; } + + size_t Count() const { return _Cards.size(); } + + void Clear() { _Cards.clear(); } + + void Push(Card card); + + void MoveCardsTo(CardsSlots &targetSlots, int first); + + void Pop(int num); + + std::vector & GetCards() { return _Cards; } +private: + void UpdateHideLevel(); +}; + diff --git a/蜘蛛纸牌/Debug/Card.obj b/蜘蛛纸牌/Debug/Card.obj new file mode 100644 index 0000000..4025eea Binary files /dev/null and b/蜘蛛纸牌/Debug/Card.obj differ diff --git a/蜘蛛纸牌/Debug/CardsSlots.obj b/蜘蛛纸牌/Debug/CardsSlots.obj new file mode 100644 index 0000000..2d918db Binary files /dev/null and b/蜘蛛纸牌/Debug/CardsSlots.obj differ diff --git a/蜘蛛纸牌/Debug/Game.obj b/蜘蛛纸牌/Debug/Game.obj new file mode 100644 index 0000000..67f10c1 Binary files /dev/null and b/蜘蛛纸牌/Debug/Game.obj differ diff --git a/蜘蛛纸牌/Debug/View.obj b/蜘蛛纸牌/Debug/View.obj new file mode 100644 index 0000000..85ba6ca Binary files /dev/null and b/蜘蛛纸牌/Debug/View.obj differ diff --git a/蜘蛛纸牌/Debug/main.obj b/蜘蛛纸牌/Debug/main.obj new file mode 100644 index 0000000..2e811f5 Binary files /dev/null and b/蜘蛛纸牌/Debug/main.obj differ diff --git a/蜘蛛纸牌/Debug/vc141.idb b/蜘蛛纸牌/Debug/vc141.idb new file mode 100644 index 0000000..9c51be6 Binary files /dev/null and b/蜘蛛纸牌/Debug/vc141.idb differ diff --git a/蜘蛛纸牌/Debug/vc141.pdb b/蜘蛛纸牌/Debug/vc141.pdb new file mode 100644 index 0000000..6eea21b Binary files /dev/null and b/蜘蛛纸牌/Debug/vc141.pdb differ diff --git a/蜘蛛纸牌/Debug/蜘蛛纸牌.Build.CppClean.log b/蜘蛛纸牌/Debug/蜘蛛纸牌.Build.CppClean.log new file mode 100644 index 0000000..82ead5d --- /dev/null +++ b/蜘蛛纸牌/Debug/蜘蛛纸牌.Build.CppClean.log @@ -0,0 +1,7 @@ +f:\c++\vs\蜘蛛纸牌\蜘蛛纸牌\debug\vc141.pdb +f:\c++\vs\蜘蛛纸牌\蜘蛛纸牌\debug\vc141.idb +f:\c++\vs\蜘蛛纸牌\蜘蛛纸牌\debug\card.obj +f:\c++\vs\蜘蛛纸牌\蜘蛛纸牌\debug\cardsslots.obj +f:\c++\vs\蜘蛛纸牌\蜘蛛纸牌\debug\蜘蛛纸牌.tlog\cl.command.1.tlog +f:\c++\vs\蜘蛛纸牌\蜘蛛纸牌\debug\蜘蛛纸牌.tlog\cl.read.1.tlog +f:\c++\vs\蜘蛛纸牌\蜘蛛纸牌\debug\蜘蛛纸牌.tlog\cl.write.1.tlog diff --git a/蜘蛛纸牌/Debug/蜘蛛纸牌.exe b/蜘蛛纸牌/Debug/蜘蛛纸牌.exe new file mode 100644 index 0000000..6d77102 Binary files /dev/null and b/蜘蛛纸牌/Debug/蜘蛛纸牌.exe differ diff --git a/蜘蛛纸牌/Debug/蜘蛛纸牌.ilk b/蜘蛛纸牌/Debug/蜘蛛纸牌.ilk new file mode 100644 index 0000000..c90c242 Binary files /dev/null and b/蜘蛛纸牌/Debug/蜘蛛纸牌.ilk differ diff --git a/蜘蛛纸牌/Debug/蜘蛛纸牌.log b/蜘蛛纸牌/Debug/蜘蛛纸牌.log new file mode 100644 index 0000000..d493d52 --- /dev/null +++ b/蜘蛛纸牌/Debug/蜘蛛纸牌.log @@ -0,0 +1,2 @@ + main.cpp + 蜘蛛纸牌.vcxproj -> F:\C++\VS\蜘蛛纸牌\蜘蛛纸牌\Debug\蜘蛛纸牌.exe diff --git a/蜘蛛纸牌/Debug/蜘蛛纸牌.pdb b/蜘蛛纸牌/Debug/蜘蛛纸牌.pdb new file mode 100644 index 0000000..535d41b Binary files /dev/null and b/蜘蛛纸牌/Debug/蜘蛛纸牌.pdb differ diff --git a/蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/CL.command.1.tlog b/蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/CL.command.1.tlog new file mode 100644 index 0000000..305dfb6 Binary files /dev/null and b/蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/CL.command.1.tlog differ diff --git a/蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/CL.read.1.tlog b/蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/CL.read.1.tlog new file mode 100644 index 0000000..2fb71b5 Binary files /dev/null and b/蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/CL.read.1.tlog differ diff --git a/蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/CL.write.1.tlog b/蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/CL.write.1.tlog new file mode 100644 index 0000000..b608b42 Binary files /dev/null and b/蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/CL.write.1.tlog differ diff --git a/蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/link.command.1.tlog b/蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/link.command.1.tlog new file mode 100644 index 0000000..fd60d63 Binary files /dev/null and b/蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/link.command.1.tlog differ diff --git a/蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/link.read.1.tlog b/蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/link.read.1.tlog new file mode 100644 index 0000000..38527fd Binary files /dev/null and b/蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/link.read.1.tlog differ diff --git a/蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/link.write.1.tlog b/蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/link.write.1.tlog new file mode 100644 index 0000000..72e478d Binary files /dev/null and b/蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/link.write.1.tlog differ diff --git a/蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/蜘蛛纸牌.lastbuildstate b/蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/蜘蛛纸牌.lastbuildstate new file mode 100644 index 0000000..79d7789 --- /dev/null +++ b/蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/蜘蛛纸牌.lastbuildstate @@ -0,0 +1,2 @@ +#TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.16299.0 +Debug|Win32|F:\C++\VS\蜘蛛纸牌\蜘蛛纸牌\| diff --git a/蜘蛛纸牌/Game.cpp b/蜘蛛纸牌/Game.cpp new file mode 100644 index 0000000..5cd7df0 --- /dev/null +++ b/蜘蛛纸牌/Game.cpp @@ -0,0 +1,329 @@ +#include "Game.h" +#include + +Game::Game(Difficulty difficulty) :_pView(new View(*this)) +{ + SetDifficulty(difficulty); +} + +Game::~Game() +{ +} + + +void Game::Show() +{ + _pView->ShowGame(); +} + +void Game::SetDifficulty(Difficulty newDifficulty) +{ + _Difficulty = newDifficulty; + switch (newDifficulty) + { + case easy: + for (int i = 0; i < GroupsNum; ++i) + { + for (int j = 0; j < CardValueNum; ++j) + { + _Cards[i * CardValueNum + j] = Card((CardValue)j, CardType::Spade); + } + } + break; + case normal: + for (int i = 0; i < GroupsNum; ++i) + { + for (int j = 0; j < CardValueNum; ++j) + { + _Cards[i * CardValueNum + j] = Card((CardValue)j, j % 2 ? CardType::Heart : CardType::Spade); + } + } + break; + case hard: + for (int i = 0; i < GroupsNum; ++i) + { + for (int j = 0, k = 0; j < CardValueNum; ++j, k = (k + 1) % 4) + { + _Cards[i * CardValueNum + j] = Card((CardValue)j, (CardType)k); + } + } + break; + default: + break; + } +} + + +void Game::Shuffle() +{ + static std::random_device rd; + std::default_random_engine e1(rd()); + std::uniform_int_distribution uniform_dist(0, _Cards.size() - 1); + for (int i = 0; i < _Cards.size(); ++i) + { + std::swap(_Cards[i], _Cards[uniform_dist(e1)]); + } +} + +void Game::InitScenes() +{ + ReservedCount = ReservedQuantity; + SuccessCount = 0; + IsVictory = false; + for (int i = 0; i < Scenes.size(); ++i) + Scenes[i].Clear(); + + for (int i = ReservedQuantity * Scenes.size(), j = 0; i < _Cards.size(); ++i, j = (j+1) % Scenes.size()) + Scenes[j].Push(_Cards[i]); + + for (int i = 0; i < Scenes.size(); ++i) + Scenes[i].SetHideLevel(Scenes[i].Count() - 1); + + PSelected.SetValue(-1, -1); + PCurrent.SetValue(0, Scenes[0].Count() - 1); +} + +void Game::StartNewGame() +{ + Shuffle(); + InitScenes(); +} + +void Game::Deal() +{ + if (ReservedCount < 1) + return; + + // ֮ǰѡеȡ + PSelected.SetValue(-1, -1); + + // Ϊÿһ۷һ + for (int i = 0; i < Scenes.size(); ++i) + { + Scenes[i].Push(_Cards[(ReservedCount-1) * Scenes.size() + i]); + } + // һ + ReservedCount--; +} + +void Game::CurMove(Dir dir) +{ + int width = Scenes.size(); + int height = Scenes[PCurrent.x].Count(); + switch (dir) + { + case left: + if (PCurrent.x == 0) + PCurrent.x = width -1; + else + PCurrent.x--; + break; + case up: + if (height == 0) + PCurrent.y = 0; + else if (PCurrent.y == 0) + PCurrent.y = height - 1; + else + PCurrent.y--; + break; + case right: + if (PCurrent.x == width - 1) + PCurrent.x = 0; + else + PCurrent.x++; + break; + case down: + if (height == 0) + PCurrent.y = 0; + else if (PCurrent.y == height - 1) + PCurrent.y = 0; + else + PCurrent.y++; + break; + default: + break; + } + + // һûκ ָ + if (Scenes[PCurrent.x].Count() == 0) + PCurrent.y = 0; + // ߶ȸڵǰ߶ + // ֮ǰĸ߶0 + // ֮ǰһеĶʱ + // ָǰеĶ + else if (PCurrent.y >= Scenes[PCurrent.x].Count() + || height == 0 + || PCurrent.y == height - 1) + PCurrent.y = Scenes[PCurrent.x].Count() - 1; +} + +bool Game::Select() +{ + if (PCurrent.x < 0 || PCurrent.x >= Scenes.size()) + return false; + + if (Scenes[PCurrent.x].Count() == 0 && PCurrent.y != 0) + return false; + + // ѡ֮ǰѡģȡѡ + if (PSelected == PCurrent) + { + PSelected.SetValue(-1, -1); + return true; + } + + // ֮ǰδѡκζ + if (PSelected.x == -1) + { + // жϵǰѡɲѡ + if (CheckIsOptional(PCurrent)) + { + // ѡѡλãtrue + PSelected = PCurrent; + return true; + } + else + { + return false; + } + } + // ˵֮ǰѡ˶ƶ + else + { + // ѡĺ֮ǰѡͬһ ѡDzм + if (PCurrent.x == PSelected.x || PCurrent.y != Scenes[PCurrent.x].Count() - 1) + { + // һɶû + if (Scenes[PCurrent.x].Count() == 0) + { + // ֱƶȥ + MoveCards(PSelected, PCurrent.x); + PSelected.SetValue(-1, -1); + return true; + } + if (CheckIsOptional(PCurrent)) + { + PSelected = PCurrent; + return true; + } + else + { + return false; + } + } + // ˵ѡеһ + else + { + // ƶȥ + if (CheckIsOrderly( + Scenes[PCurrent.x].GetCards().at(PCurrent.y), + Scenes[PSelected.x].GetCards().at(PSelected.y), + _Difficulty)) + { + // ֱƶȥ + MoveCards(PSelected, PCurrent.x); + PSelected.SetValue(-1, -1); + return true; + } + // ѡһ + else + { + PSelected = PCurrent; + return true; + } + } + } +} + +void Game::MoveCards(Point point, int SlotsIndex) +{ + // ָλõƶӦIJ + Scenes[point.x].MoveCardsTo(Scenes[SlotsIndex], point.y); + + // Ƿ + if (CheckIsSuccess(SlotsIndex)) + { + // һ飬򵯳һ + Scenes[SlotsIndex].Pop(CardValueNum); + // Ȼɼ + SuccessCount++; + + if (SuccessCount == GroupsNum) + IsVictory = true; + } +} + + +bool Game::CheckIsOptional(Point point) +{ + // һɶû + if (Scenes[point.x].Count() == 0) + return false; + + if (point.y < Scenes[point.x].GetHideLevel()) + return false; + + if (point.y == Scenes[point.x].Count() - 1) + return true; + + + for (int i = point.y; i < Scenes[point.x].Count() - 1; ++i) + { + // ǷֻҪһǴģֱ޷ѡ + if (!CheckIsOrderly(Scenes[point.x].GetCards().at(i), Scenes[point.x].GetCards().at(i + 1), _Difficulty)) + { + return false; + } + } + + return true; +} + +bool Game::CheckIsOrderly(Card cur, Card next, Difficulty difficulty) +{ + if (cur.GetValue() != next.GetValue() + 1) + return false; + + // Ѷȼ黨ɫ + switch (difficulty) + { + // ѶȲɫ + case easy: + return true; + + // ͨѶҪǷں + case normal: + return cur.GetType() == CardType::Spade && next.GetType() == CardType::Heart + || cur.GetType() == CardType::Heart && next.GetType() == CardType::Spade; + + // ѶҪǷպҡҡ÷˳ + case hard: + return cur.GetType() == CardType::Spade && next.GetType() == CardType::Heart + || cur.GetType() == CardType::Heart && next.GetType() == CardType::Club + || cur.GetType() == CardType::Club && next.GetType() == CardType::Diamond + || cur.GetType() == CardType::Diamond && next.GetType() == CardType::Spade; + default: + break; + } + return false; +} + +// һǷ +bool Game::CheckIsSuccess(int SlotsIndex) +{ + // ж۵㲻㹻һ + if (Scenes[SlotsIndex].Count() < CardValueNum) + return false; + + // ʾһƣֱӷ + if (Scenes[SlotsIndex].Count() - Scenes[SlotsIndex].GetHideLevel() < CardValueNum) + return false; + + std::vector Cards = Scenes[SlotsIndex].GetCards(); + // ȻжDzAֱӷ + if (Cards.back().GetValue() != CardValue::_A) + return false; + + // Ȼ鵹һλÿʼǷֱӷؼ + return CheckIsOptional(Point(SlotsIndex, Cards.size() - CardValueNum)); +} diff --git a/蜘蛛纸牌/Game.h b/蜘蛛纸牌/Game.h new file mode 100644 index 0000000..041e53e --- /dev/null +++ b/蜘蛛纸牌/Game.h @@ -0,0 +1,122 @@ +#pragma once +#include +#include +#include "Card.h" +#include "View.h" +#include "CardsSlots.h" + +// Ѷ +enum Difficulty +{ + // + easy, + // ͨ + normal, + // + hard, +}; + +// Ʋ +const int SlotsNum = 10; + +// +const int GroupsNum = 8; + +// Ԥ Ԥ = Ԥ * = 5 * 10 = 50 Է +const int ReservedQuantity = 5; + +struct Point { + int x, y; + + Point() + :x(0), y(0) + {} + + Point(int a, int b) + :x(a), y(b) + {} + + void SetValue(int a, int b) + { + x = a, y = b; + } + + bool operator == (const Point p) const + { + return x == p.x && y == p.y; + } +}; + +enum Dir { + left, + up, + right, + down +}; + +class View; +class Game +{ +private: + // Ϸ + std::array _Cards; + + // ϷѶ + Difficulty _Difficulty; + + View *_pView; + + std::array Scenes; + + // ԤƵĴ + int ReservedCount; + + // ɹϵļ + int SuccessCount; + + Point PSelected; + Point PCurrent; + + bool IsVictory; +public: + friend class View; + + Game(Difficulty difficulty = Difficulty::easy); + ~Game(); + + void Show(); + + void SetDifficulty(Difficulty newDifficulty); + Difficulty GetDifficulty() const { return _Difficulty; } + + bool GetIsVictory() const { return IsVictory; } + + // ϴ + void Shuffle(); + + // ʼ + void InitScenes(); + + // ʼһϷ + void StartNewGame(); + + // ƣԤƴ㹻²Żᷢɹ + void Deal(); + +public: + // ƶ + void CurMove(Dir dir); + + // ѡǰָ Ƿѡɹ + bool Select(); + +private: + void MoveCards(Point point, int SlotsIndex); + + bool CheckIsOptional(Point point); + + bool CheckIsOrderly(Card cur, Card next, Difficulty difficulty); + + bool CheckIsSuccess(int SlotsIndex); +}; + diff --git a/蜘蛛纸牌/View.cpp b/蜘蛛纸牌/View.cpp new file mode 100644 index 0000000..916bc00 --- /dev/null +++ b/蜘蛛纸牌/View.cpp @@ -0,0 +1,85 @@ +#include "View.h" +#include + +const char *CardTypeView[] = { + "", + "", + "÷", + "", +}; + +const char *CardValueView[] = { + " A"," 2"," 3"," 4"," 5"," 6"," 7"," 8"," 9","10"," J"," Q"," K" +}; + + +View::~View() +{ +} + +void View::ShowCard(bool isNull) +{ + std::cout << (isNull ? " " : "XXXXXX"); +} +void View::ShowCard(Card card) +{ + std::cout << CardTypeView[card.GetType()] << CardValueView[card.GetValue()]; +} + +void View::ShowGame() +{ + bool flag = true; + char lc = '[', rc = ']'; + for (int level = 0; flag; ++level) + { + flag = false; + for (int i = 0; i < _Game.Scenes.size(); ++i) + { + if (_Game.PSelected.y == level && _Game.PSelected.x == i) + lc = rc = '*'; + else if (_Game.PCurrent.y == level && _Game.PCurrent.x == i) + lc = '>', rc = '<'; + else + lc = '[', rc = ']'; + + // ǻûIJ + if (level < _Game.Scenes[i].GetHideLevel()) + { + std::cout << lc; + ShowCard(false); + std::cout << rc; + flag = true; + } + // Ƶ + else if (level < _Game.Scenes[i].Count()) + { + std::cout << lc; + ShowCard(_Game.Scenes[i].GetCards()[level]); + std::cout << rc; + flag = true; + } + // ǿյIJ + else if (level == 0 && _Game.Scenes[i].Count() == 0) + { + // ϣֹ + if (_Game.PCurrent.y == level && _Game.PCurrent.x == i) + lc = '>', rc = '<'; + else + lc = ' ', rc = ' '; + std::cout << lc; + ShowCard(true); + std::cout << rc; + } + // ȫ + else + { + std::cout << ' '; + ShowCard(true); + std::cout << ' '; + } + } + std::cout << std::endl; + } + + std::cout << "\n\n\nǰѾɣ" << _Game.SuccessCount << "\tʣ෢ƴ" << _Game.ReservedCount << "" << std::endl; +} diff --git a/蜘蛛纸牌/View.h b/蜘蛛纸牌/View.h new file mode 100644 index 0000000..4122713 --- /dev/null +++ b/蜘蛛纸牌/View.h @@ -0,0 +1,25 @@ +#pragma once + +#include "Card.h" +#include "CardType.h" +#include "Game.h" + +extern const char *CardTypeView[]; +extern const char *CardValueView[]; + +class Game; +class View +{ +private: + Game &_Game; + +public: + View(Game &game) :_Game(game) {} + ~View(); + + void ShowCard(bool isNull); + void ShowCard(Card card); + + void ShowGame(); +}; + diff --git a/蜘蛛纸牌/main.cpp b/蜘蛛纸牌/main.cpp new file mode 100644 index 0000000..acb3a5d --- /dev/null +++ b/蜘蛛纸牌/main.cpp @@ -0,0 +1,90 @@ +#include +#include +using namespace std; +#include "Game.h" + +void showGame(); +bool input(); + +Game game; + +int main() +{ + game.StartNewGame(); + + while (true) + { + showGame(); + while(!input()) + ; + if (game.GetIsVictory()) + { + system("cls"); + std::cout << "游戏胜利!按任意键开始新游戏" << std::endl; + game.StartNewGame(); + } + } + getchar(); + return 0; +} + +void showGame() +{ + system("cls"); + game.Show(); + std::cout << "\n\n\n" + << "[w] [s] [a] [d] 移动光标 [e] 发牌 [r] 开始新游戏 [q] 退出游戏" << std::endl + << "[1] 简单难度 [2] 普通难度 [3] 困难难度" << std::endl; +} + +bool input() +{ + switch (_getch()) + { + case 'w': + case 'W': + game.CurMove(Dir::up); + break; + case 's': + case 'S': + game.CurMove(Dir::down); + break; + case 'a': + case 'A': + game.CurMove(Dir::left); + break; + case 'd': + case 'D': + game.CurMove(Dir::right); + break; + case ' ': + game.Select(); + break; + case 'e': + case 'E': + game.Deal(); + break; + case 'r': + case 'R': + game.StartNewGame(); + break; + case '1': + game.SetDifficulty(Difficulty::easy); + game.StartNewGame(); + break; + case '2': + game.SetDifficulty(Difficulty::normal); + game.StartNewGame(); + break; + case '3': + game.SetDifficulty(Difficulty::hard); + game.StartNewGame(); + break; + case 'q': + exit(0); + default: + return false; + break; + } + return true; +} \ No newline at end of file diff --git a/蜘蛛纸牌/蜘蛛纸牌.sln b/蜘蛛纸牌/蜘蛛纸牌.sln new file mode 100644 index 0000000..994286d --- /dev/null +++ b/蜘蛛纸牌/蜘蛛纸牌.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27130.2036 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "蜘蛛纸牌", "蜘蛛纸牌.vcxproj", "{2358BF32-823A-4544-A768-0F7CB1421917}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2358BF32-823A-4544-A768-0F7CB1421917}.Debug|x64.ActiveCfg = Debug|x64 + {2358BF32-823A-4544-A768-0F7CB1421917}.Debug|x64.Build.0 = Debug|x64 + {2358BF32-823A-4544-A768-0F7CB1421917}.Debug|x86.ActiveCfg = Debug|Win32 + {2358BF32-823A-4544-A768-0F7CB1421917}.Debug|x86.Build.0 = Debug|Win32 + {2358BF32-823A-4544-A768-0F7CB1421917}.Release|x64.ActiveCfg = Release|x64 + {2358BF32-823A-4544-A768-0F7CB1421917}.Release|x64.Build.0 = Release|x64 + {2358BF32-823A-4544-A768-0F7CB1421917}.Release|x86.ActiveCfg = Release|Win32 + {2358BF32-823A-4544-A768-0F7CB1421917}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {839C1040-BA87-4924-9F44-029555EEB49C} + EndGlobalSection +EndGlobal diff --git a/蜘蛛纸牌/蜘蛛纸牌.vcxproj b/蜘蛛纸牌/蜘蛛纸牌.vcxproj new file mode 100644 index 0000000..df70938 --- /dev/null +++ b/蜘蛛纸牌/蜘蛛纸牌.vcxproj @@ -0,0 +1,166 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {2358BF32-823A-4544-A768-0F7CB1421917} + Win32Proj + 蜘蛛纸牌 + 10.0.16299.0 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + NotUsing + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Use + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + NotUsing + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Use + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/蜘蛛纸牌/蜘蛛纸牌.vcxproj.filters b/蜘蛛纸牌/蜘蛛纸牌.vcxproj.filters new file mode 100644 index 0000000..aeb9715 --- /dev/null +++ b/蜘蛛纸牌/蜘蛛纸牌.vcxproj.filters @@ -0,0 +1,51 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + \ No newline at end of file diff --git a/蜘蛛纸牌/蜘蛛纸牌.vcxproj.user b/蜘蛛纸牌/蜘蛛纸牌.vcxproj.user new file mode 100644 index 0000000..6e2aec7 --- /dev/null +++ b/蜘蛛纸牌/蜘蛛纸牌.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file