x01.MagicCube: 简单操作

看最强大脑,发现魔方还是比较好玩的,便买了一个,对照七步还原法,居然也能成功还原。

为什么不写一个魔方程序呢?在网上找了找,略作修改,进行简单操作,还是不错的,其操作代码如下:

 protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
switch (e.Key) {
case Key.Escape:
this.Close(); // 退出
break;
case Key.S:
if ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) {
stage.Reset(); // 重置
break;
}
stage.Upset(); // 打乱
break;
case Key.L:
if ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) {
stage.RotateOneGroup(, Axises.X, true); // 左反拧
break;
}
stage.RotateOneGroup(, Axises.X, false); // 左顺拧
break;
case Key.M:
if ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) {
stage.RotateOneGroup(, Axises.X, true); // 中反拧
break;
}
stage.RotateOneGroup(, Axises.X, false); // 中顺拧
break;
case Key.R:
if ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) {
stage.RotateOneGroup(, Axises.X, true); // 右反拧
break;
}
stage.RotateOneGroup(, Axises.X, false); // 右顺拧
break;
case Key.U:
if ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) {
stage.RotateOneGroup(, Axises.Y, false); // 上反拧
break;
}
stage.RotateOneGroup(, Axises.Y, true); // 上顺拧
break;
case Key.D:
if ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) {
stage.RotateOneGroup(, Axises.Y, false); // 下反拧
break;
}
stage.RotateOneGroup(, Axises.Y, true); // 下顺拧
break;
case Key.F:
if ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) {
stage.RotateOneGroup(, Axises.Z, false); // 前反拧
break;
}
stage.RotateOneGroup(, Axises.Z, true); // 前顺拧
break;
case Key.B:
if ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) {
stage.RotateOneGroup(, Axises.Z, true); // 后反拧
break;
}
stage.RotateOneGroup(, Axises.Z, false); // 后顺拧
break;
case Key.Left:
stage.RotateAll(Axises.Y, true); // 向左整体旋转
break;
case Key.Right:
stage.RotateAll(Axises.Y, false); // 向右整体旋转
break;
case Key.Up:
stage.RotateAll(Axises.X, true); // 向上整体旋转
break;
case Key.Down:
stage.RotateAll(Axises.X, false); // 向下整体旋转
break;
default:
break;
}
}

用到了一些关于 3D 方面的知识,可参看 x01.EarthRun,整体并不难,就不多言了。效果图如下:

x01.MagicCube: 简单操作

源代码:https://github.com/chinax01/x01.MagicCube

上一篇:python jquery


下一篇:XAML: 获取元素的位置