コード例 #1
0
ファイル: net.c プロジェクト: johan--/netnuclear
void close_server() {
   while (socket_list)
      remove_socket(socket_list);

   online = 0;
   server = 0;
   init_door();
   if (screen == GAME_SCREEN_WORLD)
      init_telegraph();
   init_game(0);
}
コード例 #2
0
ファイル: net.c プロジェクト: johan--/netnuclear
/* disconnect from the server (if client) */
void server_disconnect() {
   struct socket_node *p;

   if (online && !server) {
      p = socket_list;
      while (p->type != SOCKET_SERVER)
         p = p->next;

      remove_socket(p);
      online = 0;
      init_door();
      if (screen == GAME_SCREEN_WORLD)
         init_telegraph();
      init_game(0);
   }
}
コード例 #3
0
int main() {
  int door[3];
  int user_select_door = 0;

  int door_change = 0;
  int door_proceed = 0;

  srand ( time(NULL) ); // initialize random seed

  for ( int i = 0 ; i < REPETITION ; i++) {

    // init door
    init_door(door);
    door[get_random_1_to_n(3) - 1] = 1;

    // init user_select_door
    user_select_door = get_random_1_to_n(3);

    // 여기서 우리는 두 가지 가능성이 있다.
    // 여기서 사용자가 고른 문에는
    //    - 1. 자동차가 있는 경우
    //    - 2. 염소가 있는 경우

    // 1. 처음 선택한 문에 자동차가 있는 경우
    if ( door[user_select_door - 1] == 1) {
      // 사회자는 아무 문이나 연다. ( p = 1 )

      // 문을 바꾸면 패배한다.
      // 문을 바꾸지 않으면 승리한다.
      door_change += 0;
      door_proceed += 1;
    }

    else {
      // 사회자는 아무 문이나 연다. ( p = 1 )

      // 문을 바꾸면 승리할 수도 있고 패배할 수도 있다.
      // 문을 바꾸지 않으면 패배한다.
      door_change += get_random_1_to_n(2) - 1;
      door_proceed += 0;
    }
  }

  printf("선택 변경 시 맞추는 경우 = %lf\n", (double)door_change/REPETITION);
  printf("선택 유지 시 맞추는 경우 = %lf\n", (double)door_proceed/REPETITION);
  return 0;
}
コード例 #4
0
ファイル: main.c プロジェクト: E314c/DesExProject
//MAIN function
void main (void)
{
	/*Variable Declaration*/
	char pass[PASS_LENGTH], x; 	//pass is the pass entered. 'x' stores temp data
	int loop; 					//variable for loops
	char attempts, entered;		//amount of passcode attempts. amount of data entered (when entering passcode)
	
	/*Setup*/
	{
	DisplayInit();
	settim0 ();
	init_scan();
	init_door();
		/*This section may cause issues on DEV board as it's not configured to hold P1.4 low during normal operation*/
		P1M1|=0x10;
		P1M2&=0xEF; //sets P1.4 to '10'(input mode)
		if((P1&0x10)==0x10) //if P1.4 is held high (Hardware override to wipe eeprom)
		{
			eeprom_clear(0);
			Write("done");
			while(1); //infinite loop, Hardware must be reset again.
		}
		//*************************************************************************************************************/
		
	for(loop=0;loop<PASS_LENGTH;++loop)
	{
		pass[loop]=PASS_NULL; //sets the passcode to PASS_NULL
	}
	entered=0;
	attempts=0;
	Write("init");
	//Should I shut the door here? Spec doesn't Spec and I would assume so.
	}
	
	
	//infinite loop begins
	while(1)
	{
		/*--idling state.--*/
		
		x=passcode_entering(pass,30);	//store data to pass, 30seconds till idle
		
		if(x==KEY_ENTER)	//enter has been pressed.
		{
			while(scan()==1)
			key_flag=0;
			//code check portion
			if (code_check(pass)==1)
			{
				
				//passcode is correct
				//enter open routine
				door_routine();
				//should include passcode change section.
				
				
				//clear passcode, ready for idling
				for(loop=0;loop<PASS_LENGTH;++loop)
				{
					pass[loop]=PASS_NULL; 			//clears stored passcode
				}
				entered=0;
				attempts=0;
				Write("shut");
			}
			else 
			{
				//passcode incorrect
				++attempts;
				if(attempts>=3) //third fail will lock door down
				{
					Write("Bar ");
					
					for(clock=0;clock<(120*clock_freq);) 
						{/*enter three minute loop*/}
					
					attempts=0;	//reset attempts to 0
				}
				for(loop=0;loop<PASS_LENGTH;++loop)
				{
					pass[loop]=PASS_NULL; //clears stored passcode
				}
				Write("shut");
			}
		}//end of 'if(x==KEY_ENTER)'
		
		//clears stored passcode
		for(loop=0;loop<PASS_LENGTH;++loop)
		{
			pass[loop]=PASS_NULL; 
		}
		Write("shut");
		
		if(x==0) //display
			{
				attempts=0; //clears attempts if passcode entering times out
			}
		
	}
	//end of while(1) loop

	/*Error catching Area*/
	Write("Err1");
	while(1);
	/*********************/
}