public void DestroyCurrentField() { if (CurrentField) { CurrentField.AskDestroy(); } }
internal void VisitInsertGameObjectAttribute(string name, bool required) { if (CurrentField.FieldType == typeof(GameObject)) { var gameObject = Entity.Find(name); var isInOrder = true; if (gameObject != null) { isInOrder = false; CurrentField.SetValue(CurrentComponent, gameObject, BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic, null, null); } DependencyObjects.Add(new DependencyFieldInfo { Field = CurrentField, Component = CurrentComponent, From = name, IsInOrder = isInOrder, Required = required }); } else { throw new InvalidOperationException($"Can't insert game object with name {name} to not game object field"); } }
private void HighlightSelectedBalls(int x, int y, bool[,] visit) { int[] dx = { -1, 0, 1, 0 }; int[] dy = { 0, 1, 0, -1 }; visit[x, y] = true; var ball = CurrentField.GetBall(x, y); if (ball is OjamaBall) { return; } var color = ball.Color; ball.IsOnMouse = true; for (var i = 0; i < 4; ++i) { var tx = x + dx[i]; var ty = y + dy[i]; if (!CurrentField.IsInFieldRange(tx, ty) || visit[tx, ty] || CurrentField.GetBall(tx, ty).Color != color) { continue; } HighlightSelectedBalls(tx, ty, visit); } }
private void OnClickButton() { if (CurrentField == null || (CurrentField is UIDataPackField == false)) { return; } CurrentField.StartEdit(); }
protected override bool OnClose(params object[] args) { if (CurrentField) { CurrentField.EndManagement(); } CurrentField = null; return(true); }
public void Plant() { if (PlantAble) { CurrentField.PlantCrop(currentInfo, preview.Position); } else { MessageManager.Instance.New("存在障碍物"); } FinishPreview(); }
private void OnFieldValueChange(string stringValue) { if (CurrentField == null || (CurrentField is UIValueField == false)) { return; } UIValueField currentValueField = CurrentField as UIValueField; if (currentValueField.StringInput != stringValue) { onEdit.Invoke(); CurrentField.Edit(); } }
public void SizeFieldSlider() { var sliderSize = transform.GetChild(1).GetComponent <Slider>(); if (sliderSize == null) { throw new Exception("incorrect child index"); } int size = (int)sliderSize.value; sliderSize.interactable = false; // for dont trigger on arrow sliderSize.interactable = true; // for dont trigger on arrow CurrentField.DestroyField(); CurrentField.Init(size); sliderSize.transform.GetChild(0).GetComponent <Text>().text = "size field " + size.ToString(); }
private void OnFieldEndEdit(string stringValue) { if (CurrentField == null || (CurrentField is UIValueField == false)) { return; } UIValueField currentValueField = CurrentField as UIValueField; if (currentValueField.StringInput != stringValue) { //currentValueField.StringInput = stringValue; currentValueField.SetInput(stringValue); onEndEdit.Invoke(); CurrentField.ApplyChanges(); CurrentField.EndEdit(); } }
private void GameControlOnMouseLeftButtonUp( object sender, MouseButtonEventArgs mouseButtonEventArgs) { if (!IsRunning) { return; } var screenPoint = new Point(Cursor.Position.X, Cursor.Position.Y); var controlPoint = _gameControl.PointFromScreen(screenPoint); var ratioX = _camera.WorldWidth / _gameControl.ActualWidth; var ratioY = _camera.WorldHeight / _gameControl.ActualHeight; var worldPosition = new Vector2((float)(controlPoint.X * ratioX), (float)(controlPoint.Y * ratioY)); Microsoft.Xna.Framework.Point bordPos; if (!CurrentField.ToBordPointFromRenderPosition(worldPosition, out bordPos) || !CurrentField.IsInFieldRange(bordPos.X, bordPos.Y)) { return; } var gameConfig = CurrentField.GameConfig; var visit = new bool[gameConfig.Column + 1, gameConfig.Row + 1]; var tempCount = CurrentField.DfsDestroyableBalls(bordPos.X, bordPos.Y, visit); if (tempCount < gameConfig.MinChain) { return; } var ball = CurrentField.GetBall(bordPos.X, bordPos.Y); if (ball is OjamaBall) { return; } OutPut = bordPos; IsRunning = false; }
internal void VisitInsertComponentAttribute(string from, bool inherit, bool required) { var component = FindComponent(from, inherit, CurrentField.FieldType); var isInOrder = true; if (component != null) { isInOrder = false; CurrentField.SetValue(CurrentComponent, component, BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic, null, null); } DependencyComponents.Add( new DependencyFieldInfo { Field = CurrentField, Component = CurrentComponent, From = from, Inherit = inherit, IsInOrder = isInOrder, Required = required }); }
public override void StartTurn() { IsRunning = true; OutPut = Point.Zero; if (CurrentHead < _replayData.OutputLines.Count) { Point result; var aiLogger = CurrentField.AiLogger; aiLogger.InputLogger.WriteLine(CurrentField.GenerateTurnInfoString()); aiLogger.OutputLogger.WriteLine(_replayData.OutputLines[CurrentHead]); if (!ReplayMatchData.TryParsePoint(_replayData.OutputLines[CurrentHead], out result)) { CurrentHead = int.MaxValue; IsRunning = false; return; } OutPut = result; CurrentHead++; } IsRunning = false; }
public void SetTypeField() { var item = transform.GetChild(2).GetComponent <Dropdown>(); if (item == null) { throw new Exception("incorrect child index"); } var itemToggle = item.transform.GetChild(0).GetComponent <Toggle>(); if (itemToggle == null) { throw new Exception("incorrect child index"); } CurrentField.DestroyField(); int type = item.value; if (itemToggle.isOn) { type += 4; } CurrentField.Init((TypeField)type); }
public override void Render(GameTime gameTime) { var scale = new Vector2(Camera.RatioX, Camera.RatioY) * 32.0f / _ojamaTexture.Width; var gameConfig = GameMain.GameConfig; for (var x = 1; x <= gameConfig.Column; ++x) { var ojamas = CurrentField.GetOjamasInQueue(x); var ball = CurrentField.GetBall(x, 1); var pos = Camera.ToRenderPosition(new Vector2(ball.X, 0.0f)); SpriteBatch.Draw(_ojamaTexture, pos, scale: scale * 0.8f, color: Color.Black); var ojamaCount = ojamas.Count(ojama => !ojama.IsHard); SpriteBatch.DrawString(_font, "x" + ojamaCount, pos, Color.White, 0.0f, Vector2.Zero, scale * 4.0f, SpriteEffects.None, 0.0f); pos.Y += _ojamaTexture.Height * scale.Y; var hardOjamaCount = ojamas.Count(ojama => ojama.IsHard); SpriteBatch.Draw(_hardOjamaTexture, pos, scale: scale * 0.8f, color: Color.Black); SpriteBatch.DrawString(_font, "x" + hardOjamaCount, pos, Color.White, 0.0f, Vector2.Zero, scale * 4.0f, SpriteEffects.None, 0.0f); } }
public override void InitializeGame() { IsRunning = true; _playerAi.StartInfo.FileName = _fileName; _playerAi.StartInfo.UseShellExecute = false; _playerAi.StartInfo.CreateNoWindow = true; _playerAi.StartInfo.RedirectStandardInput = true; _playerAi.StartInfo.RedirectStandardError = true; _playerAi.StartInfo.RedirectStandardOutput = true; _playerAi.ErrorDataReceived += PlayerAiOnErrorDataReceived; var gameLogger = GameMain.GameLogger; _playerAi.Start(); _playerAi.BeginErrorReadLine(); gameLogger.WriteLine("AIのプロセスを開始"); var w = CurrentField.GameConfig.Column; var h = CurrentField.GameConfig.Row; var m = CurrentField.GameConfig.MinChain; var n = CurrentField.GameConfig.ColorsNumber; var stopWatch = new Stopwatch(); stopWatch.Start(); _inputQueue.Enqueue(w + " " + h + " " + m + " " + n); _inputQueue.Enqueue(CurrentField.Index.ToString()); _inputQueue.Enqueue(CurrentField.GetWonLoseInfoString()); var task = Task.Factory.StartNew( () => { gameLogger.Write("AIからのAI名入力待ち->"); var input = _playerAi.StandardOutput.ReadLine(); var aiLogger = CurrentField.AiLogger; aiLogger.OutputLogger.WriteLine(input); AiOutputs.Add(input ?? ""); if (_token.IsCancellationRequested) { return; } if (input != null) { stopWatch.Stop(); LeftTimeOnLaunched = LeftMilliseconds; LeftThinkTimes.Add(LeftMilliseconds); gameLogger.WriteLine("AIの初期化は正常終了 AI名:" + input + " (" + stopWatch.ElapsedMilliseconds + "ms)"); return; } stopWatch.Stop(); LeftTimeOnLaunched = LeftMilliseconds; LeftThinkTimes.Add(LeftMilliseconds); gameLogger.WriteLine("AIからのAI名入力に失敗" + " (" + stopWatch.ElapsedMilliseconds + "ms)"); Dispose(); }, _token); try { if (!task.Wait(10000)) { gameLogger.WriteLine("AI名入力の時間制限超過:" + task.Status); Dispose(); return; } } catch (AggregateException) { if (_token.IsCancellationRequested) { return; } throw; } IsRunning = false; }
public override void StartTurn() { IsRunning = true; var turnInfo = new StringBuilder(); turnInfo.Append(CurrentField.GenerateTurnInfoString()); turnInfo.Append(OtherField.GenerateTurnInfoString()); var gameLogger = GameMain.GameLogger; var stopWatch = new Stopwatch(); stopWatch.Start(); _inputQueue.Enqueue(turnInfo.ToString()); var task = Task.Factory.StartNew(() => { gameLogger.Write("AI入力待ち->"); int x, y; var aiLogger = CurrentField.AiLogger; var input = _playerAi.StandardOutput.ReadLine(); aiLogger.OutputLogger.WriteLine(input); AiOutputs.Add(input ?? ""); var lines = input?.Split(' '); if (_token.IsCancellationRequested) { return; } stopWatch.Stop(); _totalThinkTime += stopWatch.Elapsed; LeftThinkTimes.Add(LeftMilliseconds); if (lines == null || lines.Length != 2 || !int.TryParse(lines[0], out x) || !int.TryParse(lines[1], out y)) { stopWatch.Stop(); _totalThinkTime += stopWatch.Elapsed; LeftThinkTimes.Add(LeftMilliseconds); OutPut = new Point(); Dispose(); gameLogger.WriteLine("AIの出力が無効 (" + stopWatch.ElapsedMilliseconds + "ms, left " + LeftMilliseconds / 1000 + "s)"); return; } if (TotalTimeLimit < _totalThinkTime) { OutPut = new Point(); gameLogger.WriteLine("合計思考時間の時間制限超過:" + x + " " + y + " (" + stopWatch.ElapsedMilliseconds + "ms, left " + LeftMilliseconds / 1000 + "s)"); return; } gameLogger.WriteLine("OK:" + x + " " + y + " (" + stopWatch.ElapsedMilliseconds + "ms, left " + LeftMilliseconds / 1000 + "s)"); OutPut = new Point(x, y); }); try { if (!task.Wait(10000)) { gameLogger.WriteLine("1ターンの時間制限超過:" + task.Status); Dispose(); return; } } catch (AggregateException exception) when(exception.InnerExceptions.Any(e => e is OperationCanceledException)) { return; } gameLogger.WriteLine("ターン終了:" + OutPut + " 入力待ちタスク:" + task.Status); IsRunning = false; }
public override void DoTurn() { try { base.DoTurn(); CheckTile(false); if (AuxUtils.Chance(25)) { int idx; if (Size == 1) { idx = 0; } else { idx = RandomHelper.GetRandom(Size); } IvySegment seg = (IvySegment)GetSegment(idx); if (dbIvyBranches[seg.Id].Kind == IvyBranches.ibkLeaf) { idx = GetBranchByDir(seg.EntryDir, new IvyBranches(IvyBranches.ibkBranch)); if (idx >= 0) { Directions avEntries = new Directions(dbIvyBranches[idx].Entries); avEntries.Exclude(seg.EntryDir); seg.Id = idx; seg.AvailableEntries = avEntries; seg.ImageIndex = idx; } } int cnt = 0; List <int> entries = new List <int>(); for (int dir = Directions.DtNorth; dir <= Directions.DtEast; dir++) { if (seg.AvailableEntries.Contains(dir)) { cnt++; entries.Add(dir); } } if (cnt == 0) { return; } idx = RandomHelper.GetRandom(cnt); int bdir = entries[idx]; int nx = seg.X + Directions.Data[bdir].DX; int ny = seg.Y + Directions.Data[bdir].DY; seg.AvailableEntries.Exclude(bdir); int i = FindByPos(nx, ny); if (!CurrentField.IsBarrier(nx, ny) && i < 0) { int opposite = Directions.Data[bdir].Opposite; idx = GetBranchByDir(opposite, new IvyBranches(IvyBranches.ibkBranch, IvyBranches.ibkLeaf)); if (idx >= 0) { Directions avEntries = new Directions(dbIvyBranches[idx].Entries); avEntries.Exclude(opposite); IvySegment newSeg = (IvySegment)Add(); newSeg.X = nx; newSeg.Y = ny; newSeg.Id = idx; newSeg.EntryDir = opposite; newSeg.AvailableEntries = avEntries; newSeg.ImageIndex = idx; } } } CheckTile(true); } catch (Exception ex) { Logger.Write("IvyCreeper.doTurn(): " + ex.Message); } }
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result) { string msg; var o = await result; if (o is Activity) // got activity { msg = ((Activity)o).Text; Id = ((Activity)o).From.Id; } else { msg = (string)o; } if (Object == null) { if (Store.Exists(Id)) { await context.PostAsync(return_msg); } else { await context.PostAsync(welcome_msg); } Object = Store.Get(Id); } if (CurrentField != null) { var val = msg; if (CurrentField.Set(Object, val)) { CurrentField = null; Store.Update(Id, Object); } else { await context.PostAsync("Ошибочное значение"); } } if (CurrentField == null) { foreach (var x in Fields) { if (x.Get(Object) == null && x.IsApplicable(Object)) { CurrentField = x; break; } } } if (CurrentField == null) // all fields of the object have been filled { // await context.Forward(new MenuDialog<T>(Store), async (ctx,x) => { ctx.Done(Object); }, activity, CancellationToken.None); context.Call(new MenuDialog <T>(Store, Object), async(ctx, c) => { ctx.Done(Object); }); // context.Done(Object); } else // we have a new field to fill { if (CurrentField.Type == "geostring") { await context.PostAsync(CurrentField.Text); context.Call(new GeoDialog("GeoCities"), MessageReceivedAsync); } else { await CurrentField.Render(context); context.Wait(MessageReceivedAsync); } } }