Software Development: Event Driven Programming DH34 35 A Project Report On Snake Game Event Driven Programming C# Under Guidance ShahistaTabassum (Trainer, Syscoms Institute) HNC\ HND – IT Prepared By Maryam Jawzi 1 Software Development: Event Driven Programming DH34 35 Syscoms Institute Department of Information Technology Abu Dhabi, U.A.E CERTIFICATE This is to certify that project work entitled “Snake Game”,submitted in partial fulfillment of project of “Software Development: Event Driven Programming”, HNC is a result of bonafide work carried out by Maryam Jawzi during the academic year 2015. Under the guidance of: ………………………… Ms. ShahistaTabassum Trainer, Syscoms Institute, Abu Dhabi ………………………… Mr. Shamesh K R Chief Technology Officer, Syscoms Institute, Abu Dhabi 2 Software Development: Event Driven Programming DH34 35 Acknowledgment Letter It has been a great opportunity and honor to undertake training at Syscoms Institute of information Technology. I am are very much grateful to Mrs. ShahistaTabassum for providing all facilities and support to meet our project requirements. Her constant guidance and willingness to share her vast knowledge made us understand this project and its manifestations in great depths and helped us to complete the assigned tasks. We are highly thankful to our project internal guide Mrs. ShahistaTabassum, whose invaluable guidance helped us understands the project better. Although there may be many who remain unacknowledged in this humble note of gratitude, there are none who remain unappreciated. Maryam Jawzi 3 Software Development: Event Driven Programming DH34 35 Abstract This document specifies on the Snake Game application; it is a game that consists of a Snake and its food. In order for the Snake to grow, it eats its food and its size increases making it challenging for the player to move about. The players score increases as the snake consumes its food and grows. It improves the focus skill of the player. In this application we use C# Programming Language of Visual Studio 2015, which is designed for creating windows form application which was used for this project. 4 Software Development: Event Driven Programming DH34 35 Index Table of Contents 1.Introduction 7 2.Literature Survey 9 3.Software Requirements Specification 12 -Purpose 12 -Introduction 12 -Functional Requirements 13 -Non Functional Requirements 13 -Hardware Requirements 13 -Tools Used 13 4.Software Detailed Design 15 -System Description 15 -Data Flow Diagram 15 Design Methodology 16 -Design View 16 5.Software Implementation 17 -Pseudo Code 17 6.Testing and Results 20 -Runners 20 -Assertions 20 -What is Testing? 20 5 Software Development: Event Driven Programming DH34 35 -Testing process 21 -Test Case 22 -Testing Plan 22 7.Conclusion 23 -Future Enhancement 23 -Bibliography 23 6 Software Development: Event Driven Programming DH34 35 CHAPTER 1 INTRODUCTION C sharp(C#) is a sophisticated and type-safe object-oriented language that permits developers to construct a variety of secure and robust applications that run on the .NET Framework. You can use C# to create Windows client applications, XML Web services, distributed components, client-server applications, database applications, and more. Visual C# provides an advanced code editor, appropriate user interface designers, integrated debugger, and many other tools to make it easier to develop applications based on the C# language and the .NET Framework. The Visual C# documentation assumes that you have an understanding of basic programming concepts. C# LANGUAGE The C# language is simple language, which makes it good for beginners, but C# also includes all the support for the structured, component-based, object-oriented programming that one expects of a modern language built on the shoulders of C++ and Java. In other words, it's a fully featured language appropriate for developing large-scale applications, but at the same time it is designed to be easy to learn. The goal of C# is to provide a simple, safe, object-oriented, high-performance language for .NET development. C# is simple because there are relatively few keywords. Keywords are special words reserved by the language that have a specific meaning within all C# programs, including if, while, and for. You'll learn about these keywords in the coming chapters. C# is considered safe because the language is type-safe, which is an important mechanism to help you find bugs early in the development process, as you'll see later. This makes for code that is easier to maintain and programs that are more reliable. C# was designed, from the very start, to support object-oriented programming. In this book, we'll explain not only how to write object-oriented programs, but also why object-oriented programming has become so popular. The short answer is this: programs are becoming increasingly complex, and object-oriented programming techniques help you manage that complexity. C# was designed for .NET, and .NET was designed (in part) for developing web and web-aware programs. The Internet is a primary resource in most .NET applications. 7 Software Development: Event Driven Programming DH34 35 .NET Framework Platform Architecture The .NET Framework is a new and revolutionary platform created by Microsoft for developing applications. It is a platform for application developers. It is a Framework that supports Multiple Language and Cross language integration. IT has IDE (Integrated Development Environment). Framework is a set of utilities or can say building blocks of your application system. .NET Framework provides GUI in a GUI manner. .NET is a platform independent but with help of Mono Compilation System (MCS). MCS is a middle level interface. .NET Framework provides interoperability between languages i.e. Common Type System (CTS) . .NET Framework also includes the .NET Common Language Runtime (CLR), which is responsible for maintaining the execution of all applications developed using the .NET library. The .NET Framework consists primarily of a gigantic library of code. 8 Software Development: Event Driven Programming DH34 35 CHAPTER 2 LITERATURE SURVEY LOOPS C# provides following types of loop to handle looping requirements. Loop Type while loop for loop do...while loop nested loops Description a while loop is a control flow statement that allows code to be executed repeatedly based on a given boolean condition. It allows code to be executed repeatedly a do while loop is a control flow statement that executes a block of code at least once, and then repeatedly executes the block, or not, depending on a given boolean condition at the end of the block. A nested loop is a loop within a loop, an inner loop within the body of an outer one. DATA TYPES Type Represents Range Defa ult Valu e bool Boolean value True or False False byte 8-bit unsigned integer 0 to 255 0 char 16-bit Unicode character U +0000 to U +ffff '\0' decim 128-bit precise decimal values with 28- (-7.9 x 1028 to 7.9 x 1028) / 100 to 28 29 significant digits al 0.0M 9 Software Development: Event Driven Programming DH34 35 double 64-bit double-precision floating point (+/-)5.0 x 10-324 to (+/-)1.7 x 10308 type 0.0D float 32-bit single-precision floating point -3.4 x 1038 to + 3.4 x 1038 type 0.0F int 32-bit signed integer type -2,147,483,648 to 2,147,483,647 0 long 64-bit signed integer type -9,223,372,036,854,775,808 9,223,372,036,854,775,807 sbyte 8-bit signed integer type -128 to 127 0 short 16-bit signed integer type -32,768 to 32,767 0 uint 32-bit unsigned integer type 0 to 4,294,967,295 0 ulong 64-bit unsigned integer type 0 to 18,446,744,073,709,551,615 0 ushort 16-bit unsigned integer type 0 to 65,535 0 to 0L Classes A class is a construct that enables you to create your own custom types by grouping together variables of other types, methods and events. A class is like a blueprint. It defines the data and behavior of a type. If the class is not declared as static, client code can use it by creating objects or instances which are assigned to a variable. The variable remains in memory until all references to it go out of scope. At that time, the CLR marks it as eligible for garbage collection. If the class is declared as static, then only one copy exists in memory and client code can only access it through the class itself, not an instance variable. Unlike structs, classes support inheritance, a fundamental characteristic of object-oriented programming. Array An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed. 10 Software Development: Event Driven Programming DH34 35 Operators C# provides many operators, which are symbols that specify which operations (math, indexing, function call, etc.) to perform in an expression. You can overload many operators to change their meaning when applied to a user-defined type. Operations on integral types (such as ==, !=, <, >, &, |) are generally allowed on enumeration types. The sections list the C# operators starting with the highest precedence to the lowest. The operators within each section share the same precedence level. 11 Software Development: Event Driven Programming DH34 35 Chapter 3 SOFTWARE REQUIREMENTS SPECIFICATION (SRS) A software requirements specification (SRS) is a description of a software system to be developed, laying out functional and non-functional requirements, and may include a set of use cases that describe interactions the users will have with the software. Software requirements specification establishes the basis for an agreement between customers and contractors or suppliers (in market-driven projects, these roles may be played by the marketing and development divisions) on what the software product is to do as well as what it is not expected to do. Software requirements specification permits a rigorous assessment of requirements before design can begin and reduces later redesign. It should also provide a realistic basis for estimating product costs, risks, and schedules. The software requirements specification document enlists enough and necessary requirements that are required for the project development.[2] To derive the requirements we need to have clear and thorough understanding of the products to be developed or being developed. This is achieved and refined with detailed and continuous communications with the project team and customer till the completion of the software. Purpose The purpose of this document is to present a detailed description of the Snake Game. It explains the purpose and workings of the system and the constraints under which the system must operate and react. Introduction The Project Snake Game is an entertainment program developed using C# Programming Language. It is a read only program, where the user uses the appropriate arrow keys to the guide the Snake to its food in order to earn point and help the Snake grow. 12 Software Development: Event Driven Programming DH34 35 Functional Requirements A functional requirement defines a function of a system and its components. A function is described as a set of inputs, the behavior, and outputs. In the Snake Game, the user will use the arrow keys to control the Snake. Non Functional Requirements Nonfunctional requirements are the attributes including performance levels, security, and consider the usability, reliability, and availability. Invariably, requirements definers get wrapped up in how the product/system is expected to function and lose sight of these added elements. In the Snake Game, the user should be careful in not allowing the snake to escape outside the wall as it ends its life. Hardware Requirements 1. 2. 3. 4. The Operating System should be Windows 7, 8 or 10, 64-bit or 86-bit. The Processor speed should be 2.5 GHz. It should also be Dual Core. The Memory requirements can be 50 MB free hard drive space. The Video Card should be DirectX 9 compatible with 256 MB RAM or better. Tools Used Microsoft Visual Studio 2015 It is an integrated development environment (IDE) from Microsoft. It is used to develop computer programs for Microsoft Windows, as well as web sites, web applications and web services. Visual Studio uses Microsoft software development platforms such as Windows API, Windows Forms, Windows Presentation Foundation, Windows Store and Microsoft Silverlight. It can produce both native code and managed code. Visual Studio includes a code editor supporting IntelliSense (the code completion component) as well as code refactoring. The integrated debugger works both as a source-level debugger and 13 Software Development: Event Driven Programming DH34 35 a machine-level debugger. Other built-in tools include a forms designer for building GUI applications, web designer, class designer, and database schema designer. It accepts plug-ins that enhance the functionality at almost every level—including adding support for sourcecontrol systems (like Subversion) and adding new toolsets like editors and visual designers for domain-specific languages or toolsets for other aspects of the software development lifecycle (like the Team Foundation Server client: Team Explorer). Visual Studio supports different programming languages and allows the code editor and debugger to support (to varying degrees) nearly any programming language, provided a language-specific service exists. Built-in languages include C,[5] C++ and C++/CLI (via Visual C++), VB.NET (via Visual Basic .NET), C# (via Visual C#), and F# (as of Visual Studio 2010[6]). Support for other languages such as M, Python, and Ruby among others is available via language services installed separately. It also supports XML/XSLT, HTML/XHTML, JavaScript and CSS. Java (and J#) were supported in the past. Microsoft provides "Community" editions of its Visual Studio at no cost. Commercial versions of Visual Studio along with select past versions are available for free to students via Microsoft's DreamSpark program. 14 Software Development: Event Driven Programming DH34 35 Chapter 4 SOFTWARE DETAILED DESIGN System Description The Snake Game is an entertainment based game that enables the user to move the snake around and help it grow. The arrow keys guide the snake’s direction to its food and the score keeps moving as the user manages to feed the snake. Data Flow Diagram A flowchart is a type of diagram that represents an algorithm, workflow or process, showing the steps as boxes of various kinds, and their order by connecting them with arrows. This is the flowchart for the Snake Game. 15 Software Development: Event Driven Programming DH34 35 Design Methodology Design View The player Presses The Space Bar key to begin the game. The player uses the arrow keys to control the movement of the snake to the direction of the food. Upon consuming the food, an increase in the score is seen right down the Score tab. If the player crashes the snake along the walls, the Snake dies. An alert message then appears stating the player has lost. The game then restarts. 16 Software Development: Event Driven Programming DH34 35 Chapter 5 SOFTWARE IMPLEMENTATION Pseudo Code 17 Software Development: Event Driven Programming DH34 35 18 Software Development: Event Driven Programming DH34 35 The pseudo code of the Snake Game application enables the Snake to function and move in all the directions and also designs the Snake according to the color, shape and size that you code it to be and its food too. It constructs the settings of the Score sheet and creates the code for an alert message as to when the player loses. It creates the components and functions for the design view to display. 19 Software Development: Event Driven Programming DH34 35 Chapter 6 TESTING AND RESULTS Introduction NUnit is a unit testing framework for performing unit testing based on the .NET platform. It is a widely used tool for unit testing and is preferred by many developers today. NUnit is free to use. NUnit does not create any test scripts by itself. You have to write test scripts by yourself, but NUnit allows you to use its tools and classes to make unit testing easier. NUnit tests are easily repeatable by anyone with access to the code and test assemblies. This allows you to test the impact of your changes on the work of the entire development team in a distributed development environment. Verifying your code against the entire project maintains the integrity of the overall build. Runners NUnit provides a console runner (nunit-console.exe), which is used for batch execution of tests. The console runner works through the NUnit Test Engine, which provides it with the ability to load, explore and execute tests. When tests are to be run in a separate process, the engine makes use of the nunit-agent program to run them. The NUnit Lite runner may be used in situations where a simpler runner is more suitable. Assertions NUnit provides a rich set of assertions as static methods of the Assert class. If an assertion fails, the method call does not return and an error is reported. If a test contains multiple assertions any that follow the one that failed will not be executed. For this reason, it's usually best to try for one assertion per test. What is Testing? In computer programming, unit testing is a software testing method by which individual units of source code, sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures, are tested to determine whether they are fit for use. Intuitively, one can view a unit as the smallest testable part of an application. In 20 Software Development: Event Driven Programming DH34 35 procedural programming, a unit could be an entire module, but it is more commonly an individual function or procedure. In object-oriented programming, a unit is often an entire interface, such as a class, but could be an individual method. Unit tests are short code fragments created by programmers or occasionally by white box testers during the development process. It forms the basis for component testing. Ideally, each test case is independent from the others. Substitutes such as method stubs, mock objects, fakes, and test harnesses can be used to assist testing a module in isolation. Unit tests are typically written and run by software developers to ensure that code meets its design and behaves as intended. Testing Process 21 Software Development: Event Driven Programming DH34 35 Testing Plan A test plan lets you specify what you want to test and how to run those tests. A test plan can be applied to a specific iteration of your project. You can have just one default test suite for your test cases, or you can create a test suite hierarchy. You can also select the default configurations to use to run the tests in your test plan. The test configuration informs the tester of the set up that is required for these tests. You can have one or multiple default configurations. A test result is recorded every time that you run the test with a specific configuration. A test plan enables you to measure your testing progress, based on these test results for the test and configuration pairings. Test Case 22 Software Development: Event Driven Programming DH34 35 Chapter 7 CONCLUSION The Snake Game would improve an individual’s focus and keep them entertained in a fun way by competing scores with their friends. This Game was designed using Microsoft Visual Studio 2015. Future enhancement Better Graphics. Build more challenging levels. Add more objects for the Snake to collect. Custom the Snake to a players liking. Add sound effects. BIBLIOGRAPHY https://en.wikipedia.org/wiki/NUnit https://www.google.ae/#q=visual+studio+2015 https://en.wikipedia.org/wiki/System_requirements https://en.wikipedia.org/wiki/Non-functional_requirement https://en.wikipedia.org/wiki/Functional_requirement 23