diff --git a/Torpedo/Torpedo.sln b/Torpedo/Torpedo.sln
new file mode 100644
index 0000000..e8db519
--- /dev/null
+++ b/Torpedo/Torpedo.sln
@@ -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
diff --git a/Torpedo/Torpedo.vssscc b/Torpedo/Torpedo.vssscc
new file mode 100644
index 0000000..794f014
--- /dev/null
+++ b/Torpedo/Torpedo.vssscc
@@ -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"
+}
diff --git a/Torpedo/Torpedo/App.config b/Torpedo/Torpedo/App.config
new file mode 100644
index 0000000..d740e88
--- /dev/null
+++ b/Torpedo/Torpedo/App.config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Torpedo/Torpedo/EnemyGameRenderer.cs b/Torpedo/Torpedo/EnemyGameRenderer.cs
new file mode 100644
index 0000000..7c5201f
--- /dev/null
+++ b/Torpedo/Torpedo/EnemyGameRenderer.cs
@@ -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 FieldTypes = new ReadOnlyDictionary(new Dictionary()
+ {
+ {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
+ }
+}
diff --git a/Torpedo/Torpedo/Game.cs b/Torpedo/Torpedo/Game.cs
new file mode 100644
index 0000000..994a5ec
--- /dev/null
+++ b/Torpedo/Torpedo/Game.cs
@@ -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
+ {
+ ///
+ /// A játék mérete mezőkben
+ ///
+ public static Size GameSize { get; private set; } = new Size(10, 10);
+
+ ///
+ /// A jelenlegi játékos
+ ///
+ public static Player CurrentPlayer = Player.Player1;
+
+ private static GameType type = GameType.Singleplayer;
+ ///
+ /// Megadja a játék típusát (egyjátékos, többjátékos)
+ ///
+ public static GameType Type
+ {
+ get
+ {
+ return type;
+ }
+ set
+ {
+ type = value;
+ if (GameTypeChange != null)
+ GameTypeChange(null, new GameTypeChangeEventArgs(value));
+ }
+ }
+
+ ///
+ /// A játékmód változásakor vagy új játék kezdésekor hívódik meg
+ ///
+ public static event EventHandler GameTypeChange;
+
+ ///
+ /// A játék állapota
+ ///
+ 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
+ }
+}
diff --git a/Torpedo/Torpedo/GameForm.Designer.cs b/Torpedo/Torpedo/GameForm.Designer.cs
new file mode 100644
index 0000000..51315e1
--- /dev/null
+++ b/Torpedo/Torpedo/GameForm.Designer.cs
@@ -0,0 +1,194 @@
+namespace Torpedo
+{
+ partial class GameForm
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ 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;
+ }
+}
+
diff --git a/Torpedo/Torpedo/GameForm.cs b/Torpedo/Torpedo/GameForm.cs
new file mode 100644
index 0000000..cfdc775
--- /dev/null
+++ b/Torpedo/Torpedo/GameForm.cs
@@ -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();
+ }
+ }
+ }
+}
diff --git a/Torpedo/Torpedo/GameForm.resx b/Torpedo/Torpedo/GameForm.resx
new file mode 100644
index 0000000..0f6d8eb
--- /dev/null
+++ b/Torpedo/Torpedo/GameForm.resx
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ 17, 17
+
+
\ No newline at end of file
diff --git a/Torpedo/Torpedo/GameRenderer.cs b/Torpedo/Torpedo/GameRenderer.cs
new file mode 100644
index 0000000..0a6a497
--- /dev/null
+++ b/Torpedo/Torpedo/GameRenderer.cs
@@ -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);
+ }
+}
diff --git a/Torpedo/Torpedo/GameTypeChangeEventArgs.cs b/Torpedo/Torpedo/GameTypeChangeEventArgs.cs
new file mode 100644
index 0000000..0e8dff2
--- /dev/null
+++ b/Torpedo/Torpedo/GameTypeChangeEventArgs.cs
@@ -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;
+ }
+ }
+}
diff --git a/Torpedo/Torpedo/OwnGameRenderer.cs b/Torpedo/Torpedo/OwnGameRenderer.cs
new file mode 100644
index 0000000..69ca9af
--- /dev/null
+++ b/Torpedo/Torpedo/OwnGameRenderer.cs
@@ -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 FieldTypes = new ReadOnlyDictionary(new Dictionary()
+ {
+ {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
+ }
+}
diff --git a/Torpedo/Torpedo/Player.cs b/Torpedo/Torpedo/Player.cs
new file mode 100644
index 0000000..65146c3
--- /dev/null
+++ b/Torpedo/Torpedo/Player.cs
@@ -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
+ {
+ ///
+ /// Az első játékos
+ ///
+ public static Player Player1 { get; set; }
+
+ private static Player p2;
+ ///
+ /// A második játékos
+ ///
+ 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();
+ }
+
+ ///
+ /// Létrhehoz egy új játékost
+ /// Csak a Player osztályban használható
+ ///
+ private Player()
+ {
+
+ }
+
+ ///
+ /// A játékos hajóinak listája
+ ///
+ public List Ships = new List();
+
+ ///
+ /// Megadja a következő hajó nagyságát
+ ///
+ 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;
+ }
+ }
+ }
+}
diff --git a/Torpedo/Torpedo/Program.cs b/Torpedo/Torpedo/Program.cs
new file mode 100644
index 0000000..0506c96
--- /dev/null
+++ b/Torpedo/Torpedo/Program.cs
@@ -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
+ {
+ ///
+ /// The main entry point for the application.
+ ///
+ [STAThread]
+ static void Main()
+ {
+ Application.EnableVisualStyles();
+ Application.SetCompatibleTextRenderingDefault(false);
+ Application.Run(new GameForm());
+ }
+ }
+}
diff --git a/Torpedo/Torpedo/Properties/AssemblyInfo.cs b/Torpedo/Torpedo/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..002ee46
--- /dev/null
+++ b/Torpedo/Torpedo/Properties/AssemblyInfo.cs
@@ -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")]
diff --git a/Torpedo/Torpedo/Properties/Resources.Designer.cs b/Torpedo/Torpedo/Properties/Resources.Designer.cs
new file mode 100644
index 0000000..f7d37a3
--- /dev/null
+++ b/Torpedo/Torpedo/Properties/Resources.Designer.cs
@@ -0,0 +1,71 @@
+//------------------------------------------------------------------------------
+//
+// 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.
+//
+//------------------------------------------------------------------------------
+
+namespace Torpedo.Properties
+{
+
+
+ ///
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ ///
+ // 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()
+ {
+ }
+
+ ///
+ /// Returns the cached ResourceManager instance used by this class.
+ ///
+ [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;
+ }
+ }
+
+ ///
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture
+ {
+ get
+ {
+ return resourceCulture;
+ }
+ set
+ {
+ resourceCulture = value;
+ }
+ }
+ }
+}
diff --git a/Torpedo/Torpedo/Properties/Resources.resx b/Torpedo/Torpedo/Properties/Resources.resx
new file mode 100644
index 0000000..ffecec8
--- /dev/null
+++ b/Torpedo/Torpedo/Properties/Resources.resx
@@ -0,0 +1,117 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/Torpedo/Torpedo/Properties/Settings.Designer.cs b/Torpedo/Torpedo/Properties/Settings.Designer.cs
new file mode 100644
index 0000000..133321f
--- /dev/null
+++ b/Torpedo/Torpedo/Properties/Settings.Designer.cs
@@ -0,0 +1,30 @@
+//------------------------------------------------------------------------------
+//
+// 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.
+//
+//------------------------------------------------------------------------------
+
+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;
+ }
+ }
+ }
+}
diff --git a/Torpedo/Torpedo/Properties/Settings.settings b/Torpedo/Torpedo/Properties/Settings.settings
new file mode 100644
index 0000000..abf36c5
--- /dev/null
+++ b/Torpedo/Torpedo/Properties/Settings.settings
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/Torpedo/Torpedo/Ship.cs b/Torpedo/Torpedo/Ship.cs
new file mode 100644
index 0000000..5d92eb5
--- /dev/null
+++ b/Torpedo/Torpedo/Ship.cs
@@ -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;
+ }
+
+ ///
+ /// Mozgatja a hajót
+ ///
+ /// X elmozdulás
+ /// Y elmozdulás
+ 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
+ }
+}
diff --git a/Torpedo/Torpedo/Torpedo.csproj b/Torpedo/Torpedo/Torpedo.csproj
new file mode 100644
index 0000000..a3e5c12
--- /dev/null
+++ b/Torpedo/Torpedo/Torpedo.csproj
@@ -0,0 +1,101 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {C773245D-6119-4991-8844-F71D167D0D20}
+ WinExe
+ Properties
+ Torpedo
+ Torpedo
+ v4.5.2
+ 512
+ true
+ SAK
+ SAK
+ SAK
+ SAK
+
+
+ AnyCPU
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ AnyCPU
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Form
+
+
+ GameForm.cs
+
+
+
+
+
+
+
+
+
+
+ GameForm.cs
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+ Designer
+
+
+ True
+ Resources.resx
+
+
+ SettingsSingleFileGenerator
+ Settings.Designer.cs
+
+
+ True
+ Settings.settings
+ True
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Torpedo/Torpedo/Torpedo.csproj.vspscc b/Torpedo/Torpedo/Torpedo.csproj.vspscc
new file mode 100644
index 0000000..feffdec
--- /dev/null
+++ b/Torpedo/Torpedo/Torpedo.csproj.vspscc
@@ -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"
+}