Hyluss

game2

Oct 16th, 2018
531
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.09 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using Microsoft.Xna.Framework.Input;
  4.  
  5. namespace Game2
  6. {
  7.     /// <summary>
  8.     /// This is the main type for your game.
  9.     /// </summary>
  10.     public class Game1 : Game
  11.     {
  12.         public static int ClickedCounter =0, ShowedCards =0, CurrentType=-1, pairs=0;
  13.         public static Card SelectedCard = null;
  14.  
  15.         GraphicsDeviceManager graphics;
  16.         SpriteBatch spriteBatch;
  17.  
  18.         Texture2D background;
  19.  
  20.         Board board;
  21.         Rectangle Cursor;
  22.  
  23.         bool win = false;
  24.  
  25.         public Game1()
  26.         {
  27.             graphics = new GraphicsDeviceManager(this);
  28.             Content.RootDirectory = "Content";
  29.         }
  30.  
  31.         /// <summary>
  32.         /// Allows the game to perform any initialization it needs to before starting to run.
  33.         /// This is where it can query for any required services and load any non-graphic
  34.         /// related content.  Calling base.Initialize will enumerate through any components
  35.         /// and initialize them as well.
  36.         /// </summary>
  37.         protected override void Initialize()
  38.         {
  39.             // TODO: Add your initialization logic here
  40.             IsMouseVisible = true;
  41.             Window.AllowUserResizing = true;
  42.             Window.Title = "Test 1";
  43.  
  44.             base.Initialize();
  45.         }
  46.  
  47.         /// <summary>
  48.         /// LoadContent will be called once per game and is the place to load
  49.         /// all of your content.
  50.         /// </summary>
  51.         protected override void LoadContent()
  52.         {
  53.             // Create a new SpriteBatch, which can be used to draw textures.
  54.             spriteBatch = new SpriteBatch(GraphicsDevice);
  55.  
  56.             background = Content.Load<Texture2D>("background");
  57.  
  58.             board = new Board(Content);
  59.  
  60.             // TODO: use this.Content to load your game content here
  61.         }
  62.  
  63.         /// <summary>
  64.         /// UnloadContent will be called once per game and is the place to unload
  65.         /// game-specific content.
  66.         /// </summary>
  67.         protected override void UnloadContent()
  68.         {
  69.             // TODO: Unload any non ContentManager content here
  70.         }
  71.  
  72.         /// <summary>
  73.         /// Allows the game to run logic such as updating the world,
  74.         /// checking for collisions, gathering input, and playing audio.
  75.         /// </summary>
  76.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  77.         protected override void Update(GameTime gameTime)
  78.         {
  79.             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
  80.                 Exit();
  81.  
  82.             // TODO: Add your update logic here
  83.             UpdateCursorPosition();
  84.             ButtonsEvents();
  85.            
  86.             CheckWin();
  87.  
  88.             base.Update(gameTime);
  89.         }
  90.  
  91.         void CheckWin()
  92.         {
  93.             if (win)
  94.                 return;
  95.  
  96.             Window.Title = "ilosc ruchow: " + ClickedCounter;
  97.             if (Game1.pairs == 12)
  98.             {
  99.                 Window.Title = "wygrales. Ilosc ruchow to: " + ClickedCounter;
  100.                 win = true;
  101.             }
  102.         }
  103.  
  104.         private void ButtonsEvents()
  105.         {
  106.             board.Update(Cursor);
  107.         }
  108.  
  109.         void UpdateCursorPosition()
  110.         {
  111.             var mouseState = Mouse.GetState();
  112.             Cursor.X = mouseState.X;
  113.             Cursor.Y = mouseState.Y;
  114.         }
  115.  
  116.         /// <summary>
  117.         /// This is called when the game should draw itself.
  118.         /// </summary>
  119.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  120.         protected override void Draw(GameTime gameTime)
  121.         {
  122.             GraphicsDevice.Clear(Color.CornflowerBlue);
  123.  
  124.             // TODO: Add your drawing code here
  125.             spriteBatch.Begin();
  126.  
  127.             spriteBatch.Draw(background, GraphicsDevice.Viewport.Bounds, Color.White);
  128.             board.Draw(spriteBatch);
  129.  
  130.             spriteBatch.End();
  131.             base.Draw(gameTime);
  132.         }
  133.     }
  134. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment