public void GetSetTest()
        {
            // init + get
            MiniBoard board = new MiniBoard(5, 5);

            for (int i = 0; i < 25; i++)
            {
                Assert.AreEqual(i, (int)board.Get(i), "init + get");
            }
            //
            // set + get from i = [0,12]
            board.Set(6, 10);
            Assert.AreEqual(10, (int)board.Get(6), "set + get from i = [0,11]");
            //
            // set + get from i = [13,24]
            board.Set(18, 10);
            Assert.AreEqual(10, (int)board.Get(18), "set + get from i = [12,23]");
            //
            // set + get from i = [25]
            board.Set(24, 10);
            Assert.AreEqual(10, (int)board.Get(24), "set + get from i = [24]");
            //
            // get: out of range exception
            bool thrown = false;

            try { board.Get(25); }
            catch (IndexOutOfRangeException ex) { thrown = true; }
            Assert.IsTrue(thrown, "get: out of range exception");
            //
            // set: out of range exception
            thrown = false;
            try { board.Set(25, 25); }
            catch (IndexOutOfRangeException ex) { thrown = true; }
            Assert.IsTrue(thrown, "set: out of range exception");
        }
Esempio n. 2
0
    //Awake is always called before any Start functions
    void Awake()
    {
        //Check if instance already exists
        if (instance == null)
        {
            //if not, set instance to this
            instance = this;
        }

        //If instance already exists and it's not this:
        else if (instance != this)
        {
            //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
            Destroy(gameObject);
        }

        //Sets this to not be destroyed when reloading scene
        DontDestroyOnLoad(gameObject);

        //Get a component reference to the attached Map script
        mapScript       = GetComponent <Map>();
        playerScript    = GetComponent <Player>();
        boardScript     = GetComponent <Board>();
        miniBoardScript = GetComponent <MiniBoard>();

        //Call the InitGame function to initialize the first level
        InitGame();
    }
Esempio n. 3
0
    // Use this for initialization
    void Start()
    {
        playerSprites = Resources.LoadAll <Sprite>("playerSprites");
        //Debug.Log("Number of sprites:  "+playerSprites.Length);

        map       = gameObject.GetComponent <Map>();
        plr       = gameObject.GetComponent <Player>();
        miniBoard = gameObject.GetComponent <MiniBoard>();
    }
        public ActionResult Index(int?id, string errMessage = "",
                                  bool sectionOpen          = false, bool categoryOpen     = false, bool tagOpen     = false,
                                  bool sectionEditOpen      = false, bool categoryEditOpen = false, bool tagEditOpen = false, bool boardEditOpen = false, bool cardEditOpen = false)
        {
            BoardViewModel view = new BoardViewModel();
            string         user = User.Identity.GetUserId();

            if (db.Boards.Where(b => b.OwnerID == user).Count() > 0)
            {
                List <Board>     boards     = db.Boards.Where(b => b.OwnerID == user).ToList();
                List <MiniBoard> miniBoards = new List <MiniBoard>();
                foreach (var b in boards)
                {
                    MiniBoard m = new MiniBoard(b.ID, b.Title);
                    miniBoards.Add(m);
                }
                view.Boards = miniBoards;

                if (id == null)
                {
                    view.SelectedBoard = boards.FirstOrDefault();
                }
                else
                {
                    Board origBoard = db.Boards.Find(id);
                    if (origBoard == null)
                    {
                        return(HttpNotFound());
                    }
                    Board selectedBoard = boards.Where(b => b.ID == id).FirstOrDefault();
                    if (selectedBoard == null)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
                    }
                    view.SelectedBoard = selectedBoard;
                }

                SectionRow row = new SectionRow();
                view.SectionTable = row.getTable(view.SelectedBoard.Sections.ToList());
                foreach (var r in view.SectionTable)
                {
                    r.Row = r.Row.OrderBy(rr => rr.Order).ToList();
                }
                view.ActiveSections = row.getActiveSections(view.SelectedBoard.Sections.ToList(), view.SectionTable);
                List <Section> sections = view.SelectedBoard.Sections.OrderBy(s => s.ParentID).ThenBy(s => s.Order).ToList();
                view.SelectedBoard.Sections = sections;
                List <Card> cards = new List <Card>();
                foreach (var item in view.ActiveSections)
                {
                    cards.AddRange(item.Cards);
                    List <Card> orderCards = item.Cards.OrderBy(c => c.Order).ToList();
                    item.Cards = orderCards;
                }
                ViewBag.uncategorizedCards = cards.Count > 0 ? true : false;
            }

            ViewBag.sectionOpen      = sectionOpen;
            ViewBag.categoryOpen     = categoryOpen;
            ViewBag.tagOpen          = tagOpen;
            ViewBag.sectionEditOpen  = sectionEditOpen;
            ViewBag.categoryEditOpen = categoryEditOpen;
            ViewBag.tagEditOpen      = tagEditOpen;
            ViewBag.boardEditOpen    = boardEditOpen;
            ViewBag.cardEditOpen     = cardEditOpen;
            ViewBag.errorMessage     = errMessage;
            return(View(view));
        }
Esempio n. 5
0
    public void LoadGame()
    {
        Board     board     = GetComponent <Board>();
        MiniBoard miniBoard = GetComponent <MiniBoard>();
        Player    plr       = GetComponent <Player>();

        BinaryFormatter bf    = new BinaryFormatter();
        FileStream      file  = File.Open(Application.persistentDataPath + "/map.dat", FileMode.Open);
        int             fSeed = (int)bf.Deserialize(file);

        int[][] fCells = (int[][])bf.Deserialize(file);
        int     fX     = (int)bf.Deserialize(file);
        int     fY     = (int)bf.Deserialize(file);

        bool[][] fExplored = (bool[][])bf.Deserialize(file);
        bool     fT        = (bool)bf.Deserialize(file);

        // deserialize room data
        rooms.Clear();
        int sr = (int)bf.Deserialize(file);

        for (int r = 0; r < sr; r++)
        {
            int   sID    = (int)bf.Deserialize(file);
            float sRectX = (float)bf.Deserialize(file);
            float sRectY = (float)bf.Deserialize(file);
            float sRectW = (float)bf.Deserialize(file);
            float sRectH = (float)bf.Deserialize(file);
            Rect  sRect  = new Rect(sRectX, sRectY, sRectW, sRectH);
            rooms.Add(new Room(sID, sRect));
        }

        // deserialize hall data
        halls.Clear();
        int sh = (int)bf.Deserialize(file);

        for (int h = 0; h < sh; h++)
        {
            int hID = (int)bf.Deserialize(file);
            halls.Add(new Hall(hID));
        }

        // deserialize conn data
        int sc = (int)bf.Deserialize(file);

        for (int c = 0; c < sc; c++)
        {
            int cID     = (int)bf.Deserialize(file);
            int cX      = (int)bf.Deserialize(file);
            int cY      = (int)bf.Deserialize(file);
            int cReg1   = (int)bf.Deserialize(file);
            int cReg2   = (int)bf.Deserialize(file);
            int cType   = (int)bf.Deserialize(file);
            int cOrient = (int)bf.Deserialize(file);
            connectors.Add(new Connector(cID, cX, cY, cReg1, cReg2, cType, cOrient));
        }

        //Debug.Log("Loaded map...");
        file.Close();

        seed  = fSeed;
        cells = fCells;
        ClearHallCrumbsAndSetHallPaths();
        plr.X    = fX;
        plr.Y    = fY;
        explored = fExplored;
        board.SetTorch(fT);

        board.ResetBoard();
        miniBoard.UpdateMiniBoard();
    }