/// <summary>Загружаем все необходимое для отрисовки</summary> private void LoadSprites(SourceryGame game) { _Font = game.Font; _BigFont = game.BigFont; _Back = new AnimateSprite(game.Content.Load <Texture2D>("controls/ReloadingButton"), 3, 1); LoadSprite(game); }
/// <summary> /// Создаёт новый экземпляр класса <see cref="HelpPanel"/>. /// </summary> /// <param name="game">The game.</param> public HelpPanel(SourceryGame game) { _Texture = game.Panel; _Font = game.BigFont; Items = new List<Control>(); Type = PanelTypes.Help; }
/// <summary> /// Создаёт новый экземпляр класса <see cref="CheckBox"/>. /// </summary> /// <param name="game">Ссылка на игру</param> /// <param name="caption">Заголовок</param> public CheckBox(SourceryGame game, string caption) { Caption = caption; _Sprite = new AnimateSprite(game.CheckBox,4,1); _Font = game.Font; _Checked = false; }
/// <summary> /// Создаёт новый экземпляр класса <see cref="CheckBox"/>. /// </summary> /// <param name="game">Ссылка на игру</param> /// <param name="caption">Заголовок</param> public CheckBox(SourceryGame game, string caption) { Caption = caption; _Sprite = new AnimateSprite(game.CheckBox, 4, 1); _Font = game.Font; _Checked = false; }
/// <summary>Создаёт новый экземпляр класса <see cref="Player"/>.</summary> /// <param name="game">Ссылка на игру</param> /// <param name="type">Тип игрока</param> /// <param name="startPoint">Откуда начинает</param> public Player(SourceryGame game,XmlNode node) { _Buildings = new List<Building>(); _EnemySelector = game.Selectors[0]; _OurSelector = game.Selectors[1]; _Font = game.Font; LoadPlayerParameters(node,game); }
/// <summary> /// Создаёт новый экземпляр класса <see cref="Button"/>. /// </summary> /// <param name="texture">Текстура кнопки</param> /// <param name="text">Текст кнопки</param> /// <param name="font">Шрифт кнопки</param> public Button(SourceryGame game, string text) { _Sprite = new AnimateSprite(game.Button, 3, 1); Caption = text; _Font = game.Font; _Sound = game.ClickSound; _Game = game; }
/// <summary>Создаёт новый экземпляр класса <see cref="Magic"/>.</summary> /// <param name="node">Xml-запись</param> /// <param name="game">Ссылка на игру.</param> public Magic(XmlNode node, SourceryGame game) { _Node = node; LoadAttributes(node); _Executed = false; LoadSprites(game); _ShowText = false; _Movement = new Movement(new Rectangle(0, 0, 0, 0), null, _Speed, _Sprite, _Animation, true); }
/// <summary>Создаёт новый экземпляр класса <see cref="Level"/>.</summary> /// <param name="name">The name.</param> /// <param name="game">The game.</param> public Level(string name, SourceryGame game) { _Font = game.BigFont; _AllMagic = game.AllMagic; _Buildings = new List<Building>(); LoadXmlAttributes(name); _FloatingZone = new FloatingZone(game,_Players); _Magics = new Magics("Settings/Magic.xml",game); }
/// <summary>Создаёт новый экземпляр класса <see cref="ColorZone"/>.</summary> /// <param name="game">Ссылка на игру.</param> /// <param name="MaxResource">Максимум.</param> /// <param name="CurrentResourse">Текущее положение.</param> /// <param name="Position">Номер спрайта.</param> public ColorZone(SourceryGame game, int MaxResource, int CurrentResourse, int Position) { _MaxResourse = MaxResource; _CurrentResourse = CurrentResourse; _Sprite = new AnimateSprite(game.AllMagic, 1, 5); _Sprite.CurrentFrame = Position; _Font = game.BigFont; _Back = game.Content.Load<Texture2D>("Controls/Back"); }
/// <summary>Создаёт новый экземпляр класса <see cref="Edit"/>.</summary> /// <param name="game">Ссылка на игру.</param> /// <param name="text">Текст.</param> public Edit(SourceryGame game) { _Texture = new AnimateSprite(game.Edit, 2, 1); _Font = game.Font; _Text = game.PlayerName; _Cursor = game.Editing; _Draw = false; _Game = game; }
/// <summary> Создаёт новый экземпляр класса <see cref="Menu"/>.</summary> public Menu(string path, SourceryGame game) { _Document = new XmlDocument(); _Document.Load(path); Items = new List<MenuItem>(); var nodeSelection = _Document.SelectNodes("Menu/Item"); foreach (XmlNode node in nodeSelection) Items.Add(new MenuItem(node, null, game)); }
/// <summary> /// Создаёт новый экземпляр класса <see cref="TrackBar"/>. /// </summary> /// <param name="game">The game.</param> /// <param name="caption">The caption.</param> public TrackBar(SourceryGame game, string caption) { Caption = caption; _Game = game; _Sound = game.Content.Load <SoundEffect>("Sounds/Click"); _Font = game.Font; _Lent = new AnimateSprite(game.TrackLent, 11, 1); _Plus = new AnimateSprite(game.PlusButton, 2, 1); _Minus = new AnimateSprite(game.MinusButton, 2, 1); }
/// <summary> /// Создаёт новый экземпляр класса <see cref="TrackBar"/>. /// </summary> /// <param name="game">The game.</param> /// <param name="caption">The caption.</param> public TrackBar(SourceryGame game, string caption) { Caption = caption; _Game = game; _Sound = game.Content.Load<SoundEffect>("Sounds/Click"); _Font = game.Font; _Lent = new AnimateSprite(game.TrackLent, 11, 1); _Plus = new AnimateSprite(game.PlusButton, 2, 1); _Minus = new AnimateSprite(game.MinusButton, 2, 1); }
/// <summary> /// Создаёт новый экземпляр класса <see cref="PanelItem"/>. /// </summary> /// <param name="game">The game.</param> /// <param name="text">The text.</param> public PanelItem(SourceryGame game, string text,string fontName="") { Caption = text; _Texture = new AnimateSprite(game.ItemButton, 3, 1); if (fontName == "") _Font = game.BigFont; else _Font = game.Content.Load<SpriteFont>("Fonts/"+fontName); _Texture.CurrentFrame = 2; }
/// <summary> /// Создаёт новый экземпляр класса <see cref="NewGamePanel"/>. /// </summary> /// <param name="texture">The texture.</param> public NewGamePanel(SourceryGame game) { Type = PanelTypes.NewGame; _Game = game; _Texture = game.Panel; _StartGame = new Button(game,"Новая игра"); _StartGame.OnValueChanged += OnStartGame; Items = new List<Control>(); LoadLevels(); }
/// <summary> /// Создаёт новый экземпляр класса <see cref="ComboBox"/>. /// </summary> /// <param name="game">The game.</param> /// <param name="values">The values.</param> public ComboBox(SourceryGame game, List<String> values) { _Values = new List<Control>(); foreach (string str in values) _Values.Add(new PanelItem(game, str,"Font")); foreach (Control item in _Values) item.OnValueChanged += OnElementSelected; _Sprite = new AnimateSprite(game.ComboBox, 3, 1); _Panel = game.ItemPanel; _Font = game.Font; }
/// <summary> /// Создаёт новый экземпляр класса <see cref="SettingsPanel"/>. /// </summary> /// <param name="game">The game.</param> public SettingsPanel(SourceryGame game,Settings settings,GameScreen parent) { _Game = game; _Parent = parent; _Settings = settings; _Menu = new Menu("Settings/GameMenu.xml",game); _PanelTexture = game.Panel; _Font = game.Font; _CurrentMenu = _Menu.Items; LoadSettings(_Menu.Items); }
/// <summary> /// Создаёт новый экземпляр класса <see cref="SaveLoadPanel"/>. /// </summary> /// <param name="game">Ссылка на игру</param> /// <param name="IsSave">if set to <c>true</c> [is save].</param> public SaveLoadPanel(SourceryGame game, bool IsSave) { _Game = game; _Texture = game.Panel; Items = new List<Control>(); var _ButtonFont = game.Font; if (IsSave) _SaveLoadButton = new Button(game, "Сохранить"); else _SaveLoadButton = new Button(game, "Загрузить"); LoadGames(); }
/// <summary>Создаёт новый экземпляр класса <see cref="Magics"/>.</summary> /// <param name="path">Путь до *.xml файла</param> public Magics(string path, SourceryGame game) { _Document = new XmlDocument(); _Game = game; _Document.Load(path); MagicList = new List <Magic>(); var nodeList = _Document.SelectNodes("Magics/Magic"); foreach (XmlNode node in nodeList) { MagicList.Add(new Magic(node, game)); } }
/// <summary> /// Создаёт новый экземпляр класса <see cref="Dialog"/>. /// </summary> /// <param name="game">Ссылка на игру.</param> /// <param name="text">Текст сообщения.</param> public Dialog(SourceryGame game, string text) { _Panel = game.Panel; _Font = game.Font; _Ok = new Button(game, "Oк"); _Ok.OnValueChanged += OnOkClick; _Cancel = new Button(game, "Отмена"); _Cancel.OnValueChanged += OnCancelClick; _Text = text; _ClientWidth = game.graphics.GraphicsDevice.Viewport.Width; _ClientHeight = game.graphics.GraphicsDevice.Viewport.Height; _DialogRect = new Rectangle(_ClientWidth / 2 - 200, _ClientHeight / 2 - 100, 400, 200); }
//Загрузим соответствующий спрайт private void LoadSprite(SourceryGame game) { string name = _Node.SelectSingleNode("Animations/Texture").InnerText; int start = int.Parse(_Node.SelectSingleNode("Animations/Start").InnerText); int stop = int.Parse(_Node.SelectSingleNode("Animations/Stop").InnerText); int current = int.Parse(_Node.SelectSingleNode("Animations/Current").InnerText); _Sprite = new AnimateSprite(game.Content.Load <Texture2D>("animation/" + name), 8, 8); From = start; To = stop; Static = current; _Sprite.CurrentFrame = Static; }
/// <summary>Создаёт новый экземпляр класса <see cref="MenuItem"/>. </summary> public MenuItem(XmlNode Node,MenuItem Parent,SourceryGame game) { _Node = Node; _Parent = Parent; _Name = _Node.SelectSingleNode("Name").InnerText; _Description = _Node.SelectSingleNode("Description").InnerText; _Position = Convert.ToInt32(_Node.SelectSingleNode("Position").InnerText); Values = new List<string>(); var val = _Node.SelectSingleNode("Values"); if (val != null) { var nodeSelection = val.SelectNodes("Value"); foreach (XmlNode node in nodeSelection) Values.Add(node.InnerText); } var type = _Node.SelectSingleNode("Action").InnerText; _Action = (ActionType)Enum.Parse(typeof(ActionType), type); var controltype = _Node.SelectSingleNode("Type").InnerText; _ControlType = (ControlType)Enum.Parse(typeof(ControlType), controltype); switch (_ControlType) { case ControlType.Button: { ItemControl = new Button(game, _Name); break; } case ControlType.CheckBox: { ItemControl = new CheckBox(game, _Name); break; } case ControlType.ComboBox: { ItemControl = new ComboBox(game, Values); break; } case ControlType.TrackBar: { ItemControl = new TrackBar(game,_Name); break; } } ItemControl.OnValueChanged += OnControlChanged; var selection = _Node.SelectNodes("Item"); if (selection != null && selection.Count > 0) { Items = new List<MenuItem>(); foreach (XmlNode node in selection) Items.Add(new MenuItem(node,this,game)); } }
/// <summary>Загружает параметры игрока из XML-файла</summary> /// <param name="node">Запись об игроке.</param> /// <param name="game">Ссылка на игру.</param> public void LoadPlayerParameters(XmlNode node, SourceryGame game) { //Читаем параметры из *.lvl string playerName = node.SelectSingleNode("Name").InnerText; string fileName = node.SelectSingleNode("File").InnerText; int x = Convert.ToInt32(node.SelectSingleNode("x").InnerText); int y = Convert.ToInt32(node.SelectSingleNode("y").InnerText); int startAnimation = Convert.ToInt32(node.SelectSingleNode("StartAnimation").InnerText); var type = node.SelectSingleNode("Type").InnerText; PlayerType playerType = (PlayerType)Enum.Parse(typeof(PlayerType), type); type = node.SelectSingleNode("Color").InnerText; Colors color = (Colors)Enum.Parse(typeof(Colors), type); //Читаем параметры героя XmlDocument doc = new XmlDocument(); doc.Load("data/players/" + fileName); string textureName = doc.SelectSingleNode("Player/Texture").InnerText; int width = int.Parse(doc.SelectSingleNode("Player/width").InnerText); int height = int.Parse(doc.SelectSingleNode("Player/height").InnerText); int speed = int.Parse(doc.SelectSingleNode("Player/speed").InnerText); _Animation = new PlayerAnimation(doc.SelectSingleNode("Player/Animation")); //Задаем начальные параметры _Tile = new AnimateSprite(game.Content.Load <Texture2D>("animation/" + textureName), 8, 24); _Tile.CurrentFrame = startAnimation; LoadColor(color); _CurrentState = new Rectangle(x - width / 2, y - height / 2, width, height); _Type = playerType; if (playerName == "") { Name = game.PlayerName; } else { Name = playerName; } foreach (Cell cell in Helper.Board) { if (cell.Rect.Contains(x, y)) { _CurrentCell = cell; break; } } CurrentMagic = MaxMagic; _Movement = new Movement(_CurrentState, _CurrentCell, speed, _Tile, _Animation, false); }
/// <summary> /// Создаёт новый экземпляр класса <see cref="PanelItem"/>. /// </summary> /// <param name="game">The game.</param> /// <param name="text">The text.</param> public PanelItem(SourceryGame game, string text, string fontName = "") { Caption = text; _Texture = new AnimateSprite(game.ItemButton, 3, 1); if (fontName == "") { _Font = game.BigFont; } else { _Font = game.Content.Load <SpriteFont>("Fonts/" + fontName); } _Texture.CurrentFrame = 2; }
/// <summary>Создаёт новый экземпляр класса <see cref="FloatingZone"/>.</summary> /// <param name="game">Ссылка на игру.</param> /// <param name="players">Список игроков.</param> public FloatingZone(SourceryGame game, List<Player> players) { _Left = game.Content.Load<Texture2D>("Controls/LeftFloat"); _Right = game.Content.Load<Texture2D>("Controls/RigthFloat"); _Divider = game.Content.Load<Texture2D>("Controls/divider"); _Zones = new List<ColorZone>(); _Players = players; int i = 0; foreach (Player player in _Players) { _Zones.Add(new ColorZone(game, player.MaxMagic, player.CurrentMagic, i)); i++; } _Players = players; }
/// <summary> /// Создаёт новый экземпляр класса <see cref="SaveLoadPanel"/>. /// </summary> /// <param name="game">Ссылка на игру</param> /// <param name="IsSave">if set to <c>true</c> [is save].</param> public SaveLoadPanel(SourceryGame game, bool IsSave) { _Game = game; _Texture = game.Panel; Items = new List <Control>(); var _ButtonFont = game.Font; if (IsSave) { _SaveLoadButton = new Button(game, "Сохранить"); } else { _SaveLoadButton = new Button(game, "Загрузить"); } LoadGames(); }
/// <summary>Загружаем параметры из документа</summary> /// <param name="node">Запись.</param> /// <param name="game">Ссылка на игру.</param> private void LoadFromDocument(XmlNode node, SourceryGame game) { //Читаем настройки из файла _UpdateDelay = int.Parse(node.SelectSingleNode("UpdateDelay").InnerText); _MaxLevel = int.Parse(node.SelectSingleNode("MaxLevel").InnerText); Sprite = new AnimateSprite(game.Content.Load <Texture2D>("Game/" + node.SelectSingleNode("Texture").InnerText), 5, 5); Sprite.CurrentFrame = Convert.ToInt32(node.SelectSingleNode("position").InnerText); Signature = new AnimateSprite(game.ColorStripe, 1, 5); Signature.CurrentFrame = int.Parse(node.SelectSingleNode("signaturePosition").InnerText); X = Convert.ToInt32(node.SelectSingleNode("x").InnerText); Y = Convert.ToInt32(node.SelectSingleNode("y").InnerText); _Level = Convert.ToInt32(node.SelectSingleNode("level").InnerText); OwnerName = node.SelectSingleNode("ownerName").InnerText; MaxResource = 50 + 25 * (_Level - 1); CurrentResource = MaxResource; Reduction = MaxResource / 10; var param = node.SelectSingleNode("width"); int width = 0; int height = 0; if (param != null) { width = Convert.ToInt32(param.InnerText); } param = node.SelectSingleNode("height"); if (param != null) { height = Convert.ToInt32(param.InnerText); } //Задаем начальные параметры if (width != 0 && height != 0) { Rect = new Rectangle(X, Y, width, height); Width = width; Height = height; } else { Width = Sprite.Width; Height = Sprite.Height; Rect = new Rectangle(X, Y, Width, Height); } }
/// <summary>Создаёт новый экземпляр класса <see cref="TitleScreen"/>.</summary> public TitleScreen(SourceryGame game) { _Game = game; Settings = Helper.Settings.Screens(ScreenType.TitleScreen); }
static void Main() { using (var game = new SourceryGame()) game.Run(); }
/// <summary>Загружаем все необходимое для отрисовки</summary> private void LoadSprites(SourceryGame game) { _Font = game.Font; _BigFont = game.BigFont; _Back = new AnimateSprite(game.Content.Load<Texture2D>("controls/ReloadingButton"), 3, 1); LoadSprite(game); }
//Загрузим соответствующий спрайт private void LoadSprite(SourceryGame game) { string name = _Node.SelectSingleNode("Animations/Texture").InnerText; int start = int.Parse(_Node.SelectSingleNode("Animations/Start").InnerText); int stop = int.Parse(_Node.SelectSingleNode("Animations/Stop").InnerText); int current = int.Parse(_Node.SelectSingleNode("Animations/Current").InnerText); _Sprite = new AnimateSprite(game.Content.Load<Texture2D>("animation/"+name),8,8); From = start; To = stop; Static = current; _Sprite.CurrentFrame = Static; }
/// <summary>Создаёт новый экземпляр класса <see cref="Magic"/>.</summary> /// <param name="node">Xml-запись</param> /// <param name="game">Ссылка на игру.</param> public Magic(XmlNode node, SourceryGame game) { _Node = node; LoadAttributes(node); _Executed = false; LoadSprites(game); _ShowText = false; _Movement = new Movement(new Rectangle(0,0,0,0),null,_Speed,_Sprite,_Animation,true); }
/// <summary>Загружаем параметры из документа</summary> /// <param name="node">Запись.</param> /// <param name="game">Ссылка на игру.</param> private void LoadFromDocument(XmlNode node, SourceryGame game) { //Читаем настройки из файла _UpdateDelay = int.Parse(node.SelectSingleNode("UpdateDelay").InnerText); _MaxLevel = int.Parse(node.SelectSingleNode("MaxLevel").InnerText); Sprite = new AnimateSprite(game.Content.Load<Texture2D>("Game/" + node.SelectSingleNode("Texture").InnerText), 5, 5); Sprite.CurrentFrame = Convert.ToInt32(node.SelectSingleNode("position").InnerText); Signature = new AnimateSprite(game.ColorStripe, 1, 5); Signature.CurrentFrame = int.Parse(node.SelectSingleNode("signaturePosition").InnerText); X = Convert.ToInt32(node.SelectSingleNode("x").InnerText); Y = Convert.ToInt32(node.SelectSingleNode("y").InnerText); _Level= Convert.ToInt32(node.SelectSingleNode("level").InnerText); OwnerName = node.SelectSingleNode("ownerName").InnerText; MaxResource = 50 + 25 * (_Level - 1); CurrentResource = MaxResource; Reduction = MaxResource / 10; var param = node.SelectSingleNode("width"); int width = 0; int height = 0; if (param != null) width = Convert.ToInt32(param.InnerText); param = node.SelectSingleNode("height"); if (param != null) height = Convert.ToInt32(param.InnerText); //Задаем начальные параметры if (width != 0 && height != 0) { Rect = new Rectangle(X, Y, width, height); Width = width; Height = height; } else { Width = Sprite.Width; Height = Sprite.Height; Rect = new Rectangle(X,Y,Width,Height); } }
/// <summary>Загружает параметры игрока из XML-файла</summary> /// <param name="node">Запись об игроке.</param> /// <param name="game">Ссылка на игру.</param> public void LoadPlayerParameters(XmlNode node, SourceryGame game) { //Читаем параметры из *.lvl string playerName = node.SelectSingleNode("Name").InnerText; string fileName = node.SelectSingleNode("File").InnerText; int x = Convert.ToInt32(node.SelectSingleNode("x").InnerText); int y = Convert.ToInt32(node.SelectSingleNode("y").InnerText); int startAnimation = Convert.ToInt32(node.SelectSingleNode("StartAnimation").InnerText); var type = node.SelectSingleNode("Type").InnerText; PlayerType playerType = (PlayerType)Enum.Parse(typeof(PlayerType), type); type = node.SelectSingleNode("Color").InnerText; Colors color = (Colors)Enum.Parse(typeof(Colors), type); //Читаем параметры героя XmlDocument doc = new XmlDocument(); doc.Load("data/players/" + fileName); string textureName = doc.SelectSingleNode("Player/Texture").InnerText; int width = int.Parse(doc.SelectSingleNode("Player/width").InnerText); int height = int.Parse(doc.SelectSingleNode("Player/height").InnerText); int speed = int.Parse(doc.SelectSingleNode("Player/speed").InnerText); _Animation = new PlayerAnimation(doc.SelectSingleNode("Player/Animation")); //Задаем начальные параметры _Tile = new AnimateSprite(game.Content.Load<Texture2D>("animation/" + textureName), 8, 24); _Tile.CurrentFrame = startAnimation; LoadColor(color); _CurrentState = new Rectangle(x-width/2, y-height/2, width, height); _Type = playerType; if (playerName == "") Name = game.PlayerName; else Name = playerName; foreach (Cell cell in Helper.Board) if (cell.Rect.Contains(x, y)) { _CurrentCell = cell; break; } CurrentMagic = MaxMagic; _Movement = new Movement(_CurrentState, _CurrentCell, speed, _Tile, _Animation,false); }
/// <summary>Создаёт новый экземпляр класса <see cref="Magics"/>.</summary> /// <param name="path">Путь до *.xml файла</param> public Magics(string path,SourceryGame game) { _Document = new XmlDocument(); _Game = game; _Document.Load(path); MagicList = new List<Magic>(); var nodeList = _Document.SelectNodes("Magics/Magic"); foreach (XmlNode node in nodeList) MagicList.Add(new Magic(node,game)); }