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.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Test
- {
- public partial class Board : Form
- {
- private int BOARDWIDTH;
- private int BOARDHEIGHT;
- private int cellSize = 10;
- private bool Wrap;
- private int refreshRate;
- private World world;
- private Pen wPen = new Pen(Color.Black);
- private SolidBrush bBrush = new SolidBrush(Color.Black);
- private PictureBox pictureBox = new PictureBox();
- private Timer Timer1 = new Timer();
- public Board(World world, int cellsize, bool Wrap, int refreshRate)
- {
- this.BOARDHEIGHT = world.getWorldHeight() * cellsize;
- this.BOARDWIDTH = world.getWorldWidth() * cellsize;
- InitializeComponent();
- SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
- pictureBox.SetBounds(0, 0, this.BOARDWIDTH, this.BOARDHEIGHT);
- this.cellSize = cellsize;
- this.world = world;
- this.Wrap = Wrap;
- this.refreshRate = refreshRate;
- InitializeTimer();
- }
- private void InitializeTimer()
- {
- Timer1.Interval = refreshRate;
- Timer1.Tick += new EventHandler(Timer1_Tick);
- Timer1.Enabled = true;
- }
- private void Timer1_Tick(object Sender, EventArgs e)
- {
- Invalidate();
- if (Wrap) world.updateWorldWraparound();
- else world.updateWorld();
- }
- private void Board_Load(object sender, System.EventArgs e)
- {
- pictureBox.Dock = DockStyle.Fill;
- pictureBox.BackColor = Color.White;
- this.Controls.Add(pictureBox);
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- base.OnPaint(e);
- for (int i = 0; i < this.world.getWorldHeight(); i++)
- {
- for (int j = 0; j < this.world.getWorldWidth(); j++)
- {
- if (!this.world.getCellState(i, j))
- {
- e.Graphics.DrawRectangle(wPen, i*this.cellSize - 1, j * this.cellSize - 1, this.cellSize, this.cellSize);
- }
- else
- {
- e.Graphics.FillRectangle(bBrush, i * this.cellSize, j * this.cellSize, this.cellSize, this.cellSize);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement