コード例 #1
0
        // I have to pass a List<object> by reference with all the objects used in this class and then try cast every one
        public LoopsHandler(List <object> gameObj)
        {
            menu       = (MenuObj)gameObj[0];
            menuConfig = (MenuObj)gameObj[1];

            frameRate     = (FrameRate)gameObj[2];
            screenHandler = (ScreenHandler)gameObj[3];

            topWall    = (Wall)gameObj[4];
            bottomWall = (Wall)gameObj[5];

            player1 = (Player)gameObj[6];
            player2 = (Player)gameObj[7];

            ball        = (Ball)gameObj[8];
            statusBoard = (StatusBoard)gameObj[9];

            //gameObj.Add(menu);
            //gameObj.Add(menuConfig);

            //gameObj.Add(frameRate);
            //gameObj.Add(screenHandler);

            //gameObj.Add(topWall);
            //gameObj.Add(bottomWall);

            //gameObj.Add(player1);
            //gameObj.Add(player2);

            //gameObj.Add(ball);
            //gameObj.Add(statusBoard);
        }
コード例 #2
0
 /// <summary>
 /// 减少玩家属性值(装备)
 /// </summary>
 /// <param name="info"></param>
 public void ReduceProperties(ObjectInfo info)
 {
     PlayerStatusInfo.Instance().attack -= info.attack;
     PlayerStatusInfo.Instance().def    -= info.def;
     PlayerStatusInfo.Instance().speed  -= info.speed;
     //更新一次玩家信息界面显示
     StatusBoard.Instance().UpdateStatusShow();
 }
コード例 #3
0
    /// <summary>
    /// 减少玩家属性值(技能)
    /// </summary>
    /// <param name="type">技能加持buff类型</param>
    /// <param name="num">buff数值</param>
    public void ReduceProperties(SkillInfo.SkillEffectType type, int num)
    {
        switch (type)
        {
        case SkillInfo.SkillEffectType.ATTACK: PlayerStatusInfo.Instance().attack -= num; break;

        case SkillInfo.SkillEffectType.DEF:    PlayerStatusInfo.Instance().def -= num;    break;

        case SkillInfo.SkillEffectType.SPEED:  PlayerStatusInfo.Instance().speed -= num;  break;
        }
        //更新一次玩家信息界面显示
        StatusBoard.Instance().UpdateStatusShow();
    }
コード例 #4
0
    /// <summary>
    /// 增加玩家属性值(加点)
    /// </summary>
    /// <param name="selectName">点击的加点按钮明名称</param>
    /// <param name="num">默认一次加10点</param>
    public void AddProperties(string selectName, int num = 10)
    {
        switch (selectName)
        {
        case "AtkButton": PlayerStatusInfo.Instance().attack += num; break;

        case "DefButton": PlayerStatusInfo.Instance().def += num; break;

        case "SpButton": PlayerStatusInfo.Instance().speed += num; break;
        }
        //更新一次玩家信息界面显示
        StatusBoard.Instance().UpdateStatusShow();
    }
コード例 #5
0
    /// <summary>
    /// 增加玩家属性值(技能)
    /// </summary>
    /// <param name="type">技能加持buff类型</param>
    /// <param name="num">buff数值</param>
    public void AddProperties(SkillInfo.SkillEffectType type, int num)
    {
        Debug.Log(type.ToString());
        switch (type)
        {
        case SkillInfo.SkillEffectType.ATTACK: PlayerStatusInfo.Instance().attack += num; break;

        case SkillInfo.SkillEffectType.DEF:    PlayerStatusInfo.Instance().def += num;    break;

        case SkillInfo.SkillEffectType.SPEED:  PlayerStatusInfo.Instance().speed += num;  break;
        }
        //更新一次玩家信息界面显示
        StatusBoard.Instance().UpdateStatusShow();
    }
コード例 #6
0
 /// <summary> Draws the scoreBoard in to the screen </summary>
 private void drawScoreboard(ref StatusBoard statusBoard, ref ScreenHandler screenHandler, bool erase)
 {
     if (erase)
     {
         drawNumber(-1, statusBoard.pos, -1, ref screenHandler);
         drawNumber(-1, statusBoard.pos, 1, ref screenHandler);
     }
     else
     {
         drawNumber(statusBoard.p2_Score, statusBoard.pos, -1, ref screenHandler);
         drawNumber(statusBoard.p1_Score, statusBoard.pos, 1, ref screenHandler);
     }
     screenHandler.drawBlock(statusBoard.pos, Resources.blockTwoDots);
     // throw new NotImplementedException();
 }
コード例 #7
0
ファイル: Program.cs プロジェクト: DanielGilSaenz/PONG_GitRep
        static void Main(string[] args)
        {
            // Initialize the controller and gets the statusBoard to know if the game is over
            Controller controller = new Controller();

            statusBoard = controller.statusBoard;

            // Shows the main menu and gets the option selected (must be changed)
            controller.showMenu();

            InputHandler inputHandler = new InputHandler(controller.player1, controller.player2);

            while (statusBoard.gameIsOver == false)
            {
                inputHandler.handleKeyboard();
            }
        }
コード例 #8
0
 public async Task <ActionResult <StatusUpdate> > GetStatusUpdate(string kind, string key)
 {
     return(await StatusBoard.GetStatus(kind, key));
 }
コード例 #9
0
        /// <summary> Does the math to know where everybody is and then draws them</summary>
        private void handleFrameByFrame()
        {
            // Initializes the copies of the objects, these are used to
            // keep track of the changes and only draw once wvery change
            Ball        lastBall    = null;
            Player      lastPlayer1 = null;
            Player      lastPlayer2 = null;
            StatusBoard lastBoard   = null;

            // Creates and initializes the objects to keep the framerate
            // as constant as the machine allows
            Stopwatch stopWatch = new Stopwatch();
            TimeSpan  delay;

            stopWatch.Start();
            while (statusBoard.gameIsOver == false)
            {
                // Locks the other theads
                Locks.DRAWING = true;

                // Draws the objects if there has been any change
                if (!ball.Compare(lastBall))
                {
                    drawBall(ref ball, ref screenHandler, false);
                }
                if (!player1.Compare(lastPlayer1))
                {
                    drawPlayer(ref player1, ref screenHandler, false);
                }
                if (!player2.Compare(lastPlayer2))
                {
                    drawPlayer(ref player2, ref screenHandler, false);
                }
                if (!statusBoard.Compare(lastBoard))
                {
                    drawScoreboard(ref statusBoard, ref screenHandler, false);
                }

                // debug purposes
                if (debugOn)
                {
                    if (!player1.Compare(lastPlayer1))
                    {
                        screenHandler.drawDebug(player1, 0, 0);
                    }
                    if (!player2.Compare(lastPlayer2))
                    {
                        screenHandler.drawDebug(player2, 0, 1);
                    }
                    if (!ball.Compare(lastBall))
                    {
                        screenHandler.drawDebug(ball, 0, 2);
                    }

                    screenHandler.drawDebug(player1, 0, 0);
                    screenHandler.drawDebug(player1, 0, 0);

                    screenHandler.drawDebug(player2, 0, 1);
                    screenHandler.drawDebug(player2, 0, 1);

                    screenHandler.drawDebug(ball, 0, 2);
                    screenHandler.drawDebug(ball, 0, 2);
                }

                // Keeps a register of the objects to erase later
                lastBall    = (Ball)ball.Clone();
                lastPlayer1 = (Player)player1.Clone();
                lastPlayer2 = (Player)player2.Clone();
                lastBoard   = (StatusBoard)statusBoard.Clone();


                // THEN DOES CALCULATIONS
                // Updates the ball to the new coordinates
                // Updates the players to the new coordinates
                handleInput();
                updateBall();


                // Unlocks the other theads
                Locks.DRAWING = false;
                stopWatch.Stop();

                // Wait Till the next frame
                delay = frameRate.delayTillNextFrame - stopWatch.Elapsed;
                if (delay.Milliseconds > 0)
                {
                    Thread.Sleep(delay);
                }
                frameRate.actualFrame++;
                //Thread.Sleep(100);

                // To reset the actual frame if it is over the max FPS
                if (frameRate.actualFrame >= frameRate.FPS)
                {
                    frameRate.actualFrame = 1;
                }
                stopWatch.Reset();

                // locks the other theads
                Locks.DRAWING = true;

                // Waits for the other theads to stop doing things
                while (Locks.READING)
                {
                    ;
                }
                stopWatch.Start();


                // Erases the previous objects if there are any change
                if (!ball.Compare(lastBall))
                {
                    drawBall(ref lastBall, ref screenHandler, true);
                }
                if (!player1.Compare(lastPlayer1))
                {
                    drawPlayer(ref lastPlayer1, ref screenHandler, true);
                }
                if (!player2.Compare(lastPlayer2))
                {
                    drawPlayer(ref lastPlayer2, ref screenHandler, true);
                }
                if (!statusBoard.Compare(lastBoard))
                {
                    drawScoreboard(ref lastBoard, ref screenHandler, true);
                }
            }
        }
コード例 #10
0
        /// <summary> Initializes the objects of the playground </summary>
        private List <object> initDefault()
        {
            // This list is used to make reference to teh objects
            List <object> gameObj = new List <object>();

            // We create the menus
            menu       = new MenuObj(new string[] { "Jugar", "Configuracion", "Salir" }, null, false);
            menuConfig = new MenuObj(new string[] { "Nombre", "tipo bola", "Velocidad", "Tamaño players", "Salir" }, null, true);

            // Initialize the graphics and the controller
            FrameRate frameRate = new FrameRate(16);

            screenHandler = new ScreenHandler();

            // This is the offset on top and bottom of the walls
            int vOffset = 7;

            // Initialize the top wall
            topWall = new Wall(
                new Line(
                    new Point(30, vOffset),
                    new Point(screenHandler.max_W - 30, vOffset)
                    ));

            // Initialize the bottom wall
            bottomWall = new Wall(
                new Line(
                    new Point(30, screenHandler.max_H - vOffset),
                    new Point(screenHandler.max_W - 30, screenHandler.max_H - vOffset)
                    ));

            // Initialize the Player1
            player1 = new Player(
                Key.Up, Key.Down,
                bottomWall.line.p2.y - 1, topWall.line.p2.y + 1,
                new Point(topWall.line.p2.x, screenHandler.max_H / 2), 3
                );

            // Initialize the Player1
            player2 = new Player(
                Key.W, Key.S,
                bottomWall.line.p1.y - 1, topWall.line.p1.y + 1,
                new Point(topWall.line.p1.x, screenHandler.max_H / 2), 3
                );

            // Initialize the Ball
            ball = new Ball(new fPoint(screenHandler.max_W / 2, screenHandler.max_H / 2), new fVector(4, 1));

            // Initialize the scoreBoard
            statusBoard = new StatusBoard(new Point(screenHandler.max_W / 2, 3), 0, 0, 10);

            gameObj.Add(menu);
            gameObj.Add(menuConfig);

            gameObj.Add(frameRate);
            gameObj.Add(screenHandler);

            gameObj.Add(topWall);
            gameObj.Add(bottomWall);

            gameObj.Add(player1);
            gameObj.Add(player2);

            gameObj.Add(ball);
            gameObj.Add(statusBoard);



            return(gameObj);
        }
コード例 #11
0
ファイル: StatusBoard.cs プロジェクト: coder-of-night/RPG
 void Awake()
 {
     _instance = this;
     base.Init();
 }
コード例 #12
0
 public void ReducePoint(int num = 1)
 {
     PlayerStatusInfo.Instance().point -= num;
     //更新一次玩家信息界面显示
     StatusBoard.Instance().UpdateStatusShow();
 }
コード例 #13
0
 /// <summary>
 /// 增加升级点数
 /// </summary>
 /// <param name="num">增加数量(默认5)</param>
 public void AddPoint(int num = 5)
 {
     PlayerStatusInfo.Instance().point += num;
     //更新一次玩家信息界面显示
     StatusBoard.Instance().UpdateStatusShow();
 }
コード例 #14
0
        //........................................................................................................

        // Goals
        //........................................................................................................

        /// <summary> Checks if the ball is in goal position and updates the scoreboard if there is a goal </summary>
        public static bool handleGoal(ref Ball ball, ref Player player1, ref Player player2, ref StatusBoard statusBoard)
        {
            // Passed Player1
            if (ball.pos.x == player2.pos.x - 10)
            {
                statusBoard.p1_Score++;
                ball.pos    = fPoint.Cast(ScreenHandler.centerOfScreen);
                ball.vector = fVector.getRandom();
                return(true);
            }


            // Passed Player2
            if (ball.pos.x == player1.pos.x + 10)
            {
                statusBoard.p2_Score++;
                ball.pos    = fPoint.Cast(ScreenHandler.centerOfScreen);
                ball.vector = fVector.getRandom();
                return(true);
            }

            return(false);
        }