Teaching CS1 with Python GUI Game Programming
Abstract
Python is becoming a popular programming language in teaching
freshman programming courses. The author designed a sequence of game programming labs using Pygame to further help engage students and to improve their programming skills. The class survey showed that the adoption of Pygame is successful.
Keywords CS1; Python; Game; Pygame; Assessment
INTROUDCTION
Large fraction of first-year CS students are underprepared for a hands-on programming course. In our program, around 20% of the students attending the first programming course were absent from the classroom and ignored homework assignments. Their enrolment in the class indicates their interest in the subject, but their absence shows that the delivery of the course might not be engaging enough. Various techniques can be used to make the classroom more exciting. Recent researches show that game and graphic-themed programming courses have been successful [1, 2, 3, 4, 5]. Game design not only generated excitement, but also relates the programming coursework to real world applications.
Packages and frameworks have been developed to help students in designing multimedia interactive games. Some are Microsoft-based [6], and many are Java-based [7, 8, 9, 10]. With java, students need to learn OOrsquo;s first programming style. The instructor has to be cautious not to overload students with game projects.
However, in several papers including the authorrsquo;s previous paper [11] showed that python has many advantages in teaching first-year CS students. The easy syntax and feasible interactive mode made python ideal in both academic and industrial applications. Combining Python with game programming is promising. Attempts have been made by Csgraphics using a module library to teach graphics from day one [12]. In this paper, the author introduces a python course with game programming.
Pygame is a module library that supports drawing graphics and designing games [13]. Sophisticated games can be found on Pygame Website. A text book is given to students as reference material [14]. Using Pygame tools in teaching faces a few challenges. First, the students need to have not only some programming background, but also knowledge of graphical user interface before they can program real games. The course has to integrate game design with program development so that students can achieve better programming skills. This paper describes an innovative approach in engaging students using Pygame from day one and analyzes the results to help future development.
COURSE DESIGN
The course tries to combine the flexibility of python and the attraction of game design. This section introduces a sequence of labs and homework assignments that helps achieve this purpose.
Basic Programming skills
Before starting to design games, students need to learn basic programming skills. The course needs to blend game design with early learning process. True interactive GUI game design couldnrsquo;t happen before students can fully handle at lease sequential, branch and loop programming. These could cost half of the semester. This phase is a good opportunity to teach students how graphics are achieved in Pygame. The concepts include coordination system, pixels and refresh rate. It is straightforward to show student some simple drawing functions to draw circles, rectangular and lines. These graphics functions are then used in sequential and branch program practices and assignments.
Branch
Instead of printing strings, programming assignments were made more interesting by drawing shapes. If a certain condition is met, then a certain shape can be displayed. A more challenging homework is to draw a number of random shapes by using Pythonrsquo;s random number generating library. After generating a random number, the program then draw a certain shape based on the number. As example, if the number is 1 draw a circle and if number is 3 draw a rectangle or a line. These simple exercise are visually appealing than simply displaying strings. Figure 1 shows the result of this assignment.
FIGURE 1. Branch using shapes
Loop
Shape drawing assignment can also be applied to loops as illustrated in Figure 2. Students are required to draw adjacent circles starting from the left side of the screen and each circle is half the size of the circle to its left. The circles are drawn in a loop until the radius of the circle drops below 0.
FIGURE 2. loop using shapes
Since Pygame animation relies on refreshing the Pygame window using while loop, it is the best for students to start learning animation after finishing loop chapter. In a while loop, update() or flip() functions are used to keep on refreshing newly drawn graphs or pictures. Though it is possible for students to animate the shapes they practiced before, it is more interesting to work with images or photos.
In Pygame, pictures can be displayed with blit() function. The blit() function takes the picturesrsquo; coordinates as a tuple argument. Students can manipulate the coordinates of the objects to move them. Flip () function refreshes the screen to display the newly drawn picture.
Events are detected by a for loop nested inside the while loop. A program can close a Pygame window, by detecting a close window event in the for loop.
Understanding the role of these loops is critical for students to understand GUI display, event detection and game design. Programming concepts are reinforced in the design process.
Assignment in this chapter is to design an animation. A background image should be displayed first, and then an object should move on the background. Carefully calculating the coordinates is the key to make objects move as desired. However,
branch structures are needed
剩余内容已隐藏,支付完成后下载完整资料
英语译文共 12 页,剩余内容已隐藏,支付完成后下载完整资料
资料编号:[603798],资料为PDF文档或Word文档,PDF文档可免费转换为Word
课题毕业论文、开题报告、任务书、外文翻译、程序设计、图纸设计等资料可联系客服协助查找。
您可能感兴趣的文章
- 饮用水微生物群:一个全面的时空研究,以监测巴黎供水系统的水质外文翻译资料
- 步进电机控制和摩擦模型对复杂机械系统精确定位的影响外文翻译资料
- 具有温湿度控制的开式阴极PEM燃料电池性能的提升外文翻译资料
- 警报定时系统对驾驶员行为的影响:调查驾驶员信任的差异以及根据警报定时对警报的响应外文翻译资料
- 门禁系统的零知识认证解决方案外文翻译资料
- 车辆废气及室外环境中悬浮微粒中有机磷的含量—-个案研究外文翻译资料
- ZigBee协议对城市风力涡轮机的无线监控: 支持应用软件和传感器模块外文翻译资料
- ZigBee系统在医疗保健中提供位置信息和传感器数据传输的方案外文翻译资料
- 基于PLC的模糊控制器在污水处理系统中的应用外文翻译资料
- 光伏并联最大功率点跟踪系统独立应用程序外文翻译资料