Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Reversi for Windows Mobile

, 12 May 2009
The game Reversi for Windows Mobile using the Compact Framework.
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ziad Elmalki

United States United States
No Biography provided

| Advertise | Privacy | Mobile
Web01 | 2.8.140821.2 | Last Updated 13 May 2009
Article Copyright 2009 by Ziad Elmalki
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid