Első verizó

git-tfs-id: [https://sznp.visualstudio.com/DefaultCollection/]$/Torpedo;C12
This commit is contained in:
Norbi Peti 2016-03-12 19:44:25 +00:00
parent 57798cd3cc
commit d413d77a63
21 changed files with 1414 additions and 0 deletions

31
Torpedo/Torpedo.sln Normal file
View file

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Torpedo", "Torpedo\Torpedo.csproj", "{C773245D-6119-4991-8844-F71D167D0D20}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C773245D-6119-4991-8844-F71D167D0D20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C773245D-6119-4991-8844-F71D167D0D20}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C773245D-6119-4991-8844-F71D167D0D20}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C773245D-6119-4991-8844-F71D167D0D20}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(TeamFoundationVersionControl) = preSolution
SccNumberOfProjects = 2
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
SccTeamFoundationServer = https://sznp.visualstudio.com/defaultcollection
SccLocalPath0 = .
SccProjectUniqueName1 = Torpedo\\Torpedo.csproj
SccProjectName1 = Torpedo
SccLocalPath1 = Torpedo
EndGlobalSection
EndGlobal

10
Torpedo/Torpedo.vssscc Normal file
View file

@ -0,0 +1,10 @@
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = ""
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT"
}

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

View file

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Torpedo
{
public class EnemyGameRenderer : GameRenderer
{
public EnemyGameRenderer(Control parent) : base(parent)
{
}
private static ReadOnlyDictionary<FieldTypeEnemy, Color> FieldTypes = new ReadOnlyDictionary<FieldTypeEnemy, Color>(new Dictionary<FieldTypeEnemy, Color>()
{
{FieldTypeEnemy.Targeted, Color.LightBlue},
{FieldTypeEnemy.TargetHit, Color.Red},
{FieldTypeEnemy.EnemyShipDestroyed, Color.Black}
});
public void UpdateField(int x, int y, FieldTypeEnemy fieldtype)
{
base.UpdateField(x, y, FieldTypes[fieldtype]);
}
public override void RenderShip(Ship ship)
{
//TODO: Képek az egyes hajótípusokhoz
for (int i = 0; i < ship.Size; i++)
{
if (ship.Direction == ShipDirection.Horizontal)
UpdateField(ship.X + i, ship.Y, FieldTypeEnemy.Targeted);
else
UpdateField(ship.X, ship.Y + i, FieldTypeEnemy.Targeted);
}
//TODO: Rárajzolni a képet a mezőkre
}
public override void RenderGameField()
{
Player.Player2.Ships.ForEach(s => RenderShip(s));
}
}
public enum FieldTypeEnemy
{
Targeted,
TargetHit,
EnemyShipDestroyed
}
}

73
Torpedo/Torpedo/Game.cs Normal file
View file

@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Torpedo
{
public static class Game
{
/// <summary>
/// A játék mérete mezőkben
/// </summary>
public static Size GameSize { get; private set; } = new Size(10, 10);
/// <summary>
/// A jelenlegi játékos
/// </summary>
public static Player CurrentPlayer = Player.Player1;
private static GameType type = GameType.Singleplayer;
/// <summary>
/// <para>Megadja a játék típusát (egyjátékos, többjátékos)</para>
/// </summary>
public static GameType Type
{
get
{
return type;
}
set
{
type = value;
if (GameTypeChange != null)
GameTypeChange(null, new GameTypeChangeEventArgs(value));
}
}
/// <summary>
/// A játékmód változásakor vagy új játék kezdésekor hívódik meg
/// </summary>
public static event EventHandler<GameTypeChangeEventArgs> GameTypeChange;
/// <summary>
/// A játék állapota
/// </summary>
public static GameState State { get; set; } = GameState.Prepare;
static Game()
{
GameTypeChange += Game_GameTypeChange;
}
private static void Game_GameTypeChange(object sender, GameTypeChangeEventArgs e)
{
State = GameState.Prepare; //TODO
CurrentPlayer = Player.Player1;
}
}
public enum GameType
{
Singleplayer,
Multiplayer
}
public enum GameState
{
Prepare,
Battle
}
}

194
Torpedo/Torpedo/GameForm.Designer.cs generated Normal file
View file

@ -0,0 +1,194 @@
namespace Torpedo
{
partial class GameForm
{
/// <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()
{
this.ownPanel = new System.Windows.Forms.Panel();
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.egyjátékosToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.többjátékosToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.enemyPanel = new System.Windows.Forms.Panel();
this.shipSizeLabel = new System.Windows.Forms.Label();
this.moveUpButton = new System.Windows.Forms.Button();
this.moveRightButton = new System.Windows.Forms.Button();
this.moveDownButton = new System.Windows.Forms.Button();
this.moveLeftButton = new System.Windows.Forms.Button();
this.rotateButton = new System.Windows.Forms.Button();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
// ownPanel
//
this.ownPanel.BackColor = System.Drawing.Color.DeepSkyBlue;
this.ownPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.ownPanel.Location = new System.Drawing.Point(12, 27);
this.ownPanel.Name = "ownPanel";
this.ownPanel.Size = new System.Drawing.Size(300, 300);
this.ownPanel.TabIndex = 0;
this.ownPanel.Click += new System.EventHandler(this.ownPanel_Click);
this.ownPanel.Paint += new System.Windows.Forms.PaintEventHandler(this.ownPanel_Paint);
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.egyjátékosToolStripMenuItem,
this.többjátékosToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(723, 24);
this.menuStrip1.TabIndex = 1;
this.menuStrip1.Text = "menuStrip1";
//
// egyjátékosToolStripMenuItem
//
this.egyjátékosToolStripMenuItem.Enabled = false;
this.egyjátékosToolStripMenuItem.Name = "egyjátékosToolStripMenuItem";
this.egyjátékosToolStripMenuItem.Size = new System.Drawing.Size(75, 20);
this.egyjátékosToolStripMenuItem.Text = "Egyjátékos";
this.egyjátékosToolStripMenuItem.Click += new System.EventHandler(this.GameTypeMenuClick);
//
// többjátékosToolStripMenuItem
//
this.többjátékosToolStripMenuItem.Name = "többjátékosToolStripMenuItem";
this.többjátékosToolStripMenuItem.Size = new System.Drawing.Size(84, 20);
this.többjátékosToolStripMenuItem.Text = "Többjátékos";
this.többjátékosToolStripMenuItem.Click += new System.EventHandler(this.GameTypeMenuClick);
//
// enemyPanel
//
this.enemyPanel.BackColor = System.Drawing.Color.DeepSkyBlue;
this.enemyPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.enemyPanel.Location = new System.Drawing.Point(405, 27);
this.enemyPanel.Name = "enemyPanel";
this.enemyPanel.Size = new System.Drawing.Size(300, 300);
this.enemyPanel.TabIndex = 1;
this.enemyPanel.Paint += new System.Windows.Forms.PaintEventHandler(this.enemyPanel_Paint);
//
// shipSizeLabel
//
this.shipSizeLabel.AutoSize = true;
this.shipSizeLabel.Location = new System.Drawing.Point(12, 339);
this.shipSizeLabel.Name = "shipSizeLabel";
this.shipSizeLabel.Size = new System.Drawing.Size(81, 13);
this.shipSizeLabel.TabIndex = 2;
this.shipSizeLabel.Text = "Következő hajó";
//
// moveUpButton
//
this.moveUpButton.Location = new System.Drawing.Point(167, 333);
this.moveUpButton.Name = "moveUpButton";
this.moveUpButton.Size = new System.Drawing.Size(75, 75);
this.moveUpButton.TabIndex = 3;
this.moveUpButton.Text = "Fel";
this.moveUpButton.UseVisualStyleBackColor = true;
this.moveUpButton.Click += new System.EventHandler(this.MoveShip);
//
// moveRightButton
//
this.moveRightButton.Location = new System.Drawing.Point(248, 411);
this.moveRightButton.Name = "moveRightButton";
this.moveRightButton.Size = new System.Drawing.Size(75, 75);
this.moveRightButton.TabIndex = 4;
this.moveRightButton.Text = "Jobbra";
this.moveRightButton.UseVisualStyleBackColor = true;
this.moveRightButton.Click += new System.EventHandler(this.MoveShip);
//
// moveDownButton
//
this.moveDownButton.Location = new System.Drawing.Point(167, 411);
this.moveDownButton.Name = "moveDownButton";
this.moveDownButton.Size = new System.Drawing.Size(75, 75);
this.moveDownButton.TabIndex = 5;
this.moveDownButton.Text = "Le";
this.moveDownButton.UseVisualStyleBackColor = true;
this.moveDownButton.Click += new System.EventHandler(this.MoveShip);
//
// moveLeftButton
//
this.moveLeftButton.Location = new System.Drawing.Point(86, 411);
this.moveLeftButton.Name = "moveLeftButton";
this.moveLeftButton.Size = new System.Drawing.Size(75, 75);
this.moveLeftButton.TabIndex = 6;
this.moveLeftButton.Text = "Le";
this.moveLeftButton.UseVisualStyleBackColor = true;
this.moveLeftButton.Click += new System.EventHandler(this.MoveShip);
//
// rotateButton
//
this.rotateButton.Location = new System.Drawing.Point(405, 381);
this.rotateButton.Name = "rotateButton";
this.rotateButton.Size = new System.Drawing.Size(75, 75);
this.rotateButton.TabIndex = 7;
this.rotateButton.Text = "Forgatás";
this.rotateButton.UseVisualStyleBackColor = true;
this.rotateButton.Click += new System.EventHandler(this.rotateButton_Click);
//
// GameForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(723, 539);
this.Controls.Add(this.rotateButton);
this.Controls.Add(this.moveLeftButton);
this.Controls.Add(this.moveDownButton);
this.Controls.Add(this.moveRightButton);
this.Controls.Add(this.moveUpButton);
this.Controls.Add(this.shipSizeLabel);
this.Controls.Add(this.enemyPanel);
this.Controls.Add(this.ownPanel);
this.Controls.Add(this.menuStrip1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MainMenuStrip = this.menuStrip1;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "GameForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Torpedó";
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Panel ownPanel;
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem egyjátékosToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem többjátékosToolStripMenuItem;
private System.Windows.Forms.Panel enemyPanel;
private System.Windows.Forms.Label shipSizeLabel;
private System.Windows.Forms.Button moveUpButton;
private System.Windows.Forms.Button moveRightButton;
private System.Windows.Forms.Button moveDownButton;
private System.Windows.Forms.Button moveLeftButton;
private System.Windows.Forms.Button rotateButton;
}
}

109
Torpedo/Torpedo/GameForm.cs Normal file
View file

@ -0,0 +1,109 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Torpedo
{
public partial class GameForm : Form
{
public static GameForm Instance;
public GameForm()
{
if (Instance != null)
throw new InvalidOperationException("Csak egy példány létezhet a formból.");
InitializeComponent();
GameRenderer.Own = new OwnGameRenderer(ownPanel);
GameRenderer.Enemy = new EnemyGameRenderer(enemyPanel);
Instance = this;
Game.GameTypeChange += Game_GameTypeChange;
Game.Type = GameType.Singleplayer;
}
private void Game_GameTypeChange(object sender, GameTypeChangeEventArgs e)
{
egyjátékosToolStripMenuItem.Enabled = false;
többjátékosToolStripMenuItem.Enabled = false;
if (Player.Player1.NextShip != -1)
shipSizeLabel.Text = "Következő hajó: " + Player.Player1.NextShip;
else
shipSizeLabel.Text = "";
switch(e.NewValue)
{
case GameType.Singleplayer:
többjátékosToolStripMenuItem.Enabled = true; //Csak a másik játékmódot hagyja bekapcsolva, hogy át leheseen váltani
break;
case GameType.Multiplayer:
egyjátékosToolStripMenuItem.Enabled = true;
break;
}
}
private void ownPanel_Paint(object sender, PaintEventArgs e)
{
GameRenderer.Own.RenderGame();
}
private void GameTypeMenuClick(object sender, EventArgs e)
{
if (sender == egyjátékosToolStripMenuItem)
Game.Type = GameType.Singleplayer;
else if (sender == többjátékosToolStripMenuItem)
Game.Type = GameType.Multiplayer;
}
private void enemyPanel_Paint(object sender, PaintEventArgs e)
{
GameRenderer.Enemy.RenderGame();
}
private Ship lastship;
private void ownPanel_Click(object sender, EventArgs e)
{
if (Game.State != GameState.Prepare)
return;
if (Player.Player1.NextShip == -1)
return;
Point clickedfield = GameRenderer.Own.PixelsToFields(ownPanel.PointToClient(Cursor.Position));
Ship ship = new Ship(clickedfield.X, clickedfield.Y, Game.CurrentPlayer.NextShip, ShipDirection.Horizontal, false);
if (Ship.CheckHasShip(ship))
return;
Game.CurrentPlayer.Ships.Add(ship);
GameRenderer.Own.RenderShip(ship);
lastship = ship;
//TODO
if (Player.Player1.NextShip != -1)
shipSizeLabel.Text = "Következő hajó: " + Player.Player1.NextShip;
else
shipSizeLabel.Text = "";
}
private void MoveShip(object sender, EventArgs e)
{
if (lastship != null)
{
if (sender == moveUpButton)
lastship.Move(0, -1);
else if (sender == moveDownButton)
lastship.Move(0, 1);
else if (sender == moveLeftButton)
lastship.Move(-1, 0);
else if (sender == moveRightButton)
lastship.Move(1, 0);
}
}
private void rotateButton_Click(object sender, EventArgs e)
{
if (lastship != null)
{
lastship.Rotate();
}
}
}
}

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="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View file

@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Torpedo
{
public abstract class GameRenderer
{
public static OwnGameRenderer Own;
public static EnemyGameRenderer Enemy;
public GameRenderer(Control parent)
{
Parent = parent;
Game.GameTypeChange += Game_GameTypeChange;
}
private void Game_GameTypeChange(object sender, GameTypeChangeEventArgs e)
{
RenderGame();
}
private Control Parent;
public void RenderGame()
{
RenderLines();
RenderGameField();
}
private void RenderLines()
{
using (Graphics gr = Parent.CreateGraphics())
{
gr.Clear(Parent.BackColor);
int width = Parent.Width / Game.GameSize.Width;
int height = Parent.Height / Game.GameSize.Height;
for (int i = 1; i < Game.GameSize.Width; i++)
{
gr.DrawLine(Pens.Black, i * width, 0, i * width, Parent.Height);
}
for (int i = 1; i < Game.GameSize.Height; i++)
{
gr.DrawLine(Pens.Black, 0, i * height, Parent.Width, i * height);
}
}
}
public abstract void RenderGameField();
public Point PixelsToFields(Point p)
{
int width = Parent.Width / Game.GameSize.Width;
int height = Parent.Height / Game.GameSize.Height;
return new Point(p.X / width, p.Y / height);
}
public void DerenderShip(Ship ship)
{
for (int i = 0; i < ship.Size; i++)
{
if (ship.Direction == ShipDirection.Horizontal)
UpdateField(ship.X + i, ship.Y, Parent.BackColor);
else
UpdateField(ship.X, ship.Y + i, Parent.BackColor);
}
using (Graphics gr = Parent.CreateGraphics())
{
int width = Parent.Width / Game.GameSize.Width;
int height = Parent.Height / Game.GameSize.Height;
if (ship.Direction == ShipDirection.Horizontal)
{
for (int i = ship.X; i < ship.X + ship.Size; i++)
{
gr.DrawLine(Pens.Black, i * width, ship.Y * height, i * width, (ship.Y + 1) * height);
}
gr.DrawLine(Pens.Black, ship.X * width, ship.Y * height, (ship.X + ship.Size) * width, ship.Y * height);
gr.DrawLine(Pens.Black, ship.X * width, (ship.Y + 1) * height, (ship.X + ship.Size) * width, (ship.Y + 1) * height);
}
else
{
for (int i = ship.Y; i < ship.Y + ship.Size; i++)
{
gr.DrawLine(Pens.Black, ship.X * width, i * height, (ship.X + 1) * width, i * height);
}
gr.DrawLine(Pens.Black, ship.X * width, ship.Y * height, ship.X * width, (ship.Y + ship.Size) * height);
gr.DrawLine(Pens.Black, (ship.X + 1) * width, ship.Y, (ship.X + 1) * width, (ship.Y + ship.Size) * height);
}
}
}
protected void UpdateField(int x, int y, Color color)
{
using (Graphics gr = Parent.CreateGraphics())
{
int width = Parent.Width / Game.GameSize.Width;
int height = Parent.Height / Game.GameSize.Height;
gr.FillRectangle(new SolidBrush(color), x * width, y * height, width, height);
}
}
public abstract void RenderShip(Ship ship);
}
}

View file

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Torpedo
{
public class GameTypeChangeEventArgs : EventArgs
{
public GameType NewValue;
public GameTypeChangeEventArgs(GameType newvalue)
{
NewValue = newvalue;
}
}
}

View file

@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Torpedo
{
public class OwnGameRenderer : GameRenderer
{
public OwnGameRenderer(Control parent) : base(parent)
{
}
private static ReadOnlyDictionary<FieldTypeOwn, Color> FieldTypes = new ReadOnlyDictionary<FieldTypeOwn, Color>(new Dictionary<FieldTypeOwn, Color>()
{
{FieldTypeOwn.OwnShip, Color.LightGray},
{FieldTypeOwn.OwnShipDamaged, Color.DarkRed}
});
public void UpdateField(int x, int y, FieldTypeOwn fieldtype)
{
base.UpdateField(x, y, FieldTypes[fieldtype]);
}
public override void RenderShip(Ship ship)
{
//TODO: Képek az egyes hajótípusokhoz
for (int i = 0; i < ship.Size; i++)
{
if (ship.Direction == ShipDirection.Horizontal)
UpdateField(ship.X + i, ship.Y, FieldTypeOwn.OwnShip);
else
UpdateField(ship.X, ship.Y + i, FieldTypeOwn.OwnShip);
}
//TODO: Rárajzolni a képet a mezőkre
}
public override void RenderGameField()
{
Player.Player1.Ships.ForEach(s => RenderShip(s)); //TODO
}
}
public enum FieldTypeOwn
{
OwnShip,
OwnShipDamaged
}
}

77
Torpedo/Torpedo/Player.cs Normal file
View file

@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Torpedo
{
public class Player
{
/// <summary>
/// <para>Az első játékos</para>
/// </summary>
public static Player Player1 { get; set; }
private static Player p2;
/// <summary>
/// <para>A második játékos</para>
/// </summary>
public static Player Player2
{
get
{
return p2;
}
private set
{
p2 = value;
}
}
static Player()
{
Game.GameTypeChange += Game_GameTypeChange_Global;
}
private static void Game_GameTypeChange_Global(object sender, GameTypeChangeEventArgs e)
{
Player1 = new Player();
Player2 = new Player();
}
/// <summary>
/// <para>Létrhehoz egy új játékost</para>
/// <para>Csak a Player osztályban használható</para>
/// </summary>
private Player()
{
}
/// <summary>
/// A játékos hajóinak listája
/// </summary>
public List<Ship> Ships = new List<Ship>();
/// <summary>
/// <para>Megadja a következő hajó nagyságát</para>
/// </summary>
public int NextShip
{
get
{
if (!Ships.Any(s => s.Size == 5))
return 5;
if (!Ships.Any(s => s.Size == 4))
return 4;
if (Ships.Count(s => s.Size == 3) < 2)
return 3;
if (!Ships.Any(s => s.Size == 2))
return 2;
else
return -1;
}
}
}
}

View file

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Torpedo
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new GameForm());
}
}
}

View file

@ -0,0 +1,36 @@
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("Torpedo")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Torpedo")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[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("c773245d-6119-4991-8844-f71d167d0d20")]
// 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")]

View file

@ -0,0 +1,71 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Torpedo.Properties
{
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Torpedo.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}

View file

@ -0,0 +1,117 @@
<?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.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: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" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</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" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</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=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View file

@ -0,0 +1,30 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Torpedo.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
return defaultInstance;
}
}
}
}

View file

@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>

162
Torpedo/Torpedo/Ship.cs Normal file
View file

@ -0,0 +1,162 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Torpedo
{
public class Ship
{
public int X { get; private set; }
public int Y { get; private set; }
private int size;
public int Size
{
get
{
return size;
}
private set
{
size = value;
DamagedParts = new bool[value];
}
}
public ShipDirection Direction { get; set; }
public bool[] DamagedParts;
public bool Enemy;
public Ship(int x, int y, int size, ShipDirection direction, bool enemy)
{
X = x;
Y = y;
Size = size; //A DamagedParts-ot is inicializálja
Direction = direction;
Enemy = enemy;
}
/// <summary>
/// Mozgatja a hajót
/// </summary>
/// <param name="dx">X elmozdulás</param>
/// <param name="dy">Y elmozdulás</param>
public void Move(int dx, int dy)
{
if (CheckHasShip(this, dx, dy))
return;
if (Enemy)
GameRenderer.Enemy.DerenderShip(this);
else
GameRenderer.Own.DerenderShip(this);
X += dx;
Y += dy;
if (Enemy)
GameRenderer.Enemy.RenderShip(this);
else
GameRenderer.Own.RenderShip(this);
}
public void Rotate()
{
if (CheckHasShip(this, rotated: true))
return;
if (Enemy)
GameRenderer.Enemy.DerenderShip(this);
else
GameRenderer.Own.DerenderShip(this);
if (Direction == ShipDirection.Horizontal)
Direction = ShipDirection.Vertical;
else
Direction = ShipDirection.Horizontal;
if (Enemy)
GameRenderer.Enemy.RenderShip(this);
else
GameRenderer.Own.RenderShip(this);
}
public static bool CheckHasShip(Ship ship, int dx = 0, int dy = 0, bool rotated = false)
{
bool hasship = false;
bool dircheck = ship.Direction == ShipDirection.Horizontal;
if (rotated)
dircheck = !dircheck;
if (ship.X + dx < 0 || ship.Y + dy < 0)
return true;
if (dircheck)
{
if (ship.X + dx + ship.Size - 1 >= Game.GameSize.Width || ship.Y + dy >= Game.GameSize.Height)
return true;
}
else
{
if (ship.X + dx >= Game.GameSize.Width || ship.Y + dy + ship.Size - 1 >= Game.GameSize.Height)
return true;
}
for (int i = 0; i < ship.Size; i++)
{
if (dircheck)
{
Ship ship2 = GetShipAtField(ship.Enemy, ship.X + dx + i, ship.Y + dy);
if (ship2 != null && ship2 != ship)
{
hasship = true;
break;
}
}
else
{
Ship ship2 = GetShipAtField(ship.Enemy, ship.X + dx, ship.Y + dy + i);
if (ship2 != null && ship2 != ship)
{
hasship = true;
break;
}
}
}
return hasship;
}
public static Ship GetShipAtField(bool enemy, int x, int y)
{
Player player = null;
if (enemy)
player = Player.Player2;
else
player = Player.Player1;
return player.Ships.SingleOrDefault(s =>
{
if (s.Direction != ShipDirection.Horizontal)
{
if (s.X != x)
return false;
else
{
if (y >= s.Y && y < s.Y + s.Size)
return true;
else
return false;
}
}
else
{
if (s.Y != y)
return false;
else
{
if (x >= s.X && x < s.X + s.Size)
return true;
else
return false;
}
}
});
}
}
public enum ShipDirection
{
Horizontal,
Vertical
}
}

View file

@ -0,0 +1,101 @@
<?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>{C773245D-6119-4991-8844-F71D167D0D20}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Torpedo</RootNamespace>
<AssemblyName>Torpedo</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</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.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="EnemyGameRenderer.cs" />
<Compile Include="GameForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="GameForm.Designer.cs">
<DependentUpon>GameForm.cs</DependentUpon>
</Compile>
<Compile Include="Game.cs" />
<Compile Include="GameRenderer.cs" />
<Compile Include="GameTypeChangeEventArgs.cs" />
<Compile Include="OwnGameRenderer.cs" />
<Compile Include="Player.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Ship.cs" />
<EmbeddedResource Include="GameForm.resx">
<DependentUpon>GameForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</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>

View file

@ -0,0 +1,10 @@
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = ""
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
}