Add project files.

This commit is contained in:
2025-12-08 09:46:59 +01:00
parent 68f60acce5
commit bef0831281
6 changed files with 390 additions and 0 deletions

25
Spaceshooter.sln Normal file
View File

@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36408.4 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spaceshooter", "Spaceshooter\Spaceshooter.csproj", "{FCD2D4AE-6F52-4D83-9E1A-81ADC16ACB1F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FCD2D4AE-6F52-4D83-9E1A-81ADC16ACB1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FCD2D4AE-6F52-4D83-9E1A-81ADC16ACB1F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FCD2D4AE-6F52-4D83-9E1A-81ADC16ACB1F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FCD2D4AE-6F52-4D83-9E1A-81ADC16ACB1F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1612866E-5110-4D81-8894-1E3C87D915B7}
EndGlobalSection
EndGlobal

73
Spaceshooter/Form1.Designer.cs generated Normal file
View File

@@ -0,0 +1,73 @@
namespace Spaceshooter
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
player = new PictureBox();
gameTimer = new System.Windows.Forms.Timer(components);
((System.ComponentModel.ISupportInitialize)player).BeginInit();
SuspendLayout();
//
// player
//
player.BackColor = Color.OrangeRed;
player.Location = new Point(33, 135);
player.Name = "player";
player.Size = new Size(100, 50);
player.TabIndex = 0;
player.TabStop = false;
player.Click += player_Click;
//
// gameTimer
//
gameTimer.Enabled = true;
gameTimer.Interval = 20;
gameTimer.Tick += gameTimer_Tick;
//
// Form1
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(player);
Name = "Form1";
Text = "Form1";
Load += Form1_Load;
KeyDown += Form1_KeyDown;
KeyUp += Form1_KeyUp;
((System.ComponentModel.ISupportInitialize)player).EndInit();
ResumeLayout(false);
}
#endregion
private PictureBox player;
private System.Windows.Forms.Timer gameTimer;
}
}

141
Spaceshooter/Form1.cs Normal file
View File

@@ -0,0 +1,141 @@
using System.Drawing.Imaging;
using System.Xaml.Permissions;
namespace Spaceshooter
{
public partial class Form1 : Form
{
bool goUp, goDown;
int playerSpeed = 10;
int spawnSpeed = 10;
int bulletSpeed = 15;
int enemySpeed = 8;
int score = 0;
Random rand = new Random();
public Form1()
{
InitializeComponent();
}
private void player_Click(object sender, EventArgs e)
{
}
private void gameTimer_Tick(object sender, EventArgs e)
{
if (goUp && player.Top > 0)
{
player.Top -= playerSpeed;
}
if (goDown && player.Top + player.Height < this.ClientSize.Height)
{
player.Top += playerSpeed;
}
for (int i = this.Controls.Count - 1; i >= 0; i--)
{
Control x = this.Controls[i];
if (x is PictureBox && (string)x.Tag == "bullet")
{
x.Left += bulletSpeed;
if (x.Left > this.ClientSize.Width)
{
this.Controls.Remove(x);
x.Dispose();
}
}
if (x is PictureBox && (string)x.Tag == "enemy")
{
x.Left -= enemySpeed;
if (x.Bounds.IntersectsWith(player.Bounds))
{
gameTimer.Stop();
MessageBox.Show("Game Over! Po<50>ng " + score);
Application.Restart();
}
if (x.Left + this.ClientSize.Width < 0)
{
this.Controls.Remove(x);
x.Dispose();
}
}
}
if (rand.Next(1, 101) <= spawnSpeed)
{
MakeEnemy();
}
}
private void Shoot()
{
PictureBox bullet = new PictureBox();
bullet.Width = 10;
bullet.Height = 5;
bullet.BackColor = Color.Red;
bullet.Tag = "bullet";
bullet.Left = player.Left + player.Width;
bullet.Top = player.Top + player.Height / 2 - bullet.Height / 2;
this.Controls.Add(bullet);
bullet.BringToFront();
}
private void MakeEnemy()
{
PictureBox enemy = new PictureBox();
enemy.Width = 30;
enemy.Height = 30;
enemy.BackColor = Color.Green;
enemy.Tag = "Enemy";
enemy.Left = player.Left + 1000;
enemy.Top = rand.Next(0, (this.ClientSize.Height - enemy.Height));
this.Controls.Add(enemy);
enemy.BringToFront();
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Up || e.KeyCode == Keys.W)
{
goUp = true;
}
if (e.KeyCode == Keys.Down || e.KeyCode == Keys.S)
{
goDown = true;
}
if (e.KeyCode == Keys.Space)
{
Shoot();
}
}
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Up || e.KeyCode == Keys.W)
{
goUp = false;
}
if (e.KeyCode == Keys.Down || e.KeyCode == Keys.S)
{
goDown = false;
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}

123
Spaceshooter/Form1.resx Normal file
View File

@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="gameTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

17
Spaceshooter/Program.cs Normal file
View File

@@ -0,0 +1,17 @@
namespace Spaceshooter
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
}
}
}

View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>