Autor Beitrag
niggo233
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 46
Erhaltene Danke: 1

Win7
C#,NXT,PHP,Html,CSS,JavaScript
BeitragVerfasst: Mo 24.01.11 18:40 
Hi
ich habe ein spiel mit Leveln programmiert,jetzt möchte ich ,dass wenn man 10Punkte hat,dass das Level 2 erscheint.Aber ich weiß nicht wie das geht,kann mir jemand helfen?
Danke
Mfg
Trashkid2000
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 561
Erhaltene Danke: 137



BeitragVerfasst: Mo 24.01.11 21:01 
Ja, so:
ausblenden C#-Quelltext
1:
2:
3:
4:
if (Punkte == 10)
{
  StarteLevel2();
}
Nein, mal im Ernst: Wie sollen wir Dir den ohne einen Codeausschnitt, wo man sieht, wie das Spiel programmiert ist helfen?
niggo233 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 46
Erhaltene Danke: 1

Win7
C#,NXT,PHP,Html,CSS,JavaScript
BeitragVerfasst: Mo 24.01.11 21:24 
Hi
ok hier mein Code:
ausblenden volle Höhe C#-Quelltext
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:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
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;
using Microsoft.Xna.Framework.Storage;
using System.Collections;
using System.Media;

namespace Snake
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        bool verloren = false;
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        SpriteFont font;

        ArrayList elementX = new ArrayList();
        ArrayList elementY = new ArrayList();

        ArrayList foodX = new ArrayList();
        ArrayList foodY = new ArrayList();


        int updates = 0;
        int speed = 5;
        int hightY;
        int wightX;
        int punkte = 0;

        Texture2D bg, snake_body, snake_head,texture_food;
        string direction;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            graphics.PreferredBackBufferHeight = 700;
            graphics.PreferredBackBufferWidth = 1000;
            graphics.ApplyChanges();

            hightY = graphics.PreferredBackBufferHeight / 10;
            wightX = graphics.PreferredBackBufferWidth / 10;

            elementY.Add(0);
            elementX.Add(0);

            elementY.Add(1);
            elementX.Add(0);

            elementY.Add(2);
            elementX.Add(0);

            Random z = new Random();
            foodX.Add(z.Next(0, graphics.PreferredBackBufferWidth/10));
            foodY.Add(z.Next(0, graphics.PreferredBackBufferHeight/10));

            foodX.Add(z.Next(0, graphics.PreferredBackBufferWidth/10));
            foodY.Add(z.Next(0, graphics.PreferredBackBufferHeight/10));


            // TODO: Add your initialization logic here

            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            snake_body = Content.Load<Texture2D>("snake_body");
            snake_head = Content.Load<Texture2D>("snake_head");
            texture_food = Content.Load<Texture2D>("food");
            bg = Content.Load<Texture2D>("bg");
            font= Content.Load<SpriteFont>("SpriteFont1");
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Play(Content.Load<Song>("media"));

            // TODO: use this.Content to load your game content here
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            int i = 1;
            while (i < elementX.Count)
            {
                if (elementX[i].ToString() == elementX[0].ToString() && elementY[i].ToString() == elementY[0].ToString())
                {
                    verloren = true;
                }
                i++;
            }
            if (verloren==false)
            {

                //wenn eine Taste gedrückt wird dann mache dies

                KeyboardState ks = Keyboard.GetState();
                if (ks.IsKeyDown(Keys.Up))
                {
                    if (direction != "d") { direction = "u"; }
                }
                if (ks.IsKeyDown(Keys.Down))
                {
                    if (direction != "u") { direction = "d"; }
                }
                if (ks.IsKeyDown(Keys.Left))
                {
                    if (direction != "r") { direction = "l"; }
                }
                if (ks.IsKeyDown(Keys.Right))
                {
                    if (direction != "l") { direction = "r"; }
                }
                if (ks.IsKeyDown(Keys.Escape))
                { Exit(); }
                if (updates == speed)
                {
                    if (direction == "d")
                    {
                        elementX.Insert(0, elementX[0]);
                        elementX.RemoveAt(elementX.Count - 1);

                        elementY.Insert(0, Convert.ToUInt16(elementY[0]) + 1);
                        elementY.RemoveAt(elementY.Count - 1);

                    }
                    if (direction == "u")
                    {
                        elementX.Insert(0, elementX[0]);
                        elementX.RemoveAt(elementX.Count - 1);

                        elementY.Insert(0, Convert.ToUInt16(elementY[0]) - 1);
                        elementY.RemoveAt(elementY.Count - 1);

                    }
                    if (direction == "l")
                    {
                        elementX.Insert(0, Convert.ToUInt16(elementX[0]) - 1);
                        elementX.RemoveAt(elementX.Count - 1);
                        elementY.Insert(0, elementY[0]);
                        elementY.RemoveAt(elementY.Count - 1);

                    }
                    if (direction == "r")
                    {
                        elementX.Insert(0, Convert.ToUInt16(elementX[0]) + 1);
                        elementX.RemoveAt(elementX.Count - 1);
                        elementY.Insert(0, elementY[0]);
                        elementY.RemoveAt(elementY.Count - 1);

                    }
                    //die schlange verschieben
                    updates = 0;
                }
                else { updates++; }
                i = 0;
                while (i < foodX.Count)
                {
                    if (foodX[i].ToString() == elementX[0].ToString() && foodY[i].ToString() == elementY[0].ToString())
                    {
                        foodY.RemoveAt(i);
                        foodX.RemoveAt(i);

                        elementX.Add(-1);
                        elementY.Add(-1);


                        punkte++;
                        if (punkte == 17)
                        {
                        }
                        Random z = new Random();
                        foodX.Add(z.Next(0, graphics.PreferredBackBufferWidth / 10));
                        foodY.Add(z.Next(0, graphics.PreferredBackBufferHeight / 10));
                    }
                    i++;
                }
                if (Convert.ToInt16(elementX[0]) < 0) { elementX[0] = graphics.PreferredBackBufferWidth / 10; }
                if (Convert.ToInt16(elementX[0]) > graphics.PreferredBackBufferWidth / 10) { elementX[0] = 0; }
                if (Convert.ToInt16(elementY[0]) < 0) { elementY[0] = graphics.PreferredBackBufferHeight / 10; }
                if (Convert.ToInt16(elementY[0]) > graphics.PreferredBackBufferHeight / 10) { elementY[0] = 0; }
            }
            // TODO: Add your update logic here

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here
            spriteBatch.Begin();

            spriteBatch.Draw(bg, new Rectangle(00, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), Color.White);


            int i = 0;
            while (i < elementX.Count)
            {
                spriteBatch.Draw(snake_body,new Rectangle(Convert.ToInt16(elementX[i])*10,Convert.ToInt16(elementY[i])*10,10,10),Color.White);
                i++;
            }
            spriteBatch.Draw(snake_head, new Rectangle(Convert.ToInt16(elementX[0])*10, Convert.ToInt16(elementY[0])*101010), Color.White);
            i = 0;
            while (i < foodX.Count)
            {
                spriteBatch.Draw(texture_food, new Rectangle(Convert.ToInt16(foodX[i])*10, Convert.ToInt16(foodY[i])*101010), Color.White);
                i++;
            }
            if (verloren)
            {spriteBatch.DrawString(font,"G a m e  O v e r!!",new Vector2(50,graphics.PreferredBackBufferHeight/2),Color.White); }
            spriteBatch.DrawString(font, "Punkte: "+punkte.ToString(), new Vector2(10,10), Color.White);
            spriteBatch.End();
            //Hier wird alles gezeichnet
             

            base.Draw(gameTime);
        }
    }
}
Trashkid2000
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 561
Erhaltene Danke: 137



BeitragVerfasst: Mo 24.01.11 22:18 
Dein Code? Mit den Comments
ausblenden XML-Daten
1:
2:
3:
/// <summary>
/// This is the main type for your game
/// </summary>
Wenn es Dein Code wäre, dannn solltest Du wissen, wie Du das anstellst!
Blacksite_JaWa
Hält's aus hier
Beiträge: 1



BeitragVerfasst: Fr 11.03.11 20:32 
Zitat:

Dein Code? Mit den Comments
ausblenden C#-Quelltext
1:
2:
3:
1:/// <summary>
2:/// This is the main type for your game
3:/// </summary>

Wenn es Dein Code wäre, dannn solltest Du wissen, wie Du das anstellst!


Hi, diese Comments werde Automatisch gesetzt.
Ab welcher Version das so ist weiß ich nicht aber in XNA 4.0 ist es so.
Habe heut erst noch damit gearbeitet.

Also... Ruhig Blut und nicht gleich falsche Anschuldigungen in den Raum werfen.
Trashkid2000
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 561
Erhaltene Danke: 137



BeitragVerfasst: Fr 11.03.11 22:14 
Da Du nochmal das Thema aufgegriffen hast:
ja okay, wollte niemanden zu nahe treten. Aber wenn jemand schreibt
Zitat:
ich habe ein spiel mit Leveln programmiert...
und dann die Frage stellt
Zitat:
jetzt möchte ich ,dass wenn man 10Punkte hat,dass das Level 2 erscheint.Aber ich weiß nicht wie das geht...
frage ich mich echt, ob derjenige weiß, was er da programmiert bzw wo er denn den Code her hat.
Das ist aber meine persönliche Meinung. Und wenn ich mich irre tut es mir natürlich leid.
Marko