Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Security.Cryptography;
  6. using System.Windows.Forms;
  7. using App.Engine;
  8.  
  9. namespace App.View
  10. {
  11.  
  12.     public partial class PlaygroundDeprecated : Form
  13.     {
  14.         private System.ComponentModel.IContainer components = null;
  15.         private PictureBox pb;
  16.         private Bitmap surface = null;
  17.         private Graphics device;
  18.         private Bitmap image = null;
  19.         private Timer timer;
  20.         private Random rand;
  21.         private PictureBox pb1;
  22.        
  23.         string[] text = {
  24.             "AVATAR!",
  25.             "Know that Brittania has entered into a new age of",
  26.             "enlightenment! Know that the time has finally come",
  27.             "for the one true Lord of Brittania to take his place",
  28.             "at the head of his people. Under my guidance, Brit-",
  29.             "tania will flourish. And all of the people shall",
  30.             "rejoice and pay homage to their new... guardian!",
  31.             "Know that you, too, shall kneel before me, Avatar.",
  32.             "You, too, will soon acknowledge my authority. For I",
  33.             "shall be your companion... your provider... and your",
  34.             "master!", "",
  35.             "Ultima VII: The Black Gate",
  36.             "Copyright 1992 by Electronic Arts"
  37.         };
  38.  
  39.         public PlaygroundDeprecated()
  40.         {
  41.             //this.SuspendLayout();
  42.             //
  43.             // Form1
  44.             //
  45.             this.pb1 = new System.Windows.Forms.PictureBox();
  46.             this.pb1.Parent = this;
  47.             this.pb1.BackColor = System.Drawing.Color.Black;
  48.             this.pb1.Location = new System.Drawing.Point(0, 0);
  49.             this.pb1.Name = "box";
  50.             this.pb1.Size = new System.Drawing.Size(865, 706);
  51.             //this.pb1.TabIndex = 9;
  52.             this.pb1.TabStop = false;
  53.             ((System.ComponentModel.ISupportInitialize)(this.pb1)).BeginInit();
  54.            
  55.             //this.AutoScaleDimensions = new System.Drawing.SizeF(16F, 9F);
  56.             //this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  57.             this.ClientSize = new System.Drawing.Size(1280, 720);
  58.             this.Load += new System.EventHandler(this.Game_Load);
  59.             this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Game_FormClosed);
  60.         }
  61.        
  62.         protected override void Dispose(bool disposing)
  63.         {
  64.             if (disposing && (components != null))
  65.             {
  66.                 components.Dispose();
  67.             }
  68.             base.Dispose(disposing);
  69.         }
  70.  
  71.         private void Game_Load(object sender, EventArgs e)
  72.         {
  73.             //set up the form
  74.             this.Text = "Text drawing Demo";
  75.             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  76.             this.MaximizeBox = false;
  77.             this.Size = new Size(865, 706);
  78.  
  79.             //pb = new PictureBox();
  80.             //pb.Parent = this;
  81.            // pb.Dock = DockStyle.Fill;
  82.             //pb.BackColor = Color.Black;
  83.  
  84.             surface = new Bitmap(this.Size.Width, this.Size.Height);
  85.             pb1.Image = surface;
  86.             device = Graphics.FromImage(surface);
  87.            
  88.             var path = System.IO.Path.GetFullPath(@"img/grass.bmp");
  89.             image = LoadBitmap(path);
  90.             device.DrawImage(image, 0, 0);
  91.             rand = new Random();
  92.  
  93.             /*timer = new Timer();
  94.             timer.Interval = 20;
  95.             timer.Enabled = true;
  96.             timer.Tick += new System.EventHandler(TimerTick);*/
  97.            
  98.            
  99.             /*Font font = new Font("Times New Roman", 26, FontStyle.Regular, GraphicsUnit.Pixel);
  100.             for (int i = 0; i < text.Length; ++i)
  101.             {
  102.                 device.DrawString(text[i], font, Brushes.Blue, 10, 10+i*28);
  103.             }
  104.  
  105.             pb.Image = surface;*/
  106.         }
  107.  
  108.         public Bitmap LoadBitmap(string filename)
  109.         {
  110.             Bitmap bmp = null;
  111.             try
  112.             {
  113.                 bmp = new Bitmap(filename);
  114.             }
  115.             catch (Exception ex) { }
  116.             return bmp;
  117.         }
  118.        
  119.         //demo for lines drawing
  120.         public void drawLine()
  121.         {
  122.             //make a random color
  123.             int A = rand.Next(0, 255);
  124.             int R = rand.Next(0, 255);
  125.             int G = rand.Next(0, 255);
  126.             int B = rand.Next(0, 255);
  127.             Color color = Color.FromArgb(A, R, G, B);
  128.  
  129.             //make pen out of color
  130.             int width = rand.Next(2, 8);
  131.             Pen pen = new Pen(color, width);
  132.  
  133.             //random line ends
  134.             int x1 = rand.Next(1, this.Size.Width);
  135.             int y1 = rand.Next(1, this.Size.Height);
  136.             int x2 = rand.Next(1, this.Size.Width);
  137.             int y2 = rand.Next(1, this.Size.Height);
  138.  
  139.             //draw the line
  140.             device.DrawLine(pen, x1, y1, x2, y2);
  141.  
  142.             //refresh the drawing surface
  143.             pb.Image = surface;
  144.  
  145.         }
  146.        
  147.         //demo for ellipse drawing
  148.         private void drawEllipse()
  149.         {
  150.             //make a random color
  151.             int A = rand.Next(0, 255);
  152.             int R = rand.Next(0, 255);
  153.             int G = rand.Next(0, 255);
  154.             int B = rand.Next(0, 255);
  155.             Color color = Color.FromArgb(A, R, G, B);
  156.  
  157.             //make pen out of color
  158.             int width = rand.Next(2, 20);
  159.             int height = rand.Next(2, 20);
  160.             Pen pen = new Pen(color, width);
  161.  
  162.             //random line ends
  163.             int x = rand.Next(1, this.Size.Width - 50);
  164.             int y = rand.Next(1, this.Size.Height - 50);
  165.  
  166.             //draw the rectangle
  167.             device.DrawEllipse(pen, x, y, width, height);
  168.  
  169.             //refresh the drawing surface
  170.             pb.Image = surface;
  171.         }
  172.  
  173.         /*
  174.         public void TimerTick(object source, EventArgs e)
  175.         {
  176.             drawEllipse();
  177.         }
  178.         */
  179.        
  180.         private void Game_FormClosed(object sender, EventArgs e)
  181.         {
  182.             device.Dispose();
  183.             surface.Dispose();
  184.             timer.Dispose();
  185.         }
  186.     }
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement