private void Yangpa_Created(YangpaObject ypo, int z) { canv_YpHome.Children.Add(ypo); Canvas.SetZIndex(ypo, z); }
private void Window_Loaded_1(object sender, RoutedEventArgs e) { //should use delegate; this.core = new YangpaCore(this); //loads class and init try { foreach (SClass cl in core.LoadClasses()) { cb_Class.Items.Add(cl); } } catch (FileLoadException) { MessageBox.Show(YangpaConstants.MSG_INV_CONF, YangpaConstants.AppTitle, MessageBoxButton.OK, MessageBoxImage.Error); this.Close(); } //add some yangpa YangpaObject.SetEnvironment(canv_YpHome, this, new YangpaObject.SimpleDelegate(Yangpa_Created), new YangpaObject.SimpleDelegate(Yangpa_Collided), rectJo); for (int i = 0; i < 4; i++) { YangpaObject ypo = new YangpaObject((YangpaObject.YType)i, new Point(80 * i, 10 + 20 * (i % 2))); canv_YpHome.Children.Add(ypo); } //YType.Half is 99 //canv_YpHome.Children.Add(new YangpaObject(YangpaObject.YType.Half, new Point(240, 30))); }
/// <summary> /// Called when YangpaObject delegate is collided /// </summary> /// <param name="y"></param> /// <param name="c"></param> private void Yangpa_Collided(YangpaObject y, int c) { //prevents dragging before class select if (core.instance_Current == null) { if (y != null) ClearAllYangpa(); } else if (core.instance_Current.JoMember[0].Count < 1 && y != null) { MessageBox.Show(YangpaConstants.MSG_SET_MEMBER_BEFORE_MOVE, YangpaConstants.AppTitle, MessageBoxButton.OK, MessageBoxImage.Error); ClearAllYangpa(); } else //starts code here { int[][] ia = core.instance_Current.JoScore; //initializes array once more for (int i = 0; i < ia.Length; i++) for (int j = 0; j < ia[i].Length; j++) ia[i][j] = 0; bool hasHalf = false; foreach (UIElement o in canv_YpHome.Children) { YangpaObject yangpa = o as YangpaObject; if (yangpa != null) { if (yangpa.Type == YangpaObject.YType.Half) hasHalf = true; else { int jindex = yangpa.CheckifinJorect(); if (jindex != -1) ia[jindex][(int)yangpa.Type] += 1; } } } for (int i = 0; i < 6; i++) labelJs[i].Content = core.instance_Current.JoScoreToActualScore(i) + "점"; YangpaDB.SaveDB(core.instance_Current, false); if (hasHalf) UpdateHalfYangpa(); } }
/// <summary> /// Updates a Yangpa display. /// </summary> private void UpdateYangpa() { //should clear it first ClearAllYangpa(); /* * q=JoIndex, i=YangpaType, j=count */ for (int q = 0; q < core.instance_Current.JoScore.Length; q++) { int[] ia = core.instance_Current.JoScore[q]; for (int i = 0; i < ia.Length; i++) { for (int j = 1; j <= ia[i]; j++) { //TODO : need to be improved Point point = new Point(20+ (j + i) * 30 + (q % 2 == 0 ? -270 : 60), 170 + 140 * (q / 2)); YangpaObject yo = new YangpaObject((YangpaObject.YType)i, point); canv_YpHome.Children.Add(yo); } } } }