資源簡介
Chat.rar
代碼片段和文件信息
#include?“Chat.h“
const?pair?Chat::ChatOutPos?=?pair(26);
const?pair?Chat::SendOutPos?=?pair(225);
const?pair?Chat::MemOutPos?=?pair(6815);
list?Chat::ChatRecords;
SocketList*?Chat::Room?=?NULL;
Chat::Chat():MaxName(16)RecSocket(NULL)
{
StartSocketLib;
srand(GetTickCount());
}
Chat::~Chat(){CloseSocketLib;}
void?Chat::SetOutPos(pair?pos)
{
HANDLE?hStd?=?GetStdHandle(STD_OUTPUT_HANDLE);
COORD?setPS;
setPS.X=pos.first; //設置光標位置
setPS.Y=pos.second;
SetConsoleCursorPosition(hStdsetPS);
}
void?Chat::CinString(void?*Receive)
{
SetOutPos(Chat::SendOutPos);
string?*Result?=?static_cast(Receive);
*Result?=?““;
cin?>>?*Result;
}
int?Chat::Menu()?
{
cout?<“1:創建房間“?< cout?<“2:進入房間“?< cout?<“請選擇你要進行的操作:“;
while(true)
{
int?select?=?0;
cin?>>?select;
if(select?==?1)
{
CreateRoom();
break;
}
else?if(select?==?2)
{
EnterRoom();
break;
}
else
{
cout?<“輸入有誤!請重新輸入:“;
}
}
return?0;
}
string?Chat::SetName()
{
int?num?=?rand()?%?MaxName;
string?name?=?AllName[num];
AllName.erase(find(AllName.begin()AllName.end()name));
return?name;
}
void?Chat::CreateRoom()
{
isServer?=?true;
Room?=?new?SocketList(true);
cout?<“創建房間成功“?< ActivateAllName();
DeleteName(myName?=?SetName());
NameInRoom.push_back(myName);
Fresh();
}
void?Chat::ActivateAllName()
{
const?int?MAXNUM?=?16;
const?string?nameArr[MAXNUM]?=?{“迅捷斥候““光輝女郎““末日使者““雪人騎士““刀鋒意志““瑪西亞之力““琴瑟仙女““寒冰射手““暗影之拳““邪惡小法師““武器大師““殤之木乃伊““卡牌大師““無極劍圣““流浪法師““不祥之刃“};
for(int?i?=?0;?i?!=?MAXNUM;?i++)
AllName.push_back(nameArr[i]);
}
void?Chat::DeleteName(string?name)
{
vector::iterator?itr?=?find(AllName.begin()AllName.end()name);
if(itr?!=?AllName.end())
AllName.erase(itr);
--MaxName;
}
void?Chat::EnterRoom()
{
isServer?=?false;
cout?<“請輸入進入的房間IP地址:“;
string?RoomIp;
cin?>>?RoomIp;
Room?=?new?SocketList(falseRoomIp);
cout?<“進入房間成功“?< Fresh();
}
void?Chat::clearText(pair?pos)
{
int?line?=?0length?=?0;
if(pos?==?SendOutPos)
{
line?=?5;
length?=?64;
}
else?if(pos?==?ChatOutPos)
{
line?=?15;
length?=?64;
}
else?if(pos?==?MemOutPos)
{
line?=?16;
length?=?15;
}
for?(int?i?=?0;?i?!=?line;?++i)
{
SetOutPos(pos);
for(int?j?=?0;?j?!=?length;?++j)
cout?<“?“;
++pos.second;
}
}
void?Chat::Fresh()
{
ThreadLib::ThreadID?CinThread;
string?*str?=?new?string;
system(“cls“);
DrawBackground();
ShowName();
while(true)
{
CinThread?=?ThreadLib::Create(?CinString?(void*)str?);
while(true)
{
detectingMsg();
if?(*str?!=?““)
{
*str?=?myName?+?“(“?+?getTime()?+?“)\n│“?+?*str;
if(isServer)
{
RecStrList.push_back(*str);
freshChatRecord();
}
Room->Send(*str);
clearText(Se
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????9836??2015-04-25?09:04??Chat\Chat.cpp
?????文件???????2017??2015-04-25?08:16??Chat\Chat.h
?????文件???32198656??2015-04-25?16:46??Chat\Chat.sdf
?????文件????????874??2015-04-19?11:09??Chat\Chat.sln
????..A..H.?????33280??2015-04-25?16:46??Chat\Chat.suo
?????文件???????4602??2015-04-25?16:45??Chat\Chat.vcxproj
?????文件???????2093??2015-04-25?16:45??Chat\Chat.vcxproj.filters
?????文件????????143??2015-04-19?11:09??Chat\Chat.vcxproj.user
?????文件???????2027??2015-04-23?00:18??Chat\Debug\Chat.Build.CppClean.log
?????文件?????210432??2015-04-25?16:45??Chat\Debug\Chat.exe
?????文件????????406??2015-04-23?00:21??Chat\Debug\Chat.exe.em
?????文件????????472??2015-04-23?00:21??Chat\Debug\Chat.exe.em
?????文件????????381??2015-04-25?16:45??Chat\Debug\Chat.exe.intermediate.manifest
?????文件????1515664??2015-04-25?16:45??Chat\Debug\Chat.ilk
?????文件?????????87??2015-04-25?16:45??Chat\Debug\Chat.lastbuildstate
?????文件???????2347??2015-04-25?16:45??Chat\Debug\Chat.log
?????文件?????815929??2015-04-25?09:04??Chat\Debug\Chat.obj
?????文件????1985536??2015-04-25?16:45??Chat\Debug\Chat.pdb
?????文件????????707??2015-04-23?14:18??Chat\Debug\Chat.vcxprojResolveAssemblyReference.cache
?????文件??????????0??2015-04-23?00:18??Chat\Debug\Chat.write.1.tlog
?????文件????????198??2015-04-23?00:18??Chat\Debug\Chat_manifest.rc
?????文件???????4106??2015-04-25?16:45??Chat\Debug\cl.command.1.tlog
?????文件?????136862??2015-04-25?16:45??Chat\Debug\CL.read.1.tlog
?????文件???????5246??2015-04-25?16:45??Chat\Debug\CL.write.1.tlog
?????文件??????????2??2015-04-25?16:45??Chat\Debug\li
?????文件??????????2??2015-04-25?16:45??Chat\Debug\li
?????文件??????????2??2015-04-25?16:45??Chat\Debug\li
?????文件??????????2??2015-04-25?16:45??Chat\Debug\li
?????文件??????????2??2015-04-25?16:45??Chat\Debug\li
?????文件??????????2??2015-04-25?16:45??Chat\Debug\li
............此處省略57個文件信息
- 上一篇:精倫電子idr210 sdk
- 下一篇:柯林斯雙解第五版多看 kindle
評論
共有 條評論