void kos_Main()
{
	Dword frame_start, frame_end;
	OnStart();
	Menu();
	for (;;)
	{
		frame_start = kos_GetTime();
		switch (kos_CheckForEvent())
		{
		case 1:
			DrawWindow();
			break;
		case 2:	// key pressed, read it and ignore
			Byte keyCode;
			kos_GetKey(keyCode);
			if (keyCode == 27)
			{
				OnExit();
			}
			break;
		case 3: // button pressed; we have only one button, close
			OnExit();
			break;
		case 6: // событие от мыши (нажатие на кнопку мыши или перемещение; сбрасывается при прочтении) 
			OnMouseMove();
			if (ms.lbclick == 1)
			{
				OnLMBClick();
			}
			break;
		default:
			OnMouseMove();
			break;
		}
		DrawBombs();
		DrawRocketsAndCrosses();
		DrawExplodes();
		frame_end = kos_GetTime();
		if (frame_end - frame_start < FRAME_TIME)
		{
			kos_Pause(FRAME_TIME - (frame_end - frame_start));
		}
		if (health <= 0)
		{
			OnExit();
		}
	}
}
Esempio n. 2
0
void process_key()
{
	Dword mouse_btn, ckeys, shift, ctrl;
	int mouse_x, mouse_y, dx = 0, dy = 0;

	// key pressed, read it 
	Byte keyCode;
	ckeys = kos_GetSpecialKeyState();
	shift = ckeys & 0x3;
	ctrl = ckeys & 0x0c;
	//if (ctrl)
	//	rtlDebugOutString("control pressed!");
	dx = 0, dy = 0;
	sel_moved = 0;
	sel_end_move = 0;
	kos_GetKey(keyCode);

	__asm
	{
		mov ah, keyCode
	}
	edit_box_key((dword)&cell_box);
	edit_box_key((dword)&file_box);


	switch (keyCode)
	{
		case 178:			// стрелки
			//dx = 0;
			dy = -1;
			break;
		case 176:
			dx = -1;
			//dy = 0;
			break;
		case 179:
			dx = 1;
			//dy = 0;
			break;
		case 177:
			//dx = 0;
			dy = 1;
			break;
		/*
		case 183:
			if (sel_y < row_count-(ny - scroll_y))	// page down
				dy = ny - scroll_y;
			else
				dy = row_count-(ny - scroll_y) - sel_y;
			dx = 0;
			redraw = 1;
			break;
		case 184:
			if (sel_y > ny - scroll_y)		// page up
				dy= - (ny - scroll_y);
			else
				dy = - (ny - scroll_y) + sel_y;
			dx = 0;
			redraw = 1;
			break;
		*/
		case 180: //home
			dx = -sel_x + 1;
			dy = 0;
			draw_grid(); //draw_window(); 
			break;
		case 181: //end
			dx = col_count - (nx - scroll_x) - 1 - sel_x;
			dy = 0;
			draw_grid(); //draw_window();
			break;
		case 27:		// escape
			cancel_edit();
			break;
		case 182:			// delete
			{
				int i,j,n0,n1,k0,k1;
				n0 = min(sel_x, sel_end_x);
				n1 = max(sel_x, sel_end_x);
				k0 = min(sel_y, sel_end_y);
				k1 = max(sel_y, sel_end_y);

				for (i = n0; i <= n1; i++)
					for (j = k0; j <= k1; j++)
					{
						if (cells[i][j])
						{
							freemem(cells[i][j]);
							cells[i][j] = NULL;
						}
					}
				calculate_values();
				draw_grid();
				break;
			}
		case 0x0D:			// enter
			if (is_edit)
			{
				stop_edit();
				draw_window();
			}
			break;
		case 22:	// contol-v
			{
				if (ctrl)
				{
					//rtlDebugOutString("control-v!");
					int i, j, x0, y0;
					x0 = min(sel_x, sel_end_x);
					y0 = min(sel_y, sel_end_y);
					int delta_x = x0 - buf_old_x;
					int delta_y = y0 - buf_old_y;

					for (i = 0; i < buf_col; i++)
						for (j = 0; j < buf_row; j++)
						{
							if (i + x0 >= col_count || j + y0 >= row_count)
								continue;
							if (cells[i + x0][j + y0])
								freemem(cells[i + x0][j + y0]);
							if (buffer[i][j])
							{
								cf_x0 = buf_old_x; cf_y0 = buf_old_y;
								cf_x1 = buf_old_x + buf_col;
								cf_y1 = buf_old_y + buf_row;
								cells[i + x0][j + y0] = change_formula(buffer[i][j], delta_x, delta_y);
								//cells[i + x0][j + y0] = (char*)allocmem(strlen(buffer[i][j]));
								//strcpy(cells[i + x0][j + y0], buffer[i][j]);
							}
							else
								cells[i + x0][j + y0] = NULL;
						}

					calculate_values();
					draw_window();
					break;
				}
			}
			case 24:	// control-x
			case 03:	// control-c
			{
				if (ctrl)
				{
					//rtlDebugOutString("control-c!");
					int i, j, x0, y0;

					freeBuffer();

					buf_col = abs(sel_end_x - sel_x) + 1;
					buf_row = abs(sel_end_y - sel_y) + 1;
					x0 = min(sel_x, sel_end_x);
					y0 = min(sel_y, sel_end_y);
					buf_old_x = x0;
					buf_old_y = y0;

					//sprintf(debuf, "%U %U %U %U", buf_col, buf_row, x0, y0);
					//rtlDebugOutString(debuf);
				
					buffer = (char***)allocmem(buf_col * sizeof(char**));
					for (i = 0; i < buf_col; i++)
					{
						buffer[i] = (char**)allocmem(buf_row * sizeof(char*));
						for (j = 0; j < buf_row; j++)
						{
							if (cells[i + x0][j + y0])
							{
								if (keyCode == 03)	// ctrl-c
								{
									buffer[i][j] = (char*)allocmem(strlen(cells[i + x0][j + y0]));
									strcpy(buffer[i][j], cells[i + x0][j + y0]);
								}
								else
								{
									buffer[i][j] = cells[i + x0][j + y0];
									cells[i + x0][j + y0] = NULL;
								}
							}
							else
								buffer[i][j] = NULL;
						}
					}
					if (keyCode == 24) 
						calculate_values();
					draw_window();
					break;
				}
			}
		case 06:		// control-f
			{
				display_formulas = !display_formulas;
				draw_grid(); //draw_window();
				break;
			}
		default:
			
			if (!is_edit && !(file_box.flags & ed_focus))
			{
				start_edit(sel_x, sel_y);
				if (keyCode == 8)
				{
					cell_box.pos = strlen(edit_text);
				}
				else
				{
					__asm
					{
						mov ah, keyCode
					}
					edit_box_key((dword)&cell_box);
				}
			}
			if (is_edit)
				edit_box_draw((dword)&cell_box);
			break;
	}
	if (dx != 0)
	{
		if (shift)
		{
			sel_end_x += dx;
			if (sel_end_x <= 1)
				sel_end_x = 1;
			else if (sel_end_x >= col_count)
				sel_end_x = col_count - 1;
		//	sprintf(debuf,"sel end x change. sel end %U %U",sel_end_x,sel_end_y);
		//	rtlDebugOutString(debuf);
			sel_moved = sel_end_move = 1;
			//stop_edit();
			//draw_grid();
		}
		else
		{
		}
	}
	if (dy != 0)
	{
		if (shift)
		{
			sel_end_y += dy;
			if (sel_end_y <= 1)
				sel_end_y = 1;
			else if (sel_end_y >= row_count)
				sel_end_y = row_count - 1;
		//	sprintf(debuf,"sel end y change. sel end %U %U",sel_end_x,sel_end_y);
		//	rtlDebugOutString(debuf);
			sel_moved = sel_end_move = 1;
			//stop_edit();
			//draw_grid();
		}
	}
	/*
	if (sel_end_x < sel_x)
	{
		Dword tmp = sel_end_x; sel_end_x = sel_x; sel_x = tmp;
	}
	if (sel_end_y < sel_y)
	{
		Dword tmp = sel_end_y; sel_end_y = sel_y; sel_y = tmp;
	}
	*/
	if ((dx || dy))
	{
		if (!shift)
		{
			if ((sel_end_x + dx) >= (col_count-1)) {dx=0;} //заглушка
			else if ((sel_end_y + dy) >= (row_count-1)) {dy=0;}
			else {
			move_sel(sel_x + dx, sel_y + dy);
			}
		}
		else
		{
			sel_moved = 0;
			stop_edit();
			draw_grid();
		}
	}
}
Esempio n. 3
0
int MainWndLoop()
{
	Byte keyCode;
	Dword buttonID;
	int result;
	static bool firstTime = true;

	//
	startGameLevel = maxGameLevel;
	//
	if ( firstTime )
	{
		//
		mainWndFace.GetSize( mcx, mcy );
		//
		firstTime = false;
		//
		DrawMainWindow();
	}
	//
	kos_ChangeWindow( -1, -1, mcx + 1, mcy + 21 );
	//
	for ( result = MW_NONE; result == MW_NONE; )
	{
		switch( kos_WaitForEvent() )
		{
		case 1:
			DrawMainWindow();
			break;

		case 2:
			if ( kos_GetKey( keyCode ) )
			{
				//
				switch ( keyCode )
				{
				case 13:					// enter
					result = MW_START_GAME;
					break;

				case 27:					// escape
					result = MW_EXIT_APP;
					break;

				default:
					break;
				}
			}
			break;

		case 3:
			if ( kos_GetButtonID( buttonID ) )
			{
				//
				switch ( buttonID )
				{
				//
				case 1:
					result = MW_EXIT_APP;
					break;
				case BT_SIZE_X_MINUS:
					if ( --startGameLevel < 1 )
						startGameLevel = 1;
					else
						DrawMainWindow();
					break;

				//
				case BT_SIZE_X_PLUS:
					if ( ++startGameLevel > maxGameLevel )
						startGameLevel = maxGameLevel;
					else
						DrawMainWindow();
					break;

				//
				default:
					break;
				}
			}

		default:
			break;
		}
	}
	// кнопки
	kos_DefineButton(
		0, 0,
		0, 0,
		BT_SIZE_X_MINUS + 0x80000000,
		0
		);
	//
	kos_DefineButton(
		0, 0,
		0, 0,
		BT_SIZE_X_PLUS + 0x80000000,
		0
		);
	//
	return result;
}
Esempio n. 4
0
void kos_Main(){
	rtlSrand(kos_GetSystemClock() / 10000);
	kos_InitHeap();
	getFilePathName();
	prepareFileData();
	draw_window();
	while (true){

		switch (kos_WaitForEvent()){
		case 1:
			draw_window();
			break;
		case 2:
			Byte keyCode;
			kos_GetKey(keyCode);

			if (status==0){ //Меню
				if (keyCode==27){
					app_halt();
				}
				if (keyCode==13){
					currentquestion=1;
					status=1;
					loadquestion();
					////// ПОМЕНЯТЬ МЕСТАМИ!!!!!!! /////////
					draw_window();

				}
			}
			if (status==1){ //Игра

			if (keyCode==8){
				status=6;
				draw_window();
			}

			if (drawA==true){
			if ((keyCode==49)||(keyCode==97)||(keyCode==65)){
					if (correctanswer==0x01){
						status=2;
					}
					else
					{
						status=-1;
					}
					drawA = true;
					drawB = true;
					drawC = true;
					drawD = true;
					
					draw_window();
			}
			}

			if (drawB==true){
			if ((keyCode==50)||(keyCode==98)||(keyCode==66)){
					if (correctanswer==0x02){
						status=2;
					}
					else
					{
						status=-1;
					}
					drawA = true;
					drawB = true;
					drawC = true;
					drawD = true;
					
					draw_window();					
				}
			}
			if (drawC==true){
			if ((keyCode==51)||(keyCode==99)||(keyCode==67)){
					if (correctanswer==0x03){
						status=2;
					}
					else
					{
						status=-1;
					}
					drawA = true;
					drawB = true;
					drawC = true;
					drawD = true;
					
					draw_window();					
				}
			}
			if (drawD==true){
			if ((keyCode==52)||(keyCode==100)||(keyCode==68)){
					if (correctanswer==0x04){
						status=2;
					}
					else
					{
						status=-1;
					}
					drawA = true;
					drawB = true;
					drawC = true;
					drawD = true;
					
					draw_window();
			}
			}
			
			if (callfriendavailable==true){ //Реализация подсказки "Звонок другу"
				if (keyCode==56){
					callfriendavailable=false;
					status=4;
					call_friend();
					draw_window();
				}
			}

			if (zalavailable==true){ //Реализация подсказки зала
				if (keyCode==57){
					zalavailable=false;
					status=5;
					call_zal();
					draw_window();
				}
			}

			if (na50available==true){ //Реализация подсказки "50 на 50"
			if (keyCode==55){
				
				if (correctanswer==0x01){
					drawA=true;

						int tmpcodee;
						
						recode1:
						tmpcodee =(rtlRand()%3)+1; 
	
						int tmpbyte;
						
						switch(tmpcodee){
						case 1:
							drawB=true;
							drawC=false;
							drawD=false;
							break;
						case 2:
							drawB=false;
							drawC=true;
							drawD=false;
						case 3:
							drawB=false;
							drawC=false;
							drawD=true;
						
						}
				}
				if (correctanswer==0x02){
					drawB=true;

						int tmpcodee;
						
						recode2:
						tmpcodee =(rtlRand()%3)+1; 
	
						int tmpbyte;
					

						switch(tmpcodee){
						case 1:
							drawA=true;
							drawC=false;
							drawD=false;
							break;
						case 2:
							drawA=false;
							drawC=true;
							drawD=false;
						case 3:
							drawA=false;
							drawC=false;
							drawD=true;
						
						}
				}
				if (correctanswer==0x03){
					drawC=true;

						int tmpcodee;
						
						recode3:
						tmpcodee =(rtlRand()%3)+1; 
						int tmpbyte;
						

						switch(tmpcodee){
						case 1:
							drawB=true;
							drawA=false;
							drawD=false;
							break;
						case 2:
							drawB=false;
							drawA=true;
							drawD=false;
						case 3:
							drawB=false;
							drawA=false;
							drawD=true;
						
						}
				}
				if (correctanswer==0x04){
					drawA=true;

						int tmpcodee;
						
						recode4:
						tmpcodee =(rtlRand()%3)+1; 
						
						int tmpbyte;
						

						switch(tmpcodee){
						case 1:
							drawB=true;
							drawC=false;
							drawA=false;
							break;
						case 2:
							drawB=false;
							drawC=true;
							drawA=false;
						case 3:
							drawB=false;
							drawC=false;
							drawA=true;
						
						}
				}
				na50available=false;
				draw_window();

			}
			}

			}
			if (status==2){ //Окно "Это - правильный ответ!"
				if (keyCode==13){
					if (currentquestion<15){
						currentquestion++;
						status=1;
						loadquestion();
						draw_window();
					}
					else
					{
						status=3;
						draw_window();
					}

				}
			}
			if (status==3){ //Вы выиграли миллион
				if (keyCode==27){
					app_halt();
				}
			}
			if (status==4){ //Совет друга
				if (keyCode==13){
					status=1;
					draw_window();
				}
			}
			if (status==5){ //Подсказка зала
				if (keyCode==13){
					status=1;
					draw_window();
				}
			}
			if (status==6){ //Вы забрали деньги ;-)
				if (keyCode==27){
					app_halt();
				}
			}
			if (status==-1){ //Вы ошиблись :-(
				if (keyCode==27){
					app_halt();
				}
			}

			//kos_DrawBar(38,118,50,130,0xBBBBBB);
			//kos_DisplayNumberToWindow (keyCode,3,40,120,0x000000, nbDecimal, false);


			break;
		case 3:
			app_halt();
			break;
		}

	}
}