示例#1
0
 //get description info for object
 public override info getInfo()
 {
     if (type == 1)
     {
         newInfo = new info("Scout", "Useful for scouting out planets", "Move:3 Damage:1 Health:" + health);
     }
     else if (type == 2)
     {
         newInfo = new info("Destroyer", "Useful for space combat", "Move:1 Damage:5 Health:" + health);
     }
     else if (type == 3)
     {
         newInfo = new info("Troop Ship", "Useful for attacking planets", "Move:2 Damage:2 Health:" + health);
     }
     return newInfo;
 }
示例#2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (this.IsActive)
            {
                KeyboardState newstate = Keyboard.GetState();
                MouseState old = mouse;
                mouse = Mouse.GetState();
                //escape exits the game
                if (newstate.IsKeyDown(Keys.Escape))
                {
                    this.Exit();
                }
                //tiles the board with white lines so player can see the separate squares
                if (newstate.IsKeyDown(Keys.T))
                {
                    if (!oldState.IsKeyDown(Keys.T))
                    {
                        tiled = tiled * -1;
                    }
                }
                //A adjusts the angle, testing purposes
                if (newstate.IsKeyDown(Keys.A))
                {
                    angle += (float).1;
                }
                //handles mouse clicks
                if (mouse.RightButton == ButtonState.Released)
                {
                    if (old.RightButton != ButtonState.Released)
                    {
                        int x = mouse.X;
                        int y = mouse.Y;
                        x = x / 64;
                        y = y / 64;
                        //if there is something selected already(previous click hit something)
                        if (selected)
                        {
                            //if the new position clicked is empty
                            if (objectboard[x, y] == null)
                            {
                                Type type = objectselected.GetType();
                                if (type.Name == "Ship")
                                {
                                    Ship temp = (Ship)objectselected;
                                    //if the new position is within moving distance, move there
                                    if (ManhattanDist(temp.getPosition(), new Vector2(x, y)) <= temp.getMove())
                                    {
                                        temp.destination = new Vector2(x, y);
                                    }
                                    //else modify the move so that it is within the moving distance
                                    else
                                    {
                                        NormalizeByMove(temp, new Vector2(x, y));
                                    }
                                    //add the object to the move list, with the approriate destination
                                    movelist.Add(objectselected);
                                }
                            }
                            else //otherwise the space clicked contains an object
                            {
                                Type type = objectselected.GetType();
                                if (type.Name == "Ship")
                                {
                                    Ship temp = (Ship)objectselected;
                                    if (ManhattanDist(temp.getPosition(), new Vector2(x, y)) <= temp.getMove())
                                    {
                                        temp.destination = new Vector2(x, y);
                                        attackmovelist.Add(objectselected);
                                    }
                                    else
                                    {
                                        NormalizeByMove(temp, new Vector2(x, y));
                                        movelist.Add(objectselected);
                                    }
                                }
                            }
                            selected = false;
                        }
                    }
                }
                    if (mouse.LeftButton == ButtonState.Released)
                    {
                        if (old.LeftButton != ButtonState.Released)
                        {
                            int x = mouse.X;
                            int y = mouse.Y;
                            x = x / 64;
                            y = y / 64;
                            //if there is something selected already(previous click got something
                            /*if (selected)
                            {
                                //if the new position clicked is empty
                                if (objectboard[x, y] == null)
                                {
                                    Type type = objectselected.GetType();
                                    if (type.Name == "Ship")
                                    {
                                        Ship temp = (Ship)objectselected;
                                        if (ManhattanDist(temp.getPosition(), new Vector2(x, y)) <= temp.getMove())
                                        {
                                            temp.destination = new Vector2(x, y);
                                        }
                                        else
                                        {
                                            NormalizeByMove(temp, new Vector2(x, y));
                                        }
                                        movelist.Add(objectselected);
                                    }
                                }
                                selected = false;
                            }*/
                            try
                            {
                                //if (movelist.Count == 0)
                                //{
                                selectedinfo = objectboard[x, y].getInfo();
                                objectselected = objectboard[x, y];
                                selected = true;
                                //}
                            }
                            catch (Exception e)
                            {
                                System.Console.WriteLine(e.Data);
                            }

                        }
                    }
                    for (int i = 0; i < 18; i++)
                    {
                        for (int j = 0; j < 13; j++)
                        {
                            objectboard[i, j] = null;
                        }
                    }
                    for (int compare = 0; compare < shiplist.Count; compare++)
                    {
                        objectboard[(int)shiplist[compare].getPosition().X, (int)shiplist[compare].getPosition().Y] = shiplist[compare];
                    }
                    oldState = newstate;
                }
                Move(gameTime);
                AttackMove(gameTime);
                RemoveDead();
                base.Update(gameTime);
        }
示例#3
0
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            for (int i = 0; i < 18; i++)
            {
                for (int j = 0; j < 13; j++)
                {
                    board[i, j] = 0;
                    objectboard[i, j] = null;
                }
            }
            board[5, 8] = 1;
            oldState = Keyboard.GetState();
            mouse = Mouse.GetState();
            int test = graphics.GraphicsDevice.Viewport.Width;
            int testx = graphics.GraphicsDevice.Viewport.Height;
            this.IsMouseVisible = true;
            lucidaConsole = Content.Load<SpriteFont>("SpriteFont1");
            selectedinfo = new info("", "", "");
            selected = false;
            Viewport v = new Viewport();
            tiled = 1;
            message = "";

            v.Height = graphics.GraphicsDevice.DisplayMode.Height;
            v.Width = graphics.GraphicsDevice.DisplayMode.Width;
            graphics.PreferredBackBufferHeight = graphics.GraphicsDevice.DisplayMode.Height;
            graphics.PreferredBackBufferWidth = graphics.GraphicsDevice.DisplayMode.Width;
            //graphics.GraphicsDevice.Viewport = v;
            graphics.ToggleFullScreen();
            base.Initialize();
        }