mirror of
https://github.com/jie65535/Ancient-Spider.git
synced 2024-07-27 18:54:53 +08:00
提交源码
编译环境 VS2017
This commit is contained in:
2
蜘蛛纸牌/Card.cpp
Normal file
2
蜘蛛纸牌/Card.cpp
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#include "Card.h"
|
||||||
|
|
37
蜘蛛纸牌/Card.h
Normal file
37
蜘蛛纸牌/Card.h
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
39
蜘蛛纸牌/CardType.h
Normal file
39
蜘蛛纸牌/CardType.h
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
enum CardType {
|
||||||
|
// <20><><EFBFBD><EFBFBD>
|
||||||
|
Spade,
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD>
|
||||||
|
Heart,
|
||||||
|
|
||||||
|
// ÷<><C3B7>
|
||||||
|
Club,
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD>
|
||||||
|
Diamond
|
||||||
|
};
|
||||||
|
|
||||||
|
const int CardTypeNum = 4;
|
||||||
|
|
||||||
|
// <20><><EFBFBD>Ƶ<EFBFBD>ֵ
|
||||||
|
enum CardValue {
|
||||||
|
_A,
|
||||||
|
_2,
|
||||||
|
_3,
|
||||||
|
_4,
|
||||||
|
_5,
|
||||||
|
_6,
|
||||||
|
_7,
|
||||||
|
_8,
|
||||||
|
_9,
|
||||||
|
_10,
|
||||||
|
_J,
|
||||||
|
_Q,
|
||||||
|
_K,
|
||||||
|
};
|
||||||
|
|
||||||
|
const int CardValueNum = 13;
|
36
蜘蛛纸牌/CardsSlots.cpp
Normal file
36
蜘蛛纸牌/CardsSlots.cpp
Normal file
@@ -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<Card> & 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--;
|
||||||
|
}
|
31
蜘蛛纸牌/CardsSlots.h
Normal file
31
蜘蛛纸牌/CardsSlots.h
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <vector>
|
||||||
|
#include "Card.h"
|
||||||
|
|
||||||
|
class CardsSlots
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::vector<Card> _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<Card> & GetCards() { return _Cards; }
|
||||||
|
private:
|
||||||
|
void UpdateHideLevel();
|
||||||
|
};
|
||||||
|
|
BIN
蜘蛛纸牌/Debug/Card.obj
Normal file
BIN
蜘蛛纸牌/Debug/Card.obj
Normal file
Binary file not shown.
BIN
蜘蛛纸牌/Debug/CardsSlots.obj
Normal file
BIN
蜘蛛纸牌/Debug/CardsSlots.obj
Normal file
Binary file not shown.
BIN
蜘蛛纸牌/Debug/Game.obj
Normal file
BIN
蜘蛛纸牌/Debug/Game.obj
Normal file
Binary file not shown.
BIN
蜘蛛纸牌/Debug/View.obj
Normal file
BIN
蜘蛛纸牌/Debug/View.obj
Normal file
Binary file not shown.
BIN
蜘蛛纸牌/Debug/main.obj
Normal file
BIN
蜘蛛纸牌/Debug/main.obj
Normal file
Binary file not shown.
BIN
蜘蛛纸牌/Debug/vc141.idb
Normal file
BIN
蜘蛛纸牌/Debug/vc141.idb
Normal file
Binary file not shown.
BIN
蜘蛛纸牌/Debug/vc141.pdb
Normal file
BIN
蜘蛛纸牌/Debug/vc141.pdb
Normal file
Binary file not shown.
7
蜘蛛纸牌/Debug/蜘蛛纸牌.Build.CppClean.log
Normal file
7
蜘蛛纸牌/Debug/蜘蛛纸牌.Build.CppClean.log
Normal file
@@ -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
|
BIN
蜘蛛纸牌/Debug/蜘蛛纸牌.exe
Normal file
BIN
蜘蛛纸牌/Debug/蜘蛛纸牌.exe
Normal file
Binary file not shown.
BIN
蜘蛛纸牌/Debug/蜘蛛纸牌.ilk
Normal file
BIN
蜘蛛纸牌/Debug/蜘蛛纸牌.ilk
Normal file
Binary file not shown.
2
蜘蛛纸牌/Debug/蜘蛛纸牌.log
Normal file
2
蜘蛛纸牌/Debug/蜘蛛纸牌.log
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
main.cpp
|
||||||
|
蜘蛛纸牌.vcxproj -> F:\C++\VS\蜘蛛纸牌\蜘蛛纸牌\Debug\蜘蛛纸牌.exe
|
BIN
蜘蛛纸牌/Debug/蜘蛛纸牌.pdb
Normal file
BIN
蜘蛛纸牌/Debug/蜘蛛纸牌.pdb
Normal file
Binary file not shown.
BIN
蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/CL.command.1.tlog
Normal file
BIN
蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/CL.command.1.tlog
Normal file
Binary file not shown.
BIN
蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/CL.read.1.tlog
Normal file
BIN
蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/CL.read.1.tlog
Normal file
Binary file not shown.
BIN
蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/CL.write.1.tlog
Normal file
BIN
蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/CL.write.1.tlog
Normal file
Binary file not shown.
BIN
蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/link.command.1.tlog
Normal file
BIN
蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/link.command.1.tlog
Normal file
Binary file not shown.
BIN
蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/link.read.1.tlog
Normal file
BIN
蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/link.read.1.tlog
Normal file
Binary file not shown.
BIN
蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/link.write.1.tlog
Normal file
BIN
蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/link.write.1.tlog
Normal file
Binary file not shown.
2
蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/蜘蛛纸牌.lastbuildstate
Normal file
2
蜘蛛纸牌/Debug/蜘蛛纸牌.tlog/蜘蛛纸牌.lastbuildstate
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.16299.0
|
||||||
|
Debug|Win32|F:\C++\VS\蜘蛛纸牌\蜘蛛纸牌\|
|
329
蜘蛛纸牌/Game.cpp
Normal file
329
蜘蛛纸牌/Game.cpp
Normal file
@@ -0,0 +1,329 @@
|
|||||||
|
#include "Game.h"
|
||||||
|
#include <random>
|
||||||
|
|
||||||
|
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<int> 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;
|
||||||
|
|
||||||
|
// <20><>֮ǰѡ<C7B0>е<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||||||
|
PSelected.SetValue(-1, -1);
|
||||||
|
|
||||||
|
// Ϊÿһ<C3BF><D2BB><EFBFBD>۷<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
|
||||||
|
for (int i = 0; i < Scenes.size(); ++i)
|
||||||
|
{
|
||||||
|
Scenes[i].Push(_Cards[(ReservedCount-1) * Scenes.size() + i]);
|
||||||
|
}
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>û<EFBFBD>κ<EFBFBD><CEBA><EFBFBD> ָ<><D6B8><EFBFBD><EFBFBD>
|
||||||
|
if (Scenes[PCurrent.x].Count() == 0)
|
||||||
|
PCurrent.y = 0;
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߶ȸ<DFB6><C8B8>ڵ<EFBFBD>ǰ<EFBFBD>߶<EFBFBD>
|
||||||
|
// <20><><EFBFBD><EFBFBD>֮ǰ<D6AE>ĸ߶<C4B8><DFB6><EFBFBD>0
|
||||||
|
// <20><><EFBFBD><EFBFBD>֮ǰ<D6AE><C7B0><EFBFBD><EFBFBD>һ<EFBFBD>еĶ<D0B5><C4B6><EFBFBD>ʱ
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ǰ<EFBFBD>еĶ<D0B5><C4B6><EFBFBD>
|
||||||
|
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;
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>֮ǰѡ<C7B0>ģ<EFBFBD><C4A3><EFBFBD>ȡ<EFBFBD><C8A1>ѡ<EFBFBD><D1A1>
|
||||||
|
if (PSelected == PCurrent)
|
||||||
|
{
|
||||||
|
PSelected.SetValue(-1, -1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD>֮ǰδѡ<CEB4><D1A1><EFBFBD>κζ<CEBA><CEB6><EFBFBD>
|
||||||
|
if (PSelected.x == -1)
|
||||||
|
{
|
||||||
|
// <20>жϵ<D0B6>ǰѡ<C7B0><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɲ<EFBFBD><C9B2><EFBFBD><EFBFBD><EFBFBD>ѡ
|
||||||
|
if (CheckIsOptional(PCurrent))
|
||||||
|
{
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD>true
|
||||||
|
PSelected = PCurrent;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>֮ǰѡ<C7B0><D1A1><EFBFBD>˶<EFBFBD><CBB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD>ĺ<EFBFBD>֮ǰѡ<C7B0><D1A1><EFBFBD><EFBFBD>ͬһ<CDAC><D2BB> <20><><EFBFBD><EFBFBD> ѡ<><D1A1><EFBFBD>Dz<EFBFBD><C7B2><EFBFBD><EFBFBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
if (PCurrent.x == PSelected.x || PCurrent.y != Scenes[PCurrent.x].Count() - 1)
|
||||||
|
{
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ɶ<EFBFBD><C9B6>û<EFBFBD><C3BB>
|
||||||
|
if (Scenes[PCurrent.x].Count() == 0)
|
||||||
|
{
|
||||||
|
// ֱ<><D6B1><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>ȥ
|
||||||
|
MoveCards(PSelected, PCurrent.x);
|
||||||
|
PSelected.SetValue(-1, -1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (CheckIsOptional(PCurrent))
|
||||||
|
{
|
||||||
|
PSelected = PCurrent;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>ȥ
|
||||||
|
if (CheckIsOrderly(
|
||||||
|
Scenes[PCurrent.x].GetCards().at(PCurrent.y),
|
||||||
|
Scenes[PSelected.x].GetCards().at(PSelected.y),
|
||||||
|
_Difficulty))
|
||||||
|
{
|
||||||
|
// ֱ<><D6B1><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>ȥ
|
||||||
|
MoveCards(PSelected, PCurrent.x);
|
||||||
|
PSelected.SetValue(-1, -1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// <20><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PSelected = PCurrent;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Game::MoveCards(Point point, int SlotsIndex)
|
||||||
|
{
|
||||||
|
// <20><>ָ<EFBFBD><D6B8>λ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
|
||||||
|
Scenes[point.x].MoveCardsTo(Scenes[SlotsIndex], point.y);
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
if (CheckIsSuccess(SlotsIndex))
|
||||||
|
{
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>飬<EFBFBD><EFBFBD><F2B5AFB3><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
|
||||||
|
Scenes[SlotsIndex].Pop(CardValueNum);
|
||||||
|
// Ȼ<><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
SuccessCount++;
|
||||||
|
|
||||||
|
if (SuccessCount == GroupsNum)
|
||||||
|
IsVictory = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Game::CheckIsOptional(Point point)
|
||||||
|
{
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ɶ<EFBFBD><C9B6>û<EFBFBD><C3BB>
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻҪ<D6BB><D2AA>һ<EFBFBD><D2BB><EFBFBD>Ǵ<EFBFBD><C7B4><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
|
||||||
|
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;
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѷȼ<D1B6><C8BC>黨ɫ
|
||||||
|
switch (difficulty)
|
||||||
|
{
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ѶȲ<D1B6><C8B2><EFBFBD><EFBFBD><EFBFBD>ɫ
|
||||||
|
case easy:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// <20><>ͨ<EFBFBD>Ѷ<EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>Ƿ<EFBFBD><C7B7>ں<EFBFBD><DABA><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
case normal:
|
||||||
|
return cur.GetType() == CardType::Spade && next.GetType() == CardType::Heart
|
||||||
|
|| cur.GetType() == CardType::Heart && next.GetType() == CardType::Spade;
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѷ<EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>պ<EFBFBD><D5BA>ҡ<EFBFBD><D2A1><EFBFBD><EFBFBD>ҡ<EFBFBD>÷<EFBFBD><C3B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
bool Game::CheckIsSuccess(int SlotsIndex)
|
||||||
|
{
|
||||||
|
// <20><><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>۵<EFBFBD><DBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㲻<EFBFBD>㹻<EFBFBD><E3B9BB><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
|
||||||
|
if (Scenes[SlotsIndex].Count() < CardValueNum)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ƣ<EFBFBD>ֱ<EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD>
|
||||||
|
if (Scenes[SlotsIndex].Count() - Scenes[SlotsIndex].GetHideLevel() < CardValueNum)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
std::vector<Card> Cards = Scenes[SlotsIndex].GetCards();
|
||||||
|
// Ȼ<><C8BB><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Dz<EFBFBD><C7B2><EFBFBD>A<EFBFBD><41><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD>
|
||||||
|
if (Cards.back().GetValue() != CardValue::_A)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Ȼ<><C8BB><EFBFBD><EFBFBD><EFBFBD>鵹<EFBFBD><E9B5B9>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>ÿ<EFBFBD>ʼ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>ӷ<EFBFBD><D3B7>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
return CheckIsOptional(Point(SlotsIndex, Cards.size() - CardValueNum));
|
||||||
|
}
|
122
蜘蛛纸牌/Game.h
Normal file
122
蜘蛛纸牌/Game.h
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <vector>
|
||||||
|
#include <array>
|
||||||
|
#include "Card.h"
|
||||||
|
#include "View.h"
|
||||||
|
#include "CardsSlots.h"
|
||||||
|
|
||||||
|
// <20>Ѷ<EFBFBD>
|
||||||
|
enum Difficulty
|
||||||
|
{
|
||||||
|
// <20><><EFBFBD><EFBFBD>
|
||||||
|
easy,
|
||||||
|
// <20><>ͨ
|
||||||
|
normal,
|
||||||
|
// <20><><EFBFBD><EFBFBD>
|
||||||
|
hard,
|
||||||
|
};
|
||||||
|
|
||||||
|
// <20>Ʋ<EFBFBD><C6B2><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
const int SlotsNum = 10;
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
const int GroupsNum = 8;
|
||||||
|
|
||||||
|
// Ԥ<><D4A4><EFBFBD><EFBFBD> Ԥ<><D4A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> = Ԥ<><D4A4><EFBFBD><EFBFBD> * <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> = 5 * 10 = 50 <20><><EFBFBD>Է<EFBFBD><D4B7><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
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:
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
std::array<Card, GroupsNum * CardValueNum> _Cards;
|
||||||
|
|
||||||
|
// <20><>Ϸ<EFBFBD>Ѷ<EFBFBD>
|
||||||
|
Difficulty _Difficulty;
|
||||||
|
|
||||||
|
View *_pView;
|
||||||
|
|
||||||
|
std::array<CardsSlots, SlotsNum> Scenes;
|
||||||
|
|
||||||
|
// Ԥ<><D4A4><EFBFBD><EFBFBD><EFBFBD>ƵĴ<C6B5><C4B4><EFBFBD>
|
||||||
|
int ReservedCount;
|
||||||
|
|
||||||
|
// <20>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵļ<CFB5><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
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; }
|
||||||
|
|
||||||
|
// ϴ<><CFB4>
|
||||||
|
void Shuffle();
|
||||||
|
|
||||||
|
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
void InitScenes();
|
||||||
|
|
||||||
|
// <20><>ʼһ<CABC><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ
|
||||||
|
void StartNewGame();
|
||||||
|
|
||||||
|
// <20><><EFBFBD>ƣ<EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD><EFBFBD>ƴ<EFBFBD><C6B4><EFBFBD><EFBFBD>㹻<EFBFBD><E3B9BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>²Żᷢ<C5BB>ɹ<EFBFBD><C9B9><EFBFBD>
|
||||||
|
void Deal();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>
|
||||||
|
void CurMove(Dir dir);
|
||||||
|
|
||||||
|
// ѡ<><D1A1><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD>ɹ<EFBFBD>
|
||||||
|
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);
|
||||||
|
};
|
||||||
|
|
85
蜘蛛纸牌/View.cpp
Normal file
85
蜘蛛纸牌/View.cpp
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
#include "View.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
const char *CardTypeView[] = {
|
||||||
|
"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
|
||||||
|
"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
|
||||||
|
"÷<EFBFBD><EFBFBD>",
|
||||||
|
"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
|
||||||
|
};
|
||||||
|
|
||||||
|
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 = ']';
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ǻ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD>
|
||||||
|
if (level < _Game.Scenes[i].GetHideLevel())
|
||||||
|
{
|
||||||
|
std::cout << lc;
|
||||||
|
ShowCard(false);
|
||||||
|
std::cout << rc;
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>
|
||||||
|
else if (level < _Game.Scenes[i].Count())
|
||||||
|
{
|
||||||
|
std::cout << lc;
|
||||||
|
ShowCard(_Game.Scenes[i].GetCards()[level]);
|
||||||
|
std::cout << rc;
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿյIJ<D5B5>
|
||||||
|
else if (level == 0 && _Game.Scenes[i].Count() == 0)
|
||||||
|
{
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><CFA3><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD>
|
||||||
|
if (_Game.PCurrent.y == level && _Game.PCurrent.x == i)
|
||||||
|
lc = '>', rc = '<';
|
||||||
|
else
|
||||||
|
lc = ' ', rc = ' ';
|
||||||
|
std::cout << lc;
|
||||||
|
ShowCard(true);
|
||||||
|
std::cout << rc;
|
||||||
|
}
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << ' ';
|
||||||
|
ShowCard(true);
|
||||||
|
std::cout << ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "\n\n\n<EFBFBD><EFBFBD>ǰ<EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD>" << _Game.SuccessCount << "<EFBFBD><EFBFBD>\tʣ<EFBFBD><EFBFBD>ƴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << _Game.ReservedCount << "<EFBFBD><EFBFBD>" << std::endl;
|
||||||
|
}
|
25
蜘蛛纸牌/View.h
Normal file
25
蜘蛛纸牌/View.h
Normal file
@@ -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();
|
||||||
|
};
|
||||||
|
|
90
蜘蛛纸牌/main.cpp
Normal file
90
蜘蛛纸牌/main.cpp
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <conio.h>
|
||||||
|
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;
|
||||||
|
}
|
31
蜘蛛纸牌/蜘蛛纸牌.sln
Normal file
31
蜘蛛纸牌/蜘蛛纸牌.sln
Normal file
@@ -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
|
166
蜘蛛纸牌/蜘蛛纸牌.vcxproj
Normal file
166
蜘蛛纸牌/蜘蛛纸牌.vcxproj
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>15.0</VCProjectVersion>
|
||||||
|
<ProjectGuid>{2358BF32-823A-4544-A768-0F7CB1421917}</ProjectGuid>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<RootNamespace>蜘蛛纸牌</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="Card.cpp" />
|
||||||
|
<ClCompile Include="CardsSlots.cpp" />
|
||||||
|
<ClCompile Include="Game.cpp" />
|
||||||
|
<ClCompile Include="main.cpp" />
|
||||||
|
<ClCompile Include="View.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="Card.h" />
|
||||||
|
<ClInclude Include="CardsSlots.h" />
|
||||||
|
<ClInclude Include="CardType.h" />
|
||||||
|
<ClInclude Include="Game.h" />
|
||||||
|
<ClInclude Include="View.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
51
蜘蛛纸牌/蜘蛛纸牌.vcxproj.filters
Normal file
51
蜘蛛纸牌/蜘蛛纸牌.vcxproj.filters
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup>
|
||||||
|
<Filter Include="源文件">
|
||||||
|
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||||
|
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="头文件">
|
||||||
|
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||||
|
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="资源文件">
|
||||||
|
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||||
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||||
|
</Filter>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="main.cpp">
|
||||||
|
<Filter>源文件</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="Card.cpp">
|
||||||
|
<Filter>源文件</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="View.cpp">
|
||||||
|
<Filter>源文件</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="Game.cpp">
|
||||||
|
<Filter>源文件</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="CardsSlots.cpp">
|
||||||
|
<Filter>源文件</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="Card.h">
|
||||||
|
<Filter>头文件</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="CardType.h">
|
||||||
|
<Filter>头文件</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="View.h">
|
||||||
|
<Filter>头文件</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Game.h">
|
||||||
|
<Filter>头文件</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="CardsSlots.h">
|
||||||
|
<Filter>头文件</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
4
蜘蛛纸牌/蜘蛛纸牌.vcxproj.user
Normal file
4
蜘蛛纸牌/蜘蛛纸牌.vcxproj.user
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup />
|
||||||
|
</Project>
|
Reference in New Issue
Block a user