示例#1
0
        public RPGGameView()
        {
            InitializeComponent();
            pb = new PictureBox[12, 13];
            for (int i = 0; i != 12; i++)
            {
                for (int j = 0; j != 13; j++)
                {
                    pb[i, j] = new PictureBox();
                    pb[i, j].Width = 30;
                    pb[i, j].Height = 30;
                    pb[i, j].Left = i * 30;
                    pb[i, j].Top = j * 30;
                    pb[i, j].Visible = true;
                    this.Controls.Add(pb[i, j]);
                }
            }

            tree = Image.FromFile("../../tree.png");
            wall = Image.FromFile("../../wall.png");
            empty = Image.FromFile("../../empty.png");
            hero = Image.FromFile("../../hero.png");
            monster = Image.FromFile("../../monster.png");
            start = Image.FromFile("../../start.png");
            end = Image.FromFile("../../end.png");

            gameController = new RPGGameController();
            gameModel = new RPGGameModel();
            gameController.AddModel(gameModel);
            gameModel.AttachObserver(this);
            this.setController(gameController);
        }
示例#2
0
        public RPGGameView()
        {
            InitializeComponent();
            pb = new PictureBox[12, 13];
            for (int i = 0; i != 12; i++)
            {
                for (int j = 0; j != 13; j++)
                {
                    pb[i, j]         = new PictureBox();
                    pb[i, j].Width   = 30;
                    pb[i, j].Height  = 30;
                    pb[i, j].Left    = i * 30;
                    pb[i, j].Top     = j * 30;
                    pb[i, j].Visible = true;
                    this.Controls.Add(pb[i, j]);
                }
            }

            tree    = Image.FromFile("../../tree.png");
            wall    = Image.FromFile("../../wall.png");
            empty   = Image.FromFile("../../empty.png");
            hero    = Image.FromFile("../../hero.png");
            monster = Image.FromFile("../../monster.png");
            start   = Image.FromFile("../../start.png");
            end     = Image.FromFile("../../end.png");

            gameController = new RPGGameController();
            gameModel      = new RPGGameModel();
            gameController.AddModel(gameModel);
            gameModel.AttachObserver(this);
            this.setController(gameController);
        }
示例#3
0
 public override void ActionPerformed(int action)
 {
     foreach (Model m in mList)
     {
         if (m is RPGGameModel)
         {
             RPGGameModel rpm = (RPGGameModel)m;
             if (action == UP || action == DOWN || action == LEFT || action == RIGHT)
             {
                 rpm.MoveHero(action);
             }
             else if (action == ATTACK)
             {
                 rpm.Attack();
             }
             else
             {
                 rpm.Update();
             }
         }
     }
 }
示例#4
0
        public void Notify(Model m)
        {
            RPGGameModel rpm   = (RPGGameModel)m;
            Board        board = rpm.Board;

            for (int i = 0; i != 12; i++)
            {
                for (int j = 0; j != 13; j++)
                {
                    switch (board.At(new RPGGame.Location(i, j)))
                    {
                    case Board.TREE:
                        pb[i, j].Image = tree;
                        break;

                    case Board.WALL:
                        pb[i, j].Image = wall;
                        break;

                    case Board.END:
                        pb[i, j].Image = end;
                        break;

                    case Board.START:
                        pb[i, j].Image = start;
                        break;

                    default:
                        pb[i, j].Image = empty;
                        break;
                    }
                }
            }
            pb[rpm.Hero.Location.X, rpm.Hero.Location.Y].Image       = hero;
            pb[rpm.Monster.Location.X, rpm.Monster.Location.Y].Image = monster;

            lblMsg.Text       = "Where to go Next?";
            btnAttack.Enabled = false;
            if (rpm.Status == RPGGameModel.CANTMOVE)
            {
                lblMsg.Text = rpm.Hero.Name + ", you can't move there!!";
            }
            if (rpm.Status == RPGGameModel.ATTACKED)
            {
                if (rpm.Hero.HP <= 0)
                {
                    lblMsg.Text = rpm.Hero.Name + ", you dead!!!";
                }
                else
                {
                    btnAttack.Enabled = true;
                    lblMsg.Text       = rpm.Hero.Name + ", you meet " + rpm.Monster.Name + ". \nYou can attack!!";
                }
                if (rpm.Monster.HP <= 0)
                {
                    lblMsg.Text = rpm.Hero.Name + ", you kill that \nlittle cute animal!!";
                }
            }
            if (rpm.Status == RPGGameModel.ENDED)
            {
                lblMsg.Text = rpm.Hero.Name + ", you found the end point!! \n(but not the end of the game, ha ha )";
            }
            if (rpm.Status == RPGGameModel.MONSTER && rpm.Hero.HP > 0)
            {
                btnAttack.Enabled = true;
                lblMsg.Text       = rpm.Hero.Name + ", you meet " + rpm.Monster.Name + ". You can attack!!";
            }
            lblHP.Text = rpm.Hero.HP.ToString();
            lblEP.Text = rpm.Hero.EP.ToString();
        }