All pastes #328849 Raw Edit

Xodus

public text v1 · immutable
#328849 ·published 2007-01-26 03:17 UTC
rendered paste body
#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion

namespace rpsX
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        ContentManager content;
        string winner;
        string item1;
        string item2;
        string set1, set2;
        Texture2D draw1, draw2;
        string check = "value";


        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            content = new ContentManager(Services);
        }


        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            
            // TODO: Add your initialization logic here

            base.Initialize();
        }
            Texture2D gOver;
            Texture2D rock;
            Texture2D paper;
            Texture2D scissor;
            Texture2D win;
            Texture2D loss;
            Texture2D vs;
            Texture2D tie;
            Texture2D splash;
            Random ai = new Random();
            SpriteBatch spriteBatch;
            Model rocks;

        /// <summary>
        /// Load your graphics content.  If loadAllContent is true, you should
        /// load content from both ResourceManagementMode pools.  Otherwise, just
        /// load ResourceManagementMode.Manual content.
        /// </summary>
        /// <param name="loadAllContent">Which type of content to load.</param>
        protected override void LoadGraphicsContent(bool loadAllContent)
        {
            if (loadAllContent)
            {
                 //TODO: Load any ResourceManagementMode.Automatic content
               rock = content.Load < Texture2D > ("images/rock");
               paper = content.Load < Texture2D > ("images/paper");
               scissor = content.Load < Texture2D > ("images/scissors");
               win = content.Load<Texture2D>("images/winner");
               loss = content.Load < Texture2D > ("images/loss");
               vs = content.Load < Texture2D > ("images/vs");
               tie = content.Load < Texture2D > ("images/tie");
               splash = content.Load<Texture2D>("images/paper");
               gOver = content.Load<Texture2D>("images/gOver");
               rock = content.Load<Model>("models\\rocks");
             
               spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
            }

            // TODO: Load any ResourceManagementMode.Manual content
        }


        /// <summary>
        /// Unload your graphics content.  If unloadAllContent is true, you should
        /// unload content from both ResourceManagementMode pools.  Otherwise, just
        /// unload ResourceManagementMode.Manual content.  Manual content will get
        /// Disposed by the GraphicsDevice during a Reset.
        /// </summary>
        /// <param name="unloadAllContent">Which type of content to unload.</param>
        protected override void UnloadGraphicsContent(bool unloadAllContent)
        {
            if (unloadAllContent == true)
            {
                content.Unload();
            }
        }


        /// <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 default game to exit on Xbox 360 and Windows
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            // TODO: Add your update logic here
            
            setAI();
            setItem();
            if (set2 == "set")
            {
                if (set1 == "set")
                {
                    {
                        checkItem(item1, item2);

                    }
                }
            }
           
            base.Update(gameTime);
        }

        #region Setting stuff
        public void setAI()
        {
            
            if (check != "1")
            {
                if (ai.Next(99) < 33)
                {
                    set1 = "set";
                    item2 = "rocks";
                    draw2 = rock;
                    check = "1";
                }

                if (ai.Next(99) >33 && ai.Next(99) < 65)
                    {
                        set1 = "set";
                        item2 = "scissor";
                        draw2 = scissor;
                        check = "1";
                    }

                if (ai.Next(99) >67)
                {
                    set1 = "set";
                    item2 = "paper";
                    draw2 = paper;
                    check = "1";
                }
            }
        }
  string gameOver1;
        public void setItem()
        {
            KeyboardState newState = Keyboard.GetState();
            if (newState.IsKeyDown(Keys.R))
            {
                item1 = "rocks";
                set2 = "set";
                draw1 = rock;
            }

            if (newState.IsKeyDown(Keys.S))
            {
                item1 = "scissor";
                set2 = "set";
                draw1 = scissor;
            }
            if (newState.IsKeyDown(Keys.P))
            {
                item1 = "paper";
                set2 = "set";
                draw1 = paper;
            }
            if (newState.IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }
            if (newState.IsKeyDown(Keys.N))
            {
                check = "value";
                item1 = null;
                winner = "value1";
                set2 = "unset";
            }
        }
#endregion
        #region GameOver
      
        public void gameOver()
        {
            if (gameOver1 == "yes")
            {
                check = "value";
                item1 = "null";
                winner= "value1";
                set2 = "unset";
            }
        }
        #endregion
        #region Seeing who wins!
        public void checkItem(string item1,string item2)
        {
            if (item1 == item2)
            {
                winner = "draw";
            }

            if (item1 == "rocks")
            {
                if (item2 == "paper")
                {
                    winner = "AI";
                }
                if (item2 == "scissor")
                {
                    winner = "player";
                }
            }

            if (item1 == "scissor")
            {
                if (item2 == "rocks")
                {
                    winner = "AI";
                }
                if (item2 == "paper")
                {
                    winner = "player";
                }
            }

            if (item1 == "paper")
            {
                if (item2 == "rocks")
                {
                    winner = "player";
                }
                if (item2 == "scissor")
                {
                    winner = "AI";
                }
            }
        }
#endregion

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(Color.CornflowerBlue);


            //spriteBatch.Begin(SpriteBlendMode.AlphaBlend);

            //if (gameOver1 == "yes")
            //{
            //    spriteBatch.Draw(gOver, new Vector2(214, 255), Color.White);
            //}

            //if (winner == "player")
            //{
            //    spriteBatch.Draw(win, new Vector2(214, 255), Color.White);
            //    gameOver();
            //}
            //if (winner == "AI")
            //{
            //    spriteBatch.Draw(loss, new Vector2(214, 255), Color.White);
            //    gameOver();
            //}
            //if(winner == "draw")
            //{
            //    spriteBatch.Draw(tie, new Vector2(214, 255), Color.White);
            //    gameOver();
            //}
            //if (set2 == "set")
            //{
            //    spriteBatch.Draw(draw1, new Vector2(0, 0), Color.White);
            //    gameOver();
            //}
            //if (set1 == "set")
            //{
            //    spriteBatch.Draw(draw2, new Vector2(0, 450), Color.White);
            //    gameOver();
            //}
            //spriteBatch.End();
            // TODO: Add your drawing code here
                Matrix[] transforms = new Matrix[rocks.Bones.Count];
    rocks.CopyAbsoluteBoneTransformsTo(transforms);

    //Draw the model, a model can have multiple meshes, so loop
    foreach (ModelMesh mesh in rocks.Meshes)
    {
        //This is where the mesh orientation is set, as well as our camera and projection
        foreach (BasicEffect effect in mesh.Effects)
        {
            effect.EnableDefaultLighting();
            effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(modelRotation)
                * Matrix.CreateTranslation(modelPosition);
            effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
            effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
                aspectRatio, 1.0f, 10000.0f);
        }
        //Draw the mesh, will use the effects set above.
        mesh.draw();
    }

            base.Draw(gameTime);
        }
    }
}