void Start() { // Cache references spawner = GetComponent <GemSpawner>(); destroyer = GetComponent <GemDestroyer>(); myCollider = GetComponent <Collider2D>(); container = GameObject.Find("Gem Container").transform; audioSource = GetComponent <AudioSource>(); // Initialize lists and arrays gemTable = new int[COL_NUM, ROW_NUM]; gemColumns = new List <Gem> [COL_NUM]; for (int x = 0; x < COL_NUM; x++) { gemColumns[x] = new List <Gem>(); } // Fill board with gems spawner.SpawnGems(true); // Break possible matches gemsToDestroy = MatchLib.CheckMatches(gemTable); // And keep doing so until there are no matches left while (gemsToDestroy.Count > 0) { destroyer.DestroyGems(true); spawner.SpawnGems(true); gemsToDestroy = MatchLib.CheckMatches(gemTable); } // Make sure there are possible moves for the player and no unbroken matches if (!MatchLib.MovementIsPossible(gemTable)) { MatchLib.Shuffle(gemColumns, gemTable); } // Disable collider myCollider.enabled = false; }
private void openToolStripMenuItem1_Click(object sender, EventArgs e) { using (OpenFileDialog dlg = new OpenFileDialog()) { dlg.Title = "Open Image"; dlg.Filter = "jpg files (*.fits)|*.fits"; if (dlg.ShowDialog() == DialogResult.OK) { this.objemgucv = new EmguCv(dlg.FileName); this.iplImage = this.objemgucv.ImageJPG; imageBox1.Image = this.iplImage; imageType = new SRSLib.ImageLib.ImageType(); SRSLib.ImageLib.OpenAnyImageType(dlg.FileName, ref imageType); //file fit path MatchLib.SetCatalogLocation(catalogpath); centerRa2000GuessRads = new MatchLib.PlateListType() { Px = imageType.N1, Py = imageType.N2, XSize = (double)imageType.N1 * 1 / 206264.806, YSize = (double)imageType.N2 * 1 / 206264.806, HaveStartingCoords = false }; MatchLib.ExtractStars(ref imageType, ref centerRa2000GuessRads); MatchLib.PlateMatch(ref centerRa2000GuessRads); button1.Enabled = true; //MatchLib.PlateMatch(ref centerRa2000GuessRads); //MatchLib.PlateMatchImage(ref imageType, ref centerRa2000GuessRads); // Create a new Bitmap object from the picture file on disk, // and assign that to the PictureBox.Image property } } }
public void UT_MatchLib_GetPars() { string str = "I10_8239_89"; var pars = MatchLib.GetPars(str); Assert.AreEqual(1, pars.Count); Assert.AreEqual(10, pars[0]); }
public void UT_ToLat() { string str = "мой текст"; string lat = MatchLib.ToLat(str); Assert.AreEqual("мoй тeкcт", lat); //speed test DateTime t0 = DateTime.Now; for (int i = 0; i < 1000000; i++) { lat = MatchLib.ToLat(str + " " + i); } DateTime t1 = DateTime.Now; TimeSpan mlnCycles = t1 - t0; }
public void Plantwave(Cv imageprocessing) { if (!String.IsNullOrEmpty(catalogpath)) { imageType = new SRSLib.ImageLib.ImageType(); SRSLib.ImageLib.OpenAnyImageType(this.path, ref imageType); //file fit path MatchLib.SetCatalogLocation(catalogpath); centerRa2000GuessRads = new MatchLib.PlateListType() { Px = imageType.N1, Py = imageType.N2, XSize = (double)imageType.N1 * 1 / 206264.806, YSize = (double)imageType.N2 * 1 / 206264.806, HaveStartingCoords = false }; MatchLib.ExtractStars(ref imageType, ref centerRa2000GuessRads); MatchLib.PlateMatch(ref centerRa2000GuessRads); } }
public void UT_MatchLib_GetParsStr() { // test 1 string str = "I10.5_8239_89"; List <string> pars = MatchLib.GetParsStr(str); Assert.AreEqual(1, pars.Count); Assert.AreEqual("10.5", pars[0]); // test 2 str = "Prf:U10.5x7,8_8239_89;"; pars = MatchLib.GetParsStr(str); Assert.AreEqual(2, pars.Count); Assert.AreEqual("10.5", pars[0]); Assert.AreEqual("7,8", pars[1]); // test 3 str = "I10_8239_89"; pars = MatchLib.GetParsStr(str); Assert.AreEqual(1, pars.Count); Assert.AreEqual("10", pars[0]); }
public void UT_IContains() { // test 1: string v = "yгoлoк75x6"; v = MatchLib.ToLat(v); List <string> lst0 = new List <string>() { "угoлoк", "l" }; lst0[0] = MatchLib.ToLat(lst0[0]); bool b0 = MatchLib.IContains(lst0, v); Assert.IsTrue(b0); // test 2: List <string> lst = new List <string>() { "уголок", "l" }; v = "уголок"; bool b = MatchLib.IContains(lst, v); Assert.IsTrue(b); // test 3: lst = new List <string>() { "балка", "i" }; v = "i20"; b = MatchLib.IContains(lst, v); Assert.IsTrue(b); }
// Hierarchy of actions: only one action per update: one gem breaking or one gem spawning void Update() { // Check if can update something in this frame if (dontUpdate) { // Reset flag dontUpdate = false; // Don't allow players to input myCollider.enabled = true; return; } // Needs to break gems if (gemsToDestroy.Count > 0) { // Check if a new move was made if (moveMade) { // Clear flag moveMade = false; // Disable player input by putting a collider in front of the gems myCollider.enabled = true; // Reset combo counter comboCounter = 0; } // Update combo counter comboCounter++; // Destroy gems and get the points int score = destroyer.DestroyGems() * basePoints * comboCounter; gemsToDestroy.Clear(); // Make score effects audioSource.PlayOneShot(destroySound); if (scorePF) { ScoreEffect effect = Instantiate( scorePF, transform.position + Vector3.up * ROW_NUM * .6f, Quaternion.identity ).GetComponent <ScoreEffect>(); effect.SetScore(score); effect.transform.SetParent(transform); } // Add points to total totalScore += score; // Flag to move and spawn gems needToSpawnGems = true; } // Needs to move and spawn gems else if (needToSpawnGems) { // Clear flag needToSpawnGems = false; spawner.SpawnGems(); // Check if more matches were made gemsToDestroy = MatchLib.CheckMatches(gemTable); // If not, check if new moves are possible if (gemsToDestroy.Count == 0 && !MatchLib.MovementIsPossible(gemTable)) { // Shuffle until a new board with possible moves and no matches is made MatchLib.Shuffle(gemColumns, gemTable); } } // Else, nothing is happening. Allow player Input else { myCollider.enabled = false; } }
public GemSelect Select(Gem gem) { // Is this the first gem selected? if (!gem1) { // Mark this gem gem1 = gem; // Play selection sound audioSource.PlayOneShot(selectSound); return(GemSelect.Select); } // Is it the same as the first one? if (gem1 == gem) { // De-select the gem gem1 = null; // Play selection sound audioSource.PlayOneShot(selectSound); return(GemSelect.Deselect); } // Are the gems adjacent? (i.e. distance = 1 < sqrt(2)) if (Vector2.Distance(gem1.transform.localPosition, gem.transform.localPosition) > 1.1f) { // Unmark gem 1 gem1.SetNotSelected(); gem1 = null; // Play selection sound audioSource.PlayOneShot(selectSound); return(GemSelect.NotValid); } // Check validity of second gem selected gem2 = gem; // Get a copy of the table of gem types int[,] table = board.GetTableCopy(); // Swap gems and check validity int x1, y1, x2, y2; x1 = gem1.GetCol(); y1 = gem1.GetRow(); x2 = gem2.GetCol(); y2 = gem2.GetRow(); table[x1, y1] = gem2.GetGemType(); table[x2, y2] = gem1.GetGemType(); // Check if this move makes a match List <int[]> matches = MatchLib.CheckMatches(table); if (matches.Count > 0) { // Swap gem positions gem1.MoveToCoordinate(x2, y2); gem2.MoveToCoordinate(x1, y1); // Swap gem positions in the board manager's tables board.SwapGems(x1, y1, x2, y2); // Pass on the list of matched gems board.SetGemsToDestroy(matches); // Notify gem1 to set the color back to normal gem1.SetNotSelected(); // Unmark gems gem1 = null; gem2 = null; // Play no sound, the board will play the destroy sound next return(GemSelect.Valid); } // else // Just change the first gem's color and unmark them gem1.SetNotSelected(); // Unmark gems gem1 = null; gem2 = null; // Play selection sound audioSource.PlayOneShot(selectSound); return(GemSelect.NotValid); }