コード例 #1
0
ファイル: GameState.cs プロジェクト: Railec/SE1cKBS
        public GameState(string name)
            : base(name)
        {
            this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true);

            this._entityHandler = null;
            this._tileHandler = null;
            this.playerObj = null;

            this.Paint += this.PaintEvent;
        }
コード例 #2
0
ファイル: GameState.cs プロジェクト: Railec/SE1cKBS
        public override void Construct()
        {
            this.aTimer = new Timer();
            aTimer.Tick += new EventHandler(TimerTick);
            aTimer.Interval = 1000;
            aTimer.Start();
            timer = 0;

            //Construction of the game state, anything that the game needs to create initially should be put here (Player, platform, etc).
            lock (this.lockObj) {
                if (this._buffer != null)
                    this._buffer.Dispose();

                this._buffer = new Bitmap(this.Size.Width, this.Size.Height);
            }

            //Finally we make the handlers that are required to do things in the gamestate.
            this._entityHandler = new EntityHandler(this);
            this._tileHandler = new TileHandler(this);

            //Tile loading
            try
            {
                this._tileHandler.LoadFromFile("map_" + level);
            }
            catch (Exception noMoreMaps)
            {
                finishedGame();
                return;
            }

            //Making a new player.
            this.playerObj = new Player(whichStartPoint(level), 0);

            this._entityHandler.AddEntity(playerObj);

            //Sorting the list so we can draw them behind each other.
            this._entityHandler.SortList();

            ((Form1)this.Form).iHandler.addKeyDown(delegate (object sender, KeyEventArgs e) {
                // Switch case to see what handling to do when a button is pressed.
                switch (e.KeyCode) {
                    case Keys.Escape:
                        ((Form1)this.Form).sHandler.activateState("MainState");
                        level = 1;
                        break;
                    case Keys.A:
                        this.playerObj.GoLeft();
                        break;
                    case Keys.D:
                        this.playerObj.GoRight();
                        break;
                    case Keys.W:
                        this.playerObj.GoUp();
                        break;
                    case Keys.Space:
                        this.playerObj.GoUp();
                        break;
                    default:
                        break;
                }
            });
            ((Form1)this.Form).iHandler.addKeyUp(delegate (object sender, KeyEventArgs e) {
                // Switch case to see what handling to do when a button is released.
                switch (e.KeyCode) {
                    case Keys.A:
                        this.playerObj.Stop();
                        break;
                    case Keys.D:
                        this.playerObj.Stop();
                        break;
                }
            });

            this.playerObj.Alive = true;

            base.Construct();
        }
コード例 #3
0
ファイル: GameState.cs プロジェクト: Railec/SE1cKBS
 public void meetEndpoint()
 {
     int xx = playerObj.Position.X;
     int yy = playerObj.Position.Y;
     Point player = new Point(xx, yy);
     if(player == endpoint) {
         Console.WriteLine("level completed");
         level++;
         this.playerObj = new Player(whichStartPoint(level), 0);
         levelComplete = true;
     }
 }
コード例 #4
0
ファイル: GameState.cs プロジェクト: Railec/SE1cKBS
        public override void Destruct()
        {
            base.Destruct();

            //Destruction of the game state.
            //All resources that were allocated in the construct phase should be disposed of here.
            lock(this.lockObj) {
                if(this._buffer != null) this._buffer.Dispose();
            }

            aTimer.Dispose();

            ((Form1)this.Form).iHandler.ClearKeys();

            this._entityHandler.ClearList();
            this._tileHandler.ClearMap();

            this._entityHandler = null;
            this._tileHandler = null;
            this.playerObj = null;
        }