コード例 #1
0
ファイル: PC2PC.C プロジェクト: mostwanteddtm/MicroSO
int chatting()
{
    char msg[80],msg_in[80];
    int status,out,in,count=0,count_in=0,i,extra;

    bioscom(0, SETTINGS, COM1); //init. port
    //alternative to outportb(),perticularly for rs 232 communication.

    window(3,23,80,23);         //message entry window
    while (1)
    {
      status = bioscom(3, 0, COM1);

      if (status & DATA_READY)
      {
	 if ((out = bioscom(2, 0, COM1) & 0x7F) != 0)// input message byte.
	    msg_in[count_in++]=out;
	 if(out==13)
	 {
	    dsply(msg_in,10);
	    count_in=0;
	    gotoxy(count+1,1);
	 }
      }

      if (kbhit())   //character entered
      {
	gotoxy(count+1,1);
	if ((in = getche()) == 27)
	   break;
	if(in==0)
	{
	   in= getch();  //special function key pressed, ignore
	   continue;
	}
	if(in==8 && count>0) { count-=2;cprintf(" \b");}     //BackSpace
	else msg[count]=in;
	if(count==70) {in=13; msg[70]=13;}

	count++;

	if(in==13 ) //Enter: Send
	{
	  i=0;
	  dsply(msg,14);
	  for(i=0;i<count;i++)
	  {
	     bioscom(1, msg[i], COM1);
	  }

	  clrscr();
	  count=0;
	}
     }
   }

    return 1;
}
コード例 #2
0
ファイル: main.c プロジェクト: WangSiyao/OS_Design
void chess(int fd_stdin,int fd_stdout)
{
    dsply();

    printf("Please choose players model 1 or computer model 2 :");
    //int player;
    //scanf("%d", &player);

		char player[80]={0};
		int r = read(fd_stdin, player, 80);
		player[r] = 0;
    
           
    do{
        input(fd_stdin,fd_stdout);
        
        if(player[0] == '1') input2(fd_stdin,fd_stdout);
        else if (player[0] == '2') judge();
        else{
            printf("Sorry! You input wrong number,Please type in again!");
            continue;
        }
        if(chkWin() == WIN) break;
        if(chkWin() == UNWIN) break;
        if(stepFlg == 5 && chkPeace() == PEACE){
            printf("Peace!");
            return 0;
        }
    }while(1);
    
    if(chkWin() == WIN)
        printf("二号玩家胜利! ");
    if(chkWin() == UNWIN)
        printf("一号玩家胜利! ");
    return 0;
}
コード例 #3
0
ファイル: main.c プロジェクト: WangSiyao/OS_Design
void input2(int fd_stdin,int fd_stdout)
{
    //int row2,col2;

    char buf[80]={0};
    char buf2[80]={0};
		
   do{
        printf("行号: ");
        int r = read(fd_stdin, buf, 80);
		buf[r] = 0;
        if(enterChsman2((int)buf - 1, (int)buf2 - 1) == 1){
            printl("2号放在了 [%d][%d].\n", (int)buf, (int)buf2);
//            chsman[row2-1][col2-1] = P2;
            dsply();
            
            break;
        }
        else
            printf("Sorry! You input wrong number!!\n");
    }while(1);
    return;
    
}
コード例 #4
0
ファイル: main.c プロジェクト: WangSiyao/OS_Design
//系统自动判断并输入函数
void judge(void)
{
    int row, col;
    int i;

    int rskAndAtkLevlRow[SIZE] = {0}, rskAndAtkLevlCol[SIZE] = {0}, rskAndAtkLevlSlsh[2] = {0};

    stepFlg++;  //纪录是第几步了

    for(row = 0; row < SIZE; row++){
        for(col = 0; col < SIZE; col++){
            rskAndAtkLevlRow[row] += chsman[row][col];
        }
    }
    for(col = 0; col < SIZE; col++){
        for(row = 0; row < SIZE; row++){
            rskAndAtkLevlCol[col] += chsman[row][col];
        }
    }
    rskAndAtkLevlSlsh[0] = chsman[0][0] + chsman[1][1] + chsman[2][2];
    rskAndAtkLevlSlsh[1] = chsman[0][2] + chsman[1][1] + chsman[2][0];

    for(i = 0; i < SIZE; i++){
        if(rskAndAtkLevlRow[i] == -2){
            chkAndPutDwnRow(i, col)
        }
    }

    for(i = 0; i< SIZE; i++){
        if(rskAndAtkLevlCol[i] == -2){
            chkAndPutDwnCol(i, col)
        }
    }

    if(rskAndAtkLevlSlsh[0] == -2){
        for(row = 0, col = 0; row < SIZE; row++, col++){
            chkAndPutDwn_Slsh(row, col)
        }
    }

    if(rskAndAtkLevlSlsh[1] == -2){
        for(row = 0, col = 2; row < SIZE; row++, col--){
            chkAndPutDwn_Slsh(row, col)
        }
    }


    for(i = 0; i < SIZE; i++){
        if(rskAndAtkLevlRow[i] == 2){
            chkAndPutDwnRow(i, col)
        }
    }

    for(i = 0; i< SIZE; i++){
        if(rskAndAtkLevlCol[i] == 2){
            chkAndPutDwnCol(i, col)
        }
    }

    if(rskAndAtkLevlSlsh[0] == 2){
        for(row = 0, col = 0; row < SIZE; row++, col++){
            chkAndPutDwn_Slsh(row, col)
        }
    }

    if(rskAndAtkLevlSlsh[1] == 2){
        for(row = 0, col = 2; row < SIZE; row++, col--){
            chkAndPutDwn_Slsh(row, col)
        }
    }

    for(row = 0; row < SIZE; row++){
        for(col = 0; col < SIZE; col++){
            if(chsman[row][col] == 0 && ((row == 0 && col == 0) || (row == 0 && col == 2) ||
                                         (row == 2 && col == 0) || (row == 2 && col == 2))){
                chsman[row][col] = P2;
                dsply();
                return;
            }
        }
    }
}
コード例 #5
0
ファイル: main.c プロジェクト: WangSiyao/OS_Design
//用户输入
void input(int fd_stdin,int fd_stdout)
{
    char buf[80]={0};
    int row = 0;
    int col = 0;
    do{
        printf("Please put in the location you wanted:\n");
       
		int r = read(fd_stdin, buf, 80);
		buf[r] = 0;
        //scanf("%d", &row);
       
        //scanf("%d", &col);

	if(buf[0] == '1'){
		row = 2;
 		col = 0;
	}
	if(buf[0] == '2'){
		row = 2;
 		col = 1;
	}
	if(buf[0] == '3'){
		row = 2;
 		col = 2;
	}
	if(buf[0] == '4'){
		row = 1;
 		col = 0;
	}
	if(buf[0] == '5'){
		row = 1;
 		col = 1;
	}
	if(buf[0] == '6'){
		row = 1;
 		col = 2;
	}
	if(buf[0] == '7'){
		row = 0;
 		col = 0;
	}
	if(buf[0] == '8'){
		row = 0;
 		col = 1;
	}
	if(buf[0] == '9'){
		row = 0;
 		col = 2;
	}
	if(buf[0] == '1'){
		row = 2;
 		col = 0;
	}


        if(enterChsman(row, col) == 1){
            printf("You put on [%d][%d].\n", row, col);
            dsply();
            break;
        }
        else
            printf("Sorry! You input wrong number!\n");
    }while(1);
    return;
}