duke_meister

Profile
Australia

See how easy it is to change from console to GDI when the code is reasonably well designed. 

I've takent the console snake game I blogged previously, and changed it to use GDI on WinForms. 95% of the code is identical.

:)

0 comments
3 entries
Advertisement
duke_meister
February 19, 2019
Bit of a cleanup
using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;

namespace GdiSnake
{
    public sealed partial class Form1 : Form
    {
        // our unchanging values:
        // playfield height & width
        const int PlayfieldWidth = 80;
        const int PlayfieldHe…
1,409 views
duke_meister
February 19, 2019
Changes I made...

So essentially the changes I made are:

  • Create a WinForms app instead of Console (obviously)
  • Move my game loop code from a for loop to a timer Tick
  • Move UpdatePlayfield() into the form Paint()
  • Change WriteAt (which wrote on the console) to DrawCell (to draw on the form)
  • 1,300 views
    duke_meister
    February 19, 2019
    All done
    using System;
    using System.Diagnostics;
    using System.Drawing;
    using System.Linq;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace GdiSnake
    {
        public sealed partial class Form1 : Form
        {
            // our unchanging values:
            // playfield height & width
            cons…
    1,902 views
    Advertisement

    Popular Blogs

    shawnhar
    Generalist
    101 Entries
    10 Followers
    15 Entries
    11 Followers
    johnhattan
    Programmer
    1,277 Entries
    48 Followers
    ApochPiQ
    Generalist
    628 Entries
    44 Followers
    dgreen02
    Generalist
    338 Entries
    56 Followers
    Advertisement