Esempio n. 1
0
File: Player.cs Progetto: bjowes/cwg
        private void UpdateJoystick(Consoden.TankGame.Direction.Enumeration moveDirection,
                                    Consoden.TankGame.Direction.Enumeration towerDirection,
                                    bool fire, bool dropMine, bool fireLaser, bool deployLaser,
                                    bool fireRedeemer, int redeemerTimer)
        {
            if (myJoystickId == null)
            {
                return;                 //we are not active in a game
            }

            Consoden.TankGame.Joystick joystick = new Consoden.TankGame.Joystick();
            joystick.PlayerId.Val       = myPlayerId;
            joystick.GameId.Val         = currentGameId;
            joystick.TankId.Val         = myTankId;
            joystick.Counter.Val        = joystickCounter++;
            joystick.MoveDirection.Val  = moveDirection;
            joystick.TowerDirection.Val = towerDirection;
            joystick.Fire.Val           = fire;
            joystick.FireLaser.Val      = fireLaser;
            joystick.MineDrop.Val       = dropMine;
            joystick.DeploySmoke.Val    = deployLaser;
            joystick.FireRedeemer.Val   = fireRedeemer;
            joystick.RedeemerTimer.Val  = redeemerTimer;
            connection.SetAll(joystick, myJoystickId, myHandlerId);
        }
Esempio n. 2
0
        //Print game state
        public void PrintState()
        {
            Console.WriteLine("Game board");
            PrintMap();

            Console.WriteLine("Own position {0},{1}", OwnPosition.X, OwnPosition.Y);
            Console.WriteLine("Enemy position {0},{1}", EnemyPosition.X, EnemyPosition.Y);

            Console.WriteLine("Active missiles");

            for (int i = 0; i < this.gameState.Missiles.Count; i++)
            {
                if (gameState.Missiles [i].IsNull())
                {
                    continue;
                }

                Consoden.TankGame.Missile missile = gameState.Missiles [i].Obj;

                Position head = new Position(missile.HeadPosX.Val, missile.HeadPosY.Val);
                Position tail = new Position(missile.TailPosX.Val, missile.TailPosY.Val);

                Consoden.TankGame.Direction.Enumeration direction = missile.Direction.Val;

                Console.WriteLine("Missile position - head {0},{1}", head.X, head.Y);
                Console.WriteLine("Missile position - tail {0},{1}", tail.X, tail.Y);
                Console.Write("Missile direction ");

                switch (direction)
                {
                case Consoden.TankGame.Direction.Enumeration.Left:
                    Console.WriteLine("Left");
                    break;

                case Consoden.TankGame.Direction.Enumeration.Right:
                    Console.WriteLine("Right");
                    break;

                case Consoden.TankGame.Direction.Enumeration.Up:
                    Console.WriteLine("Up");
                    break;

                case Consoden.TankGame.Direction.Enumeration.Down:
                    Console.WriteLine("Down");
                    break;

                case Consoden.TankGame.Direction.Enumeration.Neutral:
                    Console.WriteLine("Neutral");
                    break;
                }
                Console.WriteLine();
            }

            Console.WriteLine();
        }
Esempio n. 3
0
        //Move p one step in specified direction and returns the new position.
        public Position Move(Position p, Consoden.TankGame.Direction.Enumeration d)
        {
            switch (d)
            {
            case Consoden.TankGame.Direction.Enumeration.Left:
                return(new Position((p.X - 1 + SizeX) % SizeX, p.Y));

            case Consoden.TankGame.Direction.Enumeration.Right:
                return(new Position((p.X + 1) % SizeX, p.Y));

            case Consoden.TankGame.Direction.Enumeration.Up:
                return(new Position(p.X, (p.Y - 1 + SizeY) % SizeY));

            case Consoden.TankGame.Direction.Enumeration.Down:
                return(new Position(p.X, (p.Y + 1) % SizeY));

            default:
                return(p);
            }
        }
Esempio n. 4
0
        //Called every time player is supposed to calculate a new move.
        //The player has 1 second to calculate the move and call setJoystick.
        public void MakeMove(Consoden.TankGame.GameState gameState)
        {
            //TODO: implement your own tank logic and call setJoystick

            //-------------------------------------------------------
            //Example of a stupid tank logic:
            //Remove it and write your own brilliant version!
            //-------------------------------------------------------
            GameMap gm  = new GameMap(tankId, gameState);           //helpler object
            Bfs     bfs = new Bfs(gameState, gm.OwnPosition);       //breadth first search

            Consoden.TankGame.Direction.Enumeration moveDirection = Consoden.TankGame.Direction.Enumeration.Neutral;

            if (bfs.CanReachSquare(gm.EnemyPosition))                //if we can reach the enemy, get him
            {
                moveDirection = bfs.BacktrackFromSquare(gm.EnemyPosition);
            }
            else               //find any empty square
            {
                if (!gm.IsWall(gm.Move(gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Left)) &&
                    !gm.IsMine(gm.Move(gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Left)))
                {
                    moveDirection = Consoden.TankGame.Direction.Enumeration.Left;
                }
                else if (!gm.IsWall(gm.Move(gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Right)) &&
                         !gm.IsMine(gm.Move(gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Right)))
                {
                    moveDirection = Consoden.TankGame.Direction.Enumeration.Right;
                }
                else if (!gm.IsWall(gm.Move(gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Up)) &&
                         !gm.IsMine(gm.Move(gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Up)))
                {
                    moveDirection = Consoden.TankGame.Direction.Enumeration.Up;
                }
                else if (!gm.IsWall(gm.Move(gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Down)) &&
                         !gm.IsMine(gm.Move(gm.OwnPosition, Consoden.TankGame.Direction.Enumeration.Down)))
                {
                    moveDirection = Consoden.TankGame.Direction.Enumeration.Down;
                }
            }

            //Advanced tower aim stategy
            Consoden.TankGame.Direction.Enumeration towerDirection =
                (Consoden.TankGame.Direction.Enumeration)((1 + gm.OwnPosition.X + gm.OwnPosition.Y) % 4);

            //Of course we always want to fire
            bool fire = true;

            //Sometimes we also drop a mine
            bool dropMine = ((int)(gameState.ElapsedTime.Val) % 3) == 0;

            bool fireLaser = false;

            if (gm.getLaserCount > 0)
            {
                fireLaser = true;
            }

            bool deploySmoke = false;

            if (gm.HasSmoke)
            {
                deploySmoke = true;
            }

            bool fireRedeemer  = false;
            int  redeemerTimer = 0;

            if (gm.HasRedeemer)
            {
                fireRedeemer  = true;
                redeemerTimer = 3;
            }

            //Move our joystick.
            setJoystick(moveDirection, towerDirection, fire, dropMine, fireLaser, deploySmoke, fireRedeemer, redeemerTimer);
        }