コード例 #1
0
ファイル: GameFacade.cs プロジェクト: benmandr/JDDestroyer
        public void addGoldenTooth()
        {
            GoldenTooth goldenTooth = new GoldenTooth();

            goldenTooth.position  = new Position(50, 50);
            goldenTooth.direction = Position.DirectionRight();
            mover.addItem(goldenTooth);
        }
コード例 #2
0
        public void GoldenToothPosition(GoldenTooth goldenTooth)
        {
            GoldenToothMessage messageData = new GoldenToothMessage(goldenTooth);

            SocketMessage message = new SocketMessage();

            message.type = GoldenToothMessage.TYPE;
            message.data = JsonConvert.SerializeObject(messageData);

            gamePlayer.sendMessage(JsonConvert.SerializeObject(message));
        }
コード例 #3
0
ファイル: Bullet.cs プロジェクト: benmandr/JDDestroyer
        public bool Fly()
        {
            IEnemy hitEnemy = mover.enemyHit(this);

            if (hitEnemy != null)
            {
                StateChange stateChanger = (new StateChangeSmart()).setNext(new StateChangeAngry()).setNext(new StateChangeFrozen()).setNext(new StateChangeDefault());

                new Thread(() =>
                {
                    shooter.addScore(Config.ENEMYHITSCORE);
                    stateChanger.ChangeState(hitEnemy);
                }).Start();
                return(false);
            }

            GoldenTooth tooth = mover.GetGoldenTooth();

            if (tooth != null)
            {
                Bounds toothBounds  = new Bounds(tooth.position, Config.GOLDENTOOTHSIZE);
                Bounds bulletBounds = new Bounds(position, Config.BULLETWIDTH);
                if (toothBounds.Intersects(bulletBounds))
                {
                    shooter.addScore(Config.GOLDENTOOTHSCORE);
                    return(false);
                }
            }

            if (gamePlayers != null)
            {
                foreach (GamePlayer gamePlayer in gamePlayers.getPlayers())
                {
                    if (gamePlayer.Equals(shooter))
                    {
                        continue;
                    }
                    Bounds playerBounds = new Bounds(gamePlayer.position, Config.PLAYERSIZE);
                    Bounds bulletBounds = new Bounds(position, Config.BULLETWIDTH);
                    if (playerBounds.Intersects(bulletBounds))
                    {
                        gamePlayer.removeScore(Config.HITCOST);
                        shooter.addScore(Config.PLAYERHITSCORE);
                        return(false);
                    }
                }
            }

            Position delta = (Position)direction.Clone();

            delta.multiply(Config.BULLETSPEED);
            position.add(delta);

            Bounds Square      = Bounds.MainSquare();
            Bounds bulletBound = new Bounds(position, Config.BULLETWIDTH);

            if (!Square.Intersects(bulletBound))
            {
                return(false);
            }

            Bounds innerSquare = Bounds.InnerSquare();

            if (!split)
            {
                if (innerSquare.Intersects(bulletBound))
                {
                    split = true;
                    //to front
                    mover.addNew(new BulletAdapter((new BulletSplitFront(this)).splitBullet()));

                    //to right
                    mover.addNew(new BulletAdapter((new BulletSplitRight(this)).splitBullet()));

                    //to left
                    mover.addNew(new BulletAdapter((new BulletSplitLeft(this)).splitBullet()));

                    inner = true;
                }
            }

            if (inner && innerSquare.InBounds(bulletBound))
            {
                fullyInside = true;
            }

            if (inner && fullyInside && !innerSquare.InBounds(bulletBound))
            {
                return(false);
            }

            return(true);
        }