NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;

public class minesweeper : MonoBehaviour
{
public GameObject[] first;
public GameObject[] second;
public GameObject[] third;
public GameObject[] fourth;
public GameObject[] fifth;
public GameObject[] sixth;
public GameObject[,] matrix;

public bool isChecked = false;
//public GameObject txt;


string bomb = "*";

int opened_boxes = 0;
int opened_boxes_corner = 0;

List<GameObject[]> lista;

int nr = 0;
int random_number;

void Start()
{
lista = new List<GameObject[]>();

lista.Add(first);
lista.Add(second);
lista.Add(third);
lista.Add(fourth);
lista.Add(fifth);
lista.Add(sixth);

matrix = new GameObject[6, 6];

Randoms();
CheckForBombMain();
CheckForBombInCorner();
CheckForBombsLeft();
CheckForZeros(); // we remove the zeros cos we don't really want text on them
// supposed to open the zeros and the other nums when clicking
}


private void ChangeTheButtonsColour()
{
for (int i = 0; i < lista.Count; i++)
{
for (int j = 0; j < lista[i].Length; j++)
{
// if (lista[i][j].transform.GetComponent<ImageConversion>() == "0") ;

}
}
}

private void CheckForZeros()
{
for (int i = 0; i < lista.Count; i++)
{
for (int j = 0; j < lista[i].Length; j++)
{
if (lista[i][j].transform.GetChild(0).GetComponent<TMP_Text>().text == "0")
{
//lista[i][j].transform.GetChild(0).GetComponent<TMP_Text>().text = "";
}
}
}
}

private void CheckForBombsLeft()
{
for (int i = 0; i < lista.Count; i++)
{
for (int j = 0; j < lista[i].Length; j++)
{
if (i == 0 && j != 0 && j != 5) // we check for the 1st row and exclude the corners(cos they're already checked)
{
if (lista[i][j].transform.GetChild(0).GetComponent<TMP_Text>().text == "")
{

if (lista[i + 1][j].transform.GetChild(0).GetComponent<TMP_Text>().text == "*") //
{
opened_boxes++;
}
if (lista[i][j + 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")//
{
opened_boxes++;
}
if (lista[i + 1][j + 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")//
{
opened_boxes++;
}
if (lista[i][j - 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")//
{
opened_boxes++;
}
if (lista[i + 1][j - 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")
{
opened_boxes++;
}
lista[i][j].transform.GetChild(0).GetComponent<TMP_Text>().text = opened_boxes.ToString();
opened_boxes = 0;
}
}
if (i == 5 && j != 0 && j != 5)
{
if (lista[i][j].transform.GetChild(0).GetComponent<TMP_Text>().text == "")
{

if (lista[i][j + 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")
{
opened_boxes++;
}
if (lista[i - 1][j + 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")
{
opened_boxes++;
}
if (lista[i - 1][j].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")
{
opened_boxes++;
}
if (lista[i - 1][j - 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")
{
opened_boxes++;
}
if (lista[i][j - 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")
{
opened_boxes++;
}
lista[i][j].transform.GetChild(0).GetComponent<TMP_Text>().text = opened_boxes.ToString();
opened_boxes = 0;
}
}
if (j == 0 && i != 0 && i != 5)
{
if (lista[i][j].transform.GetChild(0).GetComponent<TMP_Text>().text == "")
{

if (lista[i - 1][j].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")
{
opened_boxes++;
}
if (lista[i - 1][j + 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")
{
opened_boxes++;
}
if (lista[i][j + 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")
{
opened_boxes++;
}
if (lista[i + 1][j + 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")
{
opened_boxes++;
}
if (lista[i + 1][j].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")
{
opened_boxes++;
}
lista[i][j].transform.GetChild(0).GetComponent<TMP_Text>().text = opened_boxes.ToString();
opened_boxes = 0;
}
}
if (j == 5 && i != 0 && i != 5)
{
if (lista[i][j].transform.GetChild(0).GetComponent<TMP_Text>().text == "")
{

if (lista[i - 1][j].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")
{
opened_boxes++;
}
if (lista[i - 1][j - 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")
{
opened_boxes++;
}
if (lista[i][j - 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")
{
opened_boxes++;
}
if (lista[i + 1][j - 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")
{
opened_boxes++;
}
if (lista[i + 1][j].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")
{
opened_boxes++;
}
lista[i][j].transform.GetChild(0).GetComponent<TMP_Text>().text = opened_boxes.ToString();
opened_boxes = 0;
}

}
}
}
}

private void CheckForBombInCorner() // check for bombs in the corners
{
for (int i = 0; i < lista.Count; i++)
{
for (int j = 0; j < lista[i].Length; j++) //
{

if (i == 0 && j == 0)
{
if (lista[i][j].transform.GetChild(0).GetComponent<TMP_Text>().text == "")
{
if (lista[i][j + 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*") // i dhe j + 1
{
opened_boxes++;
}
if (lista[i + 1][j].transform.GetChild(0).GetComponent<TMP_Text>().text == "*") // i + 1 dhe j
{
opened_boxes++;
}
if (lista[i + 1][j + 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*") // i + 1 dhe j + 1
{
opened_boxes++;
}
lista[i][j].transform.GetChild(0).GetComponent<TMP_Text>().text = opened_boxes.ToString();
opened_boxes = 0;
}
}
if (i == 0 && j == 5)
{
if (lista[i][j].transform.GetChild(0).GetComponent<TMP_Text>().text == "")
{
if (lista[i][j - 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*") // i dhe j - 1
{
opened_boxes++;
}
if (lista[i + 1][j - 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*") // i + 1 dhe j - 1
{
opened_boxes++;
}
if (lista[i + 1][j].transform.GetChild(0).GetComponent<TMP_Text>().text == "*") // i + 1 dhe j
{
opened_boxes++;
}
lista[i][j].transform.GetChild(0).GetComponent<TMP_Text>().text = opened_boxes.ToString();
opened_boxes = 0;
}
}
if (i == 5 && j == 0)
{
if (lista[i][j].transform.GetChild(0).GetComponent<TMP_Text>().text == "")
{
if (lista[i][j + 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*") // i dhe j + 1
{
opened_boxes++;
}
if (lista[i - 1][j].transform.GetChild(0).GetComponent<TMP_Text>().text == "*") // i - 1 dhe j
{
opened_boxes++;
}
if (lista[i - 1][j + 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*") // i - 1 dhe j + 1
{
opened_boxes++;
}
lista[i][j].transform.GetChild(0).GetComponent<TMP_Text>().text = opened_boxes.ToString();
opened_boxes = 0;
}
}
if (i == 5 && j == 5)
{
if (lista[i][j].transform.GetChild(0).GetComponent<TMP_Text>().text == "")
{
if (lista[i][j - 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*") // i dhe j - 1
{
opened_boxes++;
}
if (lista[i - 1][j].transform.GetChild(0).GetComponent<TMP_Text>().text == "*") // i - 1 dhe j
{
opened_boxes++;
}
if (lista[i - 1][j - 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*") // i - 1 dhe j - 1
{
opened_boxes++;
}
lista[i][j].transform.GetChild(0).GetComponent<TMP_Text>().text = opened_boxes.ToString();
opened_boxes = 0;
}
}
}
}
}


public void CheckForBombMain()
{
for (int i = 0; i < lista.Count; i++)
{
for (int j = 0; j < lista[i].Length; j++)
{

if (i == 0 || i == 5 || j == 0 || j == 5)
{
continue;
}
else
{
if (lista[i][j].transform.GetChild(0).GetComponent<TMP_Text>().text == "")
{
if (lista[i][j + 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")//
{
opened_boxes++;
}
if (lista[i][j - 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")//
{
opened_boxes++;
}
if (lista[i + 1][j].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")//
{
opened_boxes++;
}
if (lista[i - 1][j].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")//
{
opened_boxes++;
}
if (lista[i + 1][j + 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")//
{
opened_boxes++;
}
if (lista[i - 1][j - 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")//
{
opened_boxes++;
}
if (lista[i + 1][j - 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")//
{
opened_boxes++;
}
if (lista[i - 1][j + 1].transform.GetChild(0).GetComponent<TMP_Text>().text == "*")//
{
opened_boxes++;
}
lista[i][j].transform.GetChild(0).GetComponent<TMP_Text>().text = opened_boxes.ToString();
opened_boxes = 0;
}
}
}
}
}

public void Randoms()
{

List<int> random_numbers_list = new List<int>(); // 22 , 25 , 17 , 19 , 4 , 8 , 31
System.Random rnd = new System.Random();

for (int i = 0; i <= 1; i++) // for (int i = 0; i <= 10; i++)
{
random_number = rnd.Next(0, 35);
random_numbers_list.Add(random_number);
}

for (int j = 0; j < lista.Count; j++)
{
for (int i = 0; i < lista[j].Length; i++)
{
bool check = TrueFalse(random_numbers_list, nr);
if (check)
{
lista[j][i].transform.GetChild(0).GetComponent<TMP_Text>().text = "*";
}
nr++;
}
}
}

public bool TrueFalse(List<int> list, int nr)
{
for (int i = 0; i < list.Count; i++)
{
if (nr == list[i])
{
return true;
}
}
return false;
}

// Update is called once per frame
public void OnClick()
{
isChecked = true;
GameObject ga = EventSystem.current.currentSelectedGameObject;

int i = ga.transform.parent.GetSiblingIndex(); // 0
int j = ga.transform.GetSiblingIndex(); //2

Debug.Log(i + " " + j);

ga.transform.GetChild(0).GetComponent<TMP_Text>().enabled = true;
if (ga.transform.GetChild(0).GetComponent<TMP_Text>().text == "0")
{
Field(i, j);
}
isChecked = false;
}



public void Field(int x, int y)
{

if (x == 0 || y == 0 )
{
return;
}
if (x == 0 || y == 5)
{
return;
}
if (x == 5 || y == 0)
{
return;
}
if (x == 5 || y == 5)
{
return;
}
else
{
if ( lista[x][y].transform.GetChild(0).GetComponent<TMP_Text>().text == "0")
{
lista[x][y].transform.GetChild(0).GetComponent<TMP_Text>().enabled = true; // 2 - 1
Field(x + 1, y); // 3 - 1
Field(x - 1, y); // 1 - 1
Field(x, y + 1); // 2 - 2
Field(x, y - 1); // 2 - 0
Field(x - 1, y - 1);
Field(x - 1, y + 1);
Field(x + 1, y - 1);
Field(x + 1, y + 1);
}
}
}
}

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.