daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest Dec 9th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Audio;
  6. using Microsoft.Xna.Framework.Content;
  7. using Microsoft.Xna.Framework.GamerServices;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Microsoft.Xna.Framework.Input;
  10. using Microsoft.Xna.Framework.Media;
  11.  
  12. namespace Flood_Control
  13. {
  14.     /// <summary>
  15.     /// This is the main type for your game
  16.     /// </summary>
  17.     public class Game1 : Microsoft.Xna.Framework.Game
  18.     {
  19.         GraphicsDeviceManager graphics;
  20.         SpriteBatch spriteBatch;
  21.  
  22.         private Texture2D playingPieces;
  23.         private Texture2D backgroundScreen;
  24.         private Texture2D titleScreen;
  25.  
  26.         GameBoard gameBoard;
  27.  
  28.         Vector2 gameBoardDisplayOrigin = new Vector2(70, 89);
  29.  
  30.         int playerScore = 0;
  31.  
  32.         enum GameStates { TitleScreen, Playing };
  33.         GameStates gameState = GameStates.TitleScreen;
  34.  
  35.         Rectangle EmptyPiece = new Rectangle(1, 247, 40, 40);
  36.  
  37.         const float MinTimeSinceLastInput = 0.25f;
  38.         float timeSinceLastInput = 0.0f;
  39.  
  40.  
  41.  
  42.  
  43.         public Game1()
  44.         {
  45.             graphics = new GraphicsDeviceManager(this);
  46.             Content.RootDirectory = "Content";
  47.         }
  48.  
  49.         /// <summary>
  50.         /// Allows the game to perform any initialization it needs to before starting to run.
  51.         /// This is where it can query for any required services and load any non-graphic
  52.         /// related content.  Calling base.Initialize will enumerate through any components
  53.         /// and initialize them as well.
  54.         /// </summary>
  55.         ///
  56.  
  57.         private int DetermineScore(int SquareCount)
  58.         {
  59.             return (int)((Math.Pow((SquareCount / 5), 2) + SquareCount) * 10);
  60.         }
  61.  
  62.         private void CheckScoringChain(List<Vector2> WaterChain)
  63.         {
  64.             if (WaterChain.Count > 0)
  65.             {
  66.                 Vector2 LastPipe = WaterChain[WaterChain.Count - 1];
  67.                 if (LastPipe.X == GameBoard.GameBoardWidth - 1)
  68.                 {
  69.                     if (gameBoard.HasConnector(
  70.                         (int)LastPipe.X, (int)LastPipe.Y, "Right"))
  71.                     {
  72.                         playerScore += DetermineScore(WaterChain.Count);
  73.  
  74.                         foreach (Vector2 ScoringSquare in WaterChain)
  75.                         {
  76.                             gameBoard.SetSquare((int)ScoringSquare.X, (int)ScoringSquare.Y, "Empty");
  77.                         }
  78.                     }
  79.                 }
  80.             }
  81.         }
  82.  
  83.  
  84.  
  85.         protected override void Initialize()
  86.         {
  87.             // TODO: Add your initialization logic here
  88.  
  89.             this.IsMouseVisible = true;
  90.             graphics.PreferredBackBufferWidth = 800;
  91.             graphics.PreferredBackBufferHeight = 600;
  92.             graphics.ApplyChanges();
  93.             gameBoard = new GameBoard();
  94.  
  95.             base.Initialize();
  96.         }
  97.  
  98.         /// <summary>
  99.         /// LoadContent will be called once per game and is the place to load
  100.         /// all of your content.
  101.         /// </summary>
  102.         protected override void LoadContent()
  103.         {
  104.             // Create a new SpriteBatch, which can be used to draw textures.
  105.             spriteBatch = new SpriteBatch(GraphicsDevice);
  106.  
  107.             // TODO: use this.Content to load your game content here
  108.             playingPieces = Content.Load<Texture2D>(@"Textures/Tile_Sheet");
  109.             backgroundScreen = Content.Load<Texture2D>(@"Textures/Background");
  110.             titleScreen = Content.Load<Texture2D>(@"Textures/TitleScreen");
  111.  
  112.         }
  113.  
  114.         /// <summary>
  115.         /// UnloadContent will be called once per game and is the place to unload
  116.         /// all content.
  117.         /// </summary>
  118.         protected override void UnloadContent()
  119.         {
  120.             // TODO: Unload any non ContentManager content here
  121.         }
  122.  
  123.         /// <summary>
  124.         /// Allows the game to run logic such as updating the world,
  125.         /// checking for collisions, gathering input, and playing audio.
  126.         /// </summary>
  127.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  128.         protected override void Update(GameTime gameTime)
  129.         {
  130.             // Allows the game to exit
  131.             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  132.                 this.Exit();
  133.  
  134.             // TODO: Add your update logic here
  135.  
  136.             base.Update(gameTime);
  137.         }
  138.  
  139.         /// <summary>
  140.         /// This is called when the game should draw itself.
  141.         /// </summary>
  142.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  143.         protected override void Draw(GameTime gameTime)
  144.         {
  145.             GraphicsDevice.Clear(Color.CornflowerBlue);
  146.  
  147.             // TODO: Add your drawing code here
  148.  
  149.  
  150.                         if (gameState == GameStates.TitleScreen)
  151.             {
  152.                 spriteBatch.Begin();
  153.                 spriteBatch.Draw(titleScreen,
  154.                 new Rectangle(0, 0,
  155.                 this.Window.ClientBounds.Width,
  156.                 this.Window.ClientBounds.Height),
  157.                 Color.White);
  158.                 spriteBatch.End();
  159.             }
  160.                         if (gameState == GameStates.Playing)
  161.                         {
  162.                             spriteBatch.Begin();
  163.  
  164.                             spriteBatch.Draw(backgroundScreen,
  165.                                 new Rectangle(0, 0,
  166.                                     this.Window.ClientBounds.Width,
  167.                                     this.Window.ClientBounds.Height), Color.White);
  168.  
  169.                         }
  170.                        
  171.  
  172.  
  173.             for (int x = 0; x < GameBoard.GameBoardWidth; x++)
  174.                 for (int y = 0; y < GameBoard.GameBoardHeight; y++)
  175.                 {
  176.                     int pixelX = (int)gameBoardDisplayOrigin.X +
  177.                         (x * GamePiece.PieceWidth);
  178.                     int pixelY = (int)gameBoardDisplayOrigin.Y +
  179.                         (y * GamePiece.PieceHeight);
  180.  
  181.                     spriteBatch.Draw(
  182.                         playingPieces,
  183.                         new Rectangle(
  184.                             pixelX,
  185.                             pixelY,
  186.                             GamePiece.PieceWidth,
  187.                             GamePiece.PieceHeight),
  188.                         EmptyPiece,
  189.                         Color.White);
  190.                 }
  191.  
  192.             this.Window.Title = playerScore.ToString();
  193.             spriteBatch.End();
  194.  
  195.  
  196.             base.Draw(gameTime);
  197.         }
  198.     }
  199. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top