aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Main/ShiftOS/Apps/Snakey.cs
blob: d8d4a987974d0d4f48bf90e79114c2f27f01bed6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using ShiftOS.Engine;
using ShiftOS.Main.Properties;

namespace ShiftOS.Main.ShiftOS.Apps
{
    public partial class Snakey : UserControl
    {
        public Snakey()
        {
            InitializeComponent();
        }
        private struct structSnake
        {
            public Rectangle rect;
            public int x;
            public int y;
        }
        private enum directions
        {
            Rightward,
            Downward,
            Leftward,
            Upward
        }
        #region Various-Objects
        private const int INTIAL_SNAKE_RECT_COUNT = 5;
        private const int COLUMN_COUNT = 65;
        private const int ROW_COUNT = 47;
        private int curRecCount;
        private Rectangle[,] Rects;


        private bool [,] isSnakePart;
        private List<structSnake> snake;
        private Brush snakeBrush = new SolidBrush(Color.FromArgb(255, 255, 255));
        private Brush backBrush = new SolidBrush(Color.FromArgb(1, 1, 1));
        private Brush tokenBrush = new SolidBrush(Color.FromArgb(255, 255, 255));
        private directions curDirection;
        private Bitmap buffer;
        private int columnCount;
        private int rowCount;
        private int snakePoints;
        private double snakeSpeed;
        private int snakeLength;
        private Rectangle token;
        #endregion
        private int xyIndexToRect(int X, int Y)
        {
            return (Y * (columnCount)) + X;
        }
        private void rectToIndexXY(double index, double X, double Y)
        {
            X = index % (columnCount);
            Y = Math.Round(index / columnCount);
        }
        private void initSnake()
        {
            int x;
            int y;
            int index;
            snake = new List<structSnake>();
            structSnake sSnake = new structSnake();
            x = ((columnCount) - 10 / 2);
            y = ((rowCount) - 6) / 2;
            Point snakePosition = new Point(x, y);
            index = xyIndexToRect(x, y);
            for (int i = 0; i < INTIAL_SNAKE_RECT_COUNT; i++)
            {
                rectToIndexXY(index + (i - 1), x, y);
                sSnake.rect = Rects[x, y];
                sSnake.x = x;
                sSnake.y = y;
                snake.Add(sSnake);
            }
            snakeLength = INTIAL_SNAKE_RECT_COUNT;
            snakeSpeed = 1;
            length.Text = "Length: " + snakeLength.ToString();
            speed.Text = "Speed: " + snakeSpeed.ToString();
        }
        private void selectRectangles()
        {
            Graphics g = Graphics.FromImage(Resources.snakeyback);
            int i;
            structSnake sSnake = new structSnake();
            for (i = 0; i < INTIAL_SNAKE_RECT_COUNT; i++)
            {
                sSnake = snake[i];
                g.FillRectangle(snakeBrush, sSnake.rect);
                isSnakePart[sSnake.x, sSnake.y] = true;
            }
            buffer = new Bitmap(Resources.snakeyback);
            g.Dispose();
            Refresh();
        }
        private void initRectangles()
        {
            int i;
            int j;
            columnCount = COLUMN_COUNT;
            rowCount = ROW_COUNT;
            Rects = new Rectangle[columnCount, rowCount];
            isSnakePart = new bool[columnCount, rowCount];
            for (j = 0; j < rowCount; j++)
            {
                for (i = 0; i < columnCount; i++)
                {
                    //TO-DO: I can't really port this over right now. Commiting soon. -FDD
                }
            }
        }
    }
}