Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Prog1_WS2017_18_Wienkop
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Uwe Wienkop
Prog1_WS2017_18_Wienkop
Commits
86961052
Commit
86961052
authored
Jan 05, 2018
by
Uwe Wienkop
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Schiffeversenken
parent
5e120505
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
402 additions
and
0 deletions
+402
-0
Prog1_WS2017-18/11Schiffeversenken/11Schiffeversenken.csproj
Prog1_WS2017-18/11Schiffeversenken/11Schiffeversenken.csproj
+60
-0
Prog1_WS2017-18/11Schiffeversenken/App.config
Prog1_WS2017-18/11Schiffeversenken/App.config
+6
-0
Prog1_WS2017-18/11Schiffeversenken/Program.cs
Prog1_WS2017-18/11Schiffeversenken/Program.cs
+294
-0
Prog1_WS2017-18/11Schiffeversenken/Properties/AssemblyInfo.cs
...1_WS2017-18/11Schiffeversenken/Properties/AssemblyInfo.cs
+36
-0
Prog1_WS2017-18/Prog1_WS2017-18.sln
Prog1_WS2017-18/Prog1_WS2017-18.sln
+6
-0
No files found.
Prog1_WS2017-18/11Schiffeversenken/11Schiffeversenken.csproj
0 → 100644
View file @
86961052
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"14.0"
DefaultTargets=
"Build"
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>
{AB02570D-3B45-4052-B20B-5986E89C5536}
</ProjectGuid>
<OutputType>
Exe
</OutputType>
<AppDesignerFolder>
Properties
</AppDesignerFolder>
<RootNamespace>
_11Schiffeversenken
</RootNamespace>
<AssemblyName>
11Schiffeversenken
</AssemblyName>
<TargetFrameworkVersion>
v4.5.2
</TargetFrameworkVersion>
<FileAlignment>
512
</FileAlignment>
<AutoGenerateBindingRedirects>
true
</AutoGenerateBindingRedirects>
</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=
"Program.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
</ItemGroup>
<ItemGroup>
<None
Include=
"App.config"
/>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
Prog1_WS2017-18/11Schiffeversenken/App.config
0 → 100644
View file @
86961052
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
configuration
>
<
startup
>
<
supportedRuntime
version
=
"v4.0"
sku
=
".NETFramework,Version=v4.5.2"
/>
</
startup
>
</
configuration
>
\ No newline at end of file
Prog1_WS2017-18/11Schiffeversenken/Program.cs
0 → 100644
View file @
86961052
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
_11Schiffeversenken
{
// Vorgabe der Schiffslaengen: siehe main()
enum
FeldStatus
{
Wasser
=
'.'
,
WasserBesucht
=
'-'
,
SchiffIntakt
=
'x'
,
SchiffBeschaedigt
=
'*'
}
enum
Bewertung
{
Treffer
,
Beinahe
,
Daneben
,
Wiederholung
,
Ausserhalb
};
class
Spiel
{
int
spielfeldBreite
;
// Groesse des Spielfelds
int
spielfeldHoehe
;
int
AnzSchiffe
=
6
;
// Anzahl der zu erzeugenden Schiffe
FeldStatus
[,]
spielfeld
;
Schiff
[]
Schiffe
;
int
AnzTrefferBisSpielende
=
0
;
///////////////////////////////////////////////////////////////////////
// InitGrid
///////////////////////////////////////////////////////////////////////
// Initialisiert das Spielfeld ~ alle Positionen = Wasser
public
Spiel
(
int
Breite
,
int
Hoehe
,
params
int
[]
Schiffslaengen
)
{
spielfeldBreite
=
Breite
;
spielfeldHoehe
=
Hoehe
;
AnzSchiffe
=
Schiffslaengen
.
Length
;
spielfeld
=
new
FeldStatus
[
spielfeldHoehe
,
spielfeldBreite
];
for
(
int
y
=
0
;
y
<
spielfeldHoehe
;
y
++)
for
(
int
x
=
0
;
x
<
spielfeldBreite
;
x
++)
spielfeld
[
y
,
x
]
=
FeldStatus
.
Wasser
;
Schiffe
=
new
Schiff
[
Schiffslaengen
.
Length
];
for
(
int
i
=
0
;
i
<
Schiffslaengen
.
Length
;
i
++)
{
Schiffe
[
i
]
=
new
Schiff
(
Schiffslaengen
[
i
],
spielfeld
);
AnzTrefferBisSpielende
+=
Schiffslaengen
[
i
];
//SpielfeldAusgeben(true);
}
}
public
bool
Spielende
{
get
{
return
AnzTrefferBisSpielende
==
0
;
}
}
///////////////////////////////////////////////////////////////////////
// SpielfeldAusgeben
///////////////////////////////////////////////////////////////////////
// Gibt das Spielfeld auf dem Bildschirm aus
public
void
SpielfeldAusgeben
(
bool
Debug
=
false
)
{
int
y
,
x
;
for
(
y
=
0
;
y
<
spielfeldHoehe
;
y
++)
{
for
(
x
=
0
;
x
<
spielfeldBreite
;
x
++)
{
if
(
Debug
==
true
)
Console
.
Write
((
char
)
spielfeld
[
y
,
x
]);
else
{
switch
(
spielfeld
[
y
,
x
])
{
case
FeldStatus
.
Wasser
:
Console
.
BackgroundColor
=
ConsoleColor
.
Black
;
Console
.
Write
(
$"
{(
char
)
FeldStatus
.
Wasser
}
"
);
break
;
case
FeldStatus
.
WasserBesucht
:
Console
.
BackgroundColor
=
ConsoleColor
.
Blue
;
Console
.
Write
(
$"
{(
char
)
FeldStatus
.
Wasser
}
"
);
break
;
case
FeldStatus
.
SchiffBeschaedigt
:
Console
.
BackgroundColor
=
ConsoleColor
.
Red
;
Console
.
Write
(
$"
{(
char
)
spielfeld
[
y
,
x
]}
"
);
break
;
case
FeldStatus
.
SchiffIntakt
:
Console
.
BackgroundColor
=
ConsoleColor
.
Black
;
Console
.
Write
(
$"
{(
char
)
FeldStatus
.
Wasser
}
"
);
break
;
default
:
break
;
}
}
//Console.Write((spielfeld[y, x] != FeldStatus.SchiffIntakt) ? (char)spielfeld[y, x] : (char)FeldStatus.Wasser);
//else
}
Console
.
WriteLine
();
}
}
///////////////////////////////////////////////////////////////////////
// FeuereAufKoordinate - Klassifiziere die Koordinate
///////////////////////////////////////////////////////////////////////
// Wertet die letztgenannte Position genauer aus, d.h. liefert zurueck,
// was sich an dieser Position befindet (Wasser, knapp daneben, Treffer, etc.
// px, py - Koordinate
public
Bewertung
FeuereAufKoordinate
(
int
px
,
int
py
)
{
int
x
,
y
;
if
(
px
<
1
||
px
>=
spielfeldBreite
-
1
||
py
<
1
||
py
>=
spielfeldHoehe
-
1
)
{
Console
.
WriteLine
(
"\nAusserhalb des Wertebereichs"
);
return
Bewertung
.
Ausserhalb
;
}
if
(
spielfeld
[
py
,
px
]
==
FeldStatus
.
SchiffIntakt
)
{
spielfeld
[
py
,
px
]
=
FeldStatus
.
SchiffBeschaedigt
;
Console
.
WriteLine
(
"\nTreffer!!!"
);
foreach
(
Schiff
schiff
in
Schiffe
)
{
if
(
schiff
.
WurdeDiesesSchiffGetroffen
(
px
,
py
))
break
;
}
AnzTrefferBisSpielende
--;
return
Bewertung
.
Treffer
;
}
if
(
spielfeld
[
py
,
px
]
==
FeldStatus
.
SchiffBeschaedigt
||
spielfeld
[
py
,
px
]
==
FeldStatus
.
WasserBesucht
)
{
Console
.
WriteLine
(
"\nDen hatten wir doch schon 'mal"
);
return
Bewertung
.
Wiederholung
;
}
for
(
y
=
py
-
1
;
y
<=
py
+
1
;
y
++)
{
for
(
x
=
px
-
1
;
x
<=
px
+
1
;
x
++)
{
if
(
spielfeld
[
y
,
x
]
==
FeldStatus
.
SchiffIntakt
||
spielfeld
[
y
,
x
]
==
FeldStatus
.
SchiffBeschaedigt
)
{
spielfeld
[
py
,
px
]
=
FeldStatus
.
WasserBesucht
;
Console
.
WriteLine
(
"\nKnapp daneben!!!"
);
return
Bewertung
.
Beinahe
;
}
}
}
spielfeld
[
py
,
px
]
=
FeldStatus
.
WasserBesucht
;
Console
.
WriteLine
(
"\nEinfach Wasser!!!"
);
return
Bewertung
.
Daneben
;
}
}
class
Schiff
{
int
laenge
;
int
anzTreffer
;
// Anzahl der schon erhaltenen Treffer
int
[]
xPos
;
// alle Koordinaten des Schiffs
int
[]
yPos
;
FeldStatus
[]
zustand
;
// Zustand der Schiffspositionen (eSchiff oder eSchiffB = getroffen)
static
Random
R
=
new
Random
();
///////////////////////////////////////////////////////////////////////
// PositioniereSchiff
///////////////////////////////////////////////////////////////////////
// Positioniert ein Schiff auf dem Spielfeld. Hierzu werden zufällig
// Startposition und Orientierung ermittelt. Sollte eine legale Positionierung
// eines Schiffs dieser Länge nicht zulaessig sein, so werden erneut
// Startpos. und Orientierung gewuerfelt. Es ist darauf zu achten, dass
// 1) das Spielfeld hinreichend gross ist, so dass dieses Verfahren erfolgreich
// sein kann und 2) dass grosse Schiffe VOR kleinen positioniert werden.
//
// Laenge - Laenge dieses Schiffs
// grid - Spielfeld mit ggf. schon eingetragenen anderen Schiffen
// auch dieses Schiff wird nach erfolgreicher Positionierung im
// Spielfeld vermerkt
public
Schiff
(
int
Laenge
,
FeldStatus
[,]
grid
)
{
int
spielfeldBreite
=
grid
.
GetLength
(
1
);
int
spielfeldHoehe
=
grid
.
GetLength
(
0
);
xPos
=
new
int
[
Laenge
];
yPos
=
new
int
[
Laenge
];
zustand
=
new
FeldStatus
[
Laenge
];
int
xP
,
yP
,
Richtung
;
int
dx
,
dy
;
bool
belegt
;
int
anzVersuche
=
0
;
do
{
Richtung
=
R
.
Next
(
0
,
2
);
if
(
Richtung
==
0
)
// horizontales Schiff
{
xP
=
R
.
Next
(
spielfeldBreite
-
1
-
Laenge
)
+
1
;
yP
=
R
.
Next
(
spielfeldHoehe
-
2
)
+
1
;
dx
=
1
;
dy
=
0
;
}
else
// vertikales Schiff
{
xP
=
R
.
Next
(
spielfeldBreite
-
2
)
+
1
;
yP
=
R
.
Next
(
spielfeldHoehe
-
1
-
Laenge
)
+
1
;
dx
=
0
;
dy
=
1
;
}
belegt
=
false
;
int
xEnde
=
xP
+
(
Laenge
-
1
)
*
dx
+
1
;
int
yEnde
=
yP
+
(
Laenge
-
1
)
*
dy
+
1
;
for
(
int
y
=
yP
-
1
;
y
<=
yEnde
;
y
++)
{
for
(
int
x
=
xP
-
1
;
x
<=
xEnde
;
x
++)
if
(
grid
[
y
,
x
]
==
FeldStatus
.
SchiffIntakt
)
{
belegt
=
true
;
break
;
}
}
if
(!
belegt
)
{
//Console.Write($"Schiff der Länge {Laenge}, Richtung {Richtung}");
for
(
int
l
=
0
;
l
<
Laenge
;
l
++)
{
xPos
[
l
]
=
xP
+
l
*
dx
;
yPos
[
l
]
=
yP
+
l
*
dy
;
//Console.Write($" Koord({xPos[l]},{yPos[l]})");
//zustand[l] = Feldzustand.Schiff;
grid
[
yPos
[
l
],
xPos
[
l
]]
=
FeldStatus
.
SchiffIntakt
;
}
Console
.
WriteLine
();
anzTreffer
=
0
;
laenge
=
Laenge
;
}
anzVersuche
++;
}
while
(
belegt
==
true
);
//Console.WriteLine($"{anzVersuche} Versuche");
}
public
bool
WurdeDiesesSchiffGetroffen
(
int
xP
,
int
yP
)
{
bool
getroffen
=
false
;
for
(
int
l
=
0
;
l
<
laenge
;
l
++)
if
(
xPos
[
l
]
==
xP
&&
yPos
[
l
]
==
yP
)
{
getroffen
=
true
;
anzTreffer
++;
if
(
anzTreffer
==
laenge
)
Console
.
WriteLine
(
$"Schiff der Länge
{
laenge
}
wurde vollständig versenkt!!!"
);
break
;
}
return
getroffen
;
}
}
class
Program
{
static
void
Main
(
string
[]
args
)
{
int
[]
Schiffslaengen
=
{
4
,
3
,
3
,
2
,
2
,
2
};
Spiel
spiel
;
do
{
spiel
=
new
Spiel
(
20
,
10
,
Schiffslaengen
);
Console
.
WriteLine
(
"Willkommen beim Schiffeversenken"
);
Console
.
WriteLine
(
"================================\n"
);
Console
.
WriteLine
(
"Das Spielbrett wird vorbereitet..."
);
do
{
spiel
.
SpielfeldAusgeben
();
Console
.
Write
(
"Position: <z,s> "
);
string
[]
koord
=
Console
.
ReadLine
().
Split
(
','
);
int
yPos
=
Convert
.
ToInt32
(
koord
[
0
]);
int
xPos
=
Convert
.
ToInt32
(
koord
[
1
]);
spiel
.
FeuereAufKoordinate
(
xPos
,
yPos
);
}
while
(!
spiel
.
Spielende
);
Console
.
WriteLine
(
"Herzlichen Glueckwunsch! Sie haben alle Schiffe versenkt!"
);
Console
.
Write
(
"Noch einmal (j/n)? "
);
}
while
(
Console
.
Read
()
==
'j'
);
}
}
}
Prog1_WS2017-18/11Schiffeversenken/Properties/AssemblyInfo.cs
0 → 100644
View file @
86961052
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
(
"11Schiffeversenken"
)]
[
assembly
:
AssemblyDescription
(
""
)]
[
assembly
:
AssemblyConfiguration
(
""
)]
[
assembly
:
AssemblyCompany
(
""
)]
[
assembly
:
AssemblyProduct
(
"11Schiffeversenken"
)]
[
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
(
"ab02570d-3b45-4052-b20b-5986e89c5536"
)]
// 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"
)]
Prog1_WS2017-18/Prog1_WS2017-18.sln
View file @
86961052
...
...
@@ -97,6 +97,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "11Klimaerwaermung", "11Klim
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "11Hangman", "11Hangman\11Hangman.csproj", "{2786B97B-2DF5-4722-A927-8A064D47CE39}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "11Schiffeversenken", "11Schiffeversenken\11Schiffeversenken.csproj", "{AB02570D-3B45-4052-B20B-5986E89C5536}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
...
...
@@ -279,6 +281,10 @@ Global
{2786B97B-2DF5-4722-A927-8A064D47CE39}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2786B97B-2DF5-4722-A927-8A064D47CE39}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2786B97B-2DF5-4722-A927-8A064D47CE39}.Release|Any CPU.Build.0 = Release|Any CPU
{AB02570D-3B45-4052-B20B-5986E89C5536}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AB02570D-3B45-4052-B20B-5986E89C5536}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AB02570D-3B45-4052-B20B-5986E89C5536}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB02570D-3B45-4052-B20B-5986E89C5536}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment