From 1f6c1a9d8642e0cd7db64d2ff5e9132674b4ce33 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 7 Jan 2017 23:29:29 +0100 Subject: [PATCH] 2015.09.24 --- SnakeGame/Form1.cs | 12 ++++-- SnakeGame/Game.cs | 21 ++++++---- SnakeGame/Network.Client.cs | 1 - Web/index.php | 81 ------------------------------------- 4 files changed, 21 insertions(+), 94 deletions(-) delete mode 100644 Web/index.php diff --git a/SnakeGame/Form1.cs b/SnakeGame/Form1.cs index b93c146..9fc11b8 100644 --- a/SnakeGame/Form1.cs +++ b/SnakeGame/Form1.cs @@ -15,7 +15,7 @@ namespace SnakeGame public partial class Form1 : Form { private static Timer Timer; - private static Timer SpeedTimer; + //private static Timer SpeedTimer; private static bool timerenabled = false; public static Form1 Instance; public static bool TimerEnabled @@ -45,13 +45,17 @@ namespace SnakeGame if (value && !timerenabled) //Only start if not running already { Timer.Start(); - SpeedTimer.Start(); + //SpeedTimer.Start(); } timerenabled = value; Instance.toolStripTextBox1.Enabled = !value; })); } } + public static void SetTimer(int remtime) + { + Timer.Interval -= remtime; + } public Form1() { InitializeComponent(); @@ -73,7 +77,7 @@ namespace SnakeGame if (TimerEnabled) Timer.Start(); }; - SpeedTimer = new Timer(); + /*SpeedTimer = new Timer(); SpeedTimer.Interval = 10000; SpeedTimer.Tick += delegate { @@ -82,7 +86,7 @@ namespace SnakeGame Game.Length++; if (!TimerEnabled) SpeedTimer.Stop(); - }; + };*/ } private void Form1_Load(object sender, EventArgs e) diff --git a/SnakeGame/Game.cs b/SnakeGame/Game.cs index d9cf52a..855a8a3 100644 --- a/SnakeGame/Game.cs +++ b/SnakeGame/Game.cs @@ -20,7 +20,7 @@ namespace SnakeGame public static Label ScoreLabel; public static Label LivesLabel; public static Panel DialogPanel; - public static Player Player = new Player("Player", true); + public static Player Player = new Player("Player", true, Color.LightGreen); /// /// Opposite of Form1.TimerEnabled /// @@ -38,10 +38,10 @@ namespace SnakeGame public static void Start(GameStartMode mode) { - switch(mode) + switch (mode) { case GameStartMode.SinglePlayer: - MSGBox.ShowMSGBox("New singleplayer game", "Size:", MSGBoxType.SizeInput, new EventHandler(delegate(object s, string inp) + MSGBox.ShowMSGBox("New singleplayer game", "Size:", MSGBoxType.SizeInput, new EventHandler(delegate (object s, string inp) { int input = int.Parse(inp); if (input > 5) @@ -68,7 +68,7 @@ namespace SnakeGame MSGBox.ShowMSGBox("Please change your username from default.", "", MSGBoxType.Text); break; } - MSGBox.ShowMSGBox("New multiplayer game", "Name:\nMax. players:", MSGBoxType.MultipleInput, new EventHandler(delegate(object s, string input) + MSGBox.ShowMSGBox("New multiplayer game", "Name:\nMax. players:", MSGBoxType.MultipleInput, new EventHandler(delegate (object s, string input) { string[] strs = input.Split('\n'); int num = 0; @@ -91,8 +91,8 @@ namespace SnakeGame } //string matches = Network.Matches.Combine((match, combiner) => combiner += match.Name + " " + match.Players.Count + "/" + match.MaxPlayers + " " + match.OwnerName + "\n"); - string inputs = "IP:\n"; - MSGBox.ShowMSGBox("Connect to game", inputs, MSGBoxType.MultipleInput, new EventHandler(delegate(object s, string input) + string inputs = "IP:"; + MSGBox.ShowMSGBox("Connect to game", inputs, MSGBoxType.MultipleInput, new EventHandler(delegate (object s, string input) { IPAddress address; if (IPAddress.TryParse(input.Replace("\n", ""), out address)) @@ -123,7 +123,7 @@ namespace SnakeGame Size size = GameRenderer.Panel.Size; GameField = new SqCoord[GameSize.X, GameSize.Y]; //Player.Position = new Point { X = GameSize.X / 2, Y = 1 }; - var rand=new Random(); + var rand = new Random(); Direction dir = (Direction)rand.Next(4); do { @@ -215,6 +215,8 @@ namespace SnakeGame { Player.Score += 1000; ScoreLabel.ForeColor = Color.Blue; + Game.Length++; + Form1.SetTimer(100); Game.AddPoint(); } else @@ -231,11 +233,14 @@ namespace SnakeGame { Random rand = new Random(); int x, y; + int tries = 0; 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); + tries++; + //} while (GameField[x, y].Tick != 0 && GameField[x, y].Type == SquareType.Wall); + } while (GameField[x, y].Tick != 0 && tries < 10); GameField[x, y].Tick = -1; GameField[x, y].Type = SquareType.Point; } diff --git a/SnakeGame/Network.Client.cs b/SnakeGame/Network.Client.cs index 6dd4675..d841976 100644 --- a/SnakeGame/Network.Client.cs +++ b/SnakeGame/Network.Client.cs @@ -17,7 +17,6 @@ namespace SnakeGame { private static void ClientListenerThreadRun() { - //TODO: Game over disconnect //TODO: Synchronised point placing on respawn try { diff --git a/Web/index.php b/Web/index.php deleted file mode 100644 index 5e0bb78..0000000 --- a/Web/index.php +++ /dev/null @@ -1,81 +0,0 @@ - - Project home"; - die(); -} -else -{ - //echo "Client data"; - $conn = mysqli_connect("mysql.hostinger.hu", "u821146919_games", "SLp7q9m60J", "u821146919_games"); - if($_POST['client']=="cheesecrescent") - { //GameList - $res=mysqli_query($conn, "SELECT * FROM games"); - while($row=mysqli_fetch_array($res)) - { - if(strlen($row['playernames'])==0) - $namecount=0; - else - $namecount=count(explode(',', $row['playernames'])); - //echo ("Startdate: ".$row['startdate']." Time-1hr: ".(time()-60*60*1000)); - if($namecount==0 || strval($row['startdate'])