示例#1
0
        /**
         * Constructor
         */
        public GameView(GameBoxForm parent, GameLogic logic, GameData data, CreditSystem credit)
        {
            InitializeComponent();

            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);

            //performance buff
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

            _parent = parent;

            bullets      = new List <Bullet>();
            alienbullets = new List <Bullet>();
            this.credit  = credit;

            this.logic = logic;

            this.data = data;
            this.logic.SetGameView(this);


            scoreUtil = new ScoreUtility();

            logic.SetScoreUtil(scoreUtil);

            lblHighScore.Text = scoreUtil.getTopScore().ToString();
            InitializeStartScreen();
            InitializeGameObjects();
            this.logic.SetupCollisionHandler();
            fpsTimer.Start();
        }
示例#2
0
        /**
         * Displays the game itself
         */
        public void startGame()
        {
            data   = new GameData();
            credit = new CreditSystem();
            logic  = new GameLogic(this);
            logic.SetCreditSystem(credit);
            logic.SetGameData(data);

            /*game.SetGameLogic(logic);
             * game.SetGameData(data);
             * game.SetCreditSystem(credit);
             * logic.SetGameView(game);*/


            highScoreForm = new HighScoreForm(logic);
            game          = new GameView(this, logic, data, credit);


            game.Location = new Point(80, 90);
            this.Controls.Add(game);

            initalsForm          = new InitalsForm(logic);
            initalsForm.Location = new Point(80, 90);
            this.Controls.Add(initalsForm);
            initalsForm.Visible = false;

            highScoreForm.Location = new Point(80, 90);
            this.Controls.Add(highScoreForm);
            highScoreForm.Visible = false;
        }
示例#3
0
        public void TestCreditLimits()
        {
            CreditSystem credit = new CreditSystem();

            credit.AddCredit();
            credit.AddCredit();
            credit.AddCredit();
            credit.AddCredit();
            credit.AddCredit();
            credit.AddCredit();
            credit.AddCredit();
            credit.AddCredit();
            credit.AddCredit();
            Assert.AreEqual(9, credit.Credits);
            credit.AddCredit();
            Assert.AreEqual(9, credit.Credits);
            credit.DecrementCredits();
            credit.DecrementCredits();
            credit.DecrementCredits();
            credit.DecrementCredits();
            credit.DecrementCredits();
            credit.DecrementCredits();
            credit.DecrementCredits();
            credit.DecrementCredits();
            credit.DecrementCredits();
            Assert.AreEqual(0, credit.Credits);
            credit.DecrementCredits();
            Assert.AreEqual(0, credit.Credits);
        }
示例#4
0
        public void TestStartGameWithCredit()
        {
            GameBoxForm  box       = new GameBoxForm();
            GameLogic    gameLogic = box.GetLogic();
            CreditSystem credit    = box.GetCredit();

            credit.AddCredit();
            Assert.AreEqual(gameLogic.GetCredits(), 1);
            gameLogic.StartGame();
            Assert.AreEqual(gameLogic.GetCredits(), 0);
            Assert.IsFalse(gameLogic.IsStartScreenActive());
        }
        /// <summary>
        /// Edit a <see cref="CreditSystem"/>.
        /// </summary>
        /// <param name="creditSystem">The credit system to edit.</param>
        /// <param name="attachAsModified">
        /// If this is true and the credit system is disconnected,
        /// it is attached with a 'modified' state,
        /// else this parameter has no effect.
        /// </param>
        /// <exception cref="ArgumentException">
        /// Thrown when the <see cref="CreditSystem.FundsTransferFileConverterName"/>
        /// if the <paramref name="creditSystem"/>
        /// does not point to a registered <see cref="IFundsTransferFileConverter"/>.
        /// </exception>
        public async Task EditCreditSystemAsync(CreditSystem creditSystem, bool attachAsModified = false)
        {
            if (creditSystem == null)
            {
                throw new ArgumentNullException(nameof(creditSystem));
            }

            EnsureCreditSystemIsValid(creditSystem);

            using (GetElevatedAccessScope())
            {
                await UpdateObjectGraphAsync(creditSystem, attachAsModified);
            }
        }
示例#6
0
        public void TestMaxCredit()
        {
            GameBoxForm  box       = new GameBoxForm();
            GameLogic    gameLogic = box.GetLogic();
            CreditSystem credit    = box.GetCredit();

            credit.AddCredit();
            Assert.AreEqual(gameLogic.GetCredits(), 1);
            credit.AddCredit(8);
            Assert.AreEqual(gameLogic.GetCredits(), 9);
            credit.AddCredit(10);
            Assert.AreEqual(gameLogic.GetCredits(), 9);
            credit.AddCredit(-1);
            Assert.AreEqual(gameLogic.GetCredits(), 8);
        }
        /// <summary>
        /// Add a <see cref="CreditSystem"/>.
        /// </summary>
        /// <param name="creditSystem">The credit system to add.</param>
        /// <exception cref="ArgumentException">
        /// Thrown when the <see cref="CreditSystem.FundsTransferFileConverterName"/>
        /// if the <paramref name="creditSystem"/>
        /// does not point to a registered <see cref="IFundsTransferFileConverter"/>.
        /// </exception>
        public async Task AddCreditSystemAsync(CreditSystem creditSystem)
        {
            if (creditSystem == null)
            {
                throw new ArgumentNullException(nameof(creditSystem));
            }

            EnsureCreditSystemIsValid(creditSystem);

            using (GetElevatedAccessScope())
            {
                this.DomainContainer.CreditSystems.Add(creditSystem);

                await this.DomainContainer.SaveChangesAsync();
            }
        }
        /// <summary>
        /// Validate the credit system and ensure that its <see cref="CreditSystem.FundsTransferFileConverterName"/>
        /// points to a registered <see cref="IFundsTransferFileConverter"/> type.
        /// </summary>
        /// <param name="creditSystem">The credit system.</param>
        /// <exception cref="ArgumentException">
        /// Thrown when the <see cref="CreditSystem.FundsTransferFileConverterName"/>
        /// if the <paramref name="creditSystem"/>
        /// does not point to a registered <see cref="IFundsTransferFileConverter"/>.
        /// </exception>
        protected virtual void EnsureCreditSystemIsValid(CreditSystem creditSystem)
        {
            if (creditSystem == null)
            {
                throw new ArgumentNullException(nameof(creditSystem));
            }

            if (creditSystem.FundsTransferFileConverterName != null)
            {
                if (!this.SessionSettings.IsRegistered <IFundsTransferFileConverter>(creditSystem.FundsTransferFileConverterName))
                {
                    throw new ArgumentException(
                              $"The name '{creditSystem.FundsTransferFileConverterName}' does not correspond to a registered funds transfer file converter.",
                              nameof(creditSystem));
                }
            }
        }
示例#9
0
        static void Main(string[] args)
        {
            EmailNotificationSender emailNotificationSender = new EmailNotificationSender();
            SMSNotificationSender   smsNotificationSender   = new SMSNotificationSender();
            UINotificationSender    uiNotificationSender    = new UINotificationSender();

            CreditSystem    creditSystem    = new CreditSystem();
            DebitSystem     debitSystem     = new DebitSystem();
            PromotionSystem promotionSystem = new PromotionSystem();

            Account account = new Account()
            {
                AccountName = "Dumpi",
                Balance     = 0
            };

            ////////////////////////////////////////////////////////////////////////////////////////////
            creditSystem._notificationSender = emailNotificationSender;
            creditSystem.Credit(account, 100);
            Console.WriteLine("//////////////////////////////////////////////////////////////////////");

            creditSystem._notificationSender = smsNotificationSender;
            creditSystem.Credit(account, 100);
            Console.WriteLine("//////////////////////////////////////////////////////////////////////");

            creditSystem._notificationSender = uiNotificationSender;
            creditSystem.Credit(account, 100);
            Console.WriteLine("//////////////////////////////////////////////////////////////////////");
            ////////////////////////////////////////////////////////////////////////////////////////////


            ////////////////////////////////////////////////////////////////////////////////////////////
            debitSystem._notificationSender = emailNotificationSender;
            debitSystem.Debit(account, 100);
            Console.WriteLine("//////////////////////////////////////////////////////////////////////");

            debitSystem._notificationSender = smsNotificationSender;
            debitSystem.Debit(account, 100);
            Console.WriteLine("//////////////////////////////////////////////////////////////////////");

            debitSystem._notificationSender = uiNotificationSender;
            debitSystem.Debit(account, 200);
            Console.WriteLine("//////////////////////////////////////////////////////////////////////");
            ////////////////////////////////////////////////////////////////////////////////////////////


            ////////////////////////////////////////////////////////////////////////////////////////////
            string offer = "$1 million loan approved";

            promotionSystem._notificationSender = emailNotificationSender;
            promotionSystem.Promote(account, offer);
            Console.WriteLine("//////////////////////////////////////////////////////////////////////");

            promotionSystem._notificationSender = smsNotificationSender;
            promotionSystem.Promote(account, offer);
            Console.WriteLine("//////////////////////////////////////////////////////////////////////");

            promotionSystem._notificationSender = uiNotificationSender;
            promotionSystem.Promote(account, offer);
            Console.WriteLine("//////////////////////////////////////////////////////////////////////");
            ////////////////////////////////////////////////////////////////////////////////////////////


            //Just to stop the console
            Console.ReadLine();
        }
示例#10
0
 public void SetCreditSystem(CreditSystem credit)
 {
     this.credit = credit;
 }
示例#11
0
        public void TestCreateCreditSystem()
        {
            CreditSystem credit = new CreditSystem();

            Assert.AreEqual(0, credit.Credits);
        }