protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.game); _side = int.Parse(Intent.GetStringExtra("a_side")); _scoreDatabase = new ScoreDatabaseController(); _textView = FindViewById <TextView>(Resource.Id.textView1); var gameLinearLayout = FindViewById <LinearLayout>(Resource.Id .game_screen); //Ez a legalapbb úgynevett root layout ehhez fogunk majd mindent hozzáadni vertical-is _informationContainer = new InformationContainer(_textView, int.Parse(Intent.GetStringExtra("a_side"))); _gameArea = new GameArea(this, int.Parse(Intent.GetStringExtra("a_side")), _informationContainer); //itt átadtam ennek az activity-t és hogy mekkora legyen a pálya!!!!!!!!!!!!!!!!!!! itt lehet beállitani, hogy hányszor hányas legyen a pálya var tableLayout = _gameArea.generate_game_field(); gameLinearLayout.AddView(tableLayout); //legenáráltam az üres pályát és hozzáadtam a root layout-hoz var button = FindViewById <Button>(Resource.Id.new_game); var bckBtn = FindViewById <Button>(Resource.Id.button1); _lastSceneBtn = FindViewById <Button>(Resource.Id.button2); bckBtn.Click += (s, e) => { var score = new Score { _score = _informationContainer.HighScore, _side = _side }; _scoreDatabase.set_high_Score(score); _gameArea.save_game_Area_(); var intent = new Intent(this, typeof(MainActivity)); StartActivity(intent); }; button.Click += (s, e) => { _gameArea.New_game(); }; _lastSceneBtn.Click += (s, e) => { _gameArea.get_last_scene(); }; _lastSceneBtn.Enabled = false; // button.SetOnTouchListener(this);//touch sensor érzékelésének hozzáadása a textview-hoz set_onclick_for_buttons(tableLayout); _saveGame = new SaveGameArea(); if (_saveGame.GetGame_Area_(int.Parse(Intent.GetStringExtra("a_side"))) != null) { var getSavedData = _saveGame.GetGame_Area_(int.Parse(Intent.GetStringExtra("a_side"))); _gameArea.load_saved_game_Area(getSavedData.Places, getSavedData.Values); } else { _gameArea.add_new_number(GameButton.get_new_btn()); //az első generálás _gameArea.add_new_number(GameButton.get_new_btn()); } }
private void up_down_move(string upOrDown, bool fushionChecker) { _wasChange = false; int sor; for (var i = 0; i < _gombPlace.GetLength(0); i++) { for (var proba = 0; proba < _gombPlace.GetLength(0) - 1; proba++) { switch (upOrDown) { case "up": sor = 1; while (sor < _gombPlace.GetLength(1)) { if (_gombPlace[sor, i] == 1 && _gombPlace[sor - 1, i] == 0) { change_buttons(sor - 1, i, sor, i); _wasChange = true; } sor++; } break; case "down": sor = _gombPlace.GetLength(0) - 1; while (sor > 0) { if (_gombPlace[sor, i] == 0 && _gombPlace[sor - 1, i] == 1) { change_buttons(sor, i, sor - 1, i); _wasChange = true; } sor--; } break; } } } if (!fushionChecker) { return; } { _arrayIndexes = new ArrayIndexes[_aSide * _aSide]; var arrayOfIndex = 0; for (var i = 0; i < _gombPlace.GetLength(0); i++) { switch (upOrDown) { case "up": sor = 1; while (sor < _gombPlace.GetLength(1)) { if (_gombPlace[sor, i] == 1 && _gombPlace[sor - 1, i] == 1 && int.Parse(GameButton.get_btn_value(_gameButtons[sor, i])) == int.Parse(GameButton.get_btn_value(_gameButtons[sor - 1, i]))) { var array = new ArrayIndexes { ToX = sor - 1, ToY = i, FromX = sor, FromY = i, Direction = "up" }; _arrayIndexes[arrayOfIndex] = array; arrayOfIndex++; sor++; } sor++; } break; case "down": sor = _gombPlace.GetLength(0) - 1; while (sor > 0) { if (_gombPlace[sor, i] == 1 && _gombPlace[sor - 1, i] == 1 && int.Parse(GameButton.get_btn_value(_gameButtons[sor, i])) == int.Parse(GameButton.get_btn_value(_gameButtons[sor - 1, i]))) { var array = new ArrayIndexes { ToX = sor, ToY = i, FromX = sor - 1, FromY = i, Direction = "down" }; _arrayIndexes[arrayOfIndex] = array; arrayOfIndex++; sor--; } sor--; } break; } } if (_wasChange || arrayOfIndex > 0 && is_place_for_btn()) { add_new_number(GameButton.get_new_btn()); } frame_fushion(_arrayIndexes, arrayOfIndex); } }
private void left_right_move(string rightOrLeft, bool frameChecker) { _wasChange = false; for (var i = 0; i < _gombPlace.GetLength(0); i++) { for (var proba = 0; proba < _gombPlace.GetLength(0) - 1; proba++) { if (rightOrLeft == "left") { for (var k = 1; k < _gombPlace.GetLength(1); k++) { if (_gombPlace[i, k - 1] == 0 && _gombPlace[i, k] == 1) { change_buttons(i, k - 1, i, k); _wasChange = true; } else if (rightOrLeft == "right") { for (var j = _gombPlace.GetLength(1) - 1; j >= 1; j--) { if (_gombPlace[i, j] == 0 && _gombPlace[i, j - 1] == 1) { change_buttons(i, j, i, j - 1); _wasChange = true; } } } } } } } if (!frameChecker) { return; } { _arrayIndexes = new ArrayIndexes[_aSide * _aSide]; var arrayOfIndex = 0; for (var i = 0; i < _gombPlace.GetLength(0); i++) { if (rightOrLeft == "left") { for (var k = 1; k < _gombPlace.GetLength(1); k++) { if (_gombPlace[i, k - 1] == 1 && _gombPlace[i, k] == 1 && int.Parse(GameButton.get_btn_value(_gameButtons[i, k - 1])) == int.Parse(GameButton.get_btn_value(_gameButtons[i, k]))) { var array = new ArrayIndexes { ToX = i, ToY = k - 1, FromX = i, FromY = k, Direction = "left" }; _arrayIndexes[arrayOfIndex] = array; arrayOfIndex++; k++; } else if (rightOrLeft == "right") { for (var j = _gombPlace.GetLength(1) - 1; j >= 1; j--) { if (_gombPlace[i, j] == 1 && _gombPlace[i, j - 1] == 1 && int.Parse(GameButton.get_btn_value(_gameButtons[i, j - 1])) == int.Parse(GameButton.get_btn_value(_gameButtons[i, j]))) { var array = new ArrayIndexes { ToX = i, ToY = j, FromY = j - 1, FromX = i, Direction = "right" }; _arrayIndexes[arrayOfIndex] = array; arrayOfIndex++; j--; } } } } } } if (_wasChange || arrayOfIndex > 0 && is_place_for_btn()) { add_new_number(GameButton.get_new_btn()); } frame_fushion(_arrayIndexes, arrayOfIndex); } }