SnakeGame/SnakeGame/SquareCoord.cs

77 lines
1.9 KiB
C#
Raw Normal View History

2017-01-07 23:09:43 +01:00
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SnakeGame
{
public static class SquareCoord
{
2017-01-07 23:14:03 +01:00
/*private static int x;
2017-01-07 23:09:43 +01:00
public static int X
{
get
{
return x;
}
set
{
x = value;
Game.Refresh();
}
}
private static int y;
public static int Y
{
get
{
return y;
}
set
{
y = value;
Game.Refresh();
}
2017-01-07 23:14:03 +01:00
}*/
//private const int res = 20;
2017-01-07 23:09:43 +01:00
2017-01-07 23:14:03 +01:00
/*public static Point SqCoordToPoint(SqCoord coord)
2017-01-07 23:09:43 +01:00
{
return new Point(coord.X * res, coord.Y * res);
2017-01-07 23:14:03 +01:00
}*/
/*public static SqCoord PointToSqCoord(Point point)
2017-01-07 23:09:43 +01:00
{
return new SqCoord { X = point.X / res, Y = point.Y / res };
2017-01-07 23:14:03 +01:00
}*/
2017-01-07 23:15:15 +01:00
public static Rectangle SqCoordToRect(Point coord, Size size)
2017-01-07 23:09:43 +01:00
{
2017-01-07 23:14:03 +01:00
int resx = size.Width / Game.GameSize.X;
int resy = size.Height / Game.GameSize.Y;
return new Rectangle(coord.X * resx, coord.Y * resy, resx, resy);
2017-01-07 23:09:43 +01:00
}
}
public struct SqCoord
{
2017-01-07 23:15:15 +01:00
//public int X { get; set; } - using it in two-dimensional array; replaced with Point where needed
//public int Y { get; set; }
2017-01-07 23:09:43 +01:00
/// <summary>
2017-01-07 23:15:15 +01:00
/// Used to determine snake square "expiration". Game over if other than zero or there is a wall.
2017-01-07 23:09:43 +01:00
/// </summary>
public int Tick { get; set; }
2017-01-07 23:15:15 +01:00
public SquareType Type { get; set; }
2017-01-07 23:21:48 +01:00
//public int PlayerID { get; set; }
public string PlayerName { get; set; }
2017-01-07 23:15:15 +01:00
}
/// <summary>
/// Only consider if Tick>0
/// </summary>
public enum SquareType
{
Wall,
Point,
Player
2017-01-07 23:09:43 +01:00
}
}