|
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using GameExample.Reversi;
using GameExample.Properties;
namespace GameExample
{
public partial class MainForm : Form, IGameHost, IHaveBackground
{
private Image _backgroundImage;
public MainForm()
{
InitializeComponent();
_backgroundImage = Resources.CloudBase;
GameStyles.SetBounds(Size);
}
protected override void OnPaint(PaintEventArgs e)
{
if (_backgroundImage != null)
{
e.Graphics.DrawImage(_backgroundImage, 0, 0);
}
base.OnPaint(e);
}
private Size _size;
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
if (_size != this.Size)
{
//return;
GameStyles.SetBounds(this.Size);
_backgroundImage = Resources.CloudBase;
if (Controls.Count > 0)
{
GameScreenControl c = Controls[0] as GameScreenControl;
c.Width = this.Width;
c.Height = this.Height;
c.BackgroundImage = _backgroundImage;
c.Reset();
c.Invalidate();
c.Update();
}
}
_size = this.Size;
}
public void SetScreen(GameScreen screen, GameManager game)
{
GameScreenControl c = null;
switch (screen)
{
case GameScreen.Help:
c = new HelpScreenControl();
break;
case GameScreen.Options:
c = new OptionsMenuControl();
break;
case GameScreen.Play:
c = new PlayScreenControl();
break;
case GameScreen.MainMenu:
default:
c = new MainMenuControl();
break;
}
c.CurrentGame = game;
c.Location = new Point(0, 0);
c.Width = this.Width;
c.Height = this.Height;
c.Dock = DockStyle.Fill;
c.Reset();
this.Controls.Clear();
this.Controls.Add(c);
}
public Image BackgroundImage
{
get
{
return _backgroundImage;
}
set
{
_backgroundImage = ImageUtil.ResizeImage(value, Size);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.