Example #1
0
        private Bitmap getOutpanelBitmap(int lastPoint, String name)
        {
            int width  = OutputPanel.Width;
            int height = OutputPanel.Height;

            int smallest = Math.Min(width, height) - 1;

            // BalanceBoardState b = data.Last();
            //  var b = parent.wiiDevice.WiimoteState.BalanceBoardState;
            bool   changeColor = lastPoint < data.Count;
            Bitmap bufl        = new Bitmap(width, height);
            int    x           = 10;

            Graphics g = Graphics.FromImage(bufl);

            System.Drawing.Pen redPen   = new System.Drawing.Pen(System.Drawing.Color.Red);
            System.Drawing.Pen blackPen = new System.Drawing.Pen(System.Drawing.Color.Black);

            g.FillRectangle(Brushes.White, new Rectangle(0, 0, width, height));


            System.Drawing.Rectangle drawingRegion = new System.Drawing.Rectangle((width - smallest) / 2, (height - smallest) / 2, smallest, smallest);

            g.DrawEllipse(System.Drawing.Pens.Black, drawingRegion);

            g.DrawLine(blackPen, (width - smallest) / 2, height / 2, width - (width - smallest) / 2, height / 2);
            g.DrawLine(blackPen, width / 2, (height - smallest) / 2, width / 2, height - (height - smallest) / 2);


            int lastXPos = -1;
            int lastYPos = -1;

            for (int i = 0; i < lastPoint; i++)
            {
                BalanceBoardState b = data[i];
                int Xpos            = width / 2 + (int)((float)b.CenterOfGravity.X / 20.0 * smallest);
                int Ypos            = height / 2 + (int)((float)b.CenterOfGravity.Y / 20.0 * smallest);

                System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(Xpos - 1, Ypos - 1, 2, 2);
                if (changeColor)
                {
                    int red  = (int)((float)i * 255 / (float)lastPoint);
                    int blue = 255 - (int)((float)i * 255 / (float)lastPoint);
                    redPen.Color = Color.FromArgb(red, 0, blue);
                }

                g.DrawRectangle(redPen, rectangle);
                if ((lastXPos >= 0) && (lastYPos >= 0))
                {
                    g.DrawLine(redPen, lastXPos, lastYPos, Xpos, Ypos);
                }
                lastXPos = Xpos;
                lastYPos = Ypos;
            }


            x = 11;

            return(bufl);
        }
Example #2
0
        static void SendCenterOfGravity()
        {
            try
            {
                WiimoteState      wiimoteState = wiimote.WiimoteState;
                BalanceBoardState bbs          = wiimoteState.BalanceBoardState;

                string x = bbs.CenterOfGravity.X.ToString(System.Globalization.CultureInfo.InvariantCulture);
                string y = bbs.CenterOfGravity.Y.ToString(System.Globalization.CultureInfo.InvariantCulture);
                if (bbs.WeightKg >= MIN_WEIGHT)
                {
                    TcpClient     client  = new TcpClient("127.0.0.1", PORT);
                    string        message = x + SEPARATOR + y;
                    Byte[]        data    = System.Text.Encoding.ASCII.GetBytes(message);
                    NetworkStream stream  = client.GetStream();
                    stream.Write(data, 0, data.Length);
                    client.Close();
                    stream.Close();
                }
            }
            catch (SocketException)
            {
#if WAIT_CONNECTION
                System.Threading.Thread.Sleep(5000);
#else
                Console.WriteLine("SocketException: Cannot connect to the port {0}", PORT);
#endif
            }
        }
Example #3
0
        public WiiBalanceBoardForceProvider(Wiimote balanceBoard)
        {
            if (balanceBoard == null)
            {
                throw new ArgumentNullException("balanceboard");
            }

            this.balanceBoard = balanceBoard;
            this.balanceBoard.WiimoteChanged += (sender, args) =>
            {
                this.state = args.WiimoteState.BalanceBoardState;

                this.BatteryLevel    = args.WiimoteState.Battery;
                this.BatteryLevelRaw = (int)args.WiimoteState.BatteryRaw;

                var frame = this.GetFrame();

                if (LastFrame != null && frame.AbsoluteTime.CompareTo(LastFrame.AbsoluteTime) == 0)
                {
                    return;
                }

                this.LastFrame = frame;
                this.ForceFrameArrived(frame);
            };
        }
Example #4
0
        void updateTimer_Tick(object sender, EventArgs e)
        {
            BalanceBoardState    state  = this.balanceBoard.WiimoteState.BalanceBoardState;
            BalanceBoardSensorsF values = state.SensorValuesKg;

            this.weightValLbl.Text   = Math.Round(state.WeightKg, 1) + " kg";
            this.topLeftVal.Text     = Math.Round(values.TopLeft, 1) + " kg";
            this.topRightVal.Text    = Math.Round(values.TopRight, 1) + " kg";
            this.bottomLeftVal.Text  = Math.Round(values.BottomLeft, 1) + " kg";
            this.bottomRightVal.Text = Math.Round(values.BottomRight, 1) + " kg";
        }
Example #5
0
        void OnWiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            BalanceBoardState bbs = e.WiimoteState.BalanceBoardState;

            Dispatcher.Invoke(new Action(() =>
            {
//                nowtai.Text = ((double)(((int)(bbs.WeightKg*10)))/10).ToString();
//                afetai.Text = ((double)(((int)(bbs.WeightKg*10 + change*10)))/10).ToString();
                nowtai.Text = ((int)(((int)(bbs.WeightKg * 10))) / 10).ToString();
                afetai.Text = ((int)(((int)(bbs.WeightKg * 10 + change * 10))) / 10).ToString();
            }));
        }
        public void GetValues()
        {
            // Initializing s with the current Wiimote state
            s = bb.WiimoteState;
            // Initailizing bbs with the current Balance Board state
            bbs = s.BalanceBoardState;
            // Initializing bbKg with the current weight distribution
            bbKg = bbs.SensorValuesKg;

            // Creating a new Coordinate Object and initializing it through a constructor
            coord = new Coordinate(bbs.CenterOfGravity.X, bbs.CenterOfGravity.Y);
        }
Example #7
0
    private BalanceBoardManager()
    {
        this.exePath = Path.Combine(Application.dataPath, ServiceFolder);
        this.exePath = Path.Combine(exePath, ServiceProgram);
        Log(exePath);
        this.calibrationFilePath = Path.Combine(ConfigManager.Current.GameDirectoryPath, CalibrationFileName);

        this.BalanceBoardState = new BalanceBoardState();

        coGXMax          = new List <float>();
        coGXMin          = new List <float>();
        coGYMax          = new List <float>();
        coGYMin          = new List <float>();
        weightKgMin      = new List <float>();
        weightLbMin      = new List <float>();
        topLeftKgMin     = new List <float>();
        topRightKgMin    = new List <float>();
        bottomLeftKgMin  = new List <float>();
        bottomRightKgMin = new List <float>();
        topLeftLbMin     = new List <float>();
        topRightLbMin    = new List <float>();
        bottomLeftLbMin  = new List <float>();
        bottomRightLbMin = new List <float>();
    }
Example #8
0
        private void Update(ElapsedEventArgs e)
        {
            if (testComplete)
            {
                Invalidate();
                return;
            }
            BalanceBoardState b = parent.wiiDevice.WiimoteState.BalanceBoardState;

            currentBalanceBoardX = b.CenterOfGravity.X;
            currentBalanceBoardY = b.CenterOfGravity.Y;
            // showCurrentPosition();

            if (!started)
            {
                Invalidate();
                return;
            }
            if (currentTime == new DateTime(0))
            {
                currentTime = e.SignalTime;
            }
            else
            {
                remainingTime -= e.SignalTime - currentTime;
                currentTime    = e.SignalTime;
                int secondsLeft = remainingTime.Seconds;
                if (remainingTime.Milliseconds > 0)
                {
                    secondsLeft += 1;
                }

                if (waitingToStart)
                {
                    Timer.Text = "Starting in " + secondsLeft + " Seconds";
                    if (remainingTime <= new TimeSpan(0))
                    {
                        waitingToStart = false;
                        remainingTime  = testTime;
                    }
                    Timer.Invalidate();
                }
                else
                {
                    Timer.Text = "Test Started.  Time Remaining: " + secondsLeft + " Seconds";
                    Timer.Invalidate();

                    if (remainingTime <= new TimeSpan(0))
                    {
                        Timer.Text              = "Test Complete";
                        waitingToStart          = false;
                        remainingTime           = testTime;
                        infoUpdateTimer.Enabled = false;
                        Save.Enabled            = true;
                        Done.Enabled            = true;
                        testComplete            = true;
                        trackBar1.SetRange(0, data.Count);
                        trackBar1.Value = data.Count;
                    }
                    else
                    {
                        collectDataPoint();
                    }
                }
            }
            this.Invalidate();
        }
Example #9
0
        void OnWiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            if (game == true)
            {
                BalanceBoardState bbs = e.WiimoteState.BalanceBoardState;
                if (bbs.WeightKg < 5)
                {
                    xza      = 1302 / 2 - 35; //(Canvas.Width/2) - (ballWidth /2)
                    yza      = 740 / 2 - 35;  //(Canvas.Height/2) - (ballHeight /2)
                    leftsize = 0;
                }
                else
                {
                    xza = bbs.CenterOfGravity.X * (651 / 35) * 2 + 1302 / 2 - 35; //*(Canvas.Width/ballWidth)*倍率 + (Canvas.Width/2) - (ballWidth /2)
                    yza = bbs.CenterOfGravity.Y * (370 / 35) * 3 + 740 / 2 - 35;  //*(Canvas.Height/ballHeight)*倍率 + (Canvas.Height/2) - (ballHeight /2)
                    //                  leftsize = 700 - (350 + 14 * (bbs.CenterOfGravity.X));
                    leftsize = (1 - (xza / 790)) * 700;
                    if (xza > 1173) //枠内に収まるように
                    {
                        xza = 1173; // 1243 - 70 bdraw.Width - ballSize
                    }
                    else if (xza < 0)
                    {
                        xza = 0;
                    }

                    if (yza > 605)
                    {
                        yza = 605;// 675 - 70 bdraw.Height - ballSize
                    }
                    else if (yza < 0)
                    {
                        yza = 0;
                    }
                }
                //                * (pictureBox1.Width / ballWidth)) + (pictureBox1.Width / 2) - (ballWidth / 2)


                Dispatcher.Invoke(new Action(() =>
                {
                    //////////////重心の表示
                    if (this.drawingBalance != null)
                    {
                        this.beback.Children.Remove(this.drawingBalance);
                    }
                    this.drawingBalance = new Ellipse()
                    {
                        Fill = System.Windows.Media.Brushes.LimeGreen, Width = 70, Height = 70, Margin = new Thickness(xza, yza, 0, 0)
                    };                                                                                                                                                      //重心のマーク
                    this.beback.Children.Add(this.drawingBalance);



                    //tar1.Content = ("1ターゲット" + ta[0,0] + "," + ta[0,1]);
                    //zyuu.Content = ("2ターゲット" + ta[1, 0] + "," + ta[1, 1]);
                    atari(ta[0, 0], ta[0, 1], 1);
                    atari(ta[1, 0], ta[1, 1], 2);
                    atari(ta[2, 0], ta[2, 1], 3);
                    atari(ta[3, 0], ta[3, 1], 4);
                    atari(ta[4, 0], ta[4, 1], 5);



                    if (target1 != null)
                    {
                        this.beback.Children.Remove(this.target1);
                    }

                    //DrawingTarget = new Rectangle() { Fill = System.Windows.Media.Brushes.LightGray, Width =100, Height =100, Margin = new Thickness(0,0), };
                    this.beback.Children.Add(this.target1);

                    /*        double hlength = 35 + 44; //重心半径 - 標的半径
                     *      double xlength = xza - ta[0, 0]; //重心X座標 - 標的X座標
                     *      double ylength = yza - ta[0, 1]; //重心Y座標 - 標的Y座標
                     *
                     *      if (hlength * hlength >= xlength * xlength + ylength * ylength && target1.IsEnabled == true)
                     *      {
                     *          target1.IsEnabled = false;
                     *          target1.Background = Brushes.Yellow;
                     *          ctarget--;
                     *
                     *      }
                     */
                    //count.Content = "残り個数   " + ctarget + "個";
                    //count.Content = "残り個数 4個";

                    //////////////////////////終了条件
                    if (ctarget == 0 && target5.IsEnabled == false)
                    {
                        //this.drawingLabel1 = new Label() { Content = "", Width = 841, Height = 445, Margin = new Thickness(210, 176, 0, 0), FontSize = 350, Foreground = System.Windows.Media.Brushes.Red, FontWeight = FontWeights.Bold, HorizontalContentAlignment = HorizontalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center };
                        //this.beback.Children.Add(this.drawingLabel1);
                        game = false;

                        PlaySound("clear.wav");
                        //drawingLabel1.Content = "クリア";
                        //drawingLabel1.Foreground = System.Windows.Media.Brushes.Black;
                        dispatcharTimer.Stop();
                        startbutton.Content = "ストップ";



                        if (!Application.Current.Properties["u_id"].ToString().Equals("guest"))
                        {
                            DBConnect.Connect("kasiihara.db");
                            SQL = "INSERT INTO t_userrecord (user_id,traintype,trainclear_date)VALUES('" + user_id + "','ターゲットゲーム','" + DateTime.Now.ToString() + "')";
                            DBConnect.ExecuteReader(SQL);
                            SQL = "SELECT * FROM t_userrecord ORDER BY userrecord_id DESC";
                            DBConnect.ExecuteReader(SQL);
                            DBConnect.Reader.Read();
                            SQL = "INSERT INTO t_targetgame (userrecord_id,result_time)VALUES('" + DBConnect.Reader[0] + "', '" + time_t + "')";
                            DBConnect.ExecuteReader(SQL);
                            DBConnect.Dispose();
                        }

                        dispatcharTimer          = new DispatcherTimer(DispatcherPriority.Normal);
                        dispatcharTimer.Interval = new TimeSpan(0, 0, 1);
                        dispatcharTimer.Tick    += new EventHandler(dispatcharTimer_Tick);



                        target1.IsEnabled = true;
                        target2.IsEnabled = true;
                        target3.IsEnabled = true;
                        target4.IsEnabled = true;
                        target5.IsEnabled = true;



                        Application.Current.Properties["ftgamemodename"] = "ターゲットゲーム";

                        Application.Current.Properties["ftresult"] = time_t;

                        startbutton.Content = "スタート";

                        FTGameResult s = new FTGameResult(this.start, this.back);
                        s.Title        = "FTGameResult";
                        s.ShowDialog();
                    }
                }));
            }
        }
        static void Main(string[] args)
        {
            var sw = new System.Diagnostics.Stopwatch();

            wiimote.Connect();
            Console.WriteLine("ESC:STOP");
            String now = DateTime.Now.ToString("MMddHHmmss");

            Console.WriteLine("Start Body Tracking App!");

            //接続されている機器の数をチェック
            if (Device.GetInstalledCount() == 0)
            {
                Console.WriteLine("No k4a devices attached!");
                Console.ReadKey();
                return;
            }

            //■デバイスを開いてカメラを起動する
            Device device = null;

            // Open the first plugged in Kinect device
            try
            {
                //1台目に接続
                device = Device.Open(0);
            }
            catch (AzureKinectOpenDeviceException ex)
            {
                Console.WriteLine("Failed to open k4a device!!");
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace.ToString());
                Console.ReadKey();
                return;
            }
            // Start camera. Make sure depth camera is enabled.
            var deviceConfig = new DeviceConfiguration();

            deviceConfig.DepthMode       = DepthMode.NFOV_Unbinned;
            deviceConfig.ColorResolution = ColorResolution.Off;
            try
            {
                device.StartCameras(deviceConfig);
            }
            catch (AzureKinectStartCamerasException ex)
            {
                Console.WriteLine("Failed to open k4a device!!");
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace.ToString());
                device.Dispose();
                Console.ReadKey();
                return;
            }
            using (StreamWriter file = new StreamWriter(@"C:/Users/hackathon/Desktop/" + now + ".csv", true))
            {
                file.Write("Time[ms],PELVIS_X,PELVIS_Y,PELVIS_Z," +
                           "SPINE_NAVAL_X,SPINE_NAVAL_Y,SPINE_NAVAL_Z," +
                           "SPINE_CHEST_X,SPINE_CHEST_Y,SPINE_CHEST_Z," +
                           "NECK_X,NECK_Y,NECK_Z," +
                           "CLAVICLE_LEFT_X,CLAVICLE_LEFT_Y,CLAVICLE_LEFT_Z," +
                           "SHOULDER_LEFT_X,SHOULDER_LEFT_Y,SHOULDER_LEFT_Z," +
                           "ELBOW_LEFT_X,ELBOW_LEFT_Y,ELBOW_LEFT_Z," +
                           "WRIST_LEFT_X,WRIST_LEFT_Y,WRIST_LEFT_Z," +
                           "HAND_LEFT_X,HAND_LEFT_Y,HAND_LEFT_Z," +
                           "HANDTIP_LEFT_X,HANDTIP_LEFT_Y,HANDTIP_LEFT_Z," +
                           "THUMB_LEFT_X,THUMB_LEFT_Y,THUMB_LEFT_Z," +
                           "CLAVICLE_RIGHT_X,CLAVICLE_RIGHT_Y,CLAVICLE_RIGHT_Z," +
                           "SHOULDER_RIGHT_X,SHOULDER_RIGHT_Y,SHOULDER_RIGHT_Z," +
                           "ELBOW_RIGHT_X,ELBOW_RIGHT_Y,ELBOW_RIGHT_Z," +
                           "WRIST_RIGHT_X,WRIST_RIGHT_Y,WRIST_RIGHT_Z," +
                           "HAND_RIGHT_X,HAND_RIGHT_Y,HAND_RIGHT_Z," +
                           "HANDTIP_RIGHT_X,HANDTIP_RIGHT_Y,HANDTIP_RIGHT_Z," +
                           "THUMB_RIGHT_X,THUMB_RIGHT_Y,THUMB_RIGHT_Z," +
                           "HIP_LEFT_X,HIP_LEFT_Y,HIP_LEFT_Z," +
                           "KNEE_LEFT_X,KNEE_LEFT_Y,KNEE_LEFT_Z," +
                           "ANKLE_LEFT_X,ANKLE_LEFT_Y,ANKLE_LEFT_Z," +
                           "FOOT_LEFT_X,FOOT_LEFT_Y,FOOT_LEFT_Z," +
                           "HIP_RIGHT_X,HIP_RIGHT_Y,HIP_RIGHT_Z," +
                           "KNEE_RIGHT_X,KNEE_RIGHT_Y,KNEE_RIGHT_Z," +
                           "ANKLE_RIGHT_X,ANKLE_RIGHT_Y,ANKLE_RIGHT_Z," +
                           "FOOT_RIGHT_X,FOOT_RIGHT_Y,FOOT_RIGHT_Z," +
                           "HEAD_X,HEAD_Y,HEAD_Z," +
                           "NOSE_X,NOSE_Y,NOSE_Z," +
                           "EYE_LEFT_X,EYE_LEFT_Y,EYE_LEFT_Z," +
                           "EAR_LEFT_X,EAR_LEFT_Y,EAR_LEFT_Z," +
                           "EYE_RIGHT_X,EYE_RIGHT_Y,EYE_RIGHT_Z," +
                           "EAR_RIGHT_X,EAR_RIGHT_Y,EAR_RIGHT_Z," +
                           "Weight(kg),B_TopLeft(kg),B_TopRight(kg),B_UnderLeft(kg),B_UnderRight(kg),B_Center_X(cm),B_Center_Y(cm)" +
                           "\n");
            }


            //■トラッカーを作成する
            var calibration   = device.GetCalibration(deviceConfig.DepthMode, deviceConfig.ColorResolution);
            var trackerConfig = new TrackerConfiguration();

            trackerConfig.ProcessingMode    = TrackerProcessingMode.Gpu;    //GPUがない場合はCpuを指定
            trackerConfig.SensorOrientation = SensorOrientation.Default;
            using (var tracker = Tracker.Create(calibration, trackerConfig))
            {
                var wantExit = false;

                while (!wantExit)
                {
                    //■Azure Kinect デバイスからキャプチャを取得する
                    // Capture a depth frame
                    using (Capture sensorCapture = device.GetCapture())
                    {
                        // Queue latest frame from the sensor.
                        tracker.EnqueueCapture(sensorCapture);
                    }

                    // Try getting latest tracker frame.
                    using (Frame frame = tracker.PopResult(TimeSpan.Zero, throwOnTimeout: false))
                    {
                        if (frame != null)
                        {
                            if (frame.NumberOfBodies > 0)
                            {
                                var skeleton          = frame.GetBodySkeleton(0);
                                BalanceBoardState bbs = wiimote.WiimoteState.BalanceBoardState;
                                using (StreamWriter file = new StreamWriter(@"C:/Users/hackathon/Desktop/" + now + ".csv", true))
                                {
                                    sw.Start();
                                    file.Write(sw.ElapsedMilliseconds + ",");
                                    for (int i = 0; i < 32; i += 1)
                                    {
                                        file.Write(skeleton.GetJoint(i).Position.X + "," + skeleton.GetJoint(i).Position.Y + "," + skeleton.GetJoint(i).Position.Z + ",");
                                    }

                                    file.Write(bbs.WeightKg + "," + bbs.SensorValuesKg.TopLeft / 4 + "," + bbs.SensorValuesKg.TopRight / 4 + "," + bbs.SensorValuesKg.BottomLeft / 4 + "," + bbs.SensorValuesKg.BottomRight / 4 + "," + bbs.CenterOfGravity.X + "," + bbs.CenterOfGravity.Y);
                                    file.Write("\n");
                                    Console.WriteLine(bbs.WeightKg + "[kg]");
                                }
                            }
                        }
                    }
                    //Escキーで終了
                    if (Console.KeyAvailable)
                    {
                        var outChar = Console.ReadKey().Key.ToString();
                        if (outChar == "Escape")
                        {
                            return;
                        }
                    }
                }
            }
            device.StopCameras();
            device.Dispose();
        }
Example #11
0
        void OnWiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            ballsize  = (int)Application.Current.Properties["ballsize"];
            ballspeed = (int)Application.Current.Properties["ballspeed"];
            if (game == true)
            {
                BalanceBoardState bbs = e.WiimoteState.BalanceBoardState;
                if (bbs.WeightKg < 5)
                {
                    xza      = 600 - 35; //(Canvas.Width/2) - (ballWidth /2)
                    yza      = 337 - 35; //(Canvas.Height/2) - (ballHeight /2)
                    leftsize = 0;
                }
                else
                {
                    xza = bbs.CenterOfGravity.X * 17 * 2 + 600 - 35;  //*(Canvas.Width/ballWidth)*倍率 + (Canvas.Width/2) - (ballWidth /2)
                    yza = bbs.CenterOfGravity.Y * 9.6 * 3 + 337 - 35; //*(Canvas.Height/ballHeight)*倍率 + (Canvas.Height/2) - (ballHeight /2)
                    //                  leftsize = 700 - (350 + 14 * (bbs.CenterOfGravity.X));
                    leftsize = (1 - (xza / 790)) * 700;
                    if (xza > 978) //枠内に収まるように
                    {
                        xza = 978; // 1200 - 222 bdraw.Width - ballSize
                    }
                    else if (xza < 0)
                    {
                        xza = 0;
                    }

                    if (yza > 605)
                    {
                        yza = 605;// 675 - 70 bdraw.Height - ballSize
                    }
                    else if (yza < 0)
                    {
                        yza = 0;
                    }
                }
                //                * (pictureBox1.Width / ballWidth)) + (pictureBox1.Width / 2) - (ballWidth / 2)



                Dispatcher.Invoke(new Action(() =>
                {
                    //////////////重心の表示
                    if (this.drawingBalance != null)
                    {
                        this.beback.Children.Remove(this.drawingBalance);
                    }
                    ImageBrush kago  = new ImageBrush();
                    string abskago   = System.IO.Path.GetFullPath("Image/kago.png"); //絶対パスを取得
                    kago.ImageSource = new BitmapImage(new Uri(abskago));            //イメージソースに代入

                    this.drawingBalance = new Rectangle()
                    {
                        Fill = kago, Width = 222, Height = 45, Margin = new Thickness(xza, 630, 0, 0),
                    };
                    this.beback.Children.Add(this.drawingBalance);

                    int randtama = cRandom.Next(11);



                    /////////////玉(イチゴ)

                    ImageBrush straw  = new ImageBrush();
                    string absstraw   = System.IO.Path.GetFullPath("Image/strawberry.png"); //絶対パスを取得
                    straw.ImageSource = new BitmapImage(new Uri(absstraw));                 //イメージソースに代入

                    y += ballspeed;                                                         //落下する玉の速さ
                    if (this.drawingEllipse != null)
                    {
                        this.beback.Children.Remove(this.drawingEllipse);
                    }

                    if (y > 675)
                    {
                        x = randtama * 100;
                        y = 0;
                    }

                    this.drawingEllipse = new Ellipse()
                    {
                        Fill = straw, Width = ballsize, Height = ballsize, Margin = new Thickness(x, y, 0, 0)
                    };
                    this.beback.Children.Add(this.drawingEllipse);

                    if (this.drawingLabel != null)
                    {
                        this.beback.Children.Remove(this.drawingLabel);
                    }

                    this.drawingLabel = new Label()
                    {
                        Width = ballsize, Height = ballsize, Margin = new Thickness(x, y, 0, 0), FontSize = 60, Foreground = System.Windows.Media.Brushes.White, FontWeight = FontWeights.Bold, HorizontalContentAlignment = HorizontalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center
                    };
                    this.beback.Children.Add(this.drawingLabel);


                    /////////////玉2(芋虫)
                    ImageBrush caterpillar  = new ImageBrush();
                    string abscat           = System.IO.Path.GetFullPath("Image/caterpillar.png"); //絶対パスを取得
                    caterpillar.ImageSource = new BitmapImage(new Uri(abscat));                    //イメージソースに代入
                    y1 += ballspeed;
                    if (this.drawingEllipse1 != null)
                    {
                        this.beback.Children.Remove(this.drawingEllipse1);
                    }

                    if (y1 > 675)
                    {
                        x1 = randtama * 100;
                        y1 = 0;
                    }

                    this.drawingEllipse1 = new Ellipse()
                    {
                        Fill = caterpillar, Width = ballsize, Height = ballsize, Margin = new Thickness(x1, y1, 0, 0)
                    };
                    this.beback.Children.Add(this.drawingEllipse1);

                    if (this.drawingLabel1 != null)
                    {
                        this.beback.Children.Remove(this.drawingLabel1);
                    }

                    this.drawingLabel1 = new Label()
                    {
                        Width = ballsize, Height = ballsize, Margin = new Thickness(x1, y1, 0, 0), FontSize = 60, Foreground = System.Windows.Media.Brushes.White, FontWeight = FontWeights.Bold, HorizontalContentAlignment = HorizontalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center
                    };
                    this.beback.Children.Add(this.drawingLabel1);


                    /////////////玉3(ばなな)

                    ImageBrush banana  = new ImageBrush();
                    string absbanana   = System.IO.Path.GetFullPath("Image/banana.png");  //絶対パスを取得
                    banana.ImageSource = new BitmapImage(new Uri(absbanana));
                    y2 += ballspeed;
                    if (this.drawingEllipse2 != null)
                    {
                        this.beback.Children.Remove(this.drawingEllipse2);
                    }

                    if (y2 > 675)
                    {
                        x2 = randtama * 100;
                        y2 = 0;
                    }

                    this.drawingEllipse2 = new Ellipse()
                    {
                        Fill = banana, Width = ballsize, Height = ballsize, Margin = new Thickness(x2, y2, 0, 0)
                    };
                    this.beback.Children.Add(this.drawingEllipse2);

                    if (this.drawingLabel2 != null)
                    {
                        this.beback.Children.Remove(this.drawingLabel2);
                    }

                    this.drawingLabel2 = new Label()
                    {
                        Width = ballsize, Height = ballsize, Margin = new Thickness(x2, y2, 0, 0), FontSize = 60, Foreground = Brushes.White, FontWeight = FontWeights.Bold, HorizontalContentAlignment = HorizontalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center
                    };
                    this.beback.Children.Add(this.drawingLabel2);

                    ///////////////Ellipse,Ellipse1当たり判定 y1は7の倍数の速さで動いているから585の数値にならないy1=588になる
                    ///585%y=0ならよい 585%y1=1なら-1する
                    if (ballspeed == 3)
                    {
                        if (xza < x + ballsize / 2 && xza + 222 > x + ballsize / 2 && (630 - ballsize / 2) == y + ballsize / 2 - 1)
                        {
                            target++;
                            PlaySound("fall_up.wav");
                        }
                        else if (xza < x1 + ballsize / 2 && xza + 222 > x1 + ballsize / 2 && (630 - ballsize / 2) == y1 + ballsize / 2 - 1)
                        {
                            target--;
                            PlaySound("fall_down.wav");
                        }
                        else if (xza < x2 + ballsize / 2 && xza + 222 > x2 + ballsize / 2 && (630 - ballsize / 2) == y2 + ballsize / 2 - 1)
                        {
                            target += 3;
                            PlaySound("fall_up.wav");
                        }
                    }

                    else
                    {
                        if (xza < x + ballsize / 2 && xza + 222 > x + ballsize / 2 && (630 - ballsize / 2) == y + ballsize / 2 - ballspeed)
                        {
                            target++;
                            PlaySound("fall_up.wav");
                        }
                        else if (xza < x1 + ballsize / 2 && xza + 222 > x1 + ballsize / 2 && (630 - ballsize / 2) == y1 + ballsize / 2 - ballspeed)
                        {
                            target--;
                            PlaySound("fall_down.wav");
                        }
                        else if (xza < x2 + ballsize / 2 && xza + 222 > x2 + ballsize / 2 && (630 - ballsize / 2) == y2 + ballsize / 2 - ballspeed)
                        {
                            target += 3;
                            PlaySound("fall_up.wav");
                        }
                    }

                    if (xza < x + ballsize / 2 && xza + 222 > x + ballsize / 2 && (630 - ballsize / 2) <= y + ballsize / 2 - 25)
                    {
                        drawingEllipse.Fill = System.Windows.Media.Brushes.Transparent;
                        get.Foreground      = System.Windows.Media.Brushes.Red;
                        get.Content         = "+1";
                    }
                    else if (xza < x2 + ballsize / 2 && xza + 222 > x2 + ballsize / 2 && (630 - ballsize / 2) <= y2 + ballsize / 2 - 25)
                    {
                        drawingEllipse2.Fill = System.Windows.Media.Brushes.Transparent;
                        get.Foreground       = System.Windows.Media.Brushes.Yellow;
                        get.Content          = "+3";
                    }
                    else if (xza < x1 + ballsize / 2 && xza + 222 > x1 + ballsize / 2 && (630 - ballsize / 2) <= y1 + ballsize / 2 - 25)
                    {
                        drawingEllipse1.Fill = System.Windows.Media.Brushes.Transparent;
                        get.Foreground       = System.Windows.Media.Brushes.Blue;
                        get.Content          = "-1";
                    }
                    else
                    {
                        get.Content = "";
                    }


                    count.Content = "獲得点数    " + target + "点";
                    //con.Content = x1 +"\n"+ y1;
                    //count.Content = "獲得個数 7個";

                    /*
                     * A の左端 X 座標<B の右端 X 座標
                     * A の右端 X 座標> B の左端 X 座標
                     * A の上端 Y 座標 < B の下端 Y 座標
                     * A の下端 Y 座標 > B の上端 Y 座標
                     *
                     * if (xza<x+35 && xza+222>x+35 && 634 < y + 35 && 679 > y + 35)
                     * {
                     *  drawingEllipse.Fill = System.Windows.Media.Brushes.Black;
                     *
                     *  target++;
                     * }
                     *
                     * xza          < x+35
                     * xza+222      > x+35
                     * yza          < y+35
                     * yza+45       > y+35
                     */



                    /*Application.Current.Properties["ftgamemodename"] = "落下ゲーム";
                     *
                     * Application.Current.Properties["ftresult"] = target;
                     *
                     * Application.Current.Properties["ftresulttime"] = timese;*/


                    //FTGameResult s = new FTGameResult(this.start, this.back, 1);

                    //s.Title = "FTGameResult";
                    //s.ShowDialog();
                }));
            }
        }
Example #12
0
        void OnWiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
/*            BalanceBoardState bbs = e.WiimoteState.BalanceBoardState;
 *
 *          Dispatcher.Invoke(new Action(() =>
 *          {
 *              wei.Content = (int)double.Parse(bbs.WeightKg.ToString()) + cali;
 *          }));
 */
            if (train == true)
            {
                BalanceBoardState bbs = e.WiimoteState.BalanceBoardState;
                if (bbs.WeightKg < 5)
                {
                    xza      = 430 - 35;
                    yza      = 230 - 35;
                    leftsize = 0;
                }
                else
                {
                    xza = bbs.CenterOfGravity.X * 12 * 2 + 430 - 35;//*(Canvas.Width/ballWidth)*倍率 + (Canvas.Width/2) - (ballWidth /2)
                    yza = bbs.CenterOfGravity.Y * 6.6 * 3 + 230 - 35;
//                    leftsize = 700 - (350 + 14 * (bbs.CenterOfGravity.X));

                    leftsize = (1 - (xza / 790)) * 700;

                    if (xza > 790)
                    {
                        xza = 790;// 860 - 70 bdraw.Width - ballSize
                    }
                    else if (xza < 0)
                    {
                        xza = 0;
                    }

                    if (yza > 395)
                    {
                        yza = 395;// 465 - 70 bdraw.Height - ballSize
                    }
                    else if (yza < 0)
                    {
                        yza = 0;
                    }
                }
                //                * (pictureBox1.Width / ballWidth)) + (pictureBox1.Width / 2) - (ballWidth / 2)
                Dispatcher.Invoke(new Action(() =>
                {
                    wei.Content = (int)double.Parse(bbs.WeightKg.ToString()) + cali;
                    if (asi == true)
                    {
                        //////////////重心の表示
                        if (this.drawingBalance != null)
                        {
                            this.bdraw.Children.Remove(this.drawingBalance);
                        }
                        this.drawingBalance = new Ellipse()
                        {
                            Fill = System.Windows.Media.Brushes.GreenYellow, Width = 70, Height = 70, Margin = new Thickness(xza, yza, 0, 0)
                        };
                        this.bdraw.Children.Add(this.drawingBalance);

                        //////////////左足の荷重量表示
                        if (this.drawingLeftleg != null)
                        {
                            this.leftleg.Children.Remove(this.drawingLeftleg);
                        }
                        this.drawingLeftleg = new Rectangle()
                        {
                            Fill = System.Windows.Media.Brushes.GreenYellow, Width = leftleg.Width, MaxHeight = leftleg.Height, MinHeight = 0
                        };
                        if (leftsize < 0)
                        {
                            this.drawingLeftleg.Height = 0;
                        }
                        else if (leftsize > leftleg.Height)
                        {
                            this.drawingLeftleg.Height = leftleg.Height;
                        }
                        else
                        {
                            this.drawingLeftleg.Height = leftsize;
                        }
                        if ((((leftsize / leftleg.Height) * 100) > 70) || (((leftsize / leftleg.Height) * 100) < 30))
                        {
                            this.drawingLeftleg.Fill = System.Windows.Media.Brushes.Red;
                        }
                        this.drawingLeftleg.Margin = new Thickness(0, leftleg.Height - leftsize, 0, 0);
                        this.leftleg.Children.Add(this.drawingLeftleg);

                        /////////////////右足の荷重量表示

                        if (this.drawingRightleg != null)
                        {
                            this.rightleg.Children.Remove(this.drawingRightleg);
                        }
                        this.drawingRightleg = new Rectangle()
                        {
                            Fill = System.Windows.Media.Brushes.GreenYellow, Width = rightleg.Width, MaxHeight = rightleg.Height, MinHeight = 0
                        };
                        if (rightleg.Height - leftsize < 0)
                        {
                            this.drawingRightleg.Height = 0;
                        }
                        else if (rightleg.Height - leftsize > rightleg.Height)
                        {
                            this.drawingRightleg.Height = rightleg.Height;
                        }
                        else if (leftsize == 0)
                        {
                            this.drawingRightleg.Height = 0;
                        }
                        else
                        {
                            this.drawingRightleg.Height = rightleg.Height - leftsize;
                        }
                        if ((((leftsize / leftleg.Height) * 100) > 70) || (((leftsize / leftleg.Height) * 100) < 30))
                        {
                            this.drawingRightleg.Fill = System.Windows.Media.Brushes.Red;
                        }
                        this.drawingRightleg.Margin = new Thickness(0, rightleg.Height - (rightleg.Height - leftsize), 0, 0);
                        this.rightleg.Children.Add(this.drawingRightleg);



                        leftpar.Text = ((int)((leftsize / leftleg.Height) * 100)).ToString() + "%";
                        if ((int)((leftsize / leftleg.Height) * 100) == 0)
                        {
                            rightpar.Text = "0%";
                        }
                        else
                        {
                            rightpar.Text = (100 - ((int)((leftsize / leftleg.Height) * 100))).ToString() + "%";
                        }



                        if (trainstate == true)
                        {
                            if (asi == true)
                            {
                                if ((((leftsize / leftleg.Height) * 100) > 45) && ((leftsize / leftleg.Height) * 100) < 55)
                                {
                                    if (oto == true && han == 6)
                                    {
                                        PlaySound("100.wav");
                                        oto = false;
                                        han = 0;
                                        if (dline == false)
                                        {
                                            dline = true;
                                        }
                                    }
                                }
                                else if (((((leftsize / leftleg.Height) * 100) > 55) && ((leftsize / leftleg.Height) * 100) < 65) || ((((leftsize / leftleg.Height) * 100) > 35) && ((leftsize / leftleg.Height) * 100) < 45))
                                {
                                    if (oto == true && than == 2)
                                    {
                                        PlaySound("200.wav");
                                        oto  = false;
                                        than = 0;
                                        if (dline == false)
                                        {
                                            dline = true;
                                        }
                                    }
                                }
                                else if (((((leftsize / leftleg.Height) * 100) > 65) && ((leftsize / leftleg.Height) * 100) < 70) || ((((leftsize / leftleg.Height) * 100) > 30) && ((leftsize / leftleg.Height) * 100) < 35))
                                {
                                    if (oto == true && trhan == 1)
                                    {
                                        PlaySound("300.wav");
                                        oto   = false;
                                        trhan = 0;
                                        if (dline == false)
                                        {
                                            dline = true;
                                        }
                                    }
                                }
                                else if ((((leftsize / leftleg.Height) * 100) > 70) || (((leftsize / leftleg.Height) * 100) < 30))
                                {
                                    if (oto == true && dline == true)
                                    {
                                        PlaySound("bubbu.wav");
                                        dline = false;
                                        oto   = false;
                                    }
                                }
                            }
                        }
                    }
                    else if (asi == false)
                    {
                        weighpar = ((((double)bbs.WeightKg) / Weight) * 100);
                        /////////////////右足の荷重量表示
                        if (this.drawingRightleg != null)
                        {
                            this.rightleg.Children.Remove(this.drawingRightleg);
                        }
                        this.drawingRightleg = new Rectangle()
                        {
                            Fill = System.Windows.Media.Brushes.GreenYellow, Width = rightleg.Width, MaxHeight = rightleg.Height, MinHeight = 0
                        };

                        if (weighpar < 0)
                        {
                            this.drawingRightleg.Height = 0;
                        }
                        else if (weighpar > rightleg.Height)
                        {
                            this.drawingRightleg.Height = rightleg.Height;
                        }
                        else
                        {
                            this.drawingRightleg.Height = rightleg.Height * (weighpar / 100);
                        }
                        this.drawingRightleg.Margin = new Thickness(0, rightleg.Height * ((100 - weighpar) / 100), 0, 0);

                        if ((trb == true && weighpar > 33) || (twb == true && weighpar > 50) || (trwb == true && weighpar > 66))
                        {
                            this.drawingRightleg.Fill = System.Windows.Media.Brushes.Red;
                        }

                        this.rightleg.Children.Add(this.drawingRightleg);


                        if ((int)((leftsize / leftleg.Height) * 100) == 0)
                        {
                            rightpar.Text = "0%";
                        }
                        else
                        {
                            rightpar.Text = (int)weighpar + "%";
                        }


                        if (trainstate == true)
                        {
                            if (trb == true || twb == true || trwb == true)
                            {
                                if (((trb == true) && (weighpar < 23)) || ((twb == true) && (weighpar < 35)) || ((trwb == true) && (weighpar < 46)))
                                {
                                    if (oto == true && han == 6)
                                    {
                                        PlaySound("100.wav");
                                        oto = false;
                                        han = 0;
                                        if (dline == false)
                                        {
                                            dline = true;
                                        }
                                    }
                                }
                                else if (((trb == true) && ((weighpar > 23) && (weighpar < 30))) || ((twb == true) && ((weighpar > 35) && (weighpar < 45))) || ((trwb == true) && ((weighpar > 46) && (weighpar < 60))))
                                {
                                    if (oto == true && than == 2)
                                    {
                                        PlaySound("200.wav");
                                        oto  = false;
                                        than = 0;
                                        if (dline == false)
                                        {
                                            dline = true;
                                        }
                                    }
                                }
                                else if (((trb == true) && ((weighpar > 30) && (weighpar < 33))) || ((twb == true) && ((weighpar > 45) && (weighpar < 50))) || ((trwb == true) && ((weighpar > 60) && (weighpar < 66))))
                                {
                                    if (oto == true && trhan == 1)
                                    {
                                        PlaySound("300.wav");
                                        oto   = false;
                                        trhan = 0;
                                        if (dline == false)
                                        {
                                            dline = true;
                                        }
                                    }
                                }
                                else if (((trb == true) && (weighpar > 33)) || ((twb == true) && (weighpar > 50)) || ((trwb == true) && (weighpar > 66)))
                                {
                                    if (oto == true && dline == true)
                                    {
                                        PlaySound("bubbu.wav");
                                        dline = false;
                                        oto   = false;
                                    }
                                }
                            }
                        }
                    }
                }));
            }
        }
        void OnWiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            if (game == true)
            {
                BalanceBoardState bbs = e.WiimoteState.BalanceBoardState;
                if (bbs.WeightKg < 5)
                {
                    xza      = 621 - 35; //(Canvas.Width/2) - (ballWidth /2)
                    yza      = 337 - 35; //(Canvas.Height/2) - (ballHeight /2)
                    leftsize = 0;
                }
                else
                {
                    xza = bbs.CenterOfGravity.X * 18 * 3.5 + 621 - 35; //*(Canvas.Width/ballWidth)*倍率 + (Canvas.Width/2) - (ballWidth /2)
                    yza = bbs.CenterOfGravity.Y * 9.6 * 3 + 350 - 35;  //*(Canvas.Height/ballHeight)*倍率 + (Canvas.Height/2) - (ballHeight /2)
                    //                  leftsize = 700 - (350 + 14 * (bbs.CenterOfGravity.X));
                    leftsize = (1 - (xza / 790)) * 700;
                    if (xza > 1173) //枠内に収まるように
                    {
                        xza = 1173; // 1243 - 70 bdraw.Width - ballSize
                    }
                    else if (xza < 0)
                    {
                        xza = 0;
                    }

                    if (yza > 605)
                    {
                        yza = 605;// 675 - 70 bdraw.Height - ballSize
                    }
                    else if (yza < 0)
                    {
                        yza = 0;
                    }
                }
                //                * (pictureBox1.Width / ballWidth)) + (pictureBox1.Width / 2) - (ballWidth / 2)


                Dispatcher.Invoke(new Action(() =>
                {
                    count.Content       = "獲得個数     " + cnt + "個";
                    startbutton.Content = "ストップ";
                    gameflg             = true;
                    //////////////重心の表示
                    if (this.drawingBalance != null)
                    {
                        this.beback.Children.Remove(this.drawingBalance);
                    }
                    this.drawingBalance = new Ellipse()
                    {
                        Fill = System.Windows.Media.Brushes.LimeGreen, Width = 70, Height = 70, Margin = new Thickness(xza, yza, 0, 0)
                    };                                                                                                                                                      //重心のマーク
                    this.beback.Children.Add(this.drawingBalance);


                    atari(ta1[play_count, 0], ta1[play_count, 1], 1);
                    atari(ta2[play_count, 0], ta2[play_count, 1], 2);
                    atari(ta3[play_count, 0], ta3[play_count, 1], 3);
                    atari(ta4[play_count, 0], ta4[play_count, 1], 4);
                    atari(ta5[play_count, 0], ta5[play_count, 1], 5);



                    //////////////////////////終了条件
                    if (ctarget == 0)
                    {
                        this.beback.Children.Remove(this.target1);
                        this.beback.Children.Remove(this.target2);
                        this.beback.Children.Remove(this.target3);
                        this.beback.Children.Remove(this.target4);
                        this.beback.Children.Remove(this.target5);



                        //drawingLabel1.Content = "クリア";
                        //drawingLabel1.Foreground = System.Windows.Media.Brushes.Black;

                        target1.IsEnabled = true;
                        target2.IsEnabled = true;
                        target3.IsEnabled = true;
                        target4.IsEnabled = true;
                        target5.IsEnabled = true;

                        play_count++;
                        if (play_count > 6)
                        {
                            play_count = 0;
                        }

                        Target_Placement(play_count, play_count);


                        ctarget = 5;



                        if (!Application.Current.Properties["u_id"].ToString().Equals("guest"))
                        {
                            DBConnect.Connect("kasiihara.db");
                            SQL = "INSERT INTO t_userrecord (user_id,traintype,trainclear_date)VALUES('" + user_id + "','ターゲットゲーム','" + DateTime.Now.ToString() + "')";
                            DBConnect.ExecuteReader(SQL);
                            SQL = "SELECT * FROM t_userrecord ORDER BY userrecord_id DESC";
                            DBConnect.ExecuteReader(SQL);
                            DBConnect.Reader.Read();
                            SQL = "INSERT INTO t_targetgame (userrecord_id,result_time)VALUES('" + DBConnect.Reader[0] + "', '" + time_t + "')";
                            DBConnect.ExecuteReader(SQL);
                            DBConnect.Dispose();
                        }

                        dispatcharTimer          = new DispatcherTimer(DispatcherPriority.Normal);
                        dispatcharTimer.Interval = new TimeSpan(0, 0, 1);
                        dispatcharTimer.Tick    += new EventHandler(dispatcharTimer_Tick);



                        Application.Current.Properties["ftgamemodename"] = "ターゲットゲーム";

                        Application.Current.Properties["ftresult"] = time_t;

                        startbutton.Content = "スタート";
                    }
                }));
            }
        }
Example #14
0
        void OnWiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            if (game == true)
            {
                BalanceBoardState bbs = e.WiimoteState.BalanceBoardState;
                if (bbs.WeightKg < 5)
                {
                    xza      = 600 - 35; //(Canvas.Width/2) - (ballWidth /2)
                    yza      = 337 - 35; //(Canvas.Height/2) - (ballHeight /2)
                    leftsize = 0;
                }
                else
                {
                    xza = bbs.CenterOfGravity.X * 17 * 2 + 600 - 35;  //*(Canvas.Width/ballWidth)*倍率 + (Canvas.Width/2) - (ballWidth /2)
                    yza = bbs.CenterOfGravity.Y * 9.6 * 3 + 337 - 35; //*(Canvas.Height/ballHeight)*倍率 + (Canvas.Height/2) - (ballHeight /2)
                    //                  leftsize = 700 - (350 + 14 * (bbs.CenterOfGravity.X));
                    leftsize = (1 - (xza / 790)) * 700;
                    if (xza > 978) //枠内に収まるように
                    {
                        xza = 978; // 1200 - 222 bdraw.Width - ballSize
                    }
                    else if (xza < 0)
                    {
                        xza = 0;
                    }

                    if (yza > 605)
                    {
                        yza = 605;// 675 - 70 bdraw.Height - ballSize
                    }
                    else if (yza < 0)
                    {
                        yza = 0;
                    }
                }
                //                * (pictureBox1.Width / ballWidth)) + (pictureBox1.Width / 2) - (ballWidth / 2)



                Dispatcher.Invoke(new Action(() =>
                {
                    //////////////重心の表示
                    if (this.drawingBalance != null)
                    {
                        this.beback.Children.Remove(this.drawingBalance);
                    }
                    ImageBrush kago  = new ImageBrush();
                    string abskago   = System.IO.Path.GetFullPath("Image/kago.png"); //絶対パスを取得
                    kago.ImageSource = new BitmapImage(new Uri(abskago));            //イメージソースに代入

                    this.drawingBalance = new Rectangle()
                    {
                        Fill = kago, Width = 222, Height = 45, Margin = new Thickness(xza, 630, 0, 0),
                    };
                    this.beback.Children.Add(this.drawingBalance);

                    int randtama = cRandom.Next(11);


                    /////////////玉(イチゴ)

                    ImageBrush straw  = new ImageBrush();
                    string absstraw   = System.IO.Path.GetFullPath("Image/strawberry.png"); //絶対パスを取得
                    straw.ImageSource = new BitmapImage(new Uri(absstraw));                 //イメージソースに代入

                    //int randtama1 = cRandom1.Next(10);
                    y += ballspeed;        //落下する玉の速さ
                    if (this.drawingEllipse != null)
                    {
                        this.beback.Children.Remove(this.drawingEllipse);
                    }

                    if (y > 675)
                    {
                        x = randtama * 100;
                        y = 0;
                    }

                    this.drawingEllipse = new Ellipse()
                    {
                        Fill = straw, Width = ballsize, Height = ballsize, Margin = new Thickness(x, y, 0, 0)
                    };
                    this.beback.Children.Add(this.drawingEllipse);

                    if (this.drawingLabel != null)
                    {
                        this.beback.Children.Remove(this.drawingLabel);
                    }

                    this.drawingLabel = new Label()
                    {
                        Width = ballsize, Height = ballsize, Margin = new Thickness(x, y, 0, 0), FontSize = 60, Foreground = System.Windows.Media.Brushes.White, FontWeight = FontWeights.Bold, HorizontalContentAlignment = HorizontalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center
                    };
                    this.beback.Children.Add(this.drawingLabel);


                    /////////////玉2(芋虫)
                    ImageBrush caterpillar  = new ImageBrush();
                    string abscat           = System.IO.Path.GetFullPath("Image/caterpillar.png"); //絶対パスを取得
                    caterpillar.ImageSource = new BitmapImage(new Uri(abscat));                    //イメージソースに代入
                    y1 += ballspeed;
                    if (this.drawingEllipse1 != null)
                    {
                        this.beback.Children.Remove(this.drawingEllipse1);
                    }

                    if (y1 > 675)
                    {
                        x1 = randtama * 100;
                        y1 = 0;
                    }

                    this.drawingEllipse1 = new Ellipse()
                    {
                        Fill = caterpillar, Width = ballsize, Height = ballsize, Margin = new Thickness(x1, y1, 0, 0)
                    };
                    this.beback.Children.Add(this.drawingEllipse1);

                    if (this.drawingLabel1 != null)
                    {
                        this.beback.Children.Remove(this.drawingLabel1);
                    }

                    this.drawingLabel1 = new Label()
                    {
                        Width = ballsize, Height = ballsize, Margin = new Thickness(x1, y1, 0, 0), FontSize = 60, Foreground = System.Windows.Media.Brushes.White, FontWeight = FontWeights.Bold, HorizontalContentAlignment = HorizontalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center
                    };
                    this.beback.Children.Add(this.drawingLabel1);


                    /////////////玉3(ばなな)

                    ImageBrush banana  = new ImageBrush();
                    string absbanana   = System.IO.Path.GetFullPath("Image/banana.png");  //絶対パスを取得
                    banana.ImageSource = new BitmapImage(new Uri(absbanana));
                    y2 += ballspeed;
                    if (this.drawingEllipse2 != null)
                    {
                        this.beback.Children.Remove(this.drawingEllipse2);
                    }

                    if (y2 > 675)
                    {
                        x2 = randtama * 100;
                        y2 = 0;
                    }

                    this.drawingEllipse2 = new Ellipse()
                    {
                        Fill = banana, Width = ballsize, Height = ballsize, Margin = new Thickness(x2, y2, 0, 0)
                    };
                    this.beback.Children.Add(this.drawingEllipse2);

                    if (this.drawingLabel2 != null)
                    {
                        this.beback.Children.Remove(this.drawingLabel2);
                    }

                    this.drawingLabel2 = new Label()
                    {
                        Width = ballsize, Height = ballsize, Margin = new Thickness(x2, y2, 0, 0), FontSize = 60, Foreground = Brushes.White, FontWeight = FontWeights.Bold, HorizontalContentAlignment = HorizontalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center
                    };
                    this.beback.Children.Add(this.drawingLabel2);

                    if (ballspeed == 3)
                    {
                        if (xza < x + ballsize / 2 && xza + 222 > x + ballsize / 2 && (630 - ballsize / 2) == y + ballsize / 2 - 1)
                        {
                            target++;
                            PlaySound("fall_up.wav");
                        }
                        else if (xza < x1 + ballsize / 2 && xza + 222 > x1 + ballsize / 2 && (630 - ballsize / 2) == y1 + ballsize / 2 - 1)
                        {
                            target--;
                            PlaySound("fall_down.wav");
                        }
                        else if (xza < x2 + ballsize / 2 && xza + 222 > x2 + ballsize / 2 && (630 - ballsize / 2) == y2 + ballsize / 2 - 1)
                        {
                            target += 3;
                            PlaySound("fall_up.wav");
                        }
                    }

                    else
                    {
                        if (xza < x + ballsize / 2 && xza + 222 > x + ballsize / 2 && (630 - ballsize / 2) == y + ballsize / 2 - ballspeed)
                        {
                            target++;
                            PlaySound("fall_up.wav");
                        }
                        else if (xza < x1 + ballsize / 2 && xza + 222 > x1 + ballsize / 2 && (630 - ballsize / 2) == y1 + ballsize / 2 - ballspeed)
                        {
                            target--;
                            PlaySound("fall_down.wav");
                        }
                        else if (xza < x2 + ballsize / 2 && xza + 222 > x2 + ballsize / 2 && (630 - ballsize / 2) == y2 + ballsize / 2 - ballspeed)
                        {
                            target += 3;
                            PlaySound("fall_up.wav");
                        }
                    }

                    if (xza < x + ballsize / 2 && xza + 222 > x + ballsize / 2 && (630 - ballsize / 2) <= y + ballsize / 2 - 25)
                    {
                        drawingEllipse.Fill = System.Windows.Media.Brushes.Transparent;
                        get.Foreground      = System.Windows.Media.Brushes.Red;
                        get.Content         = "+1";
                    }
                    else if (xza < x2 + ballsize / 2 && xza + 222 > x2 + ballsize / 2 && (630 - ballsize / 2) <= y2 + ballsize / 2 - 25)
                    {
                        drawingEllipse2.Fill = System.Windows.Media.Brushes.Transparent;
                        get.Foreground       = System.Windows.Media.Brushes.Yellow;
                        get.Content          = "+3";
                    }
                    else if (xza < x1 + ballsize / 2 && xza + 222 > x1 + ballsize / 2 && (630 - ballsize / 2) <= y1 + ballsize / 2 - 25)
                    {
                        drawingEllipse1.Fill = System.Windows.Media.Brushes.Transparent;
                        get.Foreground       = System.Windows.Media.Brushes.Blue;
                        get.Content          = "-1";
                    }
                    else
                    {
                        get.Content = "";
                    }



                    count.Content = "獲得点数    " + target + "点";
                    //con.Content = x1 +"\n"+ y1;
                    //count.Content = "獲得個数 7個";

                    /*
                     * A の左端 X 座標<B の右端 X 座標
                     * A の右端 X 座標> B の左端 X 座標
                     * A の上端 Y 座標 < B の下端 Y 座標
                     * A の下端 Y 座標 > B の上端 Y 座標
                     *
                     * if (xza<x+35 && xza+222>x+35 && 634 < y + 35 && 679 > y + 35)
                     * {
                     *  drawingEllipse.Fill = System.Windows.Media.Brushes.Black;
                     *
                     *  target++;
                     * }
                     *
                     * xza          < x+35
                     * xza+222      > x+35
                     * yza          < y+35
                     * yza+45       > y+35
                     */

                    if (time_t == 0)
                    {
                        game = false;
                        PlaySound("clear.wav");
                        //countdown.Content = "クリア";
                        //countdown.Foreground = System.Windows.Media.Brushes.Black;
                        dispatcharTimer.Stop();


                        drawingLabel.Content  = "";
                        drawingLabel1.Content = "";



                        if (!Application.Current.Properties["u_id"].ToString().Equals("guest"))
                        {
                            DBConnect.Connect("kasiihara.db");
                            SQL = "INSERT INTO t_userrecord (user_id,traintype,trainclear_date)VALUES('" + user_id + "','落下ゲーム','" + DateTime.Now.ToString() + "')";
                            DBConnect.ExecuteReader(SQL);
                            SQL = "SELECT * FROM t_userrecord ORDER BY userrecord_id DESC";
                            DBConnect.ExecuteReader(SQL);
                            DBConnect.Reader.Read();
                            SQL = "INSERT INTO t_fallgame (userrecord_id,set_time,result_score)VALUES('" + DBConnect.Reader[0] + "', '" + timese + "','" + target + "')";
                            DBConnect.ExecuteReader(SQL);
                            DBConnect.Dispose();
                        }

                        dispatcharTimer          = new DispatcherTimer(DispatcherPriority.Normal);
                        dispatcharTimer.Interval = new TimeSpan(0, 0, 1);
                        dispatcharTimer.Tick    += new EventHandler(dispatcharTimer_Tick);


                        Application.Current.Properties["ftgamemodename"] = "落下ゲーム";

                        Application.Current.Properties["ftresult"] = target;

                        Application.Current.Properties["ftresulttime"] = timese;

                        startbutton.Content = "スタート";

                        FTGameResult s = new FTGameResult(this.start, this.back, 1);

                        s.Title = "FTGameResult";
                        s.ShowDialog();
                    }
                }));
            }
        }
Example #15
0
        void OnWiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            if (game == true)
            {
                BalanceBoardState bbs = e.WiimoteState.BalanceBoardState;
                if (bbs.WeightKg < 5)
                {
                    xza      = 430 - 35;
                    yza      = 230 - 35;
                    LeftSize = 0;
                }
                else
                {
                    xza = bbs.CenterOfGravity.X * 12 * 2 + 430 - 35;//*(Canvas.Width/ballWidth)*倍率 + (Canvas.Width/2) - (ballWidth /2)
                    yza = bbs.CenterOfGravity.Y * 6.6 * 3 + 230 - 35;
                    //                    leftsize = 700 - (350 + 14 * (bbs.CenterOfGravity.X));
                    LeftSize = (1 - (xza / 790)) * 700;
                    if (xza > 790)
                    {
                                       //枠内に収まるように
                        {
                            xza = 790; // 860 - 70 bdraw.Width - ballSize
                        }
                    }
                    else if (xza < 0)
                    {
                        xza = 0;
                    }

                    if (yza > 395)
                    {
                        yza = 395;// 465 - 70 bdraw.Height - ballSize
                    }
                    else if (yza < 0)
                    {
                        yza = 0;
                    }
                }
                //                * (pictureBox1.Width / ballWidth)) + (pictureBox1.Width / 2) - (ballWidth / 2)
                Dispatcher.Invoke(new Action(() =>
                {
                    //////////////重心の表示
                    if (this.DrawingBalance != null)
                    {
                        this.balancedraw.Children.Remove(this.DrawingBalance);
                    }
                    this.DrawingBalance = new Ellipse()
                    {
                        Fill = System.Windows.Media.Brushes.GreenYellow, Width = 70, Height = 70, Margin = new Thickness(xza, yza, 0, 0)
                    };                                                                                                                                                        //重心のマーク
                    this.balancedraw.Children.Add(this.DrawingBalance);

                    //////////////左足の荷重量表示
                    if (this.DrawingLeftLeg != null)
                    {
                        this.leftleg.Children.Remove(this.DrawingLeftLeg);
                    }
                    this.DrawingLeftLeg = new Rectangle()
                    {
                        Fill = System.Windows.Media.Brushes.GreenYellow, Width = leftleg.Width, MaxHeight = leftleg.Height, MinHeight = 0
                    };
                    if (LeftSize < 0)
                    {
                        this.DrawingLeftLeg.Height = 0;
                    }
                    else if (LeftSize > leftleg.Height)
                    {
                        this.DrawingLeftLeg.Height = leftleg.Height;
                    }
                    else
                    {
                        this.DrawingLeftLeg.Height = LeftSize;
                    }
                    this.DrawingLeftLeg.Margin = new Thickness(0, leftleg.Height - LeftSize, 0, 0);
                    this.leftleg.Children.Add(this.DrawingLeftLeg);

                    /////////////////右足の荷重量表示
                    if (this.DrawingRightLeg != null)
                    {
                        this.RightLeg.Children.Remove(this.DrawingRightLeg);
                    }
                    this.DrawingRightLeg = new Rectangle()
                    {
                        Fill = System.Windows.Media.Brushes.GreenYellow, Width = RightLeg.Width, MaxHeight = RightLeg.Height, MinHeight = 0
                    };
                    if (RightLeg.Height - LeftSize < 0)
                    {
                        this.DrawingRightLeg.Height = 0;
                    }
                    else if (RightLeg.Height - LeftSize > RightLeg.Height)
                    {
                        this.DrawingRightLeg.Height = RightLeg.Height;
                    }
                    else if (LeftSize == 0)
                    {
                        this.DrawingRightLeg.Height = 0;
                    }
                    else
                    {
                        this.DrawingRightLeg.Height = RightLeg.Height - LeftSize;
                    }
                    this.DrawingRightLeg.Margin = new Thickness(0, RightLeg.Height - (RightLeg.Height - LeftSize), 0, 0);
                    this.RightLeg.Children.Add(this.DrawingRightLeg);

                    //////////////////////////////////////////////

                    leftparcent.Text = ((int)((LeftSize / leftleg.Height) * 100)).ToString() + "%"; //左足荷重%
                    if ((int)((LeftSize / leftleg.Height) * 100) == 0)
                    {
                        rightparcent.Text = "0%";
                    }
                    else
                    {
                        rightparcent.Text = (100 - ((int)((LeftSize / leftleg.Height) * 100))).ToString() + "%";
                    }

                    /////////////////青い■を表示
                    if (GameState == true)
                    {
                        if (DrawingNextRight == false) //左の%表示
                        {
                            if (DrawingNextLeft != null)
                            {
                                this.next.Children.Remove(this.DrawingNextLeft);
                            }

                            this.DrawingNextLeft = new Rectangle()
                            {
                                Fill = System.Windows.Media.Brushes.Blue, Width = 50, Height = next.Height
                            };

                            this.DrawingNextLeft.Margin = new Thickness(nextx, 0, 0, 0);

                            this.next.Children.Add(this.DrawingNextLeft);
                            RightFlag.Content = "";  //黒い画面の矢印

                            LeftFlag.Content = "⬅︎"; //黒い画面の矢印

                            if ((int)((LeftSize / leftleg.Height) * 100) > (100 - line))
                            {
                                                                                         //赤い線を超えた場合
                                {
                                    PlaySound(SoundFile);
                                    DrawingNextRight = true;
                                    count++;
                                    tCount--;
                                    if (gametype == 0)
                                    {
                                                   //回数表示、スコアアタック
                                        {
                                            tim.Text = "回数:" + count + "回";
                                        }
                                    }
                                    else if (gametype == 1)// タイムアタック
                                    {
                                        cc.Text = "残り" + tCount + "回";
                                    }
                                    else //練習モード
                                    {
                                        cc.Text = "回数:" + count + "回";
                                    }
                                }
                            }
                        }
                        else if (DrawingNextRight == true)
                        {
                                                           //右の%表示
                            {
                                if (DrawingNextLeft != null)
                                {
                                    this.next.Children.Remove(this.DrawingNextLeft);
                                }

                                this.DrawingNextLeft = new Rectangle()
                                {
                                    Fill = System.Windows.Media.Brushes.Blue, Width = 50, Height = next.Height
                                };

                                this.DrawingNextLeft.Margin = new Thickness(next.Width - DrawingNextLeft.Width, 0, 0, 0);

                                this.next.Children.Add(this.DrawingNextLeft);

                                LeftFlag.Content = ""; //黒い画面の矢印


                                RightFlag.Content = "➡︎"; //黒い画面の矢印

                                if ((int)(((RightLeg.Height - LeftSize) / RightLeg.Height) * 100) > (100 - line))
                                {
                                    PlaySound(SoundFile);
                                    DrawingNextRight = false;
                                    count++;
                                    tCount--;
                                    if (gametype == 1) //タイムアタック
                                    {
                                        cc.Text = "残り" + tCount + "回";
                                    }
                                    else if (gametype == 0) //スコアアタック
                                    {
                                        tim.Text = "回数:" + count + "回";
                                    }
                                    else //練習モード
                                    {
                                        cc.Text = "回数:" + count + "回";
                                    }
                                }
                            }
                        }

                        if ((gametype == 1 && ClearCount == count) || (gametype == 0 && time_s == 0))
                        {
                                                                                                      //ゲームの終了条件
                            {
                                GameState = false;
                                PlaySound("clear.wav");
                                StopWatch.Stop();
                                dispatcharTimer.Stop();



                                if (gametype == 1)
                                {
                                               //タイムアタック時のデータベース , gametype = 1
                                    {
                                        if (!Application.Current.Properties["u_id"].ToString().Equals("guest"))
                                        {
                                            DBConnect.Connect("kasiihara.db");
                                            SQL = "INSERT INTO t_userrecord (user_id,traintype,trainclear_date)VALUES('" + user_id + "','タイムアタック','" + DateTime.Now.ToString() + "')";
                                            DBConnect.ExecuteReader(SQL);
                                            SQL = "SELECT * FROM t_userrecord ORDER BY userrecord_id DESC";
                                            DBConnect.ExecuteReader(SQL);
                                            DBConnect.Reader.Read();
                                            SQL = "INSERT INTO t_gametrain(userrecord_id,setting,clear_record,clear_line)VALUES('" + DBConnect.Reader[0] + "','" + ClearCount + "','" + time_t + "','" + lin + "')";
                                            DBConnect.ExecuteReader(SQL);
                                            DBConnect.Dispose();
                                        }

                                        //MessageBox.Show("終了です" + sw.Elapsed.Seconds + "秒");
                                        //Application.Current.Properties["sw.Elapsed.Second"] = sw.Elapsed.Seconds;
                                        Application.Current.Properties["time_t"] = time_t;
                                        //Refresh1 rf1 = new Refresh1(this.bac);


                                        tim.Text                 = "0秒";
                                        StopWatch                = new System.Diagnostics.Stopwatch();
                                        dispatcharTimer          = new DispatcherTimer(DispatcherPriority.Normal);
                                        dispatcharTimer.Interval = new TimeSpan(0, 0, 1);
                                        dispatcharTimer.Tick    += new EventHandler(dispatcharTimer_Tick);
                                        count  = 0;
                                        tCount = tCounth;
                                        nextx  = 0;
                                        time_t = 0;

                                        game = false;
                                        StartButton.Content = "スタート";

                                        GameResult w = new GameResult(this.Combo_Select, this.BackButton_Click, this.StartButton_Click);
                                        w.Title      = "GameResult";
                                        w.ShowDialog();
                                    }
                                }
                                else if (gametype == 0)//スコアタック時
                                {
                                    if (!Application.Current.Properties["u_id"].ToString().Equals("guest"))
                                    {
                                        DBConnect.Connect("kasiihara.db");
                                        SQL = "INSERT INTO t_userrecord (user_id,traintype,trainclear_date)VALUES('" + user_id + "','スコアアタック','" + DateTime.Now.ToString() + "')";
                                        DBConnect.ExecuteReader(SQL);
                                        SQL = "SELECT * FROM t_userrecord ORDER BY userrecord_id DESC";
                                        DBConnect.ExecuteReader(SQL);
                                        DBConnect.Reader.Read();
                                        SQL = "INSERT INTO t_gametrain(userrecord_id,setting,clear_record,clear_line)VALUES('" + DBConnect.Reader[0] + "','" + htimes_s + "','" + count + "','" + lin + "')";
                                        DBConnect.ExecuteReader(SQL);
                                        DBConnect.Dispose();
                                    }
                                    //MessageBox.Show("終了です" + Count + "回");
                                    Application.Current.Properties["Count"] = count;



                                    dispatcharTimer          = new DispatcherTimer(DispatcherPriority.Normal);
                                    dispatcharTimer.Interval = new TimeSpan(0, 0, 1);
                                    dispatcharTimer.Tick    += new EventHandler(dispatcharTimer_Tick);
                                    time_s = htimes_s;
                                    count  = 0;
                                    count  = 0;
                                    tCount = tCounth;
                                    nextx  = 0;
                                    time_t = 0;

                                    game = false;
                                    StartButton.Content = "スタート";


                                    GameResult w = new GameResult(this.Combo_Select, this.BackButton_Click, this.StartButton_Click);
                                    w.Title      = "GameResult";
                                    w.ShowDialog();
                                }

                                else //練習モード
                                {
                                    Application.Current.Properties["time_t"] = time_t;
                                    tim.Text                 = "0秒";
                                    StopWatch                = new System.Diagnostics.Stopwatch();
                                    dispatcharTimer          = new DispatcherTimer(DispatcherPriority.Normal);
                                    dispatcharTimer.Interval = new TimeSpan(0, 0, 1);
                                    dispatcharTimer.Tick    += new EventHandler(dispatcharTimer_Tick);
                                    count  = 0;
                                    time_t = 0;
                                }
                            }
                        }
                    }
                }));
            }
        }
Example #16
0
        void OnWiimoteChanged(object sender, WiimoteChangedEventArgs e)
        {
            if (game == true)
            {
                speed_state = Application.Current.Properties["TagSpeed"].ToString();
                size_state  = Application.Current.Properties["TagSize"].ToString();

                BalanceBoardState bbs = e.WiimoteState.BalanceBoardState;

                if (bbs.WeightKg < 5)
                {
                    xza = 1654 / 2 - 35; //(Canvas.Width/2) - (ballWidth /2)
                    yza = 700 / 2 - 35;  //(Canvas.Height/2) - (ballHeight /2)
                }
                else
                {
                    xza = bbs.CenterOfGravity.X * 1654 / 70 * 2.5 + (1654 / 2) - 35; //*(Canvas.Width/ballWidth)*倍率 + (Canvas.Width/2) - (ballWidth /2)
                    yza = bbs.CenterOfGravity.Y * 700 / 70 * 2.5 + 350 - 35;         //*(Canvas.Height/ballHeight)*倍率 + (Canvas.Height/2) - (ballHeight /2)


                    if (xza > 1644) //枠内に収まるように
                    {
                        xza = 1644; //  bdraw.Width - ballSize
                    }
                    else if (xza < 10)
                    {
                        xza = 10;
                    }

                    if (yza > 690)
                    {
                        yza = 690;//bdraw.Height - ballSize
                    }
                    else if (yza < 10)
                    {
                        yza = 10;
                    }
                }


                Dispatcher.Invoke(new Action(() =>
                {
                    //////////////重心の表示
                    if (this.drawingBalance != null)
                    {
                        this.field.Children.Remove(this.drawingBalance);
                    }


                    this.drawingBalance = new Ellipse()
                    {
                        Fill = System.Windows.Media.Brushes.LimeGreen, Width = 70, Height = 70, Margin = new Thickness(xza, yza, 0, 0)
                    };                                                                                                                                                      //重心のマーク
                    this.field.Children.Add(this.drawingBalance);



                    if (this.Enemy != null)
                    {
                        this.field.Children.Remove(this.Enemy);
                    }

                    //敵(鬼)を表示
                    ImageBrush enemy  = new ImageBrush();
                    string abspath    = System.IO.Path.GetFullPath("Image/akaoni.png"); //絶対パスを取得
                    enemy.ImageSource = new BitmapImage(new Uri(abspath));              //イメージソースに代入

                    this.Enemy = new Ellipse()
                    {
                        Fill = enemy, Width = size, Height = size, Margin = new Thickness(xe, ye, 0, 0)
                    };
                    this.field.Children.Add(this.Enemy);

                    //敵
                    //分岐:敵が自分を追尾
                    if (xza > xe)
                    {
                        xe += spe;
                    }

                    if (xza <= xe)
                    {
                        xe -= spe;
                    }
                    if (yza > ye)
                    {
                        ye += spe;
                    }
                    if (yza <= ye)
                    {
                        ye -= spe;
                    }

                    double r = 35 + size - 30; //半径の和
                    double x = xza - (xe);     //2つの円の中心のx座標の差
                    double y = yza - (ye);     //2つの円の中心のy座標の差

                    if ((r * r) > ((x * x) + (y * y)))
                    {//当たり判定、  ---三平方の定理を利用---
                        Task.Run(async() =>
                        {
                            await Task.Delay(500);
                            if ((r * r) > ((x * x) + (y * y)))
                            {
                                GameOver_flg = true;
                            }
                            else
                            {
                                GameOver_flg = false;
                            }
                        });
                    }

                    //枠内に収まるようにする
                    if (xe > 1349)
                    {
                        xe = 1349;
                    }
                    else if (xe < 5)
                    {
                        xe = 5;
                    }
                    else if (ye > 695)
                    {
                        ye = 695;
                    }
                    else if (ye < 5)
                    {
                        ye = 5;
                    }

                    if (GameOver_flg == true)
                    {
                        game = false;
                        dispatcharTimer.Stop();



                        Application.Current.Properties["GameResult"]     = "ゲームオーバー!";
                        Application.Current.Properties["GameResultTime"] = cnttime;

                        result = new TagResult(this.start, this.back);
                        result.ShowDialog();

                        startbutton.Content = "スタート";
                    }

                    if (time_t == 0)    //制限時間まで逃げきれたら
                    {
                        game = false;
                        PlaySound("clear.wav");
                        dispatcharTimer.Stop();


                        dispatcharTimer          = new DispatcherTimer(DispatcherPriority.Normal);
                        dispatcharTimer.Interval = new TimeSpan(0, 0, 1);
                        dispatcharTimer.Tick    += new EventHandler(dispatcharTimer_Tick);

                        Application.Current.Properties["GameResult"]     = "クリア!";
                        Application.Current.Properties["GameResultTime"] = cnttime;

                        result = new TagResult(this.start, this.back);
                        result.ShowDialog();

                        startbutton.Content = "スタート";
                    }
                }));
            }
        }