CS3505/5020 Software Practice II
Game loops C#
CS 3505 L02 - 1
CS3505/5020 Software Practice II Game loops C# CS 3505 L02 - 1 - - PowerPoint PPT Presentation
CS3505/5020 Software Practice II Game loops C# CS 3505 L02 - 1 HW 1 Game Loop How do games work? Sprites move across screen Fast enough so you dont see flicker Game loop controls this It can either draw the sprites
CS 3505 L02 - 1
CS 3505 L02 - 2
CS 3505 L02 - 3
CS 3505 L02 - 4
CS 3505 L02 - 5
CS 3505 L02 - 6
CS 3505 L02 - 7
CS 3505 L02 - 8
CS 3505 L02 - 9
CS 3505 L02 - 10
CS 3505 L02 - 11
CS 3505 L02 - 12
CS 3505 L02 - 13
C++ style comments (// and /* */ Files in C++ and Java
– C++: header and cpp file, multiple classes per file allowed – Java: one file with one class per file and file named same class
C#
– One file (.cs extension) – Any number of class definitions per file allowed
C# has C++ preprocessor concept (#define, etc.) Java uses the package concept, C# uses namespace
– Allow multiple namespaces per file
Also have alias: using foo = namespace.namespace.class; C# always uses . ; no more . or -> or ::
JAVA
package <Package name>; import <package hierarchy>.<class name>; class Customer { ... }
C#
using <namespace hierarchy>.<class name>; namespace <namespace name> { class Customer { ... } }
CS 3505 L02 - 14
CS 3505 L02 - 15
CS 3505 L02 - 16
CS 3505 L02 - 17
CS 3505 L02 - 18
int x = 123456; long y = x; // implicit short z = (short)x; // explicit double d = 1.2345678901234; float f = (float)d; // explicit long l = (long)d; // explicit
CS 3505 L02 - 19
CS 3505 L02 - 20
CS 3505 L02 - 21
CS 3505 L02 - 22
CS 3505 L02 - 23
CS 3505 L02 - 24
CS 3505 L02 - 25
CS 3505 L02 - 26
CS 3505 L02 - 27
CS 3505 L02 - 28
CS 3505 L02 - 29
interface IB extends IA { void f (); } interface IA { void g (); } interface IC extends IA { void f (); } class X implements IB, IC { void () { System.out.println ("g"); } void () { System.out.println ("f"); } } g f
CS 3505 L02 - 30
interface IB extends IA { void f (); } interface IA { void g (); } interface IC extends IA { void f (); } class X implements IB, IC { void () { System.out.println ("g"); } void () { System.out.println ("f"); } } g f
CS 3505 L02 - 31
class X : IB, IC { void () { Console.WriteLine ("IA.g"); } void () { Console.WriteLine ("IC.f"); } void () { Console.WriteLine ("IB.f"); } } IA.g IB.f IC.f interface IA { void g (); } interface IB : IA { void f (); } interface IC : IA { void f (); }
class Test { public static void Main () { X x = new X (); ((IA)x).g(); ((IC)x).f(); ((IB)x).f(); } }
CS 3505 L02 - 32
CS 3505 L02 - 33
CS 3505 L02 - 34
CS 3505 L02 - 35
CS 3505 L02 - 36
Same as C++ class, but all members are publ i c publ i c User-defined value type Can be allocated on the heap,
(can be used as value or reference)
Members can be publ i c publ i c, i nt er nal i nt er nal or pr i vat e pr i vat e
CS 3505 L02 - 37
CS 3505 L02 - 38
These are properties which we’ll describe later.
CS 3505 L02 - 39
CS 3505 L02 - 40
CS 3505 L02 - 41
CS 3505 L02 - 42
CS 3505 L02 - 43
CS 3505 L02 - 44
CS 3505 L02 - 45
Java – Primitives by value; Objects by ref C++ – By value with copy constructors for objects; Reference by specification C# – Primitives by value; Objects by ref; Value can be by ref by saying “ref” – “out” – just like “ref” except initial value ignored, and MUST be assigned using System; public class RefClass { public static void Main(string[] args) { int total = 20; Console.WriteLine("Original value of 'total': {0}", total); // Call the Add method Add (10, ref total); Console.WriteLine("Value after Add() call: {0}", total); } public static void Add (int i, ref int result) { result += i; } }
CS 3505 L02 - 46
Formalized getter/setter model of Java
Compiles to get_Species/set_Species for languages that