コード例 #1
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);
            int version = reader.ReadInt();

            m_PuzzleType = (PuzzleType)reader.ReadInt();
        }
コード例 #2
0
        public ValueSelector(object textbox, PuzzleType type)
        {
            InitializeComponent();
            tbx = textbox as SudokuTextBox;

            if (type.Equals(PuzzleType.Sudoku9))
            {
                DrawSudoku9Selector();
            }
            else
            {
                DrawSudoku16Selector();
            }
            //Ellipse boundary = new Ellipse();
            //boundary.SetValue(Canvas.LeftProperty, tbx.GetValue(Canvas.LeftProperty));
            //boundary.SetValue(Canvas.TopProperty, tbx.GetValue(Canvas.TopProperty));
            //boundary.Width = tbx.Width;
            //boundary.Height =tbx.Height;
            //boundary.Stroke = new SolidColorBrush(Colors.Black);
            //boundary.StrokeThickness = 1;
            //LayoutRoot.Children.Add(boundary);



            //buitendiam
            // Ellipse buiten= new Ellipse();
            // buiten.Stroke = new SolidColorBrush(Colors.Black);
            // buiten.StrokeThickness = 1;
            // buiten.Height = tbx.Height*3;
            // buiten.Width = tbx.Width*3;
            //// LayoutRoot.Children.Add(buiten);
            // buiten.SetValue(Canvas.LeftProperty, (double)tbx.GetValue(Canvas.LeftProperty) - tbx.Width);
            // buiten.SetValue(Canvas.TopProperty, (double)tbx.GetValue(Canvas.TopProperty) -tbx.Height);
        }
コード例 #3
0
    public void StartHelpPuzzle()
    {
        if (isSolved || hasLost || hasWon)
        {
            return;
        }

        currentPuzzle = PuzzleType.Help;
        goal.SetPartColor(SquidPartType.Left, Color.white);
        goal.SetPartColor(SquidPartType.Right, Color.white);
        goal.SetPartColor(SquidPartType.Top, Color.white);

        for (int i = 0; i < (int)SquidPartType.Total; i++)
        {
            goal.SetPartColor((SquidPartType)i, Color.grey);
        }

        fishies.SetActive(true);

        topFish.Randomize();
        leftFish.Randomize();
        rightFish.Randomize();

        prompt.gameObject.SetActive(true);
        prompt.Show();
    }
コード例 #4
0
ファイル: PuzzleType.cs プロジェクト: moeheart/Cubicle
 public static void LoadScene(this PuzzleType type)
 {
     if (type == PuzzleType.BlockBuilder)
     {
         SceneManager.LoadScene("Block Builder Scene", LoadSceneMode.Single);
     }
     if (type == PuzzleType.CSG)
     {
         SceneManager.LoadScene("CSG Scene", LoadSceneMode.Single);
     }
     if (type == PuzzleType.RevolutionSolid)
     {
         SceneManager.LoadScene("Revolution Solid Scene_" + DataUtil.GetCurrentRoomId().ToString(), LoadSceneMode.Single);
     }
     if (type == PuzzleType.Unfolding)
     {
         SceneManager.LoadScene("Unfolding Scene", LoadSceneMode.Single);
     }
     if (type == PuzzleType.CubeShift)
     {
         SceneManager.LoadScene("Cube Shift Scene", LoadSceneMode.Single);
     }
     if (type == PuzzleType.ViewPoint)
     {
         SceneManager.LoadScene("View Point", LoadSceneMode.Single);
     }
     if (type == PuzzleType.PlaneExploration)
     {
         SceneManager.LoadScene("Plane Exploration", LoadSceneMode.Single);
     }
     if (type == PuzzleType.TransformLimitation)
     {
         SceneManager.LoadScene("Transform Limitation", LoadSceneMode.Single);
     }
 }
コード例 #5
0
    private void Update()
    {
        if (isSolved)
        {
            solveTimer += Time.deltaTime;
            if (solveTimer >= delay)
            {
                isSolved = false;
                win.SetActive(false);
                lose.SetActive(false);
                currentPuzzle = PuzzleType.None;

                solveTimer = 0;

                //ToDo: randomize type of puzzle.
                int rand = Random.Range(0, 2);

                if (rand == 0)
                {
                    StartMatchPuzzle();
                }
                else
                {
                    StartHelpPuzzle();
                }
            }
        }
    }
コード例 #6
0
    //Given an list of answers, combine with the main list of puzzles at the first available random index.
    void InsertAnswersIntoPuzzleList(List <Answer> answerList, PuzzleType puzzleType)
    {
        Debug.Log("Inserting puzzle type " + puzzleType + " answers into main puzzle list.");

        for (int i = 0; i < answerList.Count; i++)
        {
            answerList[i].isAddedToAnswerSet = true; //Answer is being added
            int[] answerSet = { -1, -1, -1, -1 };    //an array of ints to hold answer list indices, resets each loop

            //first randomly choose which position (up, down, right, left) the correct answer will be
            int correctAnswerPosition = random.Next(0, 3); //determine where to place the answer
            answerSet[correctAnswerPosition] = i;

            //next fill the rest of answerSet
            for (int j = 0; j < answerSet.Length; j++)
            {
                while (answerSet[j] < 0)
                {
                    //option has not been set
                    //keep attempting generate a random option
                    int answerIndex = random.Next(0, answerList.Count - 1);
                    if (answerList[answerIndex].isAddedToAnswerSet == false)
                    {
                        //answer has not been added to set
                        answerSet[j] = answerIndex;
                        answerList[answerSet[j]].isAddedToAnswerSet = true;
                    }
                }
            }

            SetAllAnswersFalse(answerList); //reset for next loop

            puzzleList[GetRandomPuzzleIndex()] = new Puzzle(i, correctAnswerPosition, puzzleType, answerSet);
        }
    }
コード例 #7
0
    public void StartMatchPuzzle()
    {
        if (isSolved || hasLost || hasWon)
        {
            return;
        }

        //Randomize goal colors
        for (int i = 0; i < (int)SquidPartType.Total; i++)
        {
            SquidPartType t = (SquidPartType)i;

            if (goal.GetPartColor((SquidPartType)i) == Color.clear)
            {
                Debug.Log("goal doesn't contain part of type: " + (SquidPartType)i);
                continue;
            }
            int rand = Random.Range(0, 8);

            switch (rand)
            {
            case 0:
                goal.SetPartColor((SquidPartType)i, Color.grey);
                break;

            case 1:
                goal.SetPartColor((SquidPartType)i, Color.blue);
                break;

            case 2:
                goal.SetPartColor((SquidPartType)i, Color.cyan);
                break;

            case 3:
                goal.SetPartColor((SquidPartType)i, Color.green);
                break;

            case 4:
                goal.SetPartColor((SquidPartType)i, Color.yellow);
                break;

            case 5:
                goal.SetPartColor((SquidPartType)i, Color.red);
                break;

            case 6:
                goal.SetPartColor((SquidPartType)i, Color.magenta);
                break;

            case 7:
                goal.SetPartColor((SquidPartType)i, Color.white);
                break;
            }

            currentPuzzle = PuzzleType.Match;

            prompt.gameObject.SetActive(true);
            prompt.Show();
        }
    }
コード例 #8
0
        public const uint BIT_MASK    = 15;  // upper bound of the BITS_PER_POS range

        public PatternDatabase(PuzzleType type)
        {
            this.type = type;
            InitDatabase();
            if (type != PuzzleType.PUZZLE_3x3)  // 3x3 puzzle will use online-calculated Manahattan distance,
                                                // because the lookup time is almost the same and there is no need of PatternDB for puzzle of this size
            {
                if (!FileExists())
                {
                    for (int partition = 0; partition < parts; partition++)
                    {
                        BreadthFirstSearchGenerator(partition);
                        CleanDatabase(partition);
                        // optional space-optimization: mirror configurations
                        // optional space-optimization: clean the database: remove all values <= node.Manahattan()
                        // -> don't use that, because I want to have all precomputed (it doesn't take so much of space)
                    }
                    SaveToFile();
                }
                else
                {
                    LoadFromFile();
                }
            }
        }
コード例 #9
0
 public PuzzleTile(int x, int y, PuzzleType type, int id)
 {
     collision       = TileTerrain.Passable;
     position        = new Vector2(x, y);
     this.type       = type;
     this.id         = id;
     puzzleCompleted = false;
 }
コード例 #10
0
ファイル: Room.cs プロジェクト: moeheart/Cubicle
 public void Initialize(int id, Vector3 position, Vector3 dimension, Color color, PuzzleType puzzleType)
 {
     this.id                 = id;
     this.position           = position;
     this.dimension          = dimension;
     this.color              = color;
     this.puzzleType         = puzzleType;
     this.transform.position = position;
     this.isUnlocked         = false;
 }
コード例 #11
0
 public Puzzle(int answerIndex,
               int correctAnswerPosition,
               PuzzleType puzzleType,
               int[] options)
 {
     this.answerIndex           = answerIndex;
     this.correctAnswerPosition = correctAnswerPosition;
     this.isAddedToGame         = true;
     this.puzzleType            = puzzleType;
     this.options = options;
 }
コード例 #12
0
        public void LoadAsync(PuzzleType type)
        {
            if (this.worker != null &&
                this.worker.IsBusy)
            {
                return;
            }

            this.worker = new BackgroundWorker();
            this.worker.WorkerSupportsCancellation = true;
            this.worker.WorkerReportsProgress      = true;
            this.worker.DoWork             += new DoWorkEventHandler(worker_DoWork);
            this.worker.ProgressChanged    += new ProgressChangedEventHandler(worker_ProgressChanged);
            this.worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
            this.worker.RunWorkerAsync(type);
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: lukaszewskimar/n-puzzle
        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            puzzle_panel.Controls.Clear();
            goal_panel.Controls.Clear();

            PuzzleType type = puzzletype_comboBox.SelectedItem as PuzzleType;
            int        size = 400 / type.N;
            int        k    = 1;

            for (int i = 0; i < type.N; i++)
            {
                for (int j = 0; j < type.N; j++)
                {
                    // initial state
                    NumericUpDown iT = new NumericUpDown();
                    iT.Name   = "i_" + i.ToString() + "," + j.ToString();
                    iT.Width  = size;
                    iT.Height = size;
                    iT.Top    = i * size;
                    iT.Left   = j * size;
                    iT.Controls.RemoveAt(0);
                    this.puzzle_panel.Controls.Add(iT);

                    // goal state
                    NumericUpDown gT = new NumericUpDown();
                    gT.Name   = "g_" + i.ToString() + "," + j.ToString();
                    gT.Width  = size;
                    gT.Height = size;
                    gT.Top    = i * size;
                    gT.Left   = j * size;
                    gT.Controls.RemoveAt(0);
                    gT.Text = (k).ToString();

                    if (i != type.N - 1 || j != type.N - 1)
                    {
                        gT.Text = (k).ToString();
                    }
                    else
                    {
                        gT.Text = (0).ToString();
                    }

                    this.goal_panel.Controls.Add(gT);
                    k++;
                }
            }
        }
コード例 #14
0
    private void Generate()
    {
        puzzleType    = (PuzzleType)UnityEngine.Random.Range(0, 3);
        matchesToMove = UnityEngine.Random.Range(1, 4);
        int    nPuzzles = MatcheMaticsData.puzzles[(int)puzzleType].Length;
        string puzzle   = MatcheMaticsData.puzzles[(int)puzzleType][UnityEngine.Random.Range(0, nPuzzles)];

        matchesToMove = int.Parse("" + puzzle[4]);
        texts[0].text = puzzleType + " " + matchesToMove;
        texts[1].text = "" + puzzle[3];
        operation     = (Operation)operationSymbols.IndexOf(puzzle[3]);
        for (int i = 0; i < 3; i++)
        {
            numbers[i] = int.Parse("" + puzzle[i]);
        }
        Log("LEVEL GENERATED: Level type:" + texts[0].text + " Initial digits:" + numbers[0] + numbers[1] + numbers[2] + " Operation:" + texts[1].text);
        ResetDigits();
    }
コード例 #15
0
    public void OnPuzzleCompleted(PuzzleType type)
    {
        if (Puzzle2DTotal == 0)
        {
            _allpuzzle2DDone = true;
        }
        if (Puzzle3DTotal == 0)
        {
            _allpuzzle3DDone = true;
        }

        if (type == PuzzleType.T2D)
        {
            if ((Completed2DPuzzles + 1) < Puzzle2DTotal)
            {
                Completed2DPuzzles++;
                Progression.PuzzlesComplete++;
            }
            else
            {
                _allpuzzle2DDone = true;
                Progression.PuzzlesComplete++;
            }
        }
        else if (type == PuzzleType.T3D)
        {
            if ((Completed3DPuzzles + 1) < Puzzle3DTotal)
            {
                Completed3DPuzzles++;
                Progression.PuzzlesComplete++;
            }
            else
            {
                _allpuzzle3DDone = true;
                Progression.PuzzlesComplete++;
            }
        }

        if (_allpuzzle3DDone && _allpuzzle2DDone)
        {
            AllPuzzlesCompleted.Invoke();
        }
    }
コード例 #16
0
        public void ConfigureOnPlacement(RoomHandler room)
        {
            if (room == null | string.IsNullOrEmpty(room.GetRoomName()))
            {
                m_SelectedType = PuzzleType.None;
                return;
            }

            m_ParentRoom = room;

            if (room.GetRoomName().ToLower().StartsWith(ExpandRoomPrefabs.PuzzleRoom1.name.ToLower()))
            {
                m_SelectedType = PuzzleType.HideKeyOnRandomEnemy;
            }
            else if (room.GetRoomName().ToLower().StartsWith(ExpandRoomPrefabs.PuzzleRoom2.name.ToLower()))
            {
                m_SelectedType = PuzzleType.HideKeyOnTable;
            }
            else if (room.GetRoomName().ToLower().StartsWith(ExpandRoomPrefabs.PuzzleRoom3.name.ToLower()))
            {
                m_SelectedType = PuzzleType.BuildFakeWall;
            }
            else if (room.GetRoomName().ToLower().StartsWith(ExpandRoomPrefabs.SecretRewardRoom.name.ToLower()))
            {
                m_SelectedType = PuzzleType.PlaceChestPuzzle;
            }
            else if (room.GetRoomName().ToLower().StartsWith(ExpandRoomPrefabs.SecretBossRoom.name.ToLower()))
            {
                m_SelectedType = PuzzleType.SetupRatBoss;
            }
            else if (room.GetRoomName().ToLower().StartsWith(ExpandRoomPrefabs.Expand_West_Entrance.name.ToLower()))
            {
                m_SelectedType = PuzzleType.PlaceWinchesterSign;
            }
            else if (room.GetRoomName().ToLower().StartsWith(ExpandRoomPrefabs.Expand_West_SecretHub2.name.ToLower()))
            {
                m_SelectedType = PuzzleType.PlaceHubSign;
            }
            else
            {
                m_SelectedType = PuzzleType.None;
            }
        }
コード例 #17
0
    void HandleOptionsUpdating(PuzzleType puzzleType, List <Answer> answerList, Puzzle puzzle)
    {
        upOptionImage.SetActive(false);
        downOptionImage.SetActive(false);
        rightOptionImage.SetActive(false);
        leftOptionImage.SetActive(false);
        upOptionText.SetActive(false);
        downOptionText.SetActive(false);
        rightOptionText.SetActive(false);
        leftOptionText.SetActive(false);

        if (puzzleType == PuzzleType.MediumAnimalType ||
            puzzleType == PuzzleType.ExpressionType ||
            puzzleType == PuzzleType.ObjectType ||
            puzzleType == PuzzleType.HardFlagType ||
            puzzleType == PuzzleType.HardAnimalType ||
            puzzleType == PuzzleType.MediumFlagType)
        {
            //puzzle is image based
            //Update OptionImages
            upOptionImage.SetActive(true);
            downOptionImage.SetActive(true);
            rightOptionImage.SetActive(true);
            leftOptionImage.SetActive(true);
            upOptionImage.GetComponent <Image>().sprite    = answerList[puzzle.options[0]].imageAnswer;
            downOptionImage.GetComponent <Image>().sprite  = answerList[puzzle.options[1]].imageAnswer;
            rightOptionImage.GetComponent <Image>().sprite = answerList[puzzle.options[2]].imageAnswer;
            leftOptionImage.GetComponent <Image>().sprite  = answerList[puzzle.options[3]].imageAnswer;
        }
        else
        {
            //puzzle is text based
            //update option text
            upOptionText.SetActive(true);
            downOptionText.SetActive(true);
            rightOptionText.SetActive(true);
            leftOptionText.SetActive(true);
            upOptionText.GetComponent <TextMeshProUGUI>().SetText(answerList[puzzle.options[0]].textAnswer);
            downOptionText.GetComponent <TextMeshProUGUI>().SetText(answerList[puzzle.options[1]].textAnswer);
            rightOptionText.GetComponent <TextMeshProUGUI>().SetText(answerList[puzzle.options[2]].textAnswer);
            leftOptionText.GetComponent <TextMeshProUGUI>().SetText(answerList[puzzle.options[3]].textAnswer);
        }
    }
コード例 #18
0
ファイル: ShenzhenTypes.cs プロジェクト: qrvd/ShenzhenMod
        public ShenzhenTypes(ModuleDefinition module)
        {
            Module  = module;
            BuiltIn = module.TypeSystem;

            GameLogic      = new GameLogicType(module);
            Globals        = new GlobalsType(module);
            Index2         = new Index2Type(module);
            L              = new LType(module);
            MessageThread  = new MessageThreadType(module);
            MessageThreads = new MessageThreadsType(module);
            Optional       = new OptionalType(module);
            Puzzle         = new PuzzleType(module);
            Puzzles        = new PuzzlesType(module);
            Terminal       = new TerminalType(module);
            TextureManager = new TextureManagerType(module);
            Traces         = new TracesType(module);

            Solution = new SolutionType(module, Traces);
        }
コード例 #19
0
    public void CreatePuzzle(PuzzleType type, int controllerID, int combinationSize = 3, bool randCombination = true, bool randAlternative = true)
    {
        isComplete = false;

        puzzleType = type;
        ResetCombination();

        percentage = 0;

        this.controllerID = controllerID;

        buttonSelected = UnityEngine.Random.Range(0, randButton.Length);

        if (randCombination)
        {
            RandomizeCombination(combinationSize);
        }

        if (randAlternative)
        {
            RandomizeAlternate();
        }

        nextPress = altButton[0];

        switch (puzzleType)
        {
        case PuzzleType.Press:
            keycodeVariable.keyCodes = new ButtonCode[] { randButton[buttonSelected] };
            break;

        case PuzzleType.Alternate:
            keycodeVariable.keyCodes = altButton;
            break;

        case PuzzleType.Combination:
            keycodeVariable.keyCodes = combButtons;
            break;
        }
    }
コード例 #20
0
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            PuzzleType type = (PuzzleType)e.Argument;

            Assembly assembly   = Assembly.GetEntryAssembly();
            string   dataFolder = Path.GetDirectoryName(assembly.Location);

            dataFolder = Path.Combine(dataFolder, @"Data\Puzzle\" + PuzzleSetting.Instance.Type.ToString());

            DirectoryInfo di = null;

            if (!Directory.Exists(dataFolder))
            {
                di = Directory.CreateDirectory(dataFolder);
            }
            else
            {
                di = new DirectoryInfo(dataFolder);
            }

            FileInfo[] fis = di.GetFiles("*.pd");
            foreach (FileInfo fi in fis)
            {
                try
                {
                    PuzzleItem pi = PuzzleData.LoadPuzzleItem(fi.FullName);
                    if (pi.Type != type)
                    {
                        continue;
                    }
                    pi.ImageFile = fi.FullName;
                    worker.ReportProgress(0, pi);
                }
                catch (Exception ex)
                {
                    Debug.Assert(false, ex.Message);
                }
            }
        }
コード例 #21
0
 public PuzzleConnection(Point position, PuzzleType type)
 {
     Position = position;
     Type     = type;
 }
コード例 #22
0
ファイル: ControllerPuzzle.cs プロジェクト: Dsalce/TMIKinect
 /// <summary>
 /// ControllerPuzzle constructor
 /// </summary>
 public ControllerPuzzle(PuzzleType puzz)
 {
     this.puz     = new PuzzleModel();
     this.puzView = puzz;
 }
コード例 #23
0
ファイル: Program.cs プロジェクト: lukaszewskimar/n-puzzle
        private async void start_button_Click(object sender, EventArgs e)
        {
            this.results_button.Visible      = false;
            this.puzzletype_comboBox.Enabled = false;
            this.heuristics_comboBox.Enabled = false;
            this.start_button.Enabled        = false;
            this.stop_button.Enabled         = true;
            this.loading_panel.Visible       = true;
            this.error_message.Visible       = false;
            PuzzleType    type      = puzzletype_comboBox.SelectedItem as PuzzleType;
            HeuristicType heuristic = heuristics_comboBox.SelectedItem as HeuristicType;

            int[,] initial = new int[type.N, type.N];
            // prepare initial state
            foreach (Control item in puzzle_panel.Controls.OfType <NumericUpDown>())
            {
                item.Enabled = false;
                string location = item.Name.Replace("i_", "");
                int    i        = int.Parse(location.Split(',')[0]);
                int    j        = int.Parse(location.Split(',')[1]);

                if (string.IsNullOrEmpty(item.Text))
                {
                    initial[i, j] = 0;
                }
                else
                {
                    initial[i, j] = int.Parse(item.Text);
                }
            }

            Puzzle initialState = new Puzzle(initial);

            int[,] goal = new int[type.N, type.N];
            // prepare goal state
            foreach (Control item in goal_panel.Controls.OfType <NumericUpDown>())
            {
                item.Enabled = false;
                string location = item.Name.Replace("g_", "");
                int    i        = int.Parse(location.Split(',')[0]);
                int    j        = int.Parse(location.Split(',')[1]);

                if (string.IsNullOrEmpty(item.Text))
                {
                    goal[i, j] = 0;
                }
                else
                {
                    goal[i, j] = int.Parse(item.Text);
                }
            }

            Puzzle goalState = new Puzzle(goal);

            try
            {
                AStar  aStar  = new AStar(initialState, goalState);
                Result result = await Task.Run(() => aStar.Run(cts.Token, (Heuristic)heuristic.ID));

                this.results_button.Visible      = true;
                this.results_panel.Visible       = true;
                this.main_panel.Visible          = false;
                this.aboutSoftware_panel.Visible = false;
                this.closed_textBox.Text         = result.Closed.ToString();
                this.open_textbox.Text           = result.Open.ToString();

                Dictionary <int, List <Branch> > tree = new Dictionary <int, List <Branch> >();
                foreach (var item in result.Path)
                {
                    if (tree.ContainsKey(item.G))
                    {
                        tree[item.G].Add(item);
                    }
                    else
                    {
                        tree.Add(item.G, new List <Branch> {
                            item
                        });
                    }
                }
                Display(tree, results_textBox);
            }
            catch (OperationCanceledException)
            {
                cts = new CancellationTokenSource();
            }
            catch (Exception ex)
            {
                this.error_message.Text    = "Błąd: " + ex.Message;
                this.error_message.Visible = true;
            }
            finally {
                this.loading_panel.Visible       = false;
                this.puzzletype_comboBox.Enabled = true;
                this.heuristics_comboBox.Enabled = true;
                this.start_button.Enabled        = true;
                this.stop_button.Enabled         = false;

                foreach (Control item in puzzle_panel.Controls.OfType <NumericUpDown>())
                {
                    item.Enabled = true;
                }
                foreach (Control item in goal_panel.Controls.OfType <NumericUpDown>())
                {
                    item.Enabled = true;
                }
            }
        }
コード例 #24
0
ファイル: World.cs プロジェクト: moeheart/Cubicle
    private void ParseJsonString(string data)
    {
        Dictionary <string, object> dict;

        dict = Json.Deserialize(data) as Dictionary <string, object>;

        //The first run builds the walls and floors of the rooms
        foreach (KeyValuePair <string, object> entry in dict)
        {
            //entry.key should be a string, which is the roomId
            //entry.value should be a dictionary type, which contains the room information

            int   roomId = int.Parse(entry.Key);
            float posX, posY, posZ;
            float dimX, dimY, dimZ;
            float colorR, colorG, colorB, colorA;

            Dictionary <string, object> entryValueDict = (Dictionary <string, object>)entry.Value;
            List <object> positionList = ((List <object>)entryValueDict["position"]);
            List <object> dimensionList = ((List <object>)entryValueDict["dimension"]);
            List <object> colorList    = ((List <object>)entryValueDict["color"]);

            posX   = System.Convert.ToSingle(positionList[0]) * lengthPerUnit;
            posY   = System.Convert.ToSingle(positionList[1]) * lengthPerUnit;
            posZ   = System.Convert.ToSingle(positionList[2]) * lengthPerUnit;
            dimX   = System.Convert.ToSingle(dimensionList[0]);
            dimY   = System.Convert.ToSingle(dimensionList[1]);
            dimZ   = System.Convert.ToSingle(dimensionList[2]);
            colorR = System.Convert.ToSingle(colorList[0]);
            colorG = System.Convert.ToSingle(colorList[1]);
            colorB = System.Convert.ToSingle(colorList[2]);
            colorA = System.Convert.ToSingle(colorList[3]);

            string puzzleTypeString = (string)entryValueDict["puzzle type"];

            Vector3    position   = new Vector3(posX, posY, posZ);
            Vector3    dimension  = new Vector3(dimX, dimY, dimZ);
            Color      color      = new Color(colorR, colorG, colorB, colorA);
            PuzzleType puzzleType = PuzzleType.None;

            puzzleType = PuzzleTypes.GetTypeFromString(puzzleTypeString);

            Room room = Instantiate(roomPrefab) as Room;
            room.Initialize(roomId, position, dimension, color, puzzleType);
            rooms.Add(roomId, room);

            BuildRoom(position, dimension, color);
        }

        //The second run replaces blocks with doors between adjacent rooms
        foreach (KeyValuePair <string, object> entry in dict)
        {
            int  id1   = int.Parse(entry.Key);
            Room room1 = rooms[id1];
            //Dictionary<string, object> entryValueDict = (Dictionary<string,object>)entry.Value;
            //List<object> adjacentRooms = ((List<object>) entryValueDict["adjacent"]);
            for (int i = 0; i < id1; ++i)
            {
                int  id2   = i;
                Room room2 = rooms[id2];
                BuildTunnel(room1, room2);
            }
        }

        //The third run parses "doors to unlock"
        foreach (KeyValuePair <string, object> entry in dict)
        {
            int  id   = int.Parse(entry.Key);
            Room room = rooms[id];
            Dictionary <string, object> entryValueDict = (Dictionary <string, object>)entry.Value;
            if (entryValueDict.ContainsKey("doors to unlock") == true)
            {
                List <object> doorsToUnlock = ((List <object>)entryValueDict["doors to unlock"]);
                room.doorsToUnlock = new List <Door>();
                Debug.Log("newing..");
                foreach (object objPair in doorsToUnlock)
                {
                    List <object> pair = (List <object>)objPair;
                    int           r1   = System.Convert.ToInt32(pair[0]);
                    int           r2   = System.Convert.ToInt32(pair[1]);
                    IntVector2    v1   = new IntVector2(r1, r2);
                    IntVector2    v2   = new IntVector2(r2, r1);
                    if (doors.ContainsKey(v1))
                    {
                        room.doorsToUnlock.Add(doors[v1]);
                    }
                    else if (doors.ContainsKey(v2))
                    {
                        room.doorsToUnlock.Add(doors[v2]);
                    }
                }
            }

            if (entryValueDict.ContainsKey("unlock on start") == true)
            {
                List <object> unlockOnStart = ((List <object>)entryValueDict["unlock on start"]);
                foreach (object objR in unlockOnStart)
                {
                    int        r  = System.Convert.ToInt32(objR);
                    IntVector2 v1 = new IntVector2(id, r);
                    IntVector2 v2 = new IntVector2(r, id);
                    if (doors.ContainsKey(v1))
                    {
                        doors[v1].Unlock();
                    }
                    else if (doors.ContainsKey(v2))
                    {
                        doors[v2].Unlock();
                    }
                }
            }
        }
    }
コード例 #25
0
 public Puzzle(PuzzleType type, PuzzleDirection direction)
 {
     Type      = type;
     Direction = direction;
 }
コード例 #26
0
ファイル: Puzzle.cs プロジェクト: THTBa/SLight
 public void AddPuzzle(Puzzle p, PuzzleType t)
 {
     puzzles.Add(p);
     puzzleTypes.Add(t);
 }
コード例 #27
0
ファイル: PuzzleBox.cs プロジェクト: Crome696/ServUO
		public override void Deserialize(GenericReader reader) 
		{
			base.Deserialize(reader);
			int version = reader.ReadInt();
			m_PuzzleType = (PuzzleType)reader.ReadInt();
		}
コード例 #28
0
 public PuzzleBox(PuzzleType type) : base(2472)
 {
     m_PuzzleType = type;
     Movable      = false;
 }
コード例 #29
0
ファイル: PuzzleBox.cs プロジェクト: Crome696/ServUO
		public PuzzleBox(PuzzleType type) : base(2472) 
		{
			m_PuzzleType = type;
            Movable = false;
		}
コード例 #30
0
    public void InitializePuzzleSteps(PuzzleType type)
    {
        // get transforms
        Transform[] allChilds = transform.GetComponentsInChildren <Transform>();
        // filter transforms that match tags
        List <Transform> filteredTransforms = new List <Transform>();

        foreach (Transform t in allChilds)
        {
            if (t.tag.ToLower() == "puzzleinteraction")
            {
                filteredTransforms.Add(t);
                Debug.Log($"Adding {t.name} to filteredTransforms");
            }
        }
        int numberOfSteps = 0;

        switch (type)
        {
        case PuzzleType.Find:
            numberOfSteps = filteredTransforms.Count;
            break;

        case PuzzleType.FindTool:
            numberOfSteps = 2;     // one step will be to find the tool, the other will be to use the tool to find the key
            break;

        case PuzzleType.ImageOrientation:
            numberOfSteps = 1;     // can either be bookshelf or painting (todo)
            break;

        case PuzzleType.PaintingFix:
            return;

            break;
        }
        Debug.Log($"numberOfSteps = {numberOfSteps}");

        // NOw got number of puzzle transforms that we will neeed
        // next step is to choose which Transforms to use

        List <Transform> puzzlePieces = new List <Transform>();

        for (int i = 0; i < numberOfSteps; i++)
        {
            // pick a random transform to do puzzle with
            Transform selected = filteredTransforms[UnityEngine.Random.Range(0, filteredTransforms.Count)];
            puzzlePieces.Add(selected);
            // remove that transform from the pool so it cannot be selected again
            filteredTransforms.Remove(selected);
        }
        // now we have chosen the puzzle transforms
        // gotta deactivate the unused transforms by removing certain components
        foreach (Transform t in filteredTransforms)
        {
            // remove collider
            Destroy(t.GetComponent <BoxCollider2D>());
            // remove interactability
            Destroy(t.GetComponent <InteractableObject>());
        }
        // now need to setup the remaining puzzle pieces and their components/properties
        Transform          select;
        InteractableObject interact;

        switch (type)
        {
        case PuzzleType.Find:
            // set all the default properties for each puzzlepiece
            SetDefaultPuzzlePieces(puzzlePieces.ToArray());
            // now pick a random puzzle piece to hide the puzzleitem in
            select            = puzzlePieces[UnityEngine.Random.Range(0, puzzlePieces.Count)];
            interact          = select.GetComponent <InteractableObject>();
            interact.itemDrop = InteractableObject.itemType.Key;
            break;

        case PuzzleType.FindTool:
            // set all the default properties for each puzzlepiece
            SetDefaultPuzzlePieces(puzzlePieces.ToArray());
            // now pick a random piece to hide the tool in
            select = puzzlePieces[UnityEngine.Random.Range(0, puzzlePieces.Count)];
            puzzlePieces.Remove(select);
            interact          = select.GetComponent <InteractableObject>();
            interact.itemDrop = InteractableObject.itemType.PryTool;
            // now pick a random piece to hide the other thing in
            select = puzzlePieces[UnityEngine.Random.Range(0, puzzlePieces.Count)];
            puzzlePieces.Remove(select);
            interact                 = select.GetComponent <InteractableObject>();
            interact.itemDrop        = InteractableObject.itemType.Key;
            interact.itemRequirement = InteractableObject.itemType.PryTool;
            break;
        }
    }