public int CountBombs(int fieldY, int fieldX) { if (BombField[fieldY][fieldX] == 9) { return(9); } int count = 0; for (int j = -1; j < 2; j++) { for (int i = -1; i < 2; i++) { if ((fieldY + j) < 0 || (fieldX + i) < 0) { continue; } if ((fieldY + j) >= BombField.Count() || (fieldX + i) >= BombField[0].Count()) { continue; } if (BombField[fieldY + j][fieldX + i] == 9) { count++; } } } return(count); }
private void setAllFields() { for (int j = 0; j < BombField.Count(); j++) { for (int i = 0; i < BombField[0].Count(); i++) { BombField[j][i] = CountBombs(j, i); } } }
private void spaceBtn_Click(object sender, MouseEventArgs e) { Space space = sender as Space; BombField bf = Global.MainBombField; if (space.Status == SpaceStatus.Pressed) { return; } if (e.Button == MouseButtons.Right) { if (space.Status == SpaceStatus.Empty && bf.BombsLeft <= 0) { Global.GameStatusLabel.Text = "Out of Flags"; } else { SpaceStatus rc = space.RightClick(); if (rc == SpaceStatus.Flagged) { bf.DecrementBomb(); } else if (rc == SpaceStatus.Questioned) { bf.IncrementBomb(); } } return; } if (bf.FirstPressSafe) { int bombs = bf.ClearNearbyBombs(space.X, space.Y); bf.AddBombs(space.X, space.Y, bombs); bf.FirstPressSafe = false; } if (bf.Press(space)) { Global.GameStatusLabel.Text = "BOOM!"; foreach (Space s in bf.Array) { s.MouseUp -= spaceBtn_Click; } } else if (bf.SafeSpacesLeft == 0) { Global.GameStatusLabel.Text = "Nice!"; } }
private void CreateBombs(int Bombs) { int x; int y; while (0 < Bombs) { y = rnd.Next(0, BombField.Count()); x = rnd.Next(0, BombField[0].Count()); if (BombField[y][x] != 9) { BombField[y][x] = 9; Bombs--; } } }
private void ResetBombFields() { Global.GameStatusLabel.Text = ""; BombField bf = Global.MainBombField; bf.BombsLeft = bf.Bombs; bf.SafeSpacesLeft = (bf.Height * bf.Width) - bf.Bombs; bf.BombsLeftLabel.Text = bf.BombsLeft.ToString(); bf.FirstPressSafe = (bf.Difficulty == "Slightly Harder" || (!safeCheckBox.Checked && bf.Difficulty == "Custom")) ? false : true; foreach (Space s in bf.Array) { s.Status = SpaceStatus.Empty; s.BackColor = Color.Gainsboro; s.ChangeSpaceText(String.Empty, Color.Black); s.MouseUp -= spaceBtn_Click; s.MouseUp += spaceBtn_Click; s.IsBomb = false; } bf.LoadBombs(); }
// Use this for initialization public void Spawn(Vector3 position) { float fullArc = 360.0f / segments; float renderedArc = fullArc * (1.0f - borderPercentage); float spacing = ((outerRadius - innerRadius) - thickness) / (float)layers; int randomSeed = Random.Range(0, 10); BombField field = Instantiate(fieldPrefab.gameObject).GetComponent <BombField>(); for (int j = 0; j < layers; j++) { GameObject parent = new GameObject("BombRing" + j); parent.transform.position = position; //Instantiating glow and ring GameObject glow = new GameObject("Glow" + j); glow.transform.parent = parent.transform; glow.transform.localPosition = Vector3.zero; GameObject ring = new GameObject("Ring" + j); ring.transform.parent = parent.transform; ring.transform.localPosition = Vector3.zero; Random.InitState(randomSeed); for (int i = 0; i < segments; i++) { float randomValue = Random.Range(0.0f, 1.0f);// * (0.3f * (j+1)); if (randomValue < 0.5) { randomValue = Random.Range(0.0f, 0.25f); } else { randomValue = Random.Range(0.75f, 1.0f); } CreateGlow(renderedArc, fullArc * i, innerRadius + j * spacing, 2.0f + randomValue * 10.0f); CreateRingSegment(renderedArc, fullArc * i, innerRadius + j * spacing, randomValue); } List <MeshFilter> meshFilters = GetComponentsInChildren <MeshFilter>().Where(x => x.gameObject.name.Contains("Panel")).ToList(); CombineInstance[] combine = new CombineInstance[meshFilters.Count]; for (int i = 0; i < meshFilters.Count; i++) { combine[i].mesh = meshFilters[i].sharedMesh; combine[i].transform = meshFilters[i].transform.localToWorldMatrix; meshFilters[i].gameObject.SetActive(false); Destroy(meshFilters[i].gameObject); //meshFilters[i].sharedMesh; //combine[i].transform = meshFilters[i].transform.localToWorldMatrix; //meshFilters[i].gameObject.active = false; } MeshFilter glowMF = glow.AddComponent <MeshFilter>(); glowMF.mesh.CombineMeshes(combine); glowMF.mesh.RecalculateNormals(); MeshRenderer glowMR = glow.AddComponent <MeshRenderer>(); glowMR.material = glowMaterial; RotatingLight light = glow.AddComponent <RotatingLight>(); light.selfRenderer = glowMR; meshFilters = GetComponentsInChildren <MeshFilter>().Where(x => x.gameObject.name.Contains("Arc")).ToList(); combine = new CombineInstance[meshFilters.Count]; for (int i = 0; i < meshFilters.Count; i++) { combine[i].mesh = meshFilters[i].sharedMesh; combine[i].transform = meshFilters[i].transform.localToWorldMatrix; meshFilters[i].gameObject.SetActive(false); Destroy(meshFilters[i].gameObject); //meshFilters[i].sharedMesh; //combine[i].transform = meshFilters[i].transform.localToWorldMatrix; //meshFilters[i].gameObject.active = false; } MeshFilter ringMF = ring.AddComponent <MeshFilter>(); ringMF.mesh.CombineMeshes(combine); ringMF.mesh.RecalculateNormals(); MeshRenderer ringMR = ring.AddComponent <MeshRenderer>(); ringMR.material = floorMaterial; field.fieldRings.Add(parent); } field.transform.position = this.transform.position; field.SpawnField(); }
private void Awake() { instance = this; }