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(); } })); } }
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(); } })); } }