此头文件的更老版本可以参考: ICUF_HEAD_06.h.
开发环境:Visual Studio 2019
TANXL_CONSOLE_LIST.H(ICUF_HEAD_07.H)
正在使用此头文件进行推箱子游戏的开发,完成后将公布所有源代码。
#ifndef TANXL_CONSOLE_LIST
#define TANXL_CONSOLE_LIST
#ifndef TANXL_LIST
#define TANXL_LIST 1
#define LIST 1
#else
#define LIST 0
#endif
#endif
#if LIST
#ifndef IOSTREAM
#define IOSTREAM
#include <iostream>
#endif
#ifndef STRING
#define STRING
#include <string>
#endif
#ifndef CONIO_H
#define CONIO_H
#include <conio.h>
#endif
#ifndef IOMANIP
#define IOMANIP
#include <iomanip>
#endif
const char* HeadFile = "HeadFile.txt";
inline void Col(int ColN)
{
if (ColN == 0)std::cout << "\033[0m";
else
{
std::cout << "\033[4;1;7m";
if (ColN == 1)std::cout << "\033[31m";
else if (ColN == 2)std::cout << "\033[32m";
else if (ColN == 3)std::cout << "\033[33m";
else if (ColN == 4)std::cout << "\033[34m";
else if (ColN == 5)std::cout << "\033[35m";
else if (ColN == 6)std::cout << "\033[36m";
else if (ColN == 7)std::cout << "\033[37m";
else if (ColN == 8)Col((rand() % 6) + 1);
else if (ColN == 10)std::cout << "\033[40m";
else if (ColN == 11)std::cout << "\033[41m";
else if (ColN == 12)std::cout << "\033[42m";
else if (ColN == 13)std::cout << "\033[43m";
else if (ColN == 14)std::cout << "\033[44m";
else if (ColN == 15)std::cout << "\033[45m";
else if (ColN == 16)std::cout << "\033[46m";
else if (ColN == 17)std::cout << "\033[47m";
else if (ColN == 18)Col((rand() % 6) + 11);
}
}
typedef enum class Status
{
eMainList,
eSonList
}Status;
typedef class MainList
{
public:
void SetCol(int ColS, int ColU, int ColD = 7, int SonC = 6);
void SetFont(int ColS, int ColU, int ColD, int SonC);
void RecoverTimes();
void ResetTimes();
void InitList(int Start = 0);
void Append(std::string FunctionName, int Times = 1);
void RemoveAll();
void SetLimit(int Max);
void DisplayList(MainList List);
void SetListName(std::string Name);
void ShowTitle();
void SetTitle(std::string Temp);
void SetStatus(Status Sta);
void SetSpace(int Left = 23, int Right = 17, int Title = 33);
int InsertAction();
int DisplayList(int LStart = 0, int LEnd = 9, int Switch = 0, int Return = 0);
int DisplayListS(int LStart = 0, int LEnd = 9, int Return = 0);
int CheckCurrent();
int GetLimit();
int GetPages();
int GetSonLists();
int GetTimes();
int GetTimeS();
int GetTempTimes();
Status GetStatus();
std::string GetListName();
private:
void MoveUp();
void MoveDown();
int Times{};
int TempTimes{};
int Page{ 1 };
int Pages{ 1 };
int LimitEachPage{ 9 };
int SonLists{ 0 };
int ListStatus[50]{ -1 };
int SonCol{ 6 };
int SelectedCol{ 7 };
int UnSelectedCol{ 1 };
int DefaultCol{ 1 };
int SonFont{ 10 };
int SelectedFont{ 10 };
int UnSelectedFont{ 10 };
int DefaultFont{ 10 };
int WidthL{ 23 }, WidthR{ 17 }, WidthT{ 33 };
Status Stat{ Status::eSonList };
std::string ListName;
std::string List[50]{};
std::string Title{ "欢迎使用TANXL_CONSOLE_LIST WiChG_Trade" };
}MainList;
inline void Free(MainList* Fun)
{
delete Fun;
Fun = NULL;
}
void MainList::SetCol(int ColS, int ColU, int ColD, int SonC)
{
this->SelectedCol = ColS;
this->UnSelectedCol = ColU;
this->DefaultCol = ColD;
this->SonCol = SonC;
}
void MainList::SetFont(int ColS, int ColU, int ColD, int SonC)
{
this->SelectedFont = ColS;
this->UnSelectedFont = ColU;
this->DefaultFont = ColD;
this->SonFont = SonC;
}
void MainList::RecoverTimes()
{
this->Times += ++this->TempTimes;
this->TempTimes = 0;
}
void MainList::ResetTimes()
{
this->TempTimes += ++this->Times;
this->Times = 0;
}
void MainList::InitList(int Start)
{
for (int i = 0; i < SonLists; i++)
{
ListStatus[i] = 0;
}
for (int i = SonLists; i < 50; i++)
{
ListStatus[i] = -1;
}
ListStatus[Start] = 1;
}
void MainList::DisplayList(MainList TempList)
{
int Start = (TempList.Page - 1) * TempList.LimitEachPage;
int End = Start + TempList.LimitEachPage;
int UnSeCol = TempList.SonCol;
int UnSeFont = TempList.SonFont;
for (int i = Start; i < End + (9 - TempList.LimitEachPage); i++)
{
if (TempList.ListStatus[i] != -1)
{
if (TempList.ListStatus[i] == 1)
{
Col(TempList.SelectedCol);
Col(TempList.SelectedFont);
}
else
{
Col(UnSeCol);
Col(UnSeFont);
}
std::cout << std::setw(WidthL) << TempList.List[i] << std::setw(WidthR) << " " << std::endl;
Col(0);
}
}
std::cout << std::endl;
}
int MainList::DisplayList(int LStart, int LEnd, int Switch, int Return)
{
int Start = (Page - 1) * LimitEachPage;
int End = Start + LimitEachPage;
int UnSeCol = UnSelectedCol;
int UnSeFont = UnSelectedFont;
int ReturnS{};
if (Switch == 1)
std::cout << "FunId: " << CheckCurrent() << " Limit: " << LimitEachPage << " Page: " << Page << " Start: " << Start << " End: " << End << std::endl << std::endl;
if (Switch == 2)
{
UnSeCol = SonCol;
UnSeFont = SonFont;
}
for (int i = Start + LStart; i < End + (LEnd - LimitEachPage); i++)
{
if (ListStatus[i] != -1)
{
if (ListStatus[i] == 1)
{
Col(SelectedCol);
Col(SelectedFont);
}
else
{
Col(UnSeCol);
Col(UnSeFont);
}
std::cout << std::setw(WidthL) << List[i] << std::setw(WidthR) << " " << std::endl;
if (Switch != 2)
std::cout << std::endl;
Col(0);
}
}
if (Switch == 2)
std::cout << std::endl;
if (Return != 0)
ReturnS = InsertAction();
else
return 0;
return ReturnS;
}
int MainList::InsertAction()
{
char Key;
int Temp;
Key = _getch();
if (Key == 'c' || Key == 'C')
return 3;
if (SonLists == 0)
return 0;
if ((int)(Key - 48) > 0 && (int)(Key - 48) <= 9)
{
if ((int)(Key - 48) > SonLists)
InitList(SonLists - 1);
else
InitList((int)(Key - 48) - 1);
return 4;
}
else if (Key == 'w' || Key == 'W' || Key == 72)
{
MoveUp();
return 0;
}
else if (Key == 's' || Key == 'S' || Key == 80)
{
MoveDown();
return 0;
}
else if (Key == 'a' || Key == 'A' || Key == 75)
{
if (Page == GetPages() && GetPages() == 1)
{
Temp = CheckCurrent();
ListStatus[Temp] = 0;
ListStatus[0] = 1;
}
else if (Page != 1)
{
Page--;
Temp = CheckCurrent();
ListStatus[Temp] = 0;
ListStatus[Temp - LimitEachPage] = 1;
}
else
{
Page = GetPages();
Temp = CheckCurrent();
ListStatus[Temp] = 0;
ListStatus[(Page - 1) * LimitEachPage] = 1;
}
return 0;
}
else if (Key == 'd' || Key == 'D' || Key == 77)
{
if (Page == GetPages() && GetPages() == 1)
{
Temp = CheckCurrent();
ListStatus[Temp] = 0;
ListStatus[SonLists - 1] = 1;
}
else if (Page != GetPages())
{
Page++;
Temp = CheckCurrent();
ListStatus[Temp] = 0;
if (Temp + LimitEachPage >= SonLists - 1)
ListStatus[SonLists - 1] = 1;
else
ListStatus[Temp + LimitEachPage] = 1;
}
else
{
Page = 1;
Temp = CheckCurrent();
ListStatus[Temp] = 0;
ListStatus[Temp % LimitEachPage] = 1;
}
return 0;
}
else if (Key == 'z' || Key == 'Z')
{
return 1;
}
else if (Key == 'x' || Key == 'X')
{
return 2;
}
else if (Key == '\r')
return 4;
return 0;
}
int MainList::CheckCurrent()
{
for (int j = 0; j < SonLists; j++)
{
if (ListStatus[j] == 1)
return j;
}
return -1;
}
void MainList::Append(std::string FunctionName, int Times)
{
if (Times != 0)
return;
List[SonLists] = FunctionName;
SonLists += 1;
}
void MainList::RemoveAll()
{
for (int i = 0; i < 10; i++)
{
List[i] = {};
SonLists = 0;
}
}
void MainList::SetLimit(int Max)
{
LimitEachPage = (Max > 9 || Max <= 0) ? 9 : Max;
}
int MainList::GetPages()
{
if (SonLists % LimitEachPage != 0)
Pages = SonLists / LimitEachPage + 1;
else
Pages = SonLists / LimitEachPage;
return Pages;
}
int MainList::GetLimit()
{
return LimitEachPage;
}
void MainList::MoveUp()
{
int i = CheckCurrent();
if (i == 0 && SonLists == 1)
ListStatus[i] = 1;
else if (i == 0 && SonLists != 1)
{
ListStatus[i] = 0;
Page = GetPages();
ListStatus[SonLists - 1] = 1;
}
else if ((i + 1) % LimitEachPage == 1)
{
if (Page != 1)
{
Page--;
ListStatus[i] = 0;
ListStatus[i - 1] = 1;
}
else
{
Page = GetPages();
ListStatus[i] = 0;
ListStatus[SonLists - 1] = 1;
}
}
else
{
ListStatus[i] = 0;
ListStatus[i - 1] = 1;
}
}
void MainList::MoveDown()
{
int i = CheckCurrent();
if (i == 0 && SonLists == 1)
ListStatus[i] = 1;
else if (i != 0 && i == SonLists - 1)
{
ListStatus[SonLists - 1] = 0;
Page = 1;
ListStatus[0] = 1;
}
else if ((i + 1) % LimitEachPage == 0)
{
if (Page != GetPages())
{
Page++;
ListStatus[i] = 0;
ListStatus[i + 1] = 1;
}
else
{
Page = 1;
ListStatus[i] = 0;
ListStatus[0] = 1;
}
}
else
{
ListStatus[i] = 0;
ListStatus[i + 1] = 1;
}
}
void MainList::SetListName(std::string Name)
{
this->ListName = Name;
}
std::string MainList::GetListName()
{
return this->ListName;
}
void MainList::SetTitle(std::string Temp)
{
Title = Temp;
}
void MainList::ShowTitle()
{
Col(DefaultCol); Col(DefaultFont);
std::cout << std::endl << std::endl << std::endl << std::endl;
std::cout << std::setw(WidthL) << " " << std::setw(WidthT) << Title << std::setw(WidthR) << " " << std::endl << std::endl; Col(0);
}
int MainList::DisplayListS(int LStart, int LEnd, int Return)
{
int Start = (Page - 1) * LimitEachPage;
int End = Start + LimitEachPage;
int ReturnS{};
for (int i = Start + LStart; i < End + (LEnd - LimitEachPage); i++)
{
if (ListStatus[i] != -1)
{
if (ListStatus[i] == 1)
{
Col(SelectedCol);
Col(SelectedFont);
}
else
{
Col(SonCol);
Col(SonFont);
}
std::cout << std::setw(WidthL) << List[i] << std::setw(WidthR) << " " << std::endl;
Col(0);
}
}
std::cout << std::endl;
if (Return != 0)
ReturnS = InsertAction();
else
return 0;
return ReturnS;
}
int MainList::GetSonLists()
{
return SonLists;
}
int MainList::GetTimes()
{
return Times;
}
int MainList::GetTimeS()
{
return Times++;
}
int MainList::GetTempTimes()
{
return TempTimes;
}
void MainList::SetStatus(Status Sta)
{
Stat = Sta;
}
Status MainList::GetStatus()
{
return Stat;
}
void MainList::SetSpace(int Left, int Right, int Title)
{
WidthL = Left;
WidthR = Right;
WidthT = Title;
}
#endif
|