Example #1
0
        public void ModelFacade_MoveToSublocation()
        {
            LocationModel workingLM = gs.GetLM();

            Assert.AreEqual(1, workingLM.GetSubLocation().GetSublocationID(), "Should be at sublocation 1");
            Assert.IsTrue(mf.ChangeSubLocation(gs, 2), "Should be able to goto sublocation 2");
            Assert.AreEqual(2, workingLM.GetSubLocation().GetSublocationID(), "Should be at sublocation 2");
            Assert.IsFalse(mf.ChangeSubLocation(gs, 3), "Should not be able to goto sublocation 3");
            Assert.AreEqual(2, workingLM.GetSubLocation().GetSublocationID(), "Should still be at sublocation 2");

            Assert.IsTrue(mf.ChangeLocation(gs, 20), "Moving to 20 should be successful");
            Assert.IsNull(workingLM.GetSubLocation(), "Sublocation should be null");
            Assert.IsTrue(mf.ChangeSubLocation(gs, 1), "Should be able to goto sublocation 1");
            Assert.AreEqual(1, workingLM.GetSubLocation().GetSublocationID(), "Should be at sublocation 1");
            Assert.IsTrue(mf.ChangeSubLocation(gs, 2), "Should be able to goto sublocation 2");
            Assert.AreEqual(2, workingLM.GetSubLocation().GetSublocationID(), "Should be at sublocation 2");
            Assert.IsFalse(mf.ChangeSubLocation(gs, 10), "Should not be able to goto sublocation 10");
        }
Example #2
0
        /// <summary>
        /// Change sublocation to sublocation provided
        /// </summary>
        /// <param name="sublocationID">ID of the sublocation to move to</param>
        /// <returns>If the move was sucessful</returns>
        public bool ChangeSubLocation(int sublocationID)
        {
            if (mf.CanAffordMove(gs, ModelFacade.SUBLOCATION_MOVE_COST))
            {
                mf.ReduceResourcesByMoveCost(gs, ModelFacade.SUBLOCATION_MOVE_COST);

                // Thread 1 - Change sublocation
                var task1 = Task.Factory.StartNew(() =>
                {
                    mf.ChangeSubLocation(gs, sublocationID);
                    dc.UpdatePlayerStatus(gs.Clone() as GameState);
                });
                // Main Thread - Animate movement
                gameView.AnimateFrames(null);
                Task.WaitAll(task1);
                delayEndAnimation();
                return(true);
            }
            else
            {
                if (gameView.DrawYesNoOption("You do not have sufficient resources. Do you wish to risk it all?"))
                {
                    int risk = rnd.Next(1, 101);
                    if (risk <= 25)
                    {
                        // Thread 1 - Change sublocation
                        var task1 = Task.Factory.StartNew(() =>
                        {
                            mf.ChangeSubLocation(gs, sublocationID);
                            dc.UpdatePlayerStatus(gs.Clone() as GameState);
                        });
                        // Main Thread - Animate movement
                        gameView.AnimateFrames(null);
                        Task.WaitAll(task1);
                        delayEndAnimation();
                        return(true);
                    }
                    mf.ReduceResourcesByMoveCost(gs, ModelFacade.SUBLOCATION_MOVE_COST);
                    return(false);
                }
                return(false);
            }
        }