From 40f0dd7b4adf1aa14a25484fb52a9af356c42f31 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 7 Jan 2017 23:15:15 +0100 Subject: [PATCH] 2015.02.14 --- SnakeGame/Form1.Designer.cs | 56 ++++++++++-- SnakeGame/Form1.cs | 38 ++++++++ SnakeGame/Game.cs | 167 +++++++++++++++++++++++++++++------- SnakeGame/GameRenderer.cs | 17 ++-- SnakeGame/MSGBox.cs | 100 +++++++++++++++++++++ SnakeGame/Network.cs | 18 ++++ SnakeGame/SnakeGame.csproj | 2 + SnakeGame/SquareCoord.cs | 19 +++- Web/index.php | 11 +++ 9 files changed, 382 insertions(+), 46 deletions(-) create mode 100644 SnakeGame/MSGBox.cs create mode 100644 SnakeGame/Network.cs create mode 100644 Web/index.php diff --git a/SnakeGame/Form1.Designer.cs b/SnakeGame/Form1.Designer.cs index a4658a3..75d93ce 100644 --- a/SnakeGame/Form1.Designer.cs +++ b/SnakeGame/Form1.Designer.cs @@ -34,6 +34,9 @@ this.newSingleplayerGameToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.newMultiplayerGameToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.joinMultiplayerGameToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.scoreLabel = new System.Windows.Forms.Label(); + this.livesLabel = new System.Windows.Forms.Label(); + this.DialogPanel = new System.Windows.Forms.Panel(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); // @@ -44,9 +47,9 @@ | System.Windows.Forms.AnchorStyles.Right))); this.panel1.BackColor = System.Drawing.Color.Black; this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.panel1.Location = new System.Drawing.Point(12, 41); + this.panel1.Location = new System.Drawing.Point(12, 64); this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(600, 380); + this.panel1.Size = new System.Drawing.Size(600, 357); this.panel1.TabIndex = 0; this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint); // @@ -75,7 +78,8 @@ this.newSingleplayerGameToolStripMenuItem.BackColor = System.Drawing.Color.Black; this.newSingleplayerGameToolStripMenuItem.ForeColor = System.Drawing.Color.White; this.newSingleplayerGameToolStripMenuItem.Name = "newSingleplayerGameToolStripMenuItem"; - this.newSingleplayerGameToolStripMenuItem.Size = new System.Drawing.Size(197, 22); + this.newSingleplayerGameToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.N))); + this.newSingleplayerGameToolStripMenuItem.Size = new System.Drawing.Size(240, 22); this.newSingleplayerGameToolStripMenuItem.Text = "New singleplayer game"; this.newSingleplayerGameToolStripMenuItem.Click += new System.EventHandler(this.newSingleplayerGameToolStripMenuItem_Click); // @@ -84,29 +88,68 @@ this.newMultiplayerGameToolStripMenuItem.BackColor = System.Drawing.Color.Black; this.newMultiplayerGameToolStripMenuItem.ForeColor = System.Drawing.Color.White; this.newMultiplayerGameToolStripMenuItem.Name = "newMultiplayerGameToolStripMenuItem"; - this.newMultiplayerGameToolStripMenuItem.Size = new System.Drawing.Size(197, 22); + this.newMultiplayerGameToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Shift) + | System.Windows.Forms.Keys.N))); + this.newMultiplayerGameToolStripMenuItem.Size = new System.Drawing.Size(269, 22); this.newMultiplayerGameToolStripMenuItem.Text = "New multiplayer game"; // // joinMultiplayerGameToolStripMenuItem // this.joinMultiplayerGameToolStripMenuItem.BackColor = System.Drawing.Color.Black; + this.joinMultiplayerGameToolStripMenuItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; this.joinMultiplayerGameToolStripMenuItem.ForeColor = System.Drawing.Color.White; this.joinMultiplayerGameToolStripMenuItem.Name = "joinMultiplayerGameToolStripMenuItem"; - this.joinMultiplayerGameToolStripMenuItem.Size = new System.Drawing.Size(197, 22); + this.joinMultiplayerGameToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Alt) + | System.Windows.Forms.Keys.N))); + this.joinMultiplayerGameToolStripMenuItem.Size = new System.Drawing.Size(269, 22); this.joinMultiplayerGameToolStripMenuItem.Text = "Join multiplayer game"; // + // scoreLabel + // + this.scoreLabel.AutoSize = true; + this.scoreLabel.Location = new System.Drawing.Point(14, 31); + this.scoreLabel.Name = "scoreLabel"; + this.scoreLabel.Size = new System.Drawing.Size(35, 13); + this.scoreLabel.TabIndex = 2; + this.scoreLabel.Text = "Score"; + // + // livesLabel + // + this.livesLabel.AutoSize = true; + this.livesLabel.Location = new System.Drawing.Point(14, 48); + this.livesLabel.Name = "livesLabel"; + this.livesLabel.Size = new System.Drawing.Size(32, 13); + this.livesLabel.TabIndex = 3; + this.livesLabel.Text = "Lives"; + // + // DialogPanel + // + this.DialogPanel.Anchor = System.Windows.Forms.AnchorStyles.None; + this.DialogPanel.AutoSize = true; + this.DialogPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.DialogPanel.Location = new System.Drawing.Point(200, 228); + this.DialogPanel.Name = "DialogPanel"; + this.DialogPanel.Size = new System.Drawing.Size(200, 100); + this.DialogPanel.TabIndex = 0; + this.DialogPanel.Visible = false; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.Black; this.ClientSize = new System.Drawing.Size(624, 442); + this.Controls.Add(this.DialogPanel); + this.Controls.Add(this.livesLabel); + this.Controls.Add(this.scoreLabel); this.Controls.Add(this.menuStrip1); this.Controls.Add(this.panel1); this.ForeColor = System.Drawing.Color.White; this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Snake Game"; + this.Activated += new System.EventHandler(this.Form1_Activated); + this.Deactivate += new System.EventHandler(this.Form1_Deactivate); this.Load += new System.EventHandler(this.Form1_Load); this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown); this.menuStrip1.ResumeLayout(false); @@ -124,6 +167,9 @@ private System.Windows.Forms.ToolStripMenuItem newSingleplayerGameToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem newMultiplayerGameToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem joinMultiplayerGameToolStripMenuItem; + private System.Windows.Forms.Label scoreLabel; + private System.Windows.Forms.Label livesLabel; + private System.Windows.Forms.Panel DialogPanel; } } diff --git a/SnakeGame/Form1.cs b/SnakeGame/Form1.cs index c31829f..0029fb3 100644 --- a/SnakeGame/Form1.cs +++ b/SnakeGame/Form1.cs @@ -13,7 +13,9 @@ namespace SnakeGame public partial class Form1 : Form { private static Timer Timer; + private static Timer SpeedTimer; private static bool timerenabled = false; + public static Form1 Instance; public static bool TimerEnabled { get @@ -23,7 +25,10 @@ namespace SnakeGame set { if (value && !timerenabled) //Only start if not running already + { Timer.Start(); + SpeedTimer.Start(); + } timerenabled = value; } } @@ -39,6 +44,10 @@ namespace SnakeGame menuStrip1.Renderer = new ToolStripProfessionalRenderer(new MenuColorTable()); menuStrip1.ForeColor = Color.White; GameRenderer.Panel = panel1; + Game.ScoreLabel = scoreLabel; + Game.LivesLabel = livesLabel; + Game.DialogPanel = DialogPanel; + Instance = this; Timer = new Timer(); Timer.Interval = Game.UpdateTime; Timer.Tick += delegate @@ -50,6 +59,16 @@ namespace SnakeGame Timer.Start(); }; //Timer.Start(); + SpeedTimer = new Timer(); + SpeedTimer.Interval = 10000; + SpeedTimer.Tick += delegate + { + if (Game.UpdateTime - 100 > 0) + Game.UpdateTime -= 100; + Game.Length++; + if (!TimerEnabled) + SpeedTimer.Stop(); + }; } private void Form1_Load(object sender, EventArgs e) @@ -72,11 +91,30 @@ namespace SnakeGame Game.MoveDirection = Direction.Left; else if (e.KeyCode == Keys.Right) Game.MoveDirection = Direction.Right; + else if (e.KeyCode == Keys.Enter) + { + MSGBox.CloseMSGBox(); + } + Game.Refresh(); } private void newSingleplayerGameToolStripMenuItem_Click(object sender, EventArgs e) { Game.Start(GameStartMode.SinglePlayer); } + + private bool formdeactivated = false; + private void Form1_Activated(object sender, EventArgs e) + { + if (formdeactivated) + Game.Paused = false; + formdeactivated = false; + } + + private void Form1_Deactivate(object sender, EventArgs e) + { + formdeactivated = !Game.Paused; + Game.Paused = true; + } } } diff --git a/SnakeGame/Game.cs b/SnakeGame/Game.cs index 3832629..86be85d 100644 --- a/SnakeGame/Game.cs +++ b/SnakeGame/Game.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; @@ -15,21 +16,77 @@ namespace SnakeGame /// Replace MessageBox with own GUI; Add GUI to get GameSize... /// Maybe select region to set one square's size and/or visualize changes when user stops interaction /// - public static SqCoord GameSize; + public static Point GameSize; //public static List GameField; - public static int[,] GameField; - public static SqCoord PlayerPos; + public static SqCoord[,] GameField; + public static Point PlayerPos; public static int Length = 4; - public static int UpdateTime = 1000; + public static int UpdateTime = 800; public static Direction MoveDirection; + public static Label ScoreLabel; + public static Label LivesLabel; + public static Panel DialogPanel; + private static int score; + public static int Score + { + get + { + return score; + } + set + { + score = value; + ScoreLabel.Text = "Score: " + score; + } + } + private static int lives; + public static int Lives + { + get + { + return lives; + } + set + { + lives = value; + LivesLabel.Text = "Lives: " + lives; + } + } + /// + /// Opposite of Form1.TimerEnabled + /// + public static bool Paused + { + get + { + return !Form1.TimerEnabled; + } + set + { + Form1.TimerEnabled = !value; + } + } public static void Start(GameStartMode mode) { switch(mode) { case GameStartMode.SinglePlayer: - Game.Reset(); - Form1.TimerEnabled = true; + MSGBox.ShowMSGBox("New singleplayer game", "Size (X Y):", MSGBoxType.SizeInput, new EventHandler(delegate(object s, int input) + { + //string[] strs=input.Split(' '); + //int x, y; + //if (strs.Length == 2 && int.TryParse(strs[0], out x) && int.TryParse(strs[1], out y)) + if (input > 5) + { + //GameSize = new Point(x, y); + GameRenderer.Panel.CreateGraphics().FillRectangle(new SolidBrush(Color.Black), new Rectangle(new Point(), GameRenderer.Panel.Size)); + int xy=GameRenderer.Panel.Size.Width/input; + GameSize = new Point(xy, xy); + Game.Reset(); + Form1.TimerEnabled = true; + } + })); break; default: throw new ArgumentException(); @@ -43,6 +100,7 @@ namespace SnakeGame //GameSize = new SqCoord { X = size.Width / 20, Y = size.Height / 20 }; //GameField = new List(GameSize.X * GameSize.Y); //GameField = new int[GameSize.X, GameSize.Y]; + GameSize = new Point { X = size.Width / 20, Y = size.Height / 20 }; Game.Reset(); //GameField.Single(entry => entry.X == PlayerPos.X && entry.Y == PlayerPos.Y).Tick; /*for (int i = 0; i < GameField.Count; i++) @@ -55,12 +113,19 @@ namespace SnakeGame //GameRenderer.Render(); - It has no effect in loading part } - public static void Reset() + public static void Reset(bool fullreset) { Size size = GameRenderer.Panel.Size; - GameSize = new SqCoord { X = size.Width / 20, Y = size.Height / 20 }; - GameField = new int[GameSize.X, GameSize.Y]; - PlayerPos = new SqCoord { X = GameSize.X / 2, Y = 1 }; + //GameSize = new Point { X = size.Width / 20, Y = size.Height / 20 }; + GameField = new SqCoord[GameSize.X, GameSize.Y]; + PlayerPos = new Point { X = GameSize.X / 2, Y = 1 }; + if (fullreset) + { + Score = 0; + Lives = 3; + UpdateTime = 800; + Length = 4; + } for (int i = 0; i < GameSize.X; i++) { for (int j = 0; j < GameSize.Y; j++) @@ -72,71 +137,110 @@ namespace SnakeGame coord.Tick = 4; GameField.Add(coord);*/ if (i == 0 || j == 0 || i == GameSize.X - 1 || j == GameSize.Y - 1) - GameField[i, j] = -1; + { + GameField[i, j].Type = SquareType.Wall; + GameField[i, j].Tick = -1; + } else if (i == PlayerPos.X && j == PlayerPos.Y) - GameField[i, j] = 4; - else - GameField[i, j] = 0; + { + GameField[i, j].Type = SquareType.Player; + GameField[i, j].Tick = Length; + } } } + Game.AddPoint(); MoveDirection = Direction.Down; } + public static void Reset() + { + Reset(true); + } + public static void Refresh() { //Decrease any positive Ticks; if next player position is other than zero, game over //Otherwise set next player position and set Tick on player position to current Length //Console.WriteLine("Refreshing..."); //for (int i = 0; i < GameField.Count; i++) + if (!Form1.TimerEnabled) + return; //Not playing currently for (int i = 0; i < GameField.GetLength(0); i++) { for (int j = 0; j < GameField.GetLength(1); j++) { /*if (GameField[i].Tick > 0) GameField[i] = new SqCoord { X = GameField[i].X, Y = GameField[i].Y, Tick = GameField[i].Tick - 1 };*/ - if (GameField[i, j] > 0) - GameField[i, j]--; + if (GameField[i, j].Tick > 0) + GameField[i, j].Tick--; } } - SqCoord nextcoord; + Point nextcoord; switch (MoveDirection) { case Direction.Down: - nextcoord = new SqCoord { X = PlayerPos.X, Y = PlayerPos.Y + 1 }; + nextcoord = new Point { X = PlayerPos.X, Y = PlayerPos.Y + 1 }; break; case Direction.Left: - nextcoord = new SqCoord { X = PlayerPos.X - 1, Y = PlayerPos.Y }; + nextcoord = new Point { X = PlayerPos.X - 1, Y = PlayerPos.Y }; break; case Direction.Right: - nextcoord = new SqCoord { X = PlayerPos.X + 1, Y = PlayerPos.Y }; + nextcoord = new Point { X = PlayerPos.X + 1, Y = PlayerPos.Y }; break; case Direction.Up: - nextcoord = new SqCoord { X = PlayerPos.X, Y = PlayerPos.Y - 1 }; + nextcoord = new Point { X = PlayerPos.X, Y = PlayerPos.Y - 1 }; break; default: nextcoord = PlayerPos; break; } //if (Game.GetCoord(nextcoord).Tick != 0) - if (Game.GameField[nextcoord.X, nextcoord.Y] != 0) - Stop(); + if (Game.GameField[nextcoord.X, nextcoord.Y].Tick != 0 && Game.GameField[nextcoord.X, nextcoord.Y].Type != SquareType.Point) + { + Lives--; + if (Lives == 0) + Stop(); + else + Reset(false); + } else { - for (int i = 0; i < GameField.GetLength(0); i++) + /*for (int i = 0; i < GameField.GetLength(0); i++) { for (int j = 0; j < GameField.GetLength(1); j++) { if (i == nextcoord.X && j == nextcoord.Y) - { - GameField[nextcoord.X, nextcoord.Y] = Length; - PlayerPos = new SqCoord { X = i, Y = j }; - } - } + {*/ + if (GameField[nextcoord.X, nextcoord.Y].Type == SquareType.Point) + { + Score += 1000; + Game.AddPoint(); } + GameField[nextcoord.X, nextcoord.Y].Tick = Length; + GameField[nextcoord.X, nextcoord.Y].Type = SquareType.Player; + PlayerPos = new Point { X = nextcoord.X, Y = nextcoord.Y }; + if (Score > 0) + Score--; +/* } + } + }*/ GameRenderer.Render(); } } + public static void AddPoint() + { + Random rand = new Random(); + int x, y; + do + { + x = rand.Next(GameField.GetLength(0) - 1); + y = rand.Next(GameField.GetLength(1) - 1); + } while (GameField[x, y].Tick != 0 && GameField[x, y].Type == SquareType.Wall); + GameField[x, y].Tick = -1; + GameField[x, y].Type = SquareType.Point; + } + /*public static SqCoord GetCoord(SqCoord nextcoord) { return GameField.Single(entry => entry.X == nextcoord.X && entry.Y == nextcoord.Y); @@ -145,8 +249,9 @@ namespace SnakeGame public static void Stop() { //Form1.Timer.Stop(); - Form1.TimerEnabled = false; - MessageBox.Show("Game over!"); + //Form1.TimerEnabled = false; + //MessageBox.Show("Game over!"); + MSGBox.ShowMSGBox("Game over!", "", MSGBoxType.Text, pauseafter: true); } } public enum GameStartMode diff --git a/SnakeGame/GameRenderer.cs b/SnakeGame/GameRenderer.cs index 5dc4f64..67e21de 100644 --- a/SnakeGame/GameRenderer.cs +++ b/SnakeGame/GameRenderer.cs @@ -19,16 +19,21 @@ namespace SnakeGame for (int j = 0; j < Game.GameField.GetLength(1); j++) { //if (coord.Tick == -1) - if (Game.GameField[i, j] == -1) - RenderSquare(new SqCoord { X = i, Y = j }, Color.Red); - else if (Game.GameField[i, j] == 0) - RenderSquare(new SqCoord { X = i, Y = j }, Color.Black); + //if (Game.GameField[i, j].Tick == -1) + if (Game.GameField[i, j].Tick == 0) + RenderSquare(new Point { X = i, Y = j }, Color.Black); + else if (Game.GameField[i, j].Type == SquareType.Wall) + RenderSquare(new Point { X = i, Y = j }, Color.Red); + else if (Game.GameField[i, j].Type == SquareType.Player) + RenderSquare(new Point { X = i, Y = j }, Color.Green); + else if (Game.GameField[i, j].Type == SquareType.Point) + RenderSquare(new Point { X = i, Y = j }, Color.Blue); else - RenderSquare(new SqCoord { X = i, Y = j }, Color.Green); + RenderSquare(new Point { X = i, Y = j }, Color.Gray); } } } - private static void RenderSquare(SqCoord coord, Color color) + private static void RenderSquare(Point coord, Color color) { Graphics gr = Panel.CreateGraphics(); gr.FillRectangle(new SolidBrush(color), SquareCoord.SqCoordToRect(coord, Panel.Size)); diff --git a/SnakeGame/MSGBox.cs b/SnakeGame/MSGBox.cs new file mode 100644 index 0000000..1f5ac50 --- /dev/null +++ b/SnakeGame/MSGBox.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SnakeGame +{ + public static class MSGBox + { + private static int slidervalue; + private static bool pause; + public static void ShowMSGBox(string text, string inputtext, MSGBoxType type, EventHandler doneevent = null, bool pauseafter = false) + { + Game.DialogPanel.Controls.Add(new Label { Text = text, Location = new Point(10, 10), Font = new Font(FontFamily.GenericSansSerif, 10f), Size = new Size(200, 20) }); + //TextBox input = null; + switch (type) + { + case MSGBoxType.Text: + Game.DialogPanel.Size = new Size(200, 100); + slidervalue = 0; + break; + case MSGBoxType.SizeInput: + Game.DialogPanel.Size = new Size(200, 200); + Game.DialogPanel.Controls.Add(new Label { Text = inputtext, Location = new Point(10, 40), Size = new Size(100, 20) }); + slidervalue = 20; + /*Game.DialogPanel.Controls.Add(input = new TextBox + { + Text = "", + Location = new Point(10, 60), + Multiline = false, + Font = new Font(FontFamily.GenericSansSerif, 10f), + Size = new Size(100, 1) + });*/ + Graphics gr = Game.DialogPanel.CreateGraphics(); + gr.FillRectangle(new SolidBrush(Color.Blue), new Rectangle(10, 60, slidervalue, slidervalue)); + Game.DialogPanel.Paint += delegate + { + if (slidervalue == 0) + return; + gr.FillRectangle(new SolidBrush(Color.Blue), new Rectangle(10, 60, slidervalue, slidervalue)); + }; + Game.DialogPanel.Click += delegate + { + if (slidervalue == 0) + return; + Point p = Game.DialogPanel.PointToClient(Cursor.Position); + if (p.Y > 50 && p.Y < 200) + { + if (p.X < 210) //p.X - 10 < 100 + slidervalue = p.X - 10; + Game.DialogPanel.Refresh(); + } + }; + break; + default: + throw new NotImplementedException(); + } + Game.DialogPanel.Location = new Point(GameRenderer.Panel.Width / 2 - Game.DialogPanel.Width / 2, GameRenderer.Panel.Height / 2 - Game.DialogPanel.Height / 2); + Game.DialogPanel.Location = Game.DialogPanel.Parent.PointToClient(GameRenderer.Panel.PointToScreen(Game.DialogPanel.Location)); + Button btn = new Button(); + btn.Text = "OK"; + btn.Click += delegate + { + CloseMSGBox(); + if (doneevent != null) + //doneevent(btn, (input == null ? "" : input.Text)); + doneevent(btn, slidervalue); + }; + btn.FlatStyle = FlatStyle.Flat; + btn.FlatAppearance.BorderColor = Color.Blue; + btn.FlatAppearance.BorderSize = 2; + btn.FlatAppearance.CheckedBackColor = Color.DarkBlue; + btn.FlatAppearance.MouseDownBackColor = Color.DeepSkyBlue; + btn.Location = new Point(Game.DialogPanel.Size.Width / 2 - 40, Game.DialogPanel.Size.Height - 40); + btn.Size = new Size(80, 30); + Game.DialogPanel.Controls.Add(btn); + Game.Paused = true; + pause = pauseafter; + Game.DialogPanel.Visible = true; + } + public static void CloseMSGBox() + { + Game.DialogPanel.Visible = false; + Game.DialogPanel.Controls.Clear(); + Game.Paused = pause; + //Form1.Instance.Activate(); + //GameRenderer.Panel.Select(); + //Form1.Instance.Select(); + Form1.Instance.Focus(); + } + } + public enum MSGBoxType + { + Text, + SizeInput + } +} diff --git a/SnakeGame/Network.cs b/SnakeGame/Network.cs new file mode 100644 index 0000000..1324a7d --- /dev/null +++ b/SnakeGame/Network.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +namespace SnakeGame +{ + public static class Network + { + public static void SyncUpdate() + { + HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://snakegame.16mb.com/"); + request.Method = "POST"; + } + } +} diff --git a/SnakeGame/SnakeGame.csproj b/SnakeGame/SnakeGame.csproj index e7091fc..ef2fd1c 100644 --- a/SnakeGame/SnakeGame.csproj +++ b/SnakeGame/SnakeGame.csproj @@ -53,6 +53,8 @@ + + diff --git a/SnakeGame/SquareCoord.cs b/SnakeGame/SquareCoord.cs index 4a55ee2..acd15d1 100644 --- a/SnakeGame/SquareCoord.cs +++ b/SnakeGame/SquareCoord.cs @@ -45,7 +45,7 @@ namespace SnakeGame { return new SqCoord { X = point.X / res, Y = point.Y / res }; }*/ - public static Rectangle SqCoordToRect(SqCoord coord, Size size) + public static Rectangle SqCoordToRect(Point coord, Size size) { int resx = size.Width / Game.GameSize.X; int resy = size.Height / Game.GameSize.Y; @@ -54,11 +54,22 @@ namespace SnakeGame } public struct SqCoord { - public int X { get; set; } - public int Y { get; set; } + //public int X { get; set; } - using it in two-dimensional array; replaced with Point where needed + //public int Y { get; set; } /// - /// Used to determine snake square "expiration". -1 means wall. Game over if other than zero in next player position. + /// Used to determine snake square "expiration". Game over if other than zero or there is a wall. /// public int Tick { get; set; } + public SquareType Type { get; set; } + public int PlayerID { get; set; } + } + /// + /// Only consider if Tick>0 + /// + public enum SquareType + { + Wall, + Point, + Player } } diff --git a/Web/index.php b/Web/index.php new file mode 100644 index 0000000..919088a --- /dev/null +++ b/Web/index.php @@ -0,0 +1,11 @@ + + Project home"; + die(); +} +//WebPass: vhwfsQOv9E +//fötöpö: (sznpadmin) VKiSh7i1og + +?>