language: C# (mono-2.8)
date: 310 days 17 hours ago
link:
visibility: public
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
 
 
namespace XNASnake
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        KeyboardState oldState = Keyboard.GetState();
        Snake.WhereToGo keyState;
        int time;
        Apple apple;
        private int appleTime;
        private bool drawApple;
        Character Tail;
        private Snake Head;
        private int ileKwadratow;
        SpriteFont sf;
 
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferHeight = 300;
            graphics.PreferredBackBufferWidth = 300;
            Content.RootDirectory = "Content";
        }
 
        protected override void Initialize()
        {
 
            base.Initialize();
        }
 
        protected override void LoadContent()
        {
            ileKwadratow = 0;
            Tail = new Character();
            time = 0;
            spriteBatch = new SpriteBatch(GraphicsDevice);
            apple = new Apple();
            apple.texture = Content.Load<Texture2D>("Snake/Apple");
            Head = new Snake(Content.Load<Texture2D>("Snake/SnakeRectangle"));
            Tail.wezykList.Add(Head);
            sf = Content.Load<SpriteFont>("SpriteFont1");
            Head.position = new Vector2(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 2);
            Head.velocity = new Vector2(5, 0);
        }
 
        protected override void UnloadContent()
        {
 
        }
 
        public void SnakeUpdate()
        {
            Head.position += Head.velocity;
        }
 
 
 
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
 
            KeyAdapter();
            CheckApple();
 
            time += gameTime.ElapsedGameTime.Milliseconds;
            appleTime += gameTime.ElapsedGameTime.Milliseconds;
            SnakeUpdate();
 
            foreach (Snake s in Tail.wezykList)
            {
                s.position = Head.position;
            }
            
 
            if (appleTime >= 6000 || apple.isDead == true)
            {
                drawApple = true;
                apple.X = new Random().Next(0, graphics.PreferredBackBufferWidth - apple.texture.Width);
                apple.Y = 200;
                appleTime -= 6000;
                apple.isDead = false;
            }
 
            base.Update(gameTime);
        }
 
        public void KeyAdapter()
        {
            KeyboardState currentState = Keyboard.GetState();
 
            if (currentState.IsKeyDown(Keys.Up) && oldState.IsKeyUp(Keys.Up))
            {
                keyState = Snake.WhereToGo.goUP;
                Head.velocity = new Vector2(0, -3);
            }
 
            if (currentState.IsKeyDown(Keys.Down) && oldState.IsKeyUp(Keys.Down))
            {
                keyState = Snake.WhereToGo.goDOWN;
                Head.velocity = new Vector2(0, 3);
            }
            
            if (currentState.IsKeyDown(Keys.Left) && oldState.IsKeyUp(Keys.Left))
            {
                keyState = Snake.WhereToGo.goLEFT;
                Head.velocity = new Vector2(-3, 0);
            }
 
            if (currentState.IsKeyDown(Keys.Right) && oldState.IsKeyUp(Keys.Right))
            {
                keyState = Snake.WhereToGo.goRIGHT;
                Head.velocity = new Vector2(3, 0);
            }
        }
 
        public void CheckApple()
        {
            if (apple.Rectanglee().Intersects(Tail.wezykList[0].Rectanglee()))
            {
                Snake dodatek = new Snake(Content.Load<Texture2D>("Snake/SnakeRectangle"));
 
                if (keyState == Snake.WhereToGo.goDOWN)
                {
                    dodatek.position.X = Tail.wezykList[ileKwadratow].position.X;
                    dodatek.position.Y = Tail.wezykList[ileKwadratow].position.Y - 10;
                }
                if (keyState == Snake.WhereToGo.goUP)
                {
                    dodatek.position.X = Tail.wezykList[ileKwadratow].position.X;
                    dodatek.position.Y = Tail.wezykList[ileKwadratow].position.Y + 10;
                }
                if (keyState == Snake.WhereToGo.goLEFT)
                {
                    dodatek.position.X = Tail.wezykList[ileKwadratow].position.X + 10;
                    dodatek.position.Y = Tail.wezykList[ileKwadratow].position.Y;
                }
                if (keyState == Snake.WhereToGo.goRIGHT)
                {
                    dodatek.position.X = Tail.wezykList[ileKwadratow].position.X - 10;
                    dodatek.position.Y = Tail.wezykList[ileKwadratow].position.Y;
                }
 
 
                apple.isDead = true;
 
 
                ileKwadratow++;
                Tail.wezykList.Add(dodatek);
 
            }
        }
 
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin();
 
            //spriteBatch.Draw(sticzeq.wezykList[0].texture, sticzeq.wezykList[0].Rectanglee(), Color.Aqua);
            // rysowanie OK
 
            foreach (Snake s in Tail.wezykList)
            {
                spriteBatch.Draw(s.texture, s.Rectanglee(), Color.Aqua);
            }
 
            if (drawApple == true)
            {
                spriteBatch.Draw(apple.texture, apple.Rectanglee(), Color.Red);
            }
 
            spriteBatch.DrawString(sf,Convert.ToString(keyState),new Vector2(100,100),Color.Black);
            spriteBatch.DrawString(sf, Convert.ToString(Tail.wezykList.Count), new Vector2(100, 130), Color.Black);
 
 
            spriteBatch.End();
 
            base.Draw(gameTime);
        }
    }
}
 
prog.cs(18,36): error CS0234: The type or namespace name `Xna' does not exist in the namespace `Microsoft'. Are you missing an assembly reference?
Compilation failed: 1 error(s), 0 warnings