Important Note: This entire project, including all code and this README documentation, was generated by Claude AI (Anthropic) as an educational resource for A-Level Computer Science teachers and students. It is intended to demonstrate concepts and techniques, not to serve as a template for student NEA projects.
This exemplar WPF application demonstrates fundamental programming concepts required for AQA 7517 A-Level Computer Science NEA projects. It illustrates how to create a grid-based application using WPF and C#, showing key techniques that students should understand when developing their own projects.
Important: This exemplar is designed to teach concepts, not to be used as a starting point for your NEA project. Your NEA must be your own original work, addressing a problem you have identified and designed yourself.
The project consists of three main files:
- Square.cs - A custom class representing a single grid cell (AI-generated)
- MainWindow.xaml - The user interface layout definition (AI-generated)
- MainWindow.xaml.cs - The code-behind containing the application logic (AI-generated)
This exemplar demonstrates specific skills from the AQA specification that are commonly needed in grid-based or maze-style projects. Understanding these concepts will help you implement similar features in your own, original project.
This exemplar demonstrates the following Group B technical skills:
Data Structures:
- Multi-dimensional arrays: The
Square[,] gridarray stores the grid structure - Records/Classes: The
Squareclass encapsulates cell properties - Simple OOP model: Custom class with properties and methods
Algorithms:
- Simple user-defined algorithms: Coordinate conversion, wall randomization, click detection
- File handling concepts: Though not implemented here, the structure supports reading/writing grid configurations
To achieve Group A level in your NEA, you would need to incorporate more advanced techniques such as:
Data Structures:
- Complex data models (e.g., interlinked database tables)
- Advanced structures (stacks, queues, graphs, trees)
- Complex OOP with inheritance, polymorphism, interfaces
Algorithms:
- Graph/tree traversal algorithms
- Recursive algorithms
- Complex user-defined algorithms (optimization, pathfinding, scheduling)
- Advanced sorting (merge sort or similar)
This exemplar focuses on Group B level skills. Your NEA project should aim higher.
The Square class demonstrates encapsulation - bundling data and methods that operate on that data:
public class Square
{
// Properties store the state
public int X { get; set; }
public bool NorthWall { get; set; }
// Methods operate on that state
public bool ContainsPoint(double pointX, double pointY)
{
return pointX >= X && pointX < X + Size &&
pointY >= Y && pointY < Y + Size;
}
}Key Concept: Each object knows its own data and how to work with it. This makes code more maintainable and easier to reason about.
A 2D array naturally represents a grid structure:
private Square[,] grid;
grid = new Square[gridRows, gridCols];Why this matters:
- Direct mapping between logical structure (rows/columns) and data structure
- Easy access to adjacent cells:
grid[row-1, col]is the cell above - Essential for algorithms that need to navigate or analyze grid patterns
- Common in maze generation, pathfinding, game boards, cellular automata
Converting between logical (grid) and physical (pixel) coordinates:
int x = col * SQUARE_SIZE; // Grid position → Screen position
int y = row * SQUARE_SIZE;Key Concept: Programs often need to work with multiple representations of the same data. Understanding how to convert between them is crucial.
Each square has four independent walls:
public bool NorthWall { get; set; }
public bool EastWall { get; set; }
public bool SouthWall { get; set; }
public bool WestWall { get; set; }Why this design choice:
- Maze algorithms work by removing walls between cells
- Allows precise control over cell boundaries
- More flexible than drawing complete rectangles
- Demonstrates data modeling for specific problem domains
WPF applications respond to events:
private void Canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Point clickPoint = e.GetPosition(DrawingCanvas);
// Respond to user action
}Key Concept: The program waits for user actions rather than executing sequentially from start to finish. This is fundamental to interactive applications.
Safely handling user input:
if (int.TryParse(WidthTextBox.Text, out int newWidth))
{
if (newWidth >= 1 && newWidth <= 50)
{
// Safe to use newWidth
}
}Key Concept: Never trust user input. Always validate before using it. This prevents crashes and security issues.
Windows Presentation Foundation (WPF) is a framework for creating desktop applications. It separates the visual design (XAML) from the logic (C#).
1. Layout Containers
- DockPanel: Arranges children by docking them to edges (top, bottom, left, right)
- StackPanel: Stacks children vertically or horizontally
- Canvas: Allows precise positioning using coordinates
2. Controls
- Button: Triggers actions when clicked
- TextBox: Accepts user input
- TextBlock: Displays read-only text
- Menu/MenuItem: Provides organized commands
3. Event Handlers
Events link user actions to code:
<Button Content="Apply" Click="ApplyGridSize_Click"/>When clicked, the ApplyGridSize_Click method in the code-behind executes.
4. Drawing on Canvas
Line line = new Line
{
X1 = startX, Y1 = startY,
X2 = endX, Y2 = endY,
Stroke = Brushes.Black,
StrokeThickness = 2
};
Canvas.SetLeft(line, 0);
Canvas.SetTop(line, 0);
DrawingCanvas.Children.Add(line);Key Concept: Graphics are created as objects and added to the canvas. You have full control over each visual element.
for (int row = 0; row < gridRows; row++)
{
for (int col = 0; col < gridCols; col++)
{
if (grid[row, col].ContainsPoint(clickPoint.X, clickPoint.Y))
{
// Found the clicked square
return;
}
}
}Analysis:
- Time Complexity: O(n) where n is the total number of squares
- This is acceptable for small grids but could be optimized for larger ones
- Alternative: Calculate grid position directly from coordinates - O(1)
private Random random = new Random();
public void RandomiseWalls(Random random)
{
NorthWall = random.Next(2) == 1; // 50% probability
}Key Concept: Create Random once and reuse it. Creating multiple instances quickly produces identical sequences.
- ✓ Meaningful identifier names (
gridRows,DrawSquare) - ✓ Effective annotation where code is complex
- ✓ Consistent style throughout
- ✓ Well-designed user interface (menu bar, control panel, canvas)
- ✓ Modularisation of code (separate methods for distinct tasks)
- ✓ Good use of local variables
- ✓ Minimal use of global variables
- ✓ Use of constants (
SQUARE_SIZE) - ✓ Appropriate indentation
- ✓ Self-documenting code (clear variable names, logical structure)
- ✓ Modules (methods) with appropriate parameters
- ✓ Cohesive methods (each does one thing well)
- ~ Defensive programming (input validation present)
- ~ Exception handling (basic error checking, could be more comprehensive)
This exemplar uses a 2D array because it naturally represents a grid. For your project:
- Consider what data structure best represents your problem
- A list? A tree? A graph? A database?
- The choice should make your algorithms simpler, not more complex
The Square class knows how to check if it contains a point. This is better than having that logic scattered throughout the code.
Principle: Objects should manage their own data and behavior.
WPF separates the visual design (XAML) from the code (C#). This makes both easier to modify independently.
Principle: Keep different concerns separate.
Users make mistakes. Your program should:
- Validate all input
- Provide clear error messages
- Prevent invalid states
Comments should explain why you made a choice, not just what the code does:
// Using Canvas because we need precise pixel positioning for drawing lines
// StackPanel or Grid would not give us this controlImportant for NEA Success:
This exemplar teaches concepts you should understand and apply in your own way:
- ✓ Understand how 2D arrays represent grids
- ✓ Understand event-driven programming
- ✓ Understand coordinate system conversion
- ✗ Don't copy this code into your NEA
- ✗ Don't use this as a template
Your NEA must:
- Solve a problem you have identified
- Be designed by you
- Use these concepts in your own way
- Demonstrate your own problem-solving skills
- Open the solution in Visual Studio 2022 or later
- Ensure you have .NET Desktop Development workload installed
- Build and run the project (F5)
- Experiment with the features to understand how they work
- Read the code with the comments to understand the implementation
This exemplar addresses content from:
- Section 4.1: Fundamentals of Programming
- Section 4.2: Fundamentals of Data Structures (2D arrays)
- Section 4.4.1: Abstraction and automation
- Section 4.13: Systematic approach to problem solving
The technical skills demonstrated align with Group B of Table 1 (Section 4.14.3.4.1). To achieve higher marks in your NEA, you should incorporate Group A skills appropriate to your chosen problem.
- AQA 7517 Specification Section 4.14: Non-exam assessment - the computing practical project
- Microsoft WPF Documentation: https://docs.microsoft.com/en-us/dotnet/desktop/wpf/
- C# Programming Guide: https://docs.microsoft.com/en-us/dotnet/csharp/
Created by: Claude AI (Anthropic)
Purpose: Educational exemplar for AQA 7517 A-Level Computer Science
Date: November 2024
License: Provided for educational purposes for AQA 7517 A-Level Computer Science students and teachers
This resource was created as a teaching tool to demonstrate programming concepts and techniques. It is not intended to be submitted as student work or used as a template for NEA projects.
Remember: The purpose of this exemplar is to help you understand concepts. Your NEA project must be your own original work addressing your own problem. Use these concepts as building blocks, but create your own solution.