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,403 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,296 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,880 views
    Advertisement

    Popular Blogs

    shawnhar
    Generalist
    101 Entries
    8 Followers
    15 Entries
    9 Followers
    johnhattan
    Programmer
    1,277 Entries
    46 Followers
    ApochPiQ
    Generalist
    628 Entries
    43 Followers
    dgreen02
    Generalist
    338 Entries
    55 Followers
    Advertisement