Python Forum
conway's game of life
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
conway's game of life
#11
This one;
def movesquare(event): # detect movement keys
   if event.keysym == "Up":
       canvas.move(SQident, 0, -50)
   elif event.keysym == "Down":
       canvas.move(SQident, 0, 50)
   elif event.keysym == "Left":
       canvas.move(SQident, -50, 0)
   elif event.keysym == "Right":
       canvas.move(SQident, 50, 0)        
is begging for a dictionary:
moves={'Up':(0, -50),'Down':(0,50), 'Left':(-50,0), 'Right':(50,0)}
def movesquare(event): # detect movement keys
   x,y=moves[event.keysym]
   canvas.move(SQident,x,y)
There is even a way to replace the whole function by a one-liner but this can make the code a bit less readable.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply


Messages In This Thread
conway's game of life - by hanscvanleeuwen - Nov-25-2016, 07:51 PM
RE: conway's game of life - by Skaperen - Nov-26-2016, 08:25 AM
RE: conway's game of life - by hanscvanleeuwen - Nov-26-2016, 09:33 AM
RE: conway's game of life - by hanscvanleeuwen - Nov-26-2016, 12:24 PM
RE: conway's game of life - by Skaperen - Nov-27-2016, 01:45 AM
RE: conway's game of life - by Mekire - Nov-28-2016, 04:30 AM
RE: conway's game of life - by hanscvanleeuwen - Nov-28-2016, 07:55 AM
RE: conway's game of life - by heiner55 - Nov-29-2016, 02:41 PM
RE: conway's game of life - by hanscvanleeuwen - Nov-30-2016, 01:45 PM
RE: conway's game of life - by hanscvanleeuwen - Dec-07-2016, 02:02 PM
RE: conway's game of life - by Ofnuts - Dec-08-2016, 09:56 PM
RE: conway's game of life - by Mekire - Dec-09-2016, 03:35 AM
RE: conway's game of life - by hanscvanleeuwen - Dec-09-2016, 10:13 AM
RE: conway's game of life - by Mekire - Dec-09-2016, 11:03 AM
RE: conway's game of life - by hanscvanleeuwen - Dec-09-2016, 11:25 AM
RE: conway's game of life - by hanscvanleeuwen - Dec-09-2016, 01:51 PM
RE: conway's game of life - by Mekire - Dec-09-2016, 02:10 PM
RE: conway's game of life - by hanscvanleeuwen - Dec-09-2016, 04:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  While loop/half-life Miraclefruit 6 8,527 Mar-06-2017, 05:24 PM
Last Post: nilamo
  conway's game of life / Single Responsibility Principle hanscvanleeuwen 13 11,168 Dec-17-2016, 08:30 AM
Last Post: hanscvanleeuwen
  Game of life using IDLE Informatics109 4 5,110 Oct-29-2016, 01:39 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020