DEADLINE: (siehe Details zur Abgabe weiter unten)
Ziele:
Bevor wir aber mit dem eigentlichen Game anfangen, bereiten wir uns mit einigen Aufträgen darauf vor.
Das Ziel ist, in der Klasse eine Konsolen-Game-Sammlung zu erstellen, wobei ihr alle entweder alleine oder in Zweiergruppen (Kriterien unten) ein Game beisteuert. Das Framework, in welches euer Game dann eingebunden wird, wird von den Lehrpersonen vorgegeben. In diesem Framework kann man dann u.A. das Game auswählen, Spielstände speichern und Highscores einsehen.
Das Game wird bewertet und es gibt eine mündliche Prüfung dazu. Beides zusammen gibt die zweite Note in diesem Semester.
Die Kriterien an das Game sind:
Auftrag in Kürze: HangMan in Framework integrieren und in ein Single-Player-Game umwandeln.
Auftrag im Detail:
ConsoleGame
(wähle Gitignore „Visual Studio“) und klone es auf Computer. Alle erstellen ihr eigenes Repo. Für das eigentliche Game-Project wird dann ein neues Repo erzeugt.GuessNumber
studieren.public
oder private
versehen werden. Überlege dir, welcher für welche Funktion passend ist.Program.cs
aus.return new Score();
Q: Was ist der Unterschied von Funktion und Methode? A: Eine Methode ist eine Funktion, die zu einer Klasse gehört.
Das Game einer Gruppe (1-2 Leute) wird mit einer Note bewertet. Alle Personen in der Gruppe erhalten im Normalfall die gleiche Note. Ausnahme: es ist klar ersichtlich, dass eine Person deutlich mehr beigetragen hat als die andere.
Gibt es Probleme in der Gruppe, meldet dies rechtzeitig, damit wir eine Lösung finden können.
Kriterium | Punkte |
---|---|
Spielidee, Originalität, Komplexität | 10 |
Prozess, Vorgehensweise, Selbständigkeit (1) | 10 |
kontinuierliches Arbeiten und Fortschritt | |
regelmässige Commits (und Pushes) auf GitHub | |
mehrheitlich selbständig gearbeitet | |
Arbeiten mit Framework | 10 |
Plug n' Play (einfaches Einbinden in Framework) | |
Gesamter Code in einem File | |
private vs. public | |
Model vs. View | 10 |
Modellierung (Abstrahierung) | |
Aufteilung in Methoden & Klassen (letztere optional) | |
Strikte Trennung von Model- und View-Methoden/Klassen | |
GUI / Darstellung | 10 |
anspruchsvolles GUI, Anwendung der Console-Befehle | |
Programmieren | 15 |
Benennung von Variablen, Methoden usw. | |
sauber und effizient programmiert | |
Logik | |
Stabilität, Umgang mit falschen Eingaben | |
Gamespezifischer Teil | 15 |
unterschiedlicher Fokus je nach Game | |
Mündliche Prüfung (2) | 20 |
Total | 100 |
Aus den Punkten wird die Note linear berechnet (95% der Punkte: 6er, 0 Punkte: 1er).
Änderungen für 2025 usw: Gute Kommentierung in Code sollten auch Punkte geben, zB 10 dafür, aber nur 10 für mündl. P oder so
Dokumentiere die wichtigen Methoden, Felder und Eigenschaften professionel: Siehe offiziellen Guidelines für "Documentation Comments"
// Clear console Console.Clear(); // Hide cursor Console.CursorVisible = false; // Write line Console.WriteLine(); // Write at specific position Console.SetCursorPosition(20,10); Console.Write(); // Read input Console.ReadLine(); Console.ReadKey(); // Using color Console.BackgroundColor = ConsoleColor.Yellow; Console.ForegroundColor = ConsoleColor.Red; // font color // Get terminal windows width and height Console.WindowWidth; Console.WindowHeight;
Für mehr Infos, siehe Slides zu ConsoleArt
using System.Threading; // for sleep using System.Diagnostics; // for stopwatch // Let program sleep Thread.Sleep(500); // Stopwatch: Measures time since program start Stopwatch stopwatch = Stopwatch.StartNew(); long time = stopwatch.ElapsedMilliseconds;
Auf User-Input warten, z.B. für Game-Steuerung:
while (true) { if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); Console.WriteLine("key pressed: " + key.Key); } else { Console.WriteLine("no key pressed"); } Thread.Sleep(200); // sleep for 200ms, requires using System.Threading; }
// declare 2d-array and set array element values: int[,] arr = { { 1, 4, 2 }, { 3, 6, 8 } }; // declare 2d-array without setting element values (int array -> default elements are 0): int[,] arr2 = new int[3, 5]; // looks like this: // | column 1 | column 2 | column 3 | // row 1 | 1 | 4 | 2 | // row 2 | 3 | 6 | 8 | // Access element: Console.WriteLine(arr[1, 2]); // Outputs 8 // Change element: arr[0, 0] = 5; // Value 1 -> 5 // Get total number of elements in array Console.WriteLine(arr.Length); // Get dimension of array (nr columns and rows) Console.WriteLine(arr.GetLength(0)); // -> 2 (y-direction) Console.WriteLine(arr.GetLength(1)); // -> 3 (x-direction) // IMPORTANT: order is different than in math: first y, then x // Iterate over elements Console.WriteLine(); for (int y = 0; y < arr.GetLength(0); y++) { for (int x = 0; x < arr.GetLength(1); x++) { Console.WriteLine(arr[y,x]); } }
private class Point { // Field public int x; public int y; public string color; // Constructor public Point(int _x, int _y, string _color) { x = _x; y = _y; color = _color; } // Methode public void SetToStart() { x = 0; y = 0; } } private class PointWithProperty { // Field private int _x; private int _y; private string _color; // Property public int x { get { return _x; } set { if (value > 0) { _x = value; } else { _x = 0; } } } // Constructor public PointWithProperty(int _xx, int _yy, string _col) { _x = _xx; _y = _yy; _color = _col; } // Methode public void SetToStart() { _x = 0; _y = 0; } } public override Score Play(int level) { Console.CursorVisible = false; Point p = new Point(10, 7, "red"); // create new point object Console.SetCursorPosition(p.x, p.y); Console.Write(p.color); Console.ReadKey(); p.SetToStart(); // call method Console.SetCursorPosition(p.x, p.y); Console.Write(p.color); Console.ReadKey(); // Point is new data type, can thus create point array Point[] points = new Point[] { new Point(1, 1, "black"), new Point(7, 5, "yellow"), new Point(2, 12, "green") }; return new Score(); }