MainData.cpp
资源名称:1731.rar [点击查看]
上传用户:swkcbjrc
上传日期:2016-04-02
资源大小:45277k
文件大小:4k
源码类别:
游戏
开发平台:
Visual C++
- // MainData.cpp: implementation of the CMainData class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "gamehigh.h"
- #include "MainData.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CMainData::CMainData()
- {
- lpMyTable =NULL;
- myStatus =IDLESSE;
- memset(&myInfo, 0, sizeof(GAMEHIGH_USERINFO));
- }
- CMainData::~CMainData()
- {
- }
- BOOL CMainData::Async_GameHigh_LoadRoomsFromServer(DWORD dwGameTypeID, LPGAMEHIGH_ROOM& roomArray, int& noutCount)
- {
- if(dwGameTypeID < 0)
- return FALSE;
- //服务器中提取房间列表
- roomArray =NULL;
- //test data
- if( 1 == dwGameTypeID)
- {
- noutCount =3;
- roomArray =new GAMEHIGH_ROOM[noutCount];
- SAFE_CHECKPOINTER(roomArray)
- {
- memset(roomArray, 0, sizeof(GAMEHIGH_ROOM) * noutCount);
- strcpy(roomArray[0].RoomName, "越南战争");
- roomArray[0].uRoomID =0;
- strcpy(roomArray[1].RoomName, "朝鲜战场");
- roomArray[0].uRoomID =1;
- strcpy(roomArray[2].RoomName, "击沉日本岛");
- roomArray[0].uRoomID =2;
- }
- }
- return TRUE;
- }
- BOOL CMainData::Async_GameHigh_LoadTableFromRoom(DWORD dwRoomID, LPGAMEHIGH_TABLE& lpTabArray, int& nCount)
- {
- //提取桌子列表
- nCount =0;
- if(NULL != lpTabArray)
- {
- ASSERT(NULL);
- }
- lpTabArray =NULL;
- //test code
- if(2 == dwRoomID)
- {
- nCount =MAX_TABLE;
- lpTabArray =new GAMEHIGH_TABLE[nCount];
- memset(lpTabArray, 0, sizeof(GAMEHIGH_TABLE) * nCount);
- for(int i=0; i < nCount; i++)
- {
- strcpy(lpTabArray[i].Initiator, "");
- lpTabArray[i].tableID =i;
- }
- //-----------------------测试数据
- //定义第一张桌子为测试对象
- ::strcpy(lpTabArray[0].Initiator, "ghost");
- ::strcpy(lpTabArray[0].userStatus[0].userID, "ghost");
- ::strcpy(lpTabArray[0].userStatus[0].userName, "阿鬼");
- ::strcpy(lpTabArray[0].userStatus[1].userID, "Wu");
- ::strcpy(lpTabArray[0].userStatus[1].userName, "小吴");
- ::strcpy(lpTabArray[0].userStatus[2].userID, "knight");
- ::strcpy(lpTabArray[0].userStatus[2].userName, "骑士");
- }
- /*
- memset(tableData, 0, sizeof(GAMEHIGH_TABLE) * MAX_TABLE);
- //清空原有的桌子列表
- if(2 == dwRoomID)
- {
- //模拟数据,仅为测试用
- for(UINT i=0; i < MAX_TABLE; i++)
- {
- strcpy(tableData[i].Initiator, "");
- tableData[i].tableID =i;
- memset(&(tableData[i].userStatus), 0, sizeof(GAMEHIGH_USERSTATUS));
- }
- //-----------------------测试数据
- //定义第一张桌子为测试对象
- ::strcpy(tableData[0].Initiator, "ghost");
- ::strcpy(tableData[0].userStatus[0].userID, "ghost");
- ::strcpy(tableData[0].userStatus[0].userName, "阿鬼");
- ::strcpy(tableData[0].userStatus[1].userID, "Wu");
- ::strcpy(tableData[0].userStatus[1].userName, "小吴");
- ::strcpy(tableData[0].userStatus[2].userID, "knight");
- ::strcpy(tableData[0].userStatus[2].userName, "骑士");
- }
- */
- return TRUE;
- }
- LPCTSTR CMainData::Attrib_GetMyID()
- {
- return strUserID;
- }
- USERSTATUS CMainData::Attrib_GetMyStatus()
- {
- return myStatus;
- }
- LPGAMEHIGH_USERINFO CMainData::Attrib_GetMyInfo()
- {
- return &myInfo;
- }
- LPGAMEHIGH_TABLE CMainData::Attrib_GetMyTable()
- {
- return lpMyTable;
- }
- void CMainData::Attrib_SetMyTable(LPGAMEHIGH_TABLE lpTable)
- {
- ASSERT(lpTable);
- if(NULL != lpTable)
- {
- lpMyTable =lpTable;
- }
- }
- BOOL CMainData::Async_GameHigh_Login(LPCTSTR lpszUser, LPCTSTR lpszPass)
- {
- ASSERT(lpszUser);
- ASSERT(lpszPass);
- if(NULL == lpszUser ||
- NULL == lpszPass ||
- 0 != strlen(lpszUser) ||
- 0 != strlen(lpszPass))
- {
- strUserID =lpszUser;
- }
- return TRUE;
- }
- void CMainData::Implemen_StandUp(LPGAMEHIGH_TABLE lptab)
- {
- ASSERT(lptab);
- if(NULL == lptab)
- return ;
- for(int i=0; i<MAX_TABCONTAIN; i++)
- {
- if(0 == strUserID.Compare(lptab->userStatus[i].userID))
- { //找到了自已
- lptab->userStatus[i].status =IDLESSE;
- memset(lptab->userStatus[i].userID, 0, sizeof(char) * MAX_USERID_LENGTH);
- memset(lptab->userStatus[i].userName, 0, sizeof(char) * MAX_USERNAME_LENGTH);
- }
- }
- }
- int CMainData::Attrib_GetMyPos()
- {
- SAFE_CHECKPOINTER(lpMyTable)
- {
- for(int i=0; i<MAX_TABCONTAIN; i++)
- {
- if(0 == strUserID.Compare(lpMyTable->userStatus[i].userID))
- {
- return i;
- }
- }
- }
- return -1;
- }