コード例 #1
0
ファイル: Form1.cs プロジェクト: VladGanuscheak/TMPS
        private void MyEventHandler(object sender, EventArgs e)
        {
            if (sender == bt1)
            {
                game = BattleShipGame.getInstance();
                if (game != battleship)
                {
                    battleship = (BattleShipGame)game;
                    form       = new Form_Battleship();
                }
            }
            else if (sender == bt2)
            {
                game = KangarooGame.getInstance();
                if (game != kangaroo)
                {
                    kangaroo = (KangarooGame)game;
                    form     = new Form_Kangaroo();
                }
            }
            else if (sender == bt3)
            {
                game = MatchesGame.getInstance();
                if (game != matches)
                {
                    matches = (MatchesGame)game;
                    form    = new Form_Matches();
                }
            }

            //
            if (!form.IsDisposed && form != null)
            {
                form.Show();
            }
            else
            {
                if (battleship != null)
                {
                    battleship.setToNull();
                }
                if (kangaroo != null)
                {
                    kangaroo.setToNull();
                }
                if (matches != null)
                {
                    matches.setToNull();
                }
            }
        }
コード例 #2
0
        public void TestMethod1()
        {
            // Here I'll test the Background functionality of the BattleShipGame unit
            // For another games also will be created other unit test classes with its
            // series of unit test methods...

            game = BattleShipGame.getInstance();
            if (game != battleship)
            {
                battleship = (BattleShipGame)game;
            }

            battleship.setToNull();
        }
コード例 #3
0
        /*protected override void OnResize(System.EventArgs e)
         * {
         *  base.OnResize(e);
         *  foreach (Control cnt in this.Controls)
         *  {
         *      ResizeAll(cnt, base.Size);
         *  }
         *  oldSize = base.Size;
         * }
         * private void ResizeAll(Control cnt, Size newSize)
         * {
         *  int iWidth = newSize.Width - oldSize.Width;
         *  cnt.Left += (cnt.Left * iWidth) / oldSize.Width;
         *  cnt.Width += (cnt.Width * iWidth) / oldSize.Width;
         *
         *  int iHeight = newSize.Height - oldSize.Height;
         *  cnt.Top += (cnt.Top * iHeight) / oldSize.Height;
         *  cnt.Height += (cnt.Height * iHeight) / oldSize.Height;
         * }*/

        private void OnClickHandler(object sender, EventArgs e)
        {
            Button[]  bt  = { bt1, bt2, bt3 };
            Label[]   lbl = { lbl1, lbl2, lbl3, lbl4 };
            ListBox[] lb  = { lb1, lb2 };
            if (sender == bt1)
            {
                foreach (var item in bt)
                {
                    item.Visible = false;
                }
                foreach (var item in lbl)
                {
                    item.Visible = false;
                }
                foreach (var item in lb)
                {
                    item.Visible = false;
                }
                // Parametrized Singleton + Abstract Factory
                // because the user is created with specific classes inside it which override
                // different methods and are incapsulated in the abstract factory...
                game = BattleShipGame.getInstance(new User(new UndefinedBehaviour()), new User(new UndefinedBehaviour()));
            }
            else if (sender == bt2)
            {
                lbl2.Visible = true;
                lbl3.Visible = true;
                lb1.Visible  = true;
            }
            else if (sender == bt3)
            {
                lbl2.Visible = true;
                lbl3.Visible = true;
                lbl4.Visible = true;
                lb1.Visible  = true;
                lb2.Visible  = true;
            }
            else if (sender == lb1)
            {
            }
            else if (sender == lb2)
            {
            }
        }