コード例 #1
0
 private void buttonAddLevel_Click(object sender, RoutedEventArgs e)
 {
     LevelSpecs.Add(new LevelSpec {
         Name    = "",
         IdItems = new ObservableCollection <DatabaseColumn>(),
         Records = new ObservableCollection <RecordSpec>()
     });
 }
コード例 #2
0
 public void OnValidate()
 {
     levelSpecs = levelSpecs;
     if (grid.gs != null)
     {
         grid.reset();
     }
     grid = new Grid(this, levelSpecs);
     grid.generateGrid();
 }
コード例 #3
0
        private void buttonRemoveLevel_Click(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;

            if (button != null)
            {
                var levelSpec = button.DataContext as LevelSpec;
                LevelSpecs.Remove(levelSpec);
            }
        }
コード例 #4
0
        private void listBoxRecords_Drop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(DatabaseTable)))
            {
                DatabaseTable table            = e.Data.GetData(typeof(DatabaseTable)) as DatabaseTable;
                var           frameworkElement = sender as FrameworkElement;
                if (frameworkElement != null)
                {
                    var levelSpec = frameworkElement.DataContext as LevelSpec;

                    var nextRecordType = (char)((int)LevelSpecs.SelectMany(l => l.Records).Select(r => r.Type).DefaultIfEmpty('0').Max() + 1);
                    if (levelSpec.Records.FirstOrDefault(r => r.DatabaseTable == table) == null)
                    {
                        levelSpec.Records.Add(new RecordSpec {
                            Name = table.Name, DatabaseTable = table, Type = nextRecordType
                        });
                    }
                }
            }
        }
コード例 #5
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var oldCursor = Mouse.OverrideCursor;

            Mouse.OverrideCursor = Cursors.Wait;
            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();

                    DatabaseName = connection.Database;

                    DictionaryLabel = connection.Database;
                    NotifyPropertyChanged("DictionaryLabel");
                    DictionaryPath = connection.Database + ".dcf";
                    NotifyPropertyChanged("DictionaryPath");

                    DatabaseTables = GetTables(connection);
                    NotifyPropertyChanged("DatabaseTables");

                    LevelSpecs.Add(
                        new LevelSpec
                    {
                        Name    = connection.Database + " questionnaire",
                        IdItems = new ObservableCollection <DatabaseColumn>(),
                        Records = new ObservableCollection <RecordSpec>()
                    });
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Database Error: " + ex.Message);
                Close();
            }
            Mouse.OverrideCursor = oldCursor;
        }
コード例 #6
0
    public void generateGrid()
    {
        Debug.Log("generate called");
        if (mNodeList != null && mNodeList.Count > 0)
        {
            Debug.Log("node list exists and isn't 0");
            reset();
        }
        mLevelSpecs = gs.GetLevelSpecs();
        //set up the dimensions of the level
        int numNodes = mLevelSpecs.getNumNodes();
        //numNodes = number of nodes in the level total
        float aspectRatio = mLevelSpecs.getAspectRatio();

        mLength = (int)Mathf.Floor(Mathf.Sqrt(aspectRatio * (float)numNodes));
        mWidth  = (int)(numNodes / mLength);
        int tempID = 0;

        for (float z = 0 - Mathf.Floor(mWidth / 2.0f); z < Mathf.Ceil(mWidth / 2.0f); z += 1.0f)
        {
            for (float x = 0 - Mathf.Floor(mLength / 2.0f); x < Mathf.Ceil(mLength / 2.0f); x += 1.0f)
            {
                NodeType tempType;
                //based on user-defined wall-floor ratio, make the walls more dense or more sparse
                int ratioCheck = rand.Next(0, 100);
                if (ratioCheck <= (int)(100 * mLevelSpecs.getWallFloorRatio()))
                {
                    tempType = NodeType.WALL;
                }
                else
                {
                    tempType = NodeType.FLOOR;
                }

                //create nodes at each incremental position, with a random type
                Node tempNode = new Node(tempID, new Vector3(z, 0.0f, x), tempType);
                if (tempNode.getType() == NodeType.WALL)
                {
                    numWalls++;
                }
                else if (tempNode.getType() == NodeType.FLOOR)
                {
                    numFloors++;
                }
                //Debug.Log(tempID + tempNode.getType());
                //Debug.Log(tempID);
                mNodeList.Add(tempID, tempNode);
                tempID++;
            }
        }

        for (int i = 0; i < mNodeList.Count; i++)
        {
            float tempX = mNodeList[i].getPosition().x;
            float tempZ = mNodeList[i].getPosition().z;

            for (int j = 0; j < mNodeList.Count; j++)
            {
                float xDiff = Mathf.Abs(mNodeList[j].getPosition().x - tempX);
                float zDiff = Mathf.Abs(mNodeList[j].getPosition().z - tempZ);
                //if the x or z distance is exactly 1.0 (the size of a node) away, it is adjacent
                if (xDiff == 1.0f && zDiff == 0.0f || xDiff == 0.0f && zDiff == 1.0f)
                {
                    Debug.Log("it thinks that " + mNodeList[i].getID() + " (" + tempX + ", " + tempZ + ")[" + mNodeList[i].getType() + "] & " + mNodeList[j].getID() + " (" + mNodeList[j].getPosition().x + ", " + mNodeList[j].getPosition().z + ")[" + mNodeList[j].getType() + "] are adajcent");
                    //since adjacency is a mutual relationship, add i to j and j to i.
                    //duplicates will be rejected by the addAdjacenNode method
                    mNodeList[i].addAdjacentNode(mNodeList[j]);
                    mNodeList[j].addAdjacentNode(mNodeList[i]);
                }
            }
        }

        checkConstraints();
        foreach (KeyValuePair <int, Node> node in mNodeList)
        {
            gs.instantiateNode(node.Value);
        }
    }
コード例 #7
0
 public Grid(GridScript gs, LevelSpecs ls)
 {
     Debug.Log("grid conscructed");
     this.gs     = gs;
     mLevelSpecs = ls;
 }
コード例 #8
0
ファイル: SpawnManager.cs プロジェクト: ansoncoding/Unity
 // Start is called before the first frame update
 void Start()
 {
     levelSpecs = new LevelSpecs();
     GameManager.Instance.AddLevelObserver(this);
     StartCoroutine(SpawnCoroutine());
 }