Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- namespace Pizza
- {
- public partial class Form1 : Form
- {
- #region Variable
- public MapEngine miestas;
- private int scrsize;
- #endregion
- #region Initialization
- public Form1()
- {
- InitializeComponent();
- Cursor myCursor = new Cursor(@"images/other/cursor.cur");
- this.Cursor = myCursor;
- }
- #endregion
- #region Load
- public void create()
- {
- Scr scr = new Scr();
- scrsize = scr.Get();
- miestas = new MapEngine("images/images.txt", "maps/pica.txt", true, this);
- miestas.Generate(new Point(50, 50), new Point(0, 0), scrsize, false);
- Gui gui = new Gui(this);
- MiniMap minimap = new MiniMap(new Point(50, Screen.PrimaryScreen.Bounds.Height - 150), new Size(miestas.matricasize * 5, miestas.matricasize * 5), this);
- Navigator navigator = new Navigator(this, miestas, new Point((50 * scrsize) + 52, 51), minimap);
- Attributs attributs = new Attributs(100, this);
- Messenger msg = new Messenger();
- msg.ShowMessage("Hello!", "Game is loaded.", false);
- }
- #endregion
- #region test
- private void Form1_Load(object sender, EventArgs e)
- {
- this.Size = Screen.PrimaryScreen.Bounds.Size;
- this.Location = new Point(0, 0);
- /*Functions fc = new Functions();
- SuperRw rw = new SuperRw();
- string path = "info/users/Profas.txt";
- rw.Write(fc.ChangeWord(1, 2, rw.Read(path), "only", ':'), path);*/
- }
- private void Form1_Shown(object sender, EventArgs e)
- {
- MMeniu mmeniu = new MMeniu(this);
- mmeniu.ShowMeniu();
- }
- #endregion
- }
- class Skipper
- {
- #region Skipper
- public Skipper() { }
- ~Skipper() { }
- #endregion
- #region Get
- public string Get(string info, int step)
- {
- int skip = 0;
- int instep = 1;
- string buf = "";
- int row = 0;
- if (step > 1)
- {
- for (int i = 0; i < info.Length; i++)
- {
- if ((info[i] != '\n') && (info[i] != '\r'))
- {
- if (++skip == 3)
- {
- skip = 0;
- if (++instep == step)
- {
- Scr scr = new Scr();
- row = (instep / scr.Get());
- if (instep % ((scr.Get()*row)+1) == 0)
- i += 2;
- for (int j = 0; j < 3; j++)
- buf += info[++i];
- break;
- }
- }
- }
- }
- }
- else
- for (int i = 0; i < 3; i++)
- buf += info[i];
- return buf;
- }
- #endregion
- #region Set
- public string Set(string data, string info, int step)
- {
- int skip = 0;
- int instep = 1;
- string buf = "";
- if (step > 1)
- {
- for (int i = 0; i < info.Length; i++)
- {
- buf += info[i];
- if ((info[i] != '\n') && (info[i] != '\r'))
- {
- if (++skip == 3)
- {
- skip = 0;
- if (++instep == step)
- {
- if (instep == LineCount(info) + 2)
- {
- buf += "\r\n";
- i += 2;
- }
- buf += data;
- i += 3;
- }
- }
- }
- }
- }
- else
- {
- buf += data;
- for (int i = 3; i < info.Length; i++)
- buf += info[i];
- }
- return buf;
- }
- #endregion
- #region LineCount
- private int LineCount(string text)
- {
- int line = 0;
- for (int i = 0; i < text.Length; i++)
- if (text[i] == '\n')
- ++line;
- return line;
- }
- #endregion
- }
- class Scr
- {
- #region Scr
- public Scr() { }
- ~Scr() { }
- #endregion
- #region Get
- public int Get()
- {
- System.Drawing.Size size = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Size;
- if ((size.Width == 1280) && (size.Height == 1024))
- return 15;
- else
- if ((size.Width == 1280) && (size.Height == 800))
- return 12;
- else if ((size.Width == 1440) && (size.Height == 900))
- return 14;
- else if ((size.Width == 1024) && (size.Height == 768))
- return 11;
- else if ((size.Width == 1280) && ((size.Height == 768) || (size.Height == 720)))
- return 11;
- else if ((size.Width == 800) && (size.Height == 600))
- return 8;
- else if ((size.Width == 1152) && (size.Height == 864))
- return 13;
- else
- return 10;
- }
- #endregion
- }
- class Ranking
- {
- #region Variables
- //public
- public string[] Array = new string[0];
- //private
- private int ElementCounter = 0;
- #endregion
- #region Ranking
- public Ranking() { }
- ~Ranking() { }
- #endregion
- #region AddToArray
- private void AddToArray(string Data)
- {
- string Element = "";
- int Counter = 0;
- for (int i = 0; i < Data.Length; i++)
- if (Data[i] == '\n')
- ElementCounter++;
- Array = new string[ElementCounter];
- for (int i = 0; i < Data.Length; i++)
- {
- if ((Data[i] != '\n') && (Data[i] != '\r'))
- {
- if (Data[i] != ':')
- Element += Data[i];
- else
- Element += ' ';
- }
- else
- {
- Array[Counter] = Element;
- Counter++;
- i++;
- Element = "";
- }
- }
- }
- #endregion
- #region SortArray
- private void SortArray()
- {
- string x;
- for (int limit = Array.Length - 1; limit > 0; limit--)
- {
- for (int i = 0; i < limit; i++)
- {
- if (GetScore(Array[i]) < GetScore(Array[i + 1]))
- {
- x = Array[i];
- Array[i] = Array[i + 1];
- Array[i + 1] = x;
- }
- }
- }
- }
- private int GetScore(string Element)
- {
- string Score = "";
- for (int i = 0; i < Element.Length; i++)
- {
- if (Element[i] == ' ')
- {
- i++;
- while (i != Element.Length)
- Score += Element[i++];
- break;
- }
- }
- return int.Parse(Score);
- }
- #endregion
- #region ShowRanking
- public string ShowRanking(string Data, int top, bool All)
- {
- string Ranking = "";
- AddToArray(Data);
- SortArray();
- if (All == true)
- top = Array.Length;
- for (int i = 0; i < top; i++)
- Ranking += (i + 1).ToString() + ": " + Array[i] + ".\r\n";
- return Ranking;
- }
- #endregion
- }
- static class Program
- {
- #region Main
- [STAThread]
- static void Main()
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new Form1());
- }
- #endregion
- }
- class Objector
- {
- #region Objector
- public Objector() { }
- ~Objector() { }
- #endregion
- #region PictureBox
- public PictureBox OPictureBox(Point location, Image image)
- {
- try
- {
- PictureBox img = new PictureBox();
- img.Image = image;
- img.Location = location;
- img.Size = img.Image.Size;
- return img;
- }
- catch { return null; }
- }
- #endregion
- #region Form
- public Form OForm(Point location, Size size, bool border)
- {
- try
- {
- Form form = new Form();
- if (border != true)
- form.FormBorderStyle = FormBorderStyle.None;
- form.Size = size;
- form.StartPosition = FormStartPosition.Manual;
- form.Location = location;
- return form;
- }
- catch { return null; }
- }
- #endregion
- #region Label
- public Label OLabel(Point location, Color backcolor, string text)
- {
- try
- {
- Label label = new Label();
- label.Text = text;
- label.Location = location;
- label.BackColor = backcolor;
- return label;
- }
- catch { return null; }
- }
- #endregion
- #region Textbox
- public TextBox OTextBox(Point location, int width, BorderStyle borderstyle)
- {
- try
- {
- TextBox textbox = new TextBox();
- textbox.Width = width;
- textbox.Location = location;
- textbox.BorderStyle = borderstyle;
- return textbox;
- }
- catch { return null; }
- }
- #endregion
- #region GroupBox
- public GroupBox OGroupBox(Point location, Size size, string text)
- {
- try
- {
- GroupBox groupbox = new GroupBox();
- groupbox.Location = location;
- groupbox.Size = size;
- groupbox.Text = text;
- return groupbox;
- }
- catch { return null; }
- }
- #endregion
- #region Panel
- public Panel OPanel(Point location, Size size, Color color)
- {
- try
- {
- Panel panel = new Panel();
- panel.Location = location;
- panel.Size = size;
- panel.BackColor = color;
- return panel;
- }
- catch { return null; }
- }
- #endregion
- #region ListBox
- public ListBox OListBox(Point location, Size size, Color color)
- {
- try
- {
- ListBox listbox = new ListBox();
- listbox.Location = location;
- listbox.Size = size;
- listbox.BackColor = color;
- return listbox;
- }
- catch { return null; }
- }
- #endregion
- }
- class SuperRw
- {
- #region SuperRw
- public SuperRw() { }
- ~SuperRw() { }
- #endregion
- #region Read
- public string Read(string file)
- {
- FileStream rfile = new FileStream(file, FileMode.OpenOrCreate, FileAccess.Read);
- StreamReader read = new StreamReader(rfile);
- string info = read.ReadToEnd();
- read.Close();
- rfile.Close();
- return info;
- }
- #endregion
- #region Write
- public void Write(string info, string file)
- {
- FileStream wfile = new FileStream(@file, FileMode.Create, FileAccess.Write);
- StreamWriter write = new StreamWriter(wfile);
- write.Write(info);
- write.Close();
- wfile.Close();
- }
- #endregion
- #region FLineRead
- public string FLineRead(string file, int line)
- {
- string info = Read(file);
- string buf = "";
- int ln = 0;
- for (int i = 0; i < info.Length; i++)
- {
- if (info[i] == '\n')
- ln++;
- if (line == ln)
- {
- if (line != 0)
- ++i;
- while ((i != info.Length) && (info[i] != '\n'))
- if (info[i++] != '\r')
- buf += info[i - 1];
- break;
- }
- }
- return buf;
- }
- #endregion
- }
- class Navigator
- {
- #region Variable
- private Functions fc = new Functions();
- private MapEngine map;
- private MiniMap mmap;
- private Point location;
- private Label label;
- private int left;
- private int top;
- private int size;
- private int step;
- #endregion
- #region Navigator
- public Navigator(Form form, MapEngine Emap, Point start, MiniMap minimap)
- {
- step = 3;
- map = Emap;
- mmap = minimap;
- left = 0;
- top = 0;
- size = map.mapsize;
- location = start;
- Objector obj = new Objector();
- PictureBox img = obj.OPictureBox(start, Image.FromFile(@"images/other/navigator.bmp"));
- img.Click += new EventHandler(img_Click);
- label = obj.OLabel(new Point(img.Left + 2, img.Top + 163), Color.FromArgb(33, 53, 139), "Step Size: 1");
- label.Width = 85;
- label.Font = new Font("Tahoma", 11);
- label.Text = "Step Size: " + step.ToString();
- label.ForeColor = Color.LightGray;
- Label title = obj.OLabel(new Point(start.X + 5, start.Y + 5), Color.FromArgb(13, 31, 107), "Map Navigator");
- title.Size = new Size(150, 20);
- title.ForeColor = Color.White;
- title.Font = new Font("Tahoma", 12);
- form.Controls.Add(title);
- form.Controls.Add(img);
- form.Controls.Add(label);
- label.BringToFront();
- title.BringToFront();
- }
- ~Navigator() { }
- #endregion
- #region Events
- private void img_Click(object sender, EventArgs e)
- {
- // UP
- if (fc.PosCheck(Cursor.Position, new Point(65 + location.X, 35 + location.Y), new Point(95 + location.X, 80 + location.Y)) == true)
- if (top - (step - 1) > 0)
- {
- map.Generate(new Point(50, 50), new Point(left, top -= step), size, true);
- mmap.locon.Top -= step * 5;
- }
- else
- {
- map.Generate(new Point(50, 50), new Point(left, top = 0), size, true);
- mmap.locon.Top = mmap.maxLEFTTOP.Y;
- }
- else
- // DOWN
- if (fc.PosCheck(Cursor.Position, new Point(60 + location.X, 105 + location.Y), new Point(100 + location.X, 150 + location.Y)) == true)
- if ((map.mapsize + top) + (step - 1) < map.matricasize)
- {
- map.Generate(new Point(50, 50), new Point(left, top += step), size, true);
- mmap.locon.Top += step * 5;
- }
- else
- {
- map.Generate(new Point(50, 50), new Point(left, top = (map.matricasize - map.mapsize)), size, true);
- mmap.locon.Top = mmap.maxRIGHTDOWN.Y;
- }
- else
- // RIGHT
- if (fc.PosCheck(Cursor.Position, new Point(100 + location.X, 75 + location.Y), new Point(150 + location.X, 110 + location.Y)) == true)
- if ((map.mapsize + left) + (step - 1) < map.matricasize)
- {
- map.Generate(new Point(50, 50), new Point(left += step, top), size, true);
- mmap.locon.Left += step * 5;
- }
- else
- {
- map.Generate(new Point(50, 50), new Point(left = (map.matricasize - map.mapsize), top), size, true);
- mmap.locon.Left = mmap.maxRIGHTDOWN.X;
- }
- else
- // LEFT
- if (fc.PosCheck(Cursor.Position, new Point(10 + location.X, 75 + location.Y), new Point(60 + location.X, 110 + location.Y)) == true)
- if (left - (step - 1) > 0)
- {
- map.Generate(new Point(50, 50), new Point(left -= step, top), size, true);
- mmap.locon.Left -= step * 5;
- }
- else
- {
- map.Generate(new Point(50, 50), new Point(left = 0, top), size, true);
- mmap.locon.Left = mmap.maxLEFTTOP.X;
- }
- else
- // MINUS
- if (fc.PosCheck(Cursor.Position, new Point(85 + location.X, 165 + location.Y), new Point(115 + location.X, 180 + location.Y)) == true)
- if (step > 1)
- label.Text = "Step Size: " + (--step).ToString();
- else { }
- else
- // PLUS
- if (fc.PosCheck(Cursor.Position, new Point(120 + location.X, 160 + location.Y), new Point(145 + location.X, 180 + location.Y)) == true)
- if (step < 5)
- label.Text = "Step Size: " + (++step).ToString();
- }
- #endregion
- }
- #region State
- public enum State
- {
- Normal = 0,
- Pressed
- }
- #endregion
- #region MouseState
- class MouseState
- {
- public MouseState()
- {
- }
- }
- #endregion
- class MiniMap
- {
- #region Variable
- public PictureBox locon;
- public Point maxLEFTTOP;
- public Point maxRIGHTDOWN;
- #endregion
- #region MiniMap
- public MiniMap(Point start, Size size, Form form)
- {
- Objector obj = new Objector();
- Scr scr = new Scr();
- PictureBox win = obj.OPictureBox(start, Image.FromFile(@"images/other/minimap/minimap.bmp"));
- form.Controls.Add(win);
- win.BringToFront();
- PictureBox loc = obj.OPictureBox(new Point(start.X + 11, start.Y + 17), Image.FromFile(@"images/other/minimap/loc.bmp"));
- loc.Size = size;
- loc.BackgroundImage = loc.Image;
- form.Controls.Add(loc);
- loc.BringToFront();
- locon = obj.OPictureBox(new Point(start.X + 11, start.Y + 17), Image.FromFile(@"images/other/minimap/locon.bmp"));
- locon.Size = new Size(scr.Get() * 5, scr.Get() * 5);
- locon.BackgroundImage = locon.Image;
- form.Controls.Add(locon);
- locon.BringToFront();
- maxLEFTTOP = new Point(start.X + 11, start.Y + 17);
- maxRIGHTDOWN = new Point((start.X + 11 + loc.Width) - (scr.Get() * 5), (start.Y + 17 + loc.Height) - (scr.Get() * 5));
- }
- ~MiniMap() { }
- #endregion
- }
- class Messenger
- {
- #region Variable
- public bool UsersResult;
- private Form Forma;
- private PictureBox[] PicArray = new PictureBox[4];
- private Label[] Labels = new Label[5];
- private Objector obj = new Objector();
- #endregion
- #region Messenger
- public Messenger() { }
- ~Messenger() { }
- #endregion
- #region ShowMessage
- public void ShowMessage(string Title, string Text, Boolean YesNo)
- {
- for (int i = 0; i < 5; i++)
- Labels[i] = new Label();
- Forma = obj.OForm(new Point((Screen.PrimaryScreen.Bounds.Width / 2) - 150, (Screen.PrimaryScreen.Bounds.Height / 2) - 80), new Size(300, 160), false);
- Forma.FormBorderStyle = FormBorderStyle.None;
- Cursor myCursor = new Cursor(@"images/other/cursor.cur");
- Forma.Cursor = myCursor;
- PicArray[0] = obj.OPictureBox(new Point(0, 0), Image.FromFile(@"images/msg/left_1.bmp"));
- Forma.Controls.Add(PicArray[0]);
- PicArray[1] = obj.OPictureBox(new Point(25, 0), Image.FromFile(@"images/msg/middle.bmp"));
- PicArray[1].BackgroundImage = PicArray[1].Image;
- PicArray[1].Width = 300 - 50;
- Forma.Controls.Add(PicArray[1]);
- PicArray[2] = obj.OPictureBox(new Point(275, 0), Image.FromFile(@"images/msg/right_1.bmp"));
- Forma.Controls.Add(PicArray[2]);
- PicArray[2].Click += new EventHandler(Pic_Click);
- Labels[0] = obj.OLabel(new Point(3, 4), Color.FromArgb(49, 75, 108), Title);
- SetStyle(Labels[0], false);
- Labels[0].Size = new Size(250, 20);
- Labels[0].TextAlign = ContentAlignment.MiddleLeft;
- string TextCorrect = "";
- if (Text.Length < 29)
- TextCorrect = Text;
- else
- {
- int i;
- for (i = 0; i <= 20; i++)
- TextCorrect += Text[i];
- while ((i != Text.Length) && (Text[i] != ' '))
- TextCorrect += Text[i++];
- TextCorrect += "\n";
- i++;
- while (i < Text.Length)
- TextCorrect += Text[i++];
- }
- Labels[1] = obj.OLabel(new Point(5, 55), Color.FromArgb(49, 75, 108), TextCorrect);
- SetStyle(Labels[1], false);
- Labels[1].Size = new Size(Forma.Width - 10, 50);
- if (YesNo == false)
- {
- Labels[2] = obj.OLabel(new Point((Forma.Width - Labels[2].Width + 50) / 2, 120), Color.FromArgb(49, 75, 108), "OK");
- Labels[2].Click += new EventHandler(labels2_Click);
- SetStyle(Labels[2], true);
- }
- else
- {
- Labels[2] = obj.OLabel(new Point(((Forma.Width - Labels[2].Width + 50) / 2) - 30, 120), Color.FromArgb(49, 75, 108), "Yes");
- Labels[2].Click += new EventHandler(labels2_Click);
- SetStyle(Labels[2], true);
- Labels[3] = obj.OLabel(new Point(((Forma.Width - Labels[3].Width + 50) / 2) + 30, 120), Color.FromArgb(49, 75, 108), "No");
- Labels[3].Click += new EventHandler(labels3_Click);
- SetStyle(Labels[3], true);
- }
- Forma.ShowDialog();
- }
- #endregion
- #region SetStyle
- private void SetStyle(object sender, bool board)
- {
- Label get = (sender as Label);
- if (board == true)
- get.BorderStyle = BorderStyle.FixedSingle;
- get.Size = new Size(40, 25);
- get.Font = new Font("Comic Sans MS", 11F, FontStyle.Bold, GraphicsUnit.Point, ((System.Byte)(0)));
- get.TextAlign = ContentAlignment.MiddleCenter;
- Forma.Controls.Add(get);
- get.BringToFront();
- }
- #endregion
- #region Events
- void Pic_Click(object sender, EventArgs e)
- {
- Functions fc = new Functions();
- if (fc.PosCheck(new Point(Cursor.Position.X - Forma.Location.X, Cursor.Position.Y - Forma.Location.Y), new Point(275, 0), new Point(300, 25)) == true)
- {
- UsersResult = false;
- Forma.Close();
- }
- }
- void labels2_Click(object sender, EventArgs e)
- {
- UsersResult = true;
- Forma.Close();
- }
- void labels3_Click(object sender, EventArgs e)
- {
- UsersResult = false;
- Forma.Close();
- }
- #endregion
- }
- class InfoBox
- {
- #region Variable
- private Form form;
- public Label text;
- #endregion
- #region InfoBox
- public InfoBox(Point start, Form forma)
- {
- form = forma;
- //gui
- Objector obj = new Objector();
- PictureBox[] box = new PictureBox[3];
- box[0] = obj.OPictureBox(start, Image.FromFile(@"images\infobox\left_1.bmp"));
- box[1] = obj.OPictureBox(new Point(start.X+25,start.Y), Image.FromFile(@"images\infobox\middle.bmp"));
- box[1].Width = 300;
- box[1].BackgroundImageLayout = ImageLayout.Tile;
- box[1].BackgroundImage = box[1].Image;
- box[2] = obj.OPictureBox(new Point(start.X+325,start.Y), Image.FromFile(@"images\infobox\right_1.bmp"));
- for (int i = 0; i < 3; i++)
- {
- form.Controls.Add(box[i]);
- box[i].BringToFront();
- }
- Label label = obj.OLabel(new Point(start.X + 5, start.Y + 5), Color.FromArgb(13, 31, 107), "Info Box");
- label.Height = 20;
- label.ForeColor = Color.White;
- label.Font = new Font("Tahoma", 12);
- form.Controls.Add(label);
- label.BringToFront();
- text = obj.OLabel(new Point(start.X + 10, start.Y + 30), Color.FromArgb(33, 53, 139), "Click on the map! For more information.");
- text.Size = new Size(330, 168);
- text.ForeColor = Color.LightGray;
- text.Font = new Font("Tahoma", 9);
- form.Controls.Add(text);
- text.BringToFront();
- }
- ~InfoBox() { }
- #endregion
- }
- class Gui
- {
- #region Variable
- private Form form;
- private Objector obj = new Objector();
- private int scrW;
- private int scrH;
- #endregion
- #region GUI
- public Gui(Form forma)
- {
- form = forma;
- scrW = Screen.PrimaryScreen.Bounds.Width;
- scrH = Screen.PrimaryScreen.Bounds.Height;
- Top();
- Left();
- Down();
- Right();
- }
- #endregion
- #region Top
- private void Top()
- {
- PictureBox[] top = new PictureBox[2];
- top[1] = obj.OPictureBox(new Point(scrW, 0), Image.FromFile(@"images/gui/top_3.jpg"));
- top[1].Left -= top[1].Image.Width;
- top[0] = obj.OPictureBox(new Point(0, 0), Image.FromFile(@"images/gui/top_2.jpg"));
- top[0].BackgroundImage = top[0].Image;
- top[0].Width = scrW - (top[1].Image.Width);
- top[1].Click +=new EventHandler(top_Click);
- for (int i = 0; i < 2; i++)
- form.Controls.Add(top[i]);
- Label label = obj.OLabel(new Point(15, 14), Color.FromArgb(22, 78, 133), "The Pizza - Serious Business");
- label.Font = new Font("Tahoma", 15);
- label.ForeColor = Color.White;
- label.Width = 400;
- form.Controls.Add(label);
- label.BringToFront();
- }
- #endregion
- #region Left
- private void Left()
- {
- PictureBox left = obj.OPictureBox(new Point(0, 50), Image.FromFile(@"images/gui/left_1.jpg"));
- left.BackgroundImage = left.Image;
- left.Height = scrH - (50 + 150);
- left.Top = 50;
- form.Controls.Add(left);
- }
- #endregion
- #region Down
- private void Down()
- {
- PictureBox down = obj.OPictureBox(new Point(0, scrH), Image.FromFile(@"images/gui/down_1.jpg"));
- down.Top -= down.Height;
- down.BackgroundImage = down.Image;
- down.Width = scrW;
- form.Controls.Add(down);
- }
- #endregion
- #region Right
- private void Right()
- {
- PictureBox right = obj.OPictureBox(new Point(scrW - 50, 50), Image.FromFile(@"images/gui/right_1.jpg"));
- right.BackgroundImage = right.Image;
- right.Height = scrH - (50 + 150);
- form.Controls.Add(right);
- }
- #endregion
- #region Events
- private void top_Click(object sender, EventArgs e)
- {
- PictureBox img = (sender as PictureBox);
- Functions fc = new Functions();
- if (fc.PosCheck(Cursor.Position, new Point(scrW - img.Width, 0), img.Location + img.Size) == true)
- form.Close();
- }
- #endregion
- }
- class Functions
- {
- #region Functions
- public Functions()
- { }
- ~Functions() { }
- #endregion
- #region ReadWord
- public string ReadWord(int line, int word, string text, char sign, bool only_line)
- {
- string buf = "";
- string text_line = "";
- int line_nr = 0;
- int sign_nr = 1;
- bool end = false;
- --line;
- if (word > 0)
- {
- for (int i = 0; i < text.Length; i++)
- {
- if (line != 0)
- {
- if (text[i] == '\n')
- line_nr++;
- else
- continue;
- if (line_nr == line)
- {
- ++i;
- while ((i != text.Length) && (text[i] != '\n') && (text[i] != '\r'))
- text_line += text[i++];
- if (only_line != false)
- return text_line;
- break;
- }
- }
- else
- {
- while ((i != text.Length) && (text[i] != '\n') && (text[i] != '\r'))
- text_line += text[i++];
- if (only_line != false)
- return text_line;
- break;
- }
- }
- for (int i = 0; i < text_line.Length; i++)
- {
- if (word == 1)
- {
- while ((i != text_line.Length) && (text_line[i] != sign) && (text[i] != '\n') && (text[i] != '\r'))
- buf += text_line[i++];
- return buf;
- }
- else
- {
- for (int j = 0; j < text_line.Length; j++)
- {
- while (sign_nr != word)
- if (text_line[j++] == sign)
- sign_nr++;
- while ((j != text_line.Length) && (text_line[j] != '\n') && (text_line[j] != sign))
- buf += text_line[j++];
- end = true;
- if (end == true)
- break;
- }
- }
- if (end == true)
- break;
- }
- }
- else
- return null;
- if (buf != "")
- return buf;
- else
- return null;
- }
- #endregion
- #region ChangeWord
- public string ChangeWord(int line, int word, string text, string newWord, char sign)
- {
- string buf = "";
- string text_line = "";
- int line_nr = 0;
- int sign_nr = 1;
- bool end = false;
- --line;
- if (word > 0)
- {
- for (int i = 0; i < text.Length; i++)
- {
- if (line != 0)
- {
- if (text[i] == '\n')
- line_nr++;
- else
- continue;
- if (line_nr == line)
- {
- ++i;
- while ((i != text.Length) && (text[i] != '\n') && (text[i] != '\r'))
- text_line += text[i++];
- break;
- }
- }
- else
- {
- while ((i != text.Length) && (text[i] != '\n') && (text[i] != '\r'))
- text_line += text[i++];
- break;
- }
- }
- for (int i = 0; i < text_line.Length; i++)
- {
- if (word == 1)
- {
- while (text_line[i] != sign)
- i++;
- while ((i != text_line.Length) && (text_line[i] != '\n'))
- buf += text_line[i++];
- buf = newWord + buf;
- }
- else
- {
- for (int j = 0; j < text_line.Length; j++)
- {
- while (sign_nr != word)
- {
- buf += text_line[j];
- if (text_line[j++] == sign)
- sign_nr++;
- }
- buf += newWord;
- while ((j != text_line.Length) && (text_line[j] != '\n') && (text_line[j] != sign))
- j++;
- while (j != text_line.Length)
- buf += text_line[j++];
- end = true;
- if (end != false)
- break;
- }
- }
- if (end != false)
- break;
- }
- }
- else
- return null;
- int curline = 0;
- string all = "";
- for (int i = 0; i < text.Length; i++)
- {
- if (text[i] == '\n')
- curline++;
- if (curline == line_nr)
- {
- all += buf;
- while ((++i != text.Length) && (text[i] != '\n'))
- continue;
- while (i != text.Length)
- all += text[i++];
- break;
- }
- all += text[i];
- }
- if (all != "")
- return all;
- else
- return null;
- }
- #endregion
- #region PosCheck
- public bool PosCheck(System.Drawing.Point cur, System.Drawing.Point field, System.Drawing.Point fieldmax)
- {
- if ((cur.X > field.X) && (cur.X < fieldmax.X))
- if ((cur.Y > field.Y) && (cur.Y < fieldmax.Y))
- return true;
- else
- return false;
- else
- return false;
- }
- #endregion
- #region LineCount
- public int LineCount(string text)
- {
- int line = 0;
- for (int i = 0; i < text.Length; i++)
- if (text[i] == '\n')
- ++line;
- return line;
- }
- #endregion
- }
- class Coder
- {
- #region Coder
- public Coder() { }
- ~Coder() { }
- #endregion
- #region ToCode
- public string ToCode(string SourceData)
- {
- int charASCII;
- int Step;
- string Data;
- string CodedData = "";
- Data = SourceData;
- for (int i = 0; i < Data.Length;i++)
- {
- if ((Data[i] == '\n') || (Data[i] == '\r'))
- {
- CodedData = CodedData + Data[i];
- continue;
- }
- charASCII = (int)Data[i];
- Step = ((((Data.Length + i) % 7) * 52) % 92) + 33;
- if (charASCII + Step > 126)
- {
- Step = Step - (126 - charASCII);
- charASCII = Step + 33;
- }
- else
- charASCII = charASCII + Step;
- CodedData = CodedData + Convert.ToChar(charASCII);
- }
- return CodedData;
- }
- #endregion
- #region UnCode
- public string UnCode(string SourceData)
- {
- int charASCII;
- int Step;
- string Data;
- string UnCodedData = "";
- Data = SourceData;
- for (int i = 0; i < Data.Length; i++)
- {
- if ((Data[i] == '\n') || (Data[i] == '\r'))
- {
- UnCodedData = UnCodedData + Data[i];
- continue;
- }
- charASCII = (int)Data[i];
- Step = ((((Data.Length + i) % 7) * 52) % 92) + 33;
- if (charASCII - Step < 33)
- {
- Step = Step - charASCII;
- charASCII = 126 - Step - 33;
- }
- else
- charASCII = charASCII - Step;
- UnCodedData = UnCodedData + Convert.ToChar(charASCII);
- }
- return UnCodedData;
- }
- #endregion
- }
- class PopMeniu
- {
- #region Variable
- private const int buttons = 5;
- private Label[] pop = new Label[buttons];
- private Form1 form;
- private int time;
- private Timer hide = new Timer();
- private MapEngine _engine;
- #endregion
- #region PopMeniu
- public PopMeniu(Form1 forma, MapEngine engine)
- {
- form = forma;
- _engine = engine;
- Objector obj = new Objector();
- string[] names = new string[buttons] { " MENIU", "Create", "Delete", "Information", "Close" };
- for (int i = 0; i < buttons; i++)
- {
- pop[i] = obj.OLabel(new Point(Cursor.Position.X, Cursor.Position.Y +(i*20)), Color.LightCoral, names[i]);
- pop[i].Font = new Font("Tahoma", 12);
- pop[i].Tag = i;
- pop[i].BorderStyle = BorderStyle.FixedSingle;
- pop[i].MouseEnter +=new EventHandler(pop_enter);
- pop[i].MouseLeave +=new EventHandler(pop_leave);
- form.Controls.Add(pop[i]);
- pop[i].BringToFront();
- }
- pop[4].MouseClick +=new MouseEventHandler(close_click);
- pop[1].MouseClick +=new MouseEventHandler(create_click);
- pop[0].BackColor = Color.Black;
- pop[0].ForeColor = Color.White;
- Timer hide = new Timer();
- hide.Interval = 800;
- hide.Tick +=new EventHandler(hide_Tick);
- hide.Enabled = true;
- }
- ~PopMeniu() { }
- #endregion
- #region Clear
- private void Clear()
- {
- for (int i = 0; i < buttons; i++)
- {
- form.Controls.Remove(pop[i]);
- pop[i] = null;
- }
- hide = null;
- GC.Collect();
- }
- #endregion
- #region Events
- //Hover
- private void pop_enter(object sender, EventArgs e)
- {
- if ((sender as Label).Tag.ToString() != "0")
- (sender as Label).BackColor = Color.LightGray;
- }
- private void pop_leave(object sender, EventArgs e)
- {
- if ((sender as Label).Tag.ToString() != "0")
- (sender as Label).BackColor = Color.LightCoral;
- }
- //Click
- private void close_click(object sender, MouseEventArgs e)
- {
- Clear();
- }
- private void create_click(object sender, MouseEventArgs e)
- {
- BuySystem buysystem = new BuySystem(form, _engine);
- Clear();
- }
- //Tick
- private void hide_Tick(object sender, EventArgs e)
- {
- if(time++==2)
- {
- Clear();
- (sender as Timer).Enabled = false;
- (sender as Timer).Dispose();
- }
- }
- #endregion
- }
- public partial class MapEngine
- {
- #region Variable
- //private
- private Objector obj = new Objector();
- private Form1 form;
- private PictureBox locator;
- private string mapinfo;
- private string _mapinfo;
- private string listinfo;
- private Functions fc = new Functions();
- private InfoBox infobox;
- //public
- public int mapsize;
- public int matricasize;
- public int currentimg;
- public PictureBox[] img = new PictureBox[0];
- #endregion
- #region MapEngine
- public MapEngine(string file, string map, bool locator, object forma)
- {
- form = (forma as Form1);
- Scr scr = new Scr();
- infobox = new InfoBox(new Point((50 * scr.Get()) + 52, (Screen.PrimaryScreen.Bounds.Height - 352)), form);
- SuperRw rw = new SuperRw();
- listinfo = rw.Read(file);
- mapinfo = rw.Read(map);
- matricasize = fc.LineCount(mapinfo) + 1;
- if (locator != false)
- Locator();
- }
- ~MapEngine() { }
- #endregion
- #region Generate
- public void Generate(Point start, Point skip, int size, bool reload)
- {
- mapsize = size;
- if (reload != true)
- img = new PictureBox[size * size];
- string p_map = "";
- string numbers = "";
- int curskip = 0;
- int nr = 0;
- int a = 0;
- int b = 0;
- int step = 0;
- for (int i = 0; i < mapinfo.Length; )
- {
- while (curskip != skip.Y)
- if (mapinfo[i++] == '\n')
- curskip++;
- i += (skip.X * 3);
- curskip = 0;
- while (i != mapinfo.Length)
- {
- p_map += mapinfo[i];
- if (++curskip == 3)
- {
- curskip = 0;
- step++;
- }
- if (step == size)
- {
- while ((i != mapinfo.Length) && (mapinfo[i] != '\n'))
- i++;
- if (i != mapinfo.Length)
- {
- p_map += "\r\n";
- i += (skip.X * 3);
- }
- step = 0;
- }
- if (i != mapinfo.Length)
- i++;
- }
- break;
- }
- curskip = 0;
- for (int i = 0; i <= p_map.Length; i++)
- if ((i != p_map.Length) && (p_map[i] != '\n') && (p_map[i] != '\r'))
- {
- curskip++;
- numbers += p_map[i];
- if (curskip == 2)
- {
- if (nr == size * size)
- break;
- if (reload != true)
- {
- img[nr] = obj.OPictureBox(new Point(((50 * a) + start.X), (50 * b) + start.Y), GetImg(numbers, listinfo));
- img[nr].Tag = nr;
- img[nr].MouseMove += new MouseEventHandler(img_MouseMove);
- img[nr].MouseClick += new MouseEventHandler(img_Click);
- }
- else
- img[nr].Image = GetImg(numbers, listinfo);
- img[nr].Name = GetPath(numbers, listinfo);
- numbers = p_map[++i].ToString();
- Rotate(img[nr], numbers);
- curskip = 0;
- numbers = "";
- if (reload != true)
- form.Controls.Add(img[nr]);
- a++;
- nr++;
- if (a == size)
- {
- b++;
- a = 0;
- }
- }
- }
- _mapinfo = p_map;
- }
- #endregion
- #region Clean
- public void Clean()
- {
- for (int i = 0; i < mapsize * mapsize; i++)
- form.Controls.Remove(img[i]);
- }
- #endregion
- #region Locator
- private void Locator()
- {
- locator = obj.OPictureBox(new Point(0, 0), Image.FromFile(@"images/other/locator.bmp"));
- form.Controls.Add(locator);
- }
- #endregion
- #region img_Events
- private void img_MouseMove(object sender, MouseEventArgs e)
- {
- PictureBox img = (sender as PictureBox);
- if ((e.Location.X + img.Left > img.Left) && (e.Location.X + img.Left < img.Left + 50))
- if ((e.Location.Y + img.Top > img.Top) && (e.Location.Y + img.Top < img.Top + 50))
- {
- locator.Location = new Point(img.Left + 20, img.Top + 20);
- currentimg = Convert.ToInt32(img.Tag);
- }
- }
- #endregion
- #region Rotate
- private PictureBox Rotate(PictureBox img, string numbers)
- {
- if (numbers == "1")
- img.Image.RotateFlip(RotateFlipType.Rotate90FlipNone);
- if (numbers == "2")
- img.Image.RotateFlip(RotateFlipType.Rotate180FlipNone);
- if (numbers == "3")
- img.Image.RotateFlip(RotateFlipType.Rotate270FlipNone);
- if (numbers == "4")
- img.Image.RotateFlip(RotateFlipType.Rotate90FlipX);
- return img;
- }
- #endregion
- #region GetImg
- private Image GetImg(string nr, string text)
- {
- for (int i = 0; i < fc.LineCount(text) + 2; i++)
- if (nr == fc.ReadWord(i, 1, text, ':', false))
- return Image.FromFile(@"images/" + fc.ReadWord(i, 2, text, ':', false) + ".bmp");
- return null;
- }
- #endregion
- #region GetPath
- private string GetPath(string nr, string text)
- {
- for (int i = 0; i < fc.LineCount(text) + 2; i++)
- if (nr == fc.ReadWord(i, 1, text, ':', false))
- return "images/" + fc.ReadWord(i, 2, text, ':', false);
- return null;
- }
- #endregion
- #region Events
- private void img_Click(object sender, MouseEventArgs e)
- {
- PictureBox path = (sender as PictureBox);
- Skipper skipper = new Skipper();
- Messenger msg = new Messenger();
- if (e.Button == MouseButtons.Left)
- infobox.text.Text = "Path: " + path.Name + " \n\rTag: " + currentimg.ToString() + "."
- + "\n\rNr from matrica: " + skipper.Get(_mapinfo, currentimg + 1) + ". \n\rMatrica:\n\r" + _mapinfo;
- if (e.Button == MouseButtons.Right)
- {
- PopMeniu pop = new PopMeniu(form, this);
- }
- }
- #endregion
- }
- public interface IAtrributs
- {
- #region Properties
- int money { get; set; }
- int population { get; set; }
- int rank { get; set; }
- int money_income { get; set; }
- int people_income { get; set; }
- int tax { get; set; }
- #endregion
- }
- public class Attributs : IAtrributs
- {
- #region Variable
- private int _money;
- private int _population;
- private int _rank;
- private int _money_income;
- private int _people_income;
- private int _tax;
- private int labels;
- private Label[] lattr = new Label[7];
- public int money
- {
- get
- {
- return _money;
- }
- set
- {
- _money = value;
- }
- }
- public int population
- {
- get
- {
- return _population;
- }
- set
- {
- _population = value;
- }
- }
- public int rank
- {
- get
- {
- return _rank;
- }
- set
- {
- _rank = value;
- }
- }
- public int money_income
- {
- get
- {
- return _money_income;
- }
- set
- {
- _money_income = value;
- }
- }
- public int people_income
- {
- get
- {
- return _people_income;
- }
- set
- {
- _people_income = value;
- }
- }
- public int tax
- {
- get
- {
- return _tax;
- }
- set
- {
- _tax = value;
- }
- }
- #endregion
- #region Attributs
- public Attributs(int start_money, Form form)
- {
- labels = 7;
- money = start_money;
- population = 1;
- rank = 0;
- money_income = 10;
- people_income = 1;
- tax = 10;
- Gui(form);
- }
- ~Attributs() { }
- #endregion
- #region GUI
- private void Gui(Form form)
- {
- Objector obj = new Objector();
- for (int i = 0; i < labels; i++)
- lattr[i] = new Label();
- int scrH = Screen.PrimaryScreen.Bounds.Height;
- Color bg = Color.FromArgb(22, 78, 133);
- lattr[0] = obj.OLabel(new Point(250, scrH - 100), bg, "Money: " + money.ToString() + "$.");
- lattr[1] = obj.OLabel(new Point(250, scrH - 75), bg, "Population: " + population.ToString() + "/100.");
- lattr[2] = obj.OLabel(new Point(250, scrH - 50), bg, "Rank: " + rank.ToString() + ".");
- lattr[3] = obj.OLabel(new Point(410, scrH - 100), bg, "Money Income: " + money_income.ToString() + "$/Day.");
- lattr[4] = obj.OLabel(new Point(410, scrH - 75), bg, "People Income: " + people_income.ToString() + "/Day.");
- lattr[5] = obj.OLabel(new Point(410, scrH - 50), bg, "TAX: " + tax.ToString() + "/Day");
- lattr[6] = obj.OLabel(new Point(230, scrH - 125), bg, "STATISTICS: ");
- for (int i = 0; i < labels; i++)
- {
- lattr[i].ForeColor = Color.White;
- lattr[i].Width = 250;
- lattr[i].Font = new Font("Tahoma", 12);
- form.Controls.Add(lattr[i]);
- lattr[i].BringToFront();
- }
- }
- #endregion
- #region Other
- public void Reload()
- {
- lattr[0].Text = "Money: " + money.ToString() + ".";
- lattr[1].Text = "Population: " + population.ToString() + "/100.";
- lattr[2].Text = "Rank: " + rank.ToString() + ".";
- lattr[3].Text = "Money Income: " + money_income.ToString() + "$/Day.";
- lattr[4].Text = "People Income: " + money_income.ToString() + "/Day.";
- lattr[5].Text = "TAX: " + tax.ToString() + "/Day.";
- }
- #endregion
- }
- class MMeniu
- {
- #region Variables
- //public
- public string Username = "";
- public string Password = "";
- public string Email = "";
- public bool Registration;
- //private
- private Form1 form;
- private Form MainForm = new Form();
- private PictureBox[] MainFormPics = new PictureBox[3];
- private Label[] MeniuPoints = new Label[6];
- private Panel[] MeniuPanels = new Panel[6];
- private Label TopLabel = new Label();
- private Label ExitLabel = new Label();
- //Login meniu
- private Label[] Meniu1Labels = new Label[6];
- private TextBox[] Meniu1TextBoxs = new TextBox[2];
- private CheckBox Meniu1Check = new CheckBox();
- private int Checkcounter = 1;
- // Register meniu point
- private Label[] Meniu2Labels = new Label[7];
- private TextBox[] Meniu2TextBoxs = new TextBox[4];
- // About meniu point
- private Label AboutText = new Label();
- // Useful objects
- private Objector obj = new Objector();
- private Messenger msg = new Messenger();
- private SuperRw SRw = new SuperRw();
- private Functions fc = new Functions();
- #endregion
- #region MMeniu
- public MMeniu(Form1 forma)
- {
- form = forma;
- MainForm = obj.OForm(new Point((Screen.PrimaryScreen.Bounds.Width / 2) - 175, (Screen.PrimaryScreen.Bounds.Height / 2) - 200), new Size(350, 400), false);
- MainForm.BackColor = Color.FromArgb(49, 75, 108);
- Cursor myCursor = new Cursor(@"images/other/cursor.cur");
- MainForm.Cursor = myCursor;
- MainFormPics[0] = obj.OPictureBox(new Point(0, 0), Image.FromFile(@"images/mmeniu/MainForm_Left.bmp"));
- MainFormPics[1] = obj.OPictureBox(new Point(MainFormPics[0].Width, 0), Image.FromFile(@"images/mmeniu/MainForm_Middle.bmp"));
- MainFormPics[1].Width = MainForm.Width - 2 * MainFormPics[0].Width;
- MainFormPics[1].BackgroundImage = MainFormPics[1].Image;
- MainFormPics[2] = obj.OPictureBox(new Point(MainForm.Width - MainFormPics[0].Width , 0), Image.FromFile(@"images/mmeniu/MainForm_Right.bmp"));
- for (int i = 0; i < 3; i++)
- MainForm.Controls.Add(MainFormPics[i]);
- MeniuPoints[0] = obj.OLabel(new Point(2, 27), Color.FromArgb(49, 75, 108), "Ranking");
- MeniuPoints[1] = obj.OLabel(new Point(85, 27), Color.FromArgb(49, 75, 108), "Stats");
- MeniuPoints[2] = obj.OLabel(new Point(85*2, 27), Color.FromArgb(49, 75, 108), "Options");
- MeniuPoints[3] = obj.OLabel(new Point(85*3, 27), Color.FromArgb(49, 75, 108), "About");
- MeniuPoints[4] = obj.OLabel(new Point(2, 56), Color.FromArgb(49, 75, 108), "Login");
- MeniuPoints[5] = obj.OLabel(new Point(170, 56), Color.FromArgb(49, 75, 108), "Register");
- for (int i = 0; i <= 3; i++)
- {
- SetStyle(MeniuPoints[i], true, true, 13F,new Size(93, 30));
- MainForm.Controls.Add(MeniuPoints[i]);
- MeniuPoints[i].BringToFront();
- }
- for (int i = 4; i < 6; i++)
- {
- SetStyle(MeniuPoints[i], true, true, 15F, new Size(93, 30));
- MeniuPoints[i].Width = 178;
- MainForm.Controls.Add(MeniuPoints[i]);
- MeniuPoints[i].BringToFront();
- }
- for (int i = 0; i < 6; i++)
- {
- MeniuPanels[i] = obj.OPanel(new Point(4, 88), new Size(342, 300), Color.FromArgb(49, 75, 108));
- MainForm.Controls.Add(MeniuPanels[i]);
- MeniuPanels[i].Visible = false;
- }
- MeniuPanels[0].BringToFront();
- MeniuPanels[0].Visible = true;
- MeniuPoints[4].BackColor = Color.FromArgb(10, 100, 120);
- TopLabel = obj.OLabel(new Point(3, 3), Color.FromArgb(49, 75, 108), "The Pizza - Serious Business");
- SetStyle(TopLabel, false, false, 11F, new Size(300, 20));
- MainForm.Controls.Add(TopLabel);
- TopLabel.BringToFront();
- ExitLabel = obj.OLabel(new Point(270, 360), Color.FromArgb(49, 75, 108), "Exit");
- SetStyle(ExitLabel, true, true, 11F, new Size(70,25));
- MainForm.Controls.Add(ExitLabel);
- // Events
- MainFormPics[2].Click += new EventHandler(MainFormPics2_Click);
- ExitLabel.Click += new EventHandler(ExitLabel_Click);
- MeniuPoints[0].Click += new EventHandler(MeniuPoints0_Click);
- MeniuPoints[1].Click += new EventHandler(MeniuPoints1_Click);
- MeniuPoints[2].Click += new EventHandler(MeniuPoints2_Click);
- MeniuPoints[3].Click += new EventHandler(MeniuPoints3_Click);
- MeniuPoints[4].Click += new EventHandler(MeniuPoints4_Click);
- MeniuPoints[5].Click += new EventHandler(MeniuPoints5_Click);
- SetLogin();
- SetRegistration();
- SetAbout();
- ExitLabel.BringToFront();
- }
- ~MMeniu() { }
- #endregion
- #region SetLogin
- private void SetLogin()
- {
- Meniu1Labels[0] = obj.OLabel(new Point(10,10), Color.FromArgb(49, 75, 108), "Username");
- Meniu1Labels[1] = obj.OLabel(new Point(10,70), Color.FromArgb(49, 75, 108), "Password");
- Meniu1Labels[2] = obj.OLabel(new Point(85, 180), Color.FromArgb(49, 75, 108), "OK");
- Meniu1Labels[3] = obj.OLabel(new Point(175, 180), Color.FromArgb(49, 75, 108), "Clear");
- for (int i = 0; i < 2; i++)
- SetStyle(Meniu1Labels[i], false, true, 10F,new Size(93, 30));
- for (int i = 2; i < 4; i++)
- SetStyle(Meniu1Labels[i], true, true, 11F, new Size(70, 25));
- for (int i = 0; i < 4; i++)
- {
- MeniuPanels[0].Controls.Add(Meniu1Labels[i]);
- Meniu1Labels[i].BringToFront();
- }
- Meniu1TextBoxs[0] = obj.OTextBox(new Point(23, 45), 140, BorderStyle.FixedSingle);
- Meniu1TextBoxs[1] = obj.OTextBox(new Point(23, 105), 140, BorderStyle.FixedSingle);
- Meniu1TextBoxs[1].PasswordChar = '*';
- for (int i = 0; i < 2; i++)
- {
- MeniuPanels[0].Controls.Add(Meniu1TextBoxs[i]);
- Meniu1TextBoxs[i].BringToFront();
- }
- Meniu1Check.Location = new Point(23, 136);
- Meniu1Check.Text = "Remember me";
- Meniu1Check.Width = 120;
- Meniu1Check.Font = new Font("Comic Sans MS", 9F, FontStyle.Bold, GraphicsUnit.Point, ((System.Byte)(0)));
- Meniu1Check.BringToFront();
- //Events
- Meniu1Labels[2].Click += new EventHandler(Meniu1Labels2_Click);
- Meniu1Labels[3].Click += new EventHandler(Meniu1Labels3_Click);
- Meniu1Check.CheckStateChanged += new EventHandler(Meniu1Check_CheckStateChanged);
- MeniuPanels[0].Controls.Add(Meniu1Check);
- MeniuPanels[0].BringToFront();
- //fortest
- string file = SRw.Read("info/remember.txt");
- Meniu1TextBoxs[0].Text = fc.ReadWord(1, 1, file, ':', false);
- Meniu1TextBoxs[1].Text = fc.ReadWord(1, 2, file, ':', false);
- if (Meniu1TextBoxs[0].Text != "")
- Meniu1Check.Checked = true;
- }
- #endregion
- #region SetRegistration
- private void SetRegistration()
- {
- Meniu2Labels[0] = obj.OLabel(new Point(23, 10), Color.FromArgb(49, 75, 108), "Username");
- Meniu2Labels[1] = obj.OLabel(new Point(23, 70), Color.FromArgb(49, 75, 108), "Password");
- Meniu2Labels[2] = obj.OLabel(new Point(23, 130), Color.FromArgb(49, 75, 108), "Repeat Password");
- Meniu2Labels[3] = obj.OLabel(new Point(23, 190), Color.FromArgb(49, 75, 108), "Email");
- Meniu2Labels[4] = obj.OLabel(new Point(85, 272), Color.FromArgb(49, 75, 108), "OK");
- Meniu2Labels[5] = obj.OLabel(new Point(175, 272), Color.FromArgb(49, 75, 108), "Clear");
- for (int i = 0; i < 4; i++)
- SetStyle(Meniu2Labels[i], false, false, 10F, new Size(150, 30));
- for (int i = 4; i < 6; i++)
- SetStyle(Meniu2Labels[i], true, true, 11F, new Size(70, 25));
- for (int i = 0; i < 6; i++)
- {
- MeniuPanels[1].Controls.Add(Meniu2Labels[i]);
- Meniu2Labels[i].BringToFront();
- }
- Meniu2TextBoxs[0] = obj.OTextBox(new Point(23, 40), 140, BorderStyle.FixedSingle);
- Meniu2TextBoxs[1] = obj.OTextBox(new Point(23, 96), 140, BorderStyle.FixedSingle);
- Meniu2TextBoxs[1].PasswordChar = '*';
- Meniu2TextBoxs[2] = obj.OTextBox(new Point(23, 152), 140, BorderStyle.FixedSingle);
- Meniu2TextBoxs[2].PasswordChar = '*';
- Meniu2TextBoxs[3] = obj.OTextBox(new Point(23, 212), 140, BorderStyle.FixedSingle);
- for (int i = 0; i < 4; i++)
- {
- MeniuPanels[1].Controls.Add(Meniu2TextBoxs[i]);
- Meniu2TextBoxs[i].BringToFront();
- }
- // Events
- Meniu2Labels[4].Click += new EventHandler(Meniu2Labels4_Click);
- Meniu2Labels[5].Click += new EventHandler(Meniu2Labels5_Click);
- }
- #endregion
- #region SetAbout
- private void SetAbout()
- {
- AboutText = obj.OLabel(new Point(5, 5), Color.FromArgb(49, 75, 108), "This is About meniu point");
- SetStyle(AboutText, false, false, 10F, new Size(300, 200));
- MeniuPanels[2].Controls.Add(AboutText);
- }
- #endregion
- #region SetStyle
- private void SetStyle(object sender, bool board, bool Align, float TextSize, Size size)
- {
- Label get = (sender as Label);
- if (board == true)
- get.BorderStyle = BorderStyle.FixedSingle;
- get.Size = size;
- get.Font = new Font("Comic Sans MS",TextSize, FontStyle.Bold, GraphicsUnit.Point, ((System.Byte)(0)));
- if (Align == true)
- get.TextAlign = ContentAlignment.MiddleCenter;
- get.BringToFront();
- }
- #endregion
- #region ShowMeniu
- public void ShowMeniu()
- {
- MainForm.Show();
- }
- #endregion
- #region Events
- #region MainForm Events
- private void MainFormPics2_Click(object sender, EventArgs e)
- {
- if (fc.PosCheck(new Point(Cursor.Position.X - MainForm.Location.X, Cursor.Position.Y - MainForm.Location.Y), new Point(325, 0), new Point(350, 25)) == true)
- MainForm.Close();
- }
- private void ExitLabel_Click(object sender, EventArgs e)
- {
- MainForm.Close();
- form.Close();
- }
- #endregion
- #region Login Events
- private void MeniuPoints4_Click(object sender, EventArgs e)
- {
- for (int i = 0; i < 6; i++)
- {
- MeniuPoints[i].BackColor = Color.FromArgb(49, 75, 108);
- MeniuPanels[i].Visible = false;
- }
- MeniuPanels[0].BringToFront();
- ExitLabel.BringToFront();
- MeniuPanels[0].Visible = true;
- MeniuPoints[4].BackColor = Color.FromArgb(10, 100, 120);
- }
- private void Meniu1Labels2_Click(object sender, EventArgs e)
- {
- if ((Meniu1TextBoxs[0].Text == "") || (Meniu1TextBoxs[1].Text == "")) msg.ShowMessage("Error", "Please fill all the gaps.", false);
- else
- {
- Username = Meniu1TextBoxs[0].Text;
- Password = Meniu1TextBoxs[1].Text;
- if (Check(Username, Password) == true)
- {
- if ((Checkcounter % 2) == 0)
- SRw.Write(Meniu1TextBoxs[0].Text + ":" + Meniu1TextBoxs[1].Text, "info/remember.txt");
- else
- SRw.Write("", "info/remember.txt");
- msg.ShowMessage("Login", "Login was successful.", false);
- MainForm.Visible = false;
- form.create();
- }
- else
- msg.ShowMessage("Login", "Login Failed.", false);
- }
- }
- private bool Check(string user, string password)
- {
- string path = "info/users/" + user + ".txt";
- if (File.Exists(path) == true)
- {
- string file = SRw.Read(path);
- if (fc.ReadWord(1, 2, file, ':', false) == password)
- return true;
- else
- return false;
- }
- else
- return false;
- }
- private void Meniu1Labels3_Click(object sender, EventArgs e)
- {
- Meniu1TextBoxs[0].Text = "";
- Meniu1TextBoxs[1].Text = "";
- }
- private void Meniu1Check_CheckStateChanged(object sender, EventArgs e)
- {
- Checkcounter++;
- }
- #endregion
- #region Register Events
- private void MeniuPoints5_Click(object sender, EventArgs e)
- {
- for (int i = 0; i < 6; i++)
- {
- MeniuPoints[i].BackColor = Color.FromArgb(49, 75, 108);
- MeniuPanels[i].Visible = false;
- }
- MeniuPanels[1].BringToFront();
- ExitLabel.BringToFront();
- MeniuPanels[1].Visible = true;
- MeniuPoints[5].BackColor = Color.FromArgb(10, 100, 120);
- }
- private void Meniu2Labels4_Click(object sender, EventArgs e)
- {
- if (Meniu2TextBoxs[1].Text == Meniu2TextBoxs[2].Text)
- {
- if ((Meniu2TextBoxs[0].Text == "") || (Meniu2TextBoxs[1].Text == "") || (Meniu2TextBoxs[2].Text == "") || (Meniu2TextBoxs[3].Text == "" ))
- {
- msg.ShowMessage("Error", "Please fill all the gaps.",false);
- }
- else
- {
- Registration = true;
- Username = Meniu2TextBoxs[0].Text;
- Password = Meniu2TextBoxs[1].Text;
- Email = Meniu2TextBoxs[3].Text;
- if (Create(Username, Password, Email) == true)
- {
- msg.ShowMessage("Registration", "Registration is Successful.", false);
- for (int i = 0; i < 4; i++)
- Meniu2TextBoxs[i].Text = "";
- }
- else
- msg.ShowMessage("Registration", "Failed to Create.", false);
- }
- }
- else
- msg.ShowMessage("Registration", "Passwords don't match.", false);
- }
- private bool Create(string user, string password, string email)
- {
- string path = "info/users/" + user + ".txt";
- if (File.Exists(@path) == true)
- return false;
- else
- {
- string save = user + ":" + password + ":" + email + ":1000";
- SRw.Write(save, path);
- return true;
- }
- }
- private void Meniu2Labels5_Click(object sender, EventArgs e)
- {
- for (int i = 0; i < 4; i++)
- Meniu2TextBoxs[i].Text = "";
- }
- #endregion
- #region About Events
- private void MeniuPoints3_Click(object sender, EventArgs e)
- {
- for (int i = 0; i < 6; i++)
- {
- MeniuPoints[i].BackColor = Color.FromArgb(49, 75, 108);
- MeniuPanels[i].Visible = false;
- }
- MeniuPanels[2].BringToFront();
- ExitLabel.BringToFront();
- MeniuPanels[2].Visible = true;
- MeniuPoints[3].BackColor = Color.FromArgb(10, 100, 120);
- }
- #endregion
- #region Options Events
- private void MeniuPoints2_Click(object sender, EventArgs e)
- {
- for (int i = 0; i < 6; i++)
- {
- MeniuPoints[i].BackColor = Color.FromArgb(49, 75, 108);
- MeniuPanels[i].Visible = false;
- }
- MeniuPanels[3].BringToFront();
- ExitLabel.BringToFront();
- MeniuPanels[3].Visible = true;
- MeniuPoints[2].BackColor = Color.FromArgb(10, 100, 120);
- }
- #endregion
- #region Stats Events
- private void MeniuPoints1_Click(object sender, EventArgs e)
- {
- for (int i = 0; i < 6; i++)
- {
- MeniuPoints[i].BackColor = Color.FromArgb(49, 75, 108);
- MeniuPanels[i].Visible = false;
- }
- MeniuPanels[4].BringToFront();
- ExitLabel.BringToFront();
- MeniuPanels[4].Visible = true;
- MeniuPoints[1].BackColor = Color.FromArgb(10, 100, 120);
- }
- #endregion
- #region Ranking Events
- private void MeniuPoints0_Click(object sender, EventArgs e)
- {
- for (int i = 0; i < 6; i++)
- {
- MeniuPoints[i].BackColor = Color.FromArgb(49, 75, 108);
- MeniuPanels[i].Visible = false;
- }
- MeniuPanels[5].BringToFront();
- ExitLabel.BringToFront();
- MeniuPanels[5].Visible = true;
- MeniuPoints[0].BackColor = Color.FromArgb(10, 100, 120);
- Ranking rank = new Ranking();
- Label ranks = obj.OLabel(new Point(10, 10), Color.FromArgb(49, 75, 108), "Ranking:\r\n\r\n"+
- rank.ShowRanking(SRw.Read("info/ranking.txt"), 0, true));
- MeniuPanels[5].Controls.Add(ranks);
- ranks.ForeColor = Color.LightGray;
- ranks.Size = new Size(300, 500);
- ranks.Font = new Font("Tahoma", 12);
- ranks.BringToFront();
- }
- #endregion
- #endregion
- }
- class BuySystem
- {
- #region Variable
- private PictureBox[] img = new PictureBox[3];
- private PictureBox[] block = new PictureBox[0];
- private Panel panel = new Panel();
- private SuperRw rw = new SuperRw();
- private Functions fc = new Functions();
- private Messenger msg = new Messenger();
- private PictureBox show;
- private Label info;
- private Form form;
- private MapEngine _engine;
- private string size;
- #endregion
- #region BuySystem
- public BuySystem(Form forma, object sender)
- {
- Objector obj = new Objector();
- form = forma;
- _engine = (sender as MapEngine);
- panel = obj.OPanel(new Point(120, 120), new Size(500, 350), Color.Black);
- form.Controls.Add(panel);
- panel.BringToFront();
- img[0] = obj.OPictureBox(new Point(0, 0), Image.FromFile(@"images/buy/left_1.bmp"));
- img[1] = obj.OPictureBox(new Point(25, 0), Image.FromFile(@"images/buy/middle.bmp"));
- img[1].Width = 450;
- img[1].BackgroundImage = img[1].Image;
- img[2] = obj.OPictureBox(new Point(475, 0), Image.FromFile(@"images/buy/right_1.bmp"));
- for (int i = 0; i < 3; i++)
- panel.Controls.Add(img[i]);
- show = obj.OPictureBox(new Point(60, 60), Image.FromFile(@"images/buy_list/test.bmp"));
- panel.Controls.Add(show);
- show.BringToFront();
- Label label = obj.OLabel(new Point(5, 5), Color.FromArgb(13, 31, 107), "Buy System");
- label.Height = 20;
- SetStyle(label);
- Label list = obj.OLabel(new Point(300, 40), Color.FromArgb(33, 53, 139), "List of Items:");
- list.Size = new Size(140, 20);
- SetStyle(list);
- info = obj.OLabel(new Point(60, 220), Color.FromArgb(33, 53, 139), "_info_");
- SetStyle(info);
- info.Size = new Size(200, 80);
- info.Font = new Font("Tahoma", 10);
- Label[] button = new Label[2];
- button[0] = obj.OLabel(new Point(40, 300), Color.FromArgb(33, 53, 139), "Buy");
- button[0].Click +=new EventHandler(Buy);
- button[1] = obj.OLabel(new Point(130, 300), Color.FromArgb(33, 53, 139), "Close");
- button[1].Click += new EventHandler(Close);
- for (int i = 0; i < 2; i++)
- {
- button[i].BorderStyle = BorderStyle.FixedSingle;
- SetStyle(button[i]);
- }
- ListBox listbox = obj.OListBox(new Point(300, 60), new Size(170, 270), Color.Black);
- listbox.ForeColor = Color.LightGray;
- listbox.Font = new Font("Tahoma", 12);
- listbox.Click +=new EventHandler(listbox_Click);
- string stinfo = rw.Read(@"info/buy_info.txt");
- int lines = fc.LineCount(stinfo) + 1;
- for (int i = 1; i <= lines; i++)
- listbox.Items.Add(fc.ReadWord(i, 1, stinfo, ':', false));
- listbox.SelectedIndex = 1;
- change(stinfo, lines+2, listbox);
- panel.Controls.Add(listbox);
- listbox.BringToFront();
- }
- ~BuySystem() { }
- #endregion
- #region SetStyle
- private void SetStyle(object sender)
- {
- Label label = (sender as Label);
- label.Font = new Font("Tahoma", 12);
- label.ForeColor = Color.White;
- panel.Controls.Add(label);
- label.BringToFront();
- }
- #endregion
- #region Events
- private void listbox_Click(object sender, EventArgs e)
- {
- string _info = rw.Read(@"info/buy_info.txt");
- int _lines = fc.LineCount(_info) + 2;
- change(_info, _lines, sender);
- }
- private void change(string _info, int _lines, object sender)
- {
- for (int i = 0; i < _lines; i++)
- if (fc.ReadWord(i, 1, _info, ':', false) == (sender as ListBox).Items[(sender as ListBox).SelectedIndex].ToString())
- {
- info.Text = "Cost: " + fc.ReadWord(i, 2, _info, ':', false) + " $\r\nLevel: " + fc.ReadWord(i, 3, _info, ':', false) + ".\r\n" +
- "Size: " + (size=(fc.ReadWord(i, 4, _info, ':', false))) + "^2 Blocks.\r\nAbout: " + fc.ReadWord(i, 5, _info, ':', false) + ".";
- show.Image = Image.FromFile(@"images/buy_list/" + fc.ReadWord(i, 6, _info, ':', false));
- }
- }
- private void Buy(object sender, EventArgs e)
- {
- msg.ShowMessage("Buy", "Under Construction. Continue?", true);
- if (msg.UsersResult)
- {
- panel.Controls.Clear();
- panel.Visible = false;
- CreateBlocks(Convert.ToInt32(size));
- }
- }
- private void BlockMove(object sender, MouseEventArgs e)
- {
- int sz = Convert.ToInt32(size);
- PictureBox img = (sender as PictureBox);
- int a = 0;
- int b = 0;
- int c = 0;
- int nr = 0;
- int skip = 0;
- for (int i = 0; i < (sz * sz); i++)
- {
- block[i].Location = new Point((50 * a++) + img.Left + 15, (50 * b) + img.Top + 15);
- if ((_engine.currentimg + (c + 1)) <= (_engine.mapsize * _engine.mapsize))
- if ((_engine.img[_engine.currentimg + c++].Name) != "images/out/grass")
- block[i].Image = Image.FromFile(@"images/buy/block_red.bmp");
- else
- block[i].Image = Image.FromFile(@"images/buy/block.bmp");
- nr = _engine.currentimg;
- while (nr >= _engine.mapsize)
- nr -= _engine.mapsize;
- skip = _engine.mapsize - (nr + 1) - sz;
- if (a == sz)
- {
- c += (nr + 1) + skip;
- b++;
- a = 0;
- }
- }
- }
- #endregion
- #region CreateBlocks
- private void CreateBlocks(int size)
- {
- msg.ShowMessage("Blocks", "There is " + (size*size).ToString() + " block(s).", false);
- Objector obj = new Objector();
- block = new PictureBox[size*size];
- int a=0;
- int b=0;
- for (int i = 0; i < System.Math.Pow(_engine.mapsize, 2); i++)
- _engine.img[i].MouseMove += new MouseEventHandler(BlockMove);
- for (int i = 0; i < (size*size); i++)
- {
- a++;
- block[i] = obj.OPictureBox(new Point((a*50)+200, (b*50)+200), Image.FromFile(@"images/buy/block.bmp"));
- if (a == size)
- {
- b++;
- a = 0;
- }
- form.Controls.Add(block[i]);
- block[i].BringToFront();
- }
- }
- #endregion
- #region Close
- private void Close(object sender, EventArgs e)
- {
- panel.Controls.Clear();
- panel.Visible = false;
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement