...
 
Commits (2)

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.15
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Praktikum6", "Praktikum6\Praktikum6.csproj", "{9926DAC5-8475-4A38-A76A-4722B9CBE5C1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9926DAC5-8475-4A38-A76A-4722B9CBE5C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9926DAC5-8475-4A38-A76A-4722B9CBE5C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9926DAC5-8475-4A38-A76A-4722B9CBE5C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9926DAC5-8475-4A38-A76A-4722B9CBE5C1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
</configuration>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GameOfLifeGeruest
{
class GameOfLife
{
const int feldgroesse = 30; // Größe der Welt: feldgroesse x feldgroesse
const int verzoegerung = 50; // Millisekunden
/// <summary>
/// Zeigt eine Generation an der Console an
/// </summary>
/// <param name="gen">aktuelle Generation</param>
static void Anzeigen(bool[,] gen)
{
// Fensterinhalt löschen (d. h. wir fangen wieder oben links an):
Console.Clear();
var anzN = AnzahlNachbarn(gen);
// Elemente zeilenweise ausgeben:
for (int i = 0; i < gen.GetLength(0); i++)
{
for (int j = 0; j < gen.GetLength(1); j++)
{
if (gen[i, j])
Console.Write("#");
else
Console.Write(" ");
}
Console.WriteLine();
}
}
/// <summary>
/// Erzeugt eine neue Startgeneration
/// </summary>
/// <returns>Generation; bool[,] Feld</returns>
static bool[,] BigBang()
{
bool[,] gen = new bool[feldgroesse,feldgroesse];
// Zufällig mit lebenden Zellen füllen:
// Verwende ein Random-Objekt
Random R = new Random();
// Wähle zufällig die Anzahl der lebenden Zellen, z. B.:
int anzElemente = R.Next(1, feldgroesse * feldgroesse);
for(int i = 0; i < anzElemente; i++)
{
int x = R.Next(0, feldgroesse);
int y = R.Next(0, feldgroesse);
gen[x,y] = true;
}
/////////////////////////////////////////////////////////////////////////
// 2 Interessante Startmuster zum Ausprobieren
// Einfach entsprechend ein-/auskommentieren
// Gleiter:
//int Smax = gen.GetLength(1);
//gen[13, Smax - 10] = true;
//gen[14, Smax - 11] = true;
//gen[14, Smax - 12] = true;
//gen[13, Smax - 12] = true;
//gen[12, Smax - 12] = true;
// 42:
//gen[10, 10] = gen[10, 12] = gen[10, 15] = gen[10, 16] = gen[10, 17] = true;
//gen[11, 10] = gen[11, 12] = gen[11, 17] = true;
//gen[12, 10] = gen[12, 11] = gen[12, 12] = gen[12, 15] = gen[12, 16] = gen[12, 17] = true;
//gen[13, 12] = gen[13, 15] = true;
//gen[14, 12] = gen[14, 15] = gen[14, 16] = gen[14, 17] = true;
//////////////////////////////////////////////////////////////////////////////////////////
return gen;
}
/// <summary>
/// Ermittelt für jede Zelle die Anzahl ihrer lebenden Nachbarn
/// </summary>
/// <param name="generation">aktuelle Generation</param>
/// <returns>neues Feld, enthält die ermittelten Werte</returns>
static int[,] AnzahlNachbarn(bool[,] generation)
{
// Wird sonst zu unleserlich.
int längeX = generation.GetLength(0);
int längeY = generation.GetLength(1);
int[,] anzN = new int[längeX, längeY];
for(int x = 0; x < längeX; x++)
{
for(int y = 0; y < längeY; y++)
{
// Nachbar-Indizes.
// Wäre schön, wenn der Modulo-Operator mit negativen Zahlen
// funktionieren würde. Da er es aber nicht tut, schieben
// wir das Feld einfach um die Länge nach rechts (für links)
// oder nach unten (für oben). Keine ifs notwendig.
int links = (längeX + x - 1) % längeX;
int rechts = (x + 1) % längeX;
int oben = (längeY + y - 1) % längeY;
int unten = (y + 1) % längeY;
// Hahaha, C# mag bools nicht mal explizit zu int casten.
// Dann halt auf die stumpfsinnige Art und Weise.
anzN[x, y] += generation[links, oben] ? 1 : 0;
anzN[x, y] += generation[x, oben] ? 1 : 0;
anzN[x, y] += generation[rechts, oben] ? 1 : 0;
anzN[x, y] += generation[rechts, y] ? 1 : 0;
anzN[x, y] += generation[rechts, unten] ? 1 : 0;
anzN[x, y] += generation[x, unten] ? 1 : 0;
anzN[x, y] += generation[links, unten] ? 1 : 0;
anzN[x, y] += generation[links, y] ? 1 : 0;
}
}
return anzN;
}
/// <summary>
/// Evolutionsschritt gemäß Conways Regeln
/// </summary>
/// <param name="generation">aktuelle Generation; wird durch die Funktion verändert</param>
static void Evolution(bool[,] generation)
{
int[,] anzN = AnzahlNachbarn(generation);
// Wird sonst zu unleserlich.
int längeX = generation.GetLength(0);
int längeY = generation.GetLength(1);
for(int x = 0; x < längeX; x++)
{
for(int y = 0; y < längeY; y++)
{
if(anzN[x, y] == 3)
{
generation[x, y] = true;
}
else if(anzN[x, y] < 2 || anzN[x, y] > 3)
{
generation[x, y] = false;
}
}
}
}
static void Main(string[] args)
{
// Startmuster:
bool[,] generation = BigBang();
// Simulation:
while (true)
{
Anzeigen(generation);
System.Threading.Thread.Sleep(verzoegerung); // Damit's nicht zu schnell geht
// Alternativ: Manuell weiterschalten
// Console.ReadKey();
Evolution(generation);
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9926DAC5-8475-4A38-A76A-4722B9CBE5C1}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Praktikum6</RootNamespace>
<AssemblyName>Praktikum6</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="GameOfLife.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Praktikum2")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Praktikum2")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("9926dac5-8475-4a38-a76a-4722b9cbe5c1")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
using System;
using System.Diagnostics;
namespace Vorlesung
{
class Schalter
{
private bool zustand;
public void on()
{
zustand = true;
}
public void off()
{
zustand = false;
}
public void toggle()
{
zustand = !zustand;
}
public bool status()
{
return zustand;
}
}
class Konto
{
int kontonummer;
double kontostand;
double dispokredit;
void einzahlen(double betrag)
{
kontostand += Math.Abs(betrag);
}
void auszahlen(double betrag)
{
if(betrag > 0.0)
{
kontostand = Math.Max(kontostand - betrag, -dispokredit)
}
}
double saldo()
{
return kontostand;
}
void setDispo(double d)
{
this.dispokredit = d;
}
public Konto(int kontonummer)
{
this.kontonummer = kontonummer;
this.dispokredit = 1000.0;
}
}
class Classes
{
static void Main(string[] args)
{
Konto k1 = new Konto(1234);
}
}
}