示例#1
0
DWORD WINAPI userInterfaceThread(LPVOID pM)
{
	while (main_state != 6)
	{
		system("cls");
		printMsg();
		switch (main_state)
		{
			case ROUND_START:
				printUI();
				Sleep(100);
				while(main_state != PLAY_CARD);
				break;
		
			case PLAY_CARD:
				printUI();
				Sleep(1000);
				
				WaitForSingleObject(inputMutex, INFINITE);
				break;

			case SETTLE:
				printf("玩家 %d 打出了 %s.\n", game_state.player, cardToStr(card));
				while (main_state != ROUND_END) 
				{
					Sleep(100);
				}
				// printf("下面回合结束。");
				break;

			case ROUND_END:
				Sleep(10);
				while (main_state == ROUND_END);
				printf("本回合结束,下面由 %d 玩家出牌。", game_state.player);
				Sleep(1000);
				break;

			case GAME_END:
				Sleep(10);
				printf("\n玩家 %d 赢得了本局比赛。\n", game_state.player);
				main_state = 6;
				break;
		}
	}

	return 0;
}
示例#2
0
main()
{
	
	/* variable: studentList    -> curr list
	 *           student        -> as a tmp variable to save curr info
	 *           commands       -> combine command you want to exe
	 *           id             -> analyze id of student in cmd
	 *           name           -> analyze name of student in cmd
	 *           cmd            -> analyze sub command in commande,split with  
	 *           flags          -> analyze command
	 */
	tLinkList studentList;
	tStudent student;
	char commands[1000],id[10],name[20], *cmd,flag;
	int pos;

	/* init list with my self define function then print program UI*/
	initLinkList(&studentList,dataCmp,handle);
	printUI();

	/* loop to deal with commands*/
	while(TRUE)
	{
		scanf("%s",commands);
		cmd=strtok(commands," ");
		/* loop to deal with command, split with  */
		do
		{
			/*analyze curr command to get id and name*/
			flag=cmd[0];
			if(strchr(cmd,',') !=NULL)
			{
					pos=strchr(cmd,',')-cmd;
					strncpy(id,cmd+2,pos-1);
					id[pos-2]='\0';
					strcpy(name,cmd+pos+1);
					name[strlen(name)-1]='\0';
					student.id = atoi(id);
					strcpy(student.name,name);
			}
			else
			{
					strcpy(id,cmd+2);
					id[strlen(id)-1]='\0';
					student.id = atoi(id);				
			}

			/* both upper and lower can be executed*/
			switch(toupper(flag))
			{
				case 'I' :
					insertData(&studentList,&student,sizeof(tStudent));
					break;
				case 'D' :
					if(deleteData(&studentList,&student)==SUCCESS)
						printf("%s deletes successfully!\n",id);
					else
						printf("%s not exists in the list!\n",id);
					break;				
				case 'U' :
					updateData(&studentList,&student,&student.id,sizeof(tStudent));
					break;				
				case 'Q' :
					/* query and print the data*/
					handle(queryData(&studentList,&student.id));
					break;				
				case 'P' :
					iterativeLinkList(&studentList);
					break;
				case 'C' :
					system("cls");
					printUI();
					break;
				case 'E' :
					exit(0);
					break;
				default:
					printf("command error ,please try again !\n");
			}
			cmd=strtok(NULL," ");
		}while(cmd != NULL);
	}
	system("pause");
}