#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 { /// /// This is the main type for your game /// 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); } /// /// 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. /// 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; /// /// Load your graphics content. If loadAllContent is true, you should /// load content from both ResourceManagementMode pools. Otherwise, just /// load ResourceManagementMode.Manual content. /// /// Which type of content to load. 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("images/winner"); loss = content.Load < Texture2D > ("images/loss"); vs = content.Load < Texture2D > ("images/vs"); tie = content.Load < Texture2D > ("images/tie"); splash = content.Load("images/paper"); gOver = content.Load("images/gOver"); rock = content.Load("models\\rocks"); spriteBatch = new SpriteBatch(graphics.GraphicsDevice); } // TODO: Load any ResourceManagementMode.Manual content } /// /// 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. /// /// Which type of content to unload. protected override void UnloadGraphicsContent(bool unloadAllContent) { if (unloadAllContent == true) { content.Unload(); } } /// /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input and playing audio. /// /// Provides a snapshot of timing values. 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 /// /// This is called when the game should draw itself. /// /// Provides a snapshot of timing values. 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); } } }