コード例 #1
0
ファイル: Game1.cs プロジェクト: verweij/battleships
        /// <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(SpriteSortMode.Immediate, BlendState.AlphaBlend);
            P1RightHand.Draw(spriteBatch);
            P1LeftHand.Draw(spriteBatch);
            P2RightHand.Draw(spriteBatch);
            P2LeftHand.Draw(spriteBatch);
            foreach (Boat b in Boats)
            {
                b.Draw(spriteBatch);
            }

            if (gameOver == true)
            {
                if (gameOverTimer >= 500)
                {
                    this.Exit();
                }
                gameOverTimer++;

                if (gameOverTimer > 150)
                {
                    texture = Content.Load <Texture2D>(@"images/credits");
                    spriteBatch.Draw(texture, new Vector2(0, 0), null, Color.White, 0f, new Vector2(texture.Width / 2, texture.Height / 2), 1f, SpriteEffects.None, 0f);
                }
            }

            if (inMenu == true)
            {
                texture = Content.Load <Texture2D>(@"images/resume");
                spriteBatch.Draw(texture, new Vector2(100, 300), null, Color.White, 0f, new Vector2(0, 0), 1f, SpriteEffects.None, 0f);
                texture = Content.Load <Texture2D>(@"images/exit");
                spriteBatch.Draw(texture, new Vector2(420, 300), null, Color.White, 0f, new Vector2(0, 0), 1f, SpriteEffects.None, 0f);
            }

            if (playerWins == 2)
            {
                texture = Content.Load <Texture2D>(@"images/p2wins");
                spriteBatch.Draw(texture, new Vector2(450, 400), null, Color.White, 0f, new Vector2(texture.Width / 2, texture.Height / 2), 1f, SpriteEffects.None, 0f);
            }
            if (playerWins == 1)
            {
                texture = Content.Load <Texture2D>(@"images/p1wins");
                spriteBatch.Draw(texture, new Vector2(450, 400), null, Color.White, 0f, new Vector2(texture.Width / 2, texture.Height / 2), 1f, SpriteEffects.None, 0f);
            }

            base.Draw(gameTime);
            spriteBatch.End();
        }
コード例 #2
0
ファイル: Game1.cs プロジェクト: verweij/battleships
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            // TODO: Add your update logic here

            if (gameOver == true)
            {
            }
            else if (inMenu == true)
            {
            }
            else
            {
                // public static IEnumerable<T> Randomize<T>(this IEnumerable<T> source)
                // {
                //    Random rnd = new Random();
                //    return source.OrderBy<T, int>((item) => rnd.Next());
                // }

                /*Random rnd = new Random();
                 * Boats = Boats.OrderBy(item=>rnd.Next());*/
                int p1Boats = 0;
                int p2Boats = 0;

                for (int i = Boats.Count - 1; i > -1; i--)
                {
                    Boat b = Boats.ElementAt(i);
                    if (b.health > 0)
                    {
                        b.act(Boats);
                        if (b.owner == 0)
                        {
                            p1Boats++;
                        }
                        else
                        {
                            p2Boats++;
                        }
                    }
                    else
                    {
                        Boats.Remove(b);
                    }
                }

                if (p1Boats == 0)
                {
                    playerWins = 2;
                }

                if (p2Boats == 0)
                {
                    playerWins = 1;
                }

                P1LeftHand.act(Boats);
                P1RightHand.act(Boats);
                P2LeftHand.act(Boats);
                P2RightHand.act(Boats);
            }
            if (exiting == true)
            {
                this.Exit();
            }
            base.Update(gameTime);
        }
コード例 #3
0
ファイル: Game1.cs プロジェクト: verweij/battleships
        void kinect_AllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            getSkeletons(e);
            List <Skeleton> trackedSkells = new List <Skeleton>();

            foreach (Skeleton s in allSkells)
            {
                if (s.TrackingState == SkeletonTrackingState.Tracked)
                {
                    trackedSkells.Add(s);
                }
            }

            Skeleton p1s = null, p2s = null;

            if (trackedSkells.Count > 0)
            {
                p1s = trackedSkells.ElementAt(0);
            }

            if (trackedSkells.Count > 1)
            {
                p2s = trackedSkells.ElementAt(1);
            }

            if (p1s == null)
            {
                return;
            }

            using (DepthImageFrame depth = e.OpenDepthImageFrame())
            {
                if (depth == null)
                {
                    return;
                }
                DepthImagePoint RH = depth.MapFromSkeletonPoint(p1s.Joints[JointType.HandRight].Position);
                DepthImagePoint RE = depth.MapFromSkeletonPoint(p1s.Joints[JointType.ElbowRight].Position);
                DepthImagePoint RS = depth.MapFromSkeletonPoint(p1s.Joints[JointType.ShoulderRight].Position);
                P1RightHand.updateHand(RH);
                ProcSide(RH, RE, RS, P1RightHand, "RightHand");

                DepthImagePoint LH = depth.MapFromSkeletonPoint(p1s.Joints[JointType.HandLeft].Position);
                DepthImagePoint LE = depth.MapFromSkeletonPoint(p1s.Joints[JointType.ElbowLeft].Position);
                DepthImagePoint LS = depth.MapFromSkeletonPoint(p1s.Joints[JointType.ShoulderLeft].Position);
                P1LeftHand.updateHand(LH);
                ProcSide(LH, LE, LS, P1LeftHand, "LeftHand");
            }

            if (p2s == null)
            {
                return;
            }
            using (DepthImageFrame depth = e.OpenDepthImageFrame())
            {
                if (depth == null)
                {
                    return;
                }
                DepthImagePoint RH = depth.MapFromSkeletonPoint(p2s.Joints[JointType.HandRight].Position);
                DepthImagePoint RE = depth.MapFromSkeletonPoint(p2s.Joints[JointType.ElbowRight].Position);
                DepthImagePoint RS = depth.MapFromSkeletonPoint(p2s.Joints[JointType.ShoulderRight].Position);
                P2RightHand.updateHand(RH);
                ProcSide(RH, RE, RS, P2RightHand, "RightHand");

                DepthImagePoint LH = depth.MapFromSkeletonPoint(p2s.Joints[JointType.HandLeft].Position);
                DepthImagePoint LE = depth.MapFromSkeletonPoint(p2s.Joints[JointType.ElbowLeft].Position);
                DepthImagePoint LS = depth.MapFromSkeletonPoint(p2s.Joints[JointType.ShoulderLeft].Position);
                P2LeftHand.updateHand(LH);
                ProcSide(LH, LE, LS, P2LeftHand, "LeftHand");
            }
        }