Advertisement
rohits134

Menu.cs

Jul 5th, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.28 KB | None | 0 0
  1. namespace Pong_Clone
  2. {
  3.     using System.Collections.Generic;
  4.     using Microsoft.Xna.Framework;
  5.     using Microsoft.Xna.Framework.Graphics;
  6.  
  7.     public class Menu
  8.     {
  9.  
  10.         private List<string> MenuItems;
  11.         private int iterator;
  12.         public string InfoText { get; set; }
  13.         public string Title { get; set; }
  14.         public int Iterator
  15.         {
  16.             get
  17.             {
  18.                 return iterator;
  19.             }
  20.             set
  21.             {
  22.                 iterator = value;
  23.                 if (iterator > MenuItems.Count - 1) iterator = MenuItems.Count - 1;
  24.                 if (iterator < 0) iterator = 0;
  25.             }
  26.         }
  27.  
  28.         public Menu()
  29.         {
  30.             Title = "Pong Clone";
  31.             MenuItems = new List<string>();
  32.             MenuItems.Add("Single Player");
  33.             MenuItems.Add("Multi Player");
  34.             MenuItems.Add("Exit Game");
  35.             Iterator = 0;
  36.             InfoText = string.Empty;
  37.         }
  38.  
  39.         public int GetNumberOfOptions()
  40.         {
  41.             return MenuItems.Count;
  42.         }
  43.  
  44.         public string GetItem(int index)
  45.         {
  46.             return MenuItems[index];
  47.         }
  48.  
  49.         public void DrawMenu(SpriteBatch batch, int screenWidth, SpriteFont arial)
  50.         {
  51.             batch.DrawString(arial, Title, new Vector2(screenWidth / 2 - arial.MeasureString(Title).X / 2, 20), Color.White);
  52.             int yPos = 100;
  53.             for (int i = 0; i < GetNumberOfOptions(); i++)
  54.             {
  55.                 Color colour = Color.White;
  56.                 if (i == Iterator)
  57.                 {
  58.                     colour = Color.Gray;
  59.                 }
  60.                 batch.DrawString(arial, GetItem(i), new Vector2(screenWidth / 2 - arial.MeasureString(GetItem(i)).X / 2, yPos), colour);
  61.                 yPos += 50;
  62.             }
  63.         }
  64.  
  65.         public void DrawEndScreen(SpriteBatch batch, int screenWidth, SpriteFont arial)
  66.         {
  67.             batch.DrawString(arial, InfoText, new Vector2(screenWidth / 2 - arial.MeasureString(InfoText).X / 2, 300), Color.White);
  68.             string prompt = "Press Enter to Continue";
  69.             batch.DrawString(arial, prompt, new Vector2(screenWidth / 2 - arial.MeasureString(prompt).X / 2, 400), Color.White);
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement