Разработка мобильного приложения детская развивающая игра. Теоретические основы разработки мобильных приложений
Скачать 2.75 Mb.
|
btnBaseColours = (Button) findViewById(R.id.btnBaseColours); btnColour1 = (Button) findViewById(R.id.btnColour1); btnColour2 = (Button) findViewById(R.id.btnColour2); btnColour3 = (Button) findViewById(R.id.btnColour3); btnColour4 = (Button) findViewById(R.id.btnColour4); btnColour5 = (Button) findViewById(R.id.btnColour5); btnColour6 = (Button) findViewById(R.id.btnColour6); btnColour7 = (Button) findViewById(R.id.btnColour7); btnColour8 = (Button) findViewById(R.id.btnColour8); btnColour9 = (Button) findViewById(R.id.btnColour9); btnColour10 = (Button) findViewById(R.id.btnColour10); btnColour11 = (Button) findViewById(R.id.btnColour11); btnColour12 = (Button) findViewById(R.id.btnColour12); btnColour13 = (Button) findViewById(R.id.btnColour13); btnColour14 = (Button) findViewById(R.id.btnColour14); btnColour15 = (Button) findViewById(R.id.btnColour15); btnColour16 = (Button) findViewById(R.id.btnColour16); btnColour17 = (Button) findViewById(R.id.btnColour17); btnColour18 = (Button) findViewById(R.id.btnColour18); btnColour19 = (Button) findViewById(R.id.btnColour19); btnColour20 = (Button) findViewById(R.id.btnColour20); btnColour21 = (Button) findViewById(R.id.btnColour21); tvResult = (TextView) findViewById(R.id.tvResult); fabNewGame = (FloatingActionButton) findViewById(R.id.fabNewGame); // Запуск новой игры fabNewGame.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Старт игры с первого уровня tvResult.setText(""); start= System.nanoTime(); currentLevel=1; gameLevel(currentLevel); } }); View.OnClickListener onClickListener = new View.OnClickListener() { @Override public void onClick(View view) { switch (view.getId()) { case R.id.btnColour1: if (eqColours(btnColour1) == true) { currentLevel++; gameLevel(currentLevel); } break; case R.id.btnColour2: if (eqColours(btnColour2) == true) { currentLevel++; gameLevel(currentLevel); } break; case R.id.btnColour3: if (eqColours(btnColour3) == true) { currentLevel++; gameLevel(currentLevel); } break; case R.id.btnColour4: if (eqColours(btnColour4) == true) { currentLevel++; gameLevel(currentLevel); } break; case R.id.btnColour5: if (eqColours(btnColour5) == true) { currentLevel++; gameLevel(currentLevel); } break; case R.id.btnColour6: if (eqColours(btnColour6) == true) { currentLevel++; gameLevel(currentLevel); } break; case R.id.btnColour7: if (eqColours(btnColour7) == true) { currentLevel++; gameLevel(currentLevel); } break; case R.id.btnColour8: if (eqColours(btnColour8) == true) { currentLevel++; gameLevel(currentLevel); } break; case R.id.btnColour9: if (eqColours(btnColour9) == true) { currentLevel++; gameLevel(currentLevel); } break; case R.id.btnColour10: if (eqColours(btnColour10) == true) { currentLevel++; gameLevel(currentLevel); } break; case R.id.btnColour11: if (eqColours(btnColour11) == true) { currentLevel++; gameLevel(currentLevel); } break; case R.id.btnColour12: if (eqColours(btnColour12) == true) { currentLevel++; gameLevel(currentLevel); } break; case R.id.btnColour13: if (eqColours(btnColour13) == true) { currentLevel++; gameLevel(currentLevel); } break; case R.id.btnColour14: if (eqColours(btnColour14) == true) { currentLevel++; gameLevel(currentLevel); } break; case R.id.btnColour15: if (eqColours(btnColour15) == true) { currentLevel++; gameLevel(currentLevel); } break; case R.id.btnColour16: if (eqColours(btnColour16) == true) { currentLevel++; gameLevel(currentLevel); } break; case R.id.btnColour17: if (eqColours(btnColour17) == true) { currentLevel++; gameLevel(currentLevel); } break; case R.id.btnColour18: if (eqColours(btnColour18) == true) { currentLevel++; gameLevel(currentLevel); } break; case R.id.btnColour19: if (eqColours(btnColour19) == true) { currentLevel++; gameLevel(currentLevel); } break; case R.id.btnColour20: if (eqColours(btnColour20) == true) { currentLevel++; gameLevel(currentLevel); } break; case R.id.btnColour21: if (eqColours(btnColour21) == true) { currentLevel++; gameLevel(currentLevel); } break; } } }; // Кнопкам присваивается слушатель (обработчик событий): btnBaseColours.setOnClickListener(onClickListener); btnColour1.setOnClickListener(onClickListener); btnColour2.setOnClickListener(onClickListener); btnColour3.setOnClickListener(onClickListener); btnColour4.setOnClickListener(onClickListener); btnColour5.setOnClickListener(onClickListener); btnColour6.setOnClickListener(onClickListener); btnColour7.setOnClickListener(onClickListener); btnColour8.setOnClickListener(onClickListener); btnColour9.setOnClickListener(onClickListener); btnColour10.setOnClickListener(onClickListener); btnColour11.setOnClickListener(onClickListener); btnColour12.setOnClickListener(onClickListener); btnColour13.setOnClickListener(onClickListener); btnColour14.setOnClickListener(onClickListener); btnColour15.setOnClickListener(onClickListener); btnColour16.setOnClickListener(onClickListener); btnColour17.setOnClickListener(onClickListener); btnColour18.setOnClickListener(onClickListener); btnColour19.setOnClickListener(onClickListener); btnColour20.setOnClickListener(onClickListener); btnColour21.setOnClickListener(onClickListener); // Старт игры с первого уровня tvResult.setText(""); start= System.nanoTime(); currentLevel=1; gameLevel(currentLevel); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // получим идентификатор выбранного пункта меню int id = item.getItemId(); // Операции для выбранного пункта меню switch (id) { case R.id.action_newgame: tvResult.setText(""); start= System.nanoTime(); currentLevel=1; gameLevel(currentLevel); return true; // Кнопка Home case android.R.id.home: stopService(new Intent(this, MyService.class)); onBackPressed(); default: return super.onOptionsItemSelected(item); } } } } } public class CountingActivity extends AppCompatActivity { FloatingActionButton fabNewGame; ImageButton figure1; ImageButton figure2; ImageButton figure3; ImageButton figure4; ImageButton figure5; ImageButton figure6; ImageButton figure7; ImageButton figure8; ImageButton figure9; ImageButton figure10; ImageButton btn1; ImageButton btn2; ImageButton btn3; ImageButton btn4; ImageButton btn5; ImageButton btn6; ImageButton btn7; ImageButton btn8; ImageButton btn9; ImageButton btn10; int x; // Число яблок (генерируется случайным образом) private void sbros(){ // Сброс в первоначальное состояние (новое задание) // Прячем все figure1.setVisibility(View.INVISIBLE); figure2.setVisibility(View.INVISIBLE); figure3.setVisibility(View.INVISIBLE); figure4.setVisibility(View.INVISIBLE); figure5.setVisibility(View.INVISIBLE); figure6.setVisibility(View.INVISIBLE); figure7.setVisibility(View.INVISIBLE); figure8.setVisibility(View.INVISIBLE); figure9.setVisibility(View.INVISIBLE); figure10.setVisibility(View.INVISIBLE); Random rand = new Random(); x = rand.nextInt(10) + 1; if (x >= 1) { figure1.setVisibility(View.VISIBLE); if (x >= 2) { figure2.setVisibility(View.VISIBLE); if (x >= 3) { figure3.setVisibility(View.VISIBLE); if (x >= 4) { figure4.setVisibility(View.VISIBLE); if (x >= 5) { figure5.setVisibility(View.VISIBLE); if (x >= 6) { figure6.setVisibility(View.VISIBLE); if (x >= 7) { figure7.setVisibility(View.VISIBLE); if (x >= 8) { figure8.setVisibility(View.VISIBLE); if (x >= 9) { figure9.setVisibility(View.VISIBLE); if (x >= 10) { figure10.setVisibility(View.VISIBLE); } } } } } } } } } } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_counting); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); startService(new Intent(this, MyService.class)); // Кнопка Home ActionBar actionBar = getSupportActionBar(); actionBar.setHomeButtonEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); // Общий для всего проекта класс(всплывающтие ссобщения, диалоги и пр.) final Shared shared = new Shared(this); figure1 = (ImageButton) findViewById(R.id.figure1); figure2 = (ImageButton) findViewById(R.id.figure2); figure3 = (ImageButton) findViewById(R.id.figure3); figure4 = (ImageButton) findViewById(R.id.figure4); figure5 = (ImageButton) findViewById(R.id.figure5); figure6 = (ImageButton) findViewById(R.id.figure6); figure7 = (ImageButton) findViewById(R.id.figure7); figure8 = (ImageButton) findViewById(R.id.figure8); figure9 = (ImageButton) findViewById(R.id.figure9); figure10 = (ImageButton) findViewById(R.id.figure10); btn1 = (ImageButton) findViewById(R.id.btn1); btn2 = (ImageButton) findViewById(R.id.btn2); btn3 = (ImageButton) findViewById(R.id.btn3); btn4 = (ImageButton) findViewById(R.id.btn4); btn5 = (ImageButton) findViewById(R.id.btn5); btn6 = (ImageButton) findViewById(R.id.btn6); btn7 = (ImageButton) findViewById(R.id.btn7); btn8 = (ImageButton) findViewById(R.id.btn8); btn9 = (ImageButton) findViewById(R.id.btn9); btn10 = (ImageButton) findViewById(R.id.btn10); fabNewGame = (FloatingActionButton) findViewById(R.id.fabNewGame); View.OnClickListener onClickListener = new View.OnClickListener() { @Override public void onClick(View view) { switch (view.getId()) { case R.id.fabNewGame: sbros(); break; case R.id.btn1: if (x == 1) { shared.truthToast(); } else { shared.lieToast(); } break; case R.id.btn2: if (x == 2) { shared.truthToast(); } else { shared.lieToast(); } break; case R.id.btn3: if (x == 3) { shared.truthToast(); } else { shared.lieToast(); } break; case R.id.btn4: if (x == 4) { shared.truthToast(); } else { shared.lieToast(); } break; case R.id.btn5: if (x == 5) { shared.truthToast(); } else { shared.lieToast(); } break; case R.id.btn6: if (x == 6) { shared.truthToast(); } else { shared.lieToast(); } break; case R.id.btn7: if (x == 7) { shared.truthToast(); } else { shared.lieToast(); } break; case R.id.btn8: if (x == 8) { shared.truthToast(); } else { shared.lieToast(); } break; case R.id.btn9: if (x == 9) { shared.truthToast(); } else { shared.lieToast(); } break; case R.id.btn10: if (x == 10) { shared.truthToast(); } else { shared.lieToast(); } break; } } }; // присвоим обработчики кнопкам btn1.setOnClickListener(onClickListener); btn2.setOnClickListener(onClickListener); btn3.setOnClickListener(onClickListener); btn4.setOnClickListener(onClickListener); btn5.setOnClickListener(onClickListener); btn6.setOnClickListener(onClickListener); btn7.setOnClickListener(onClickListener); btn8.setOnClickListener(onClickListener); btn9.setOnClickListener(onClickListener); btn10.setOnClickListener(onClickListener); fabNewGame.setOnClickListener(onClickListener); // Сброс в первоначальное состояние (новое задание) sbros(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // получим идентификатор выбранного пункта меню int id = item.getItemId(); // Операции для выбранного пункта меню switch (id) { case R.id.action_newgame: sbros(); return true; // Кнопка Home case android.R.id.home: stopService(new Intent(this, MyService.class)); onBackPressed(); default: return super.onOptionsItemSelected(item); } } public class TaskActivity extends AppCompatActivity { FloatingActionButton fabNewGame; ImageButton figure1; ImageButton figure2; ImageButton figure3; ImageButton figure4; ImageButton figure5; ImageButton figure6; ImageButton figure7; ImageButton figure8; ImageButton figure9; ImageButton figure10; ImageButton operation; ImageButton figure1_1; ImageButton figure1_2; ImageButton figure1_3; ImageButton figure1_4; ImageButton figure1_5; ImageButton figure1_6; ImageButton figure1_7; ImageButton figure1_8; ImageButton figure1_9; ImageButton figure1_10; ImageButton btn1; ImageButton btn2; ImageButton btn3; ImageButton btn4; ImageButton btn5; ImageButton btn6; ImageButton btn7; ImageButton btn8; ImageButton btn9; ImageButton btn10; int x,y,result, id; // Числа для счета (генерируются случайным образом) private void sbros() { // Сброс в первоначальное состояние (новое задание) // Прячем все figure1.setVisibility(View.INVISIBLE); figure2.setVisibility(View.INVISIBLE); figure3.setVisibility(View.INVISIBLE); figure4.setVisibility(View.INVISIBLE); figure5.setVisibility(View.INVISIBLE); figure6.setVisibility(View.INVISIBLE); figure7.setVisibility(View.INVISIBLE); figure8.setVisibility(View.INVISIBLE); figure9.setVisibility(View.INVISIBLE); figure10.setVisibility(View.INVISIBLE); operation.setVisibility(View.INVISIBLE); figure1_1.setVisibility(View.INVISIBLE); figure1_2.setVisibility(View.INVISIBLE); figure1_3.setVisibility(View.INVISIBLE); figure1_4.setVisibility(View.INVISIBLE); figure1_5.setVisibility(View.INVISIBLE); figure1_6.setVisibility(View.INVISIBLE); figure1_7.setVisibility(View.INVISIBLE); figure1_8.setVisibility(View.INVISIBLE); figure1_9.setVisibility(View.INVISIBLE); figure1_10.setVisibility(View.INVISIBLE); // Первое число Random rand = new Random(); x = rand.nextInt(5) + 1; if (x >= 1) { figure1.setVisibility(View.VISIBLE); if (x >= 2) { figure2.setVisibility(View.VISIBLE); if (x >= 3) { figure3.setVisibility(View.VISIBLE); if (x >= 4) { figure4.setVisibility(View.VISIBLE); if (x >= 5) { figure5.setVisibility(View.VISIBLE); if (x >= 6) { figure6.setVisibility(View.VISIBLE); if (x >= 7) { figure7.setVisibility(View.VISIBLE); if (x >= 8) { figure8.setVisibility(View.VISIBLE); if (x >= 9) { figure9.setVisibility(View.VISIBLE); if (x >= 10) { figure10.setVisibility(View.VISIBLE); } } } } } } } } } } // Второе число y = rand.nextInt(5) + 1; if (y >= 1) { figure1_1.setVisibility(View.VISIBLE); if (y >= 2) { figure1_2.setVisibility(View.VISIBLE); if (y >= 3) { figure1_3.setVisibility(View.VISIBLE); if (y >= 4) { figure1_4.setVisibility(View.VISIBLE); if (y >= 5) { figure1_5.setVisibility(View.VISIBLE); if (y >= 6) { figure1_6.setVisibility(View.VISIBLE); if (y >= 7) { figure1_7.setVisibility(View.VISIBLE); if (y >= 8) { figure1_8.setVisibility(View.VISIBLE); if (y >= 9) { figure1_9.setVisibility(View.VISIBLE); if (y >= 10) { figure1_10.setVisibility(View.VISIBLE); } } } } } } } } } } // Знак плюс или минус operation.setVisibility(View.VISIBLE); if (x > y){ id = getResources().getIdentifier("minus","drawable",getPackageName()); operation.setImageResource(id); result = x-y; } else { id = getResources().getIdentifier("plus","drawable",getPackageName()); operation.setImageResource(id); result = x+y; } // Сброс поля ввода //et15Equality.setText(""); // Сброс знака равно //int id = getResources().getIdentifier("equality_48","drawable",getPackageName()); //operation.setImageResource(id); // Какая картинка? id = getResources().getIdentifier("strawberry","drawable",getPackageName()); rand = new Random(); int p = rand.nextInt(2) + 1; if (p==1){ id = getResources().getIdentifier("strawberry","drawable",getPackageName()); } if (p==2){ id = getResources().getIdentifier("apple","drawable",getPackageName()); } if (p==3){ id = getResources().getIdentifier("apple","drawable",getPackageName()); |