From e8ee7b69663a95d97b226266ebe3ccc95e13c309 Mon Sep 17 00:00:00 2001 From: "ivaylo.zhelev" Date: Sun, 31 Jan 2021 16:42:30 +0200 Subject: Major Business Logic Implementation * Added GameHub * Added Back-End Game Loop and Game Mechanics * Added End Game and Result message --- src/Web/PUSG.Web/Models/Player.cs | 73 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/Web/PUSG.Web/Models/Player.cs (limited to 'src/Web/PUSG.Web/Models/Player.cs') diff --git a/src/Web/PUSG.Web/Models/Player.cs b/src/Web/PUSG.Web/Models/Player.cs new file mode 100644 index 0000000..cb0cc5a --- /dev/null +++ b/src/Web/PUSG.Web/Models/Player.cs @@ -0,0 +1,73 @@ +using System.Collections.Generic; + +namespace PUSG.Web.Models +{ + public class Player : BaseGameObject + { + private Dictionary directionsRight = new Dictionary + { + ["up"] = "right", + ["right"] = "down", + ["down"] = "left", + ["left"] = "up" + }; + + private Dictionary directionsLeft = new Dictionary + { + ["up"] = "left", + ["left"] = "down", + ["down"] = "right", + ["right"] = "up" + }; + + public string Color { get; set; } + + public string Direction { get; set; } + + public string Type { get; set; } + + public bool IsDead { get; set; } = false; + + public void MoveUp() + { + if (this.Y - 20 >= 0) + { + this.Y -= 20; + } + } + + public void MoveRight() + { + if (this.X + 20 <= 1366) + { + this.X += 20; + } + } + + public void MoveDown() + { + if (this.Y + 20 <= 1366) + { + this.Y += 20; + } + } + + public void MoveLeft() + { + if (this.X - 20 >= 0) + { + this.X -= 20; + } + } + + public void RotateLeft() + { + this.Direction = this.directionsLeft[this.Direction]; + } + + public void RotateRight() + { + this.Direction = this.directionsRight[this.Direction]; + } + } +} -- cgit v1.3.1-26-gb76a