public void Update(Mower mower, Random rand) { foreach (var grassArea in GrassInTotal) { if (!mower.Boundary.Intersects(grassArea)) { if (CurrentlyUnderMower.Contains(grassArea)) { CurrentlyUnderMower.Remove(grassArea); } continue; } if (CurrentlyUnderMower.Contains(grassArea)) { continue; } grassArea.DrivingOver(); LeftToMowe.Remove(grassArea); CurrentlyUnderMower.Add(grassArea); } mower.Update(); if (MyField.Contains(mower.Boundary)) { return; } mower.SetRandomOtherDirection(rand, mower.Boundary.ClipInside(MyField)); }
public IGameMove MakeMove(int[,] felder, int me) { MyField f = new MyField(felder, me); List <FieldInfo> bestFields = new List <FieldInfo>(); foreach (FieldInfo fi in f.FieldInfos) { if (bestFields.Count == 0) { bestFields.Add(fi); continue; } if (bestFields.Count > 0 && fi.Weight >= bestFields[0].Weight) { if (fi.Weight > bestFields[0].Weight) { bestFields.Clear(); } bestFields.Add(fi); } } int oneBest = 0; if (bestFields.Count > 1) { oneBest = (new Random()).Next(0, bestFields.Count); } return((IGameMove)(bestFields[oneBest].Y)); }
public static T GetObjectV2 <T>(IDataReader reader) where T : IDicSerialize, new() { T tt = new T(); Dictionary <string, MyField> dic = new Dictionary <string, MyField>(); object _obj = null; for (int i = 0; i < reader.FieldCount; i++) { object ritem = reader[i]; Type __type = ritem.GetType(); _obj = reader[reader.GetName(i)]; if (_obj == null || _obj == DBNull.Value) { if (__type == typeof(string)) { _obj = string.Empty; } else if (__type == typeof(DateTime)) { _obj = new DateTime(1970, 1, 1); } } MyField mdv = new MyField(_obj, __type); dic.Add(reader.GetName(i), mdv); } return((T)tt.ToObj(dic)); }
public static T GetObjectV2 <T>(DataTable dt, DataRow dr) where T : IDicSerialize, new() { if (dt.Rows.Count == 0) { return(default(T)); } T tt = new T(); Dictionary <string, MyField> dic = new Dictionary <string, MyField>(); object _obj = null; string _name = null; foreach (DataColumn c in dt.Columns) { _name = c.ColumnName; _obj = dr[_name]; Type __type = dt.Columns[_name].DataType; if (_obj == null || _obj == DBNull.Value) { if (__type == typeof(string)) { _obj = string.Empty; } else if (__type == typeof(DateTime)) { _obj = new DateTime(1970, 1, 1); } } MyField mdv = new MyField(_obj, __type); dic.Add(_name, mdv); } return((T)tt.ToObj(dic)); }
public static void AddUnique(this List <MyField> myFields, MyField newField) { if (myFields.Count(f => f.FieldName.EqualsNotCaseSensitive(newField.FieldName)) == 0) { myFields.Add(newField); } }
private void MyField_ClickOnBox(object sender, ShipEventArgs e) { if (ships[TypeShip].CountShip != 0) { try { MyField.SupplyShip(e.startBox, TypeShip, orientation); } catch (IndexOutOfRangeException ex) { MessageBox.Show("Выход за границы поля!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); return; } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); return; } ships[TypeShip].CountShip--; } else { MessageBox.Show("Такие корабли закончились!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (ships.GetCountShips() == 0) { buttonStartGame.IsEnabled = true; } }
public FightVsAI(MyField field) { InitializeComponent(); myField.CopyInfo(field); Game.session.myField = myField; Game.session.enemyField = enemyField; }
private DbParameter CreateMysqlParameter(IDictionary <string, MyField> dic, string key) { MyField val = dic[key]; //if (val.Data == null) val = ""; Type tp = val.Data.GetType(); SqlDbType dbType = SqlDbType.VarChar; if (tp == typeof(int)) { dbType = SqlDbType.Int; } else if (tp == typeof(bool)) { if ((bool)val.Data) { val.Data = 1; } else { val.Data = 0; } dbType = SqlDbType.Int; } else if (tp == typeof(string)) { dbType = SqlDbType.VarChar; if (val.Data == null) { val.Data = string.Empty; } } else if (tp == typeof(decimal)) { dbType = SqlDbType.Decimal; } else if (tp == typeof(double)) { dbType = SqlDbType.Decimal; } else if (tp == typeof(float)) { dbType = SqlDbType.Decimal; } else if (tp == typeof(DateTime)) { dbType = SqlDbType.DateTime; } else if (tp == typeof(Guid)) { dbType = SqlDbType.VarChar; } SqlParameter sps = new SqlParameter(string.Format("@{0}", key), val.Data); sps.SqlDbType = dbType; return(sps); }
public Form1() { InitializeComponent(); this.button2.Text = "Start game"; this.numOfFour.Text = ""; this.numOfThree.Text = ""; this.numOfTwo.Text = ""; this.numOfOne.Text = ""; MyField.CreateField(FieldOne); EnemyField.CreateField(FieldTwo); player = MyField._Player; shipDesk(oneDeck, twoDeck, threeDeck, fourDeck, numOfOne, numOfTwo, numOfThree, numOfFour); }
public static void CreateViewCS(List <RegistViewItem> itemList, string goName, string root) { MyClass mc = new MyClass("View_" + goName + ":AViewBase"); mc.AddNameSpace(new string[2] { "BDFramework.UI", "UnityEngine" }); mc.SetSelfNameSpace("Code.Game.Windows"); foreach (RegistViewItem item in itemList) { MyField f = new MyField(); f.SetType(GetUIType(item.gameObject)); f.SetFieldName(item.gameObject.name); if (item.IsBindPath) { f.AddAttribute(GetBindPath(item.gameObject, root)); } string tp = GetBindDataName(item); if (!string.IsNullOrEmpty(tp)) { f.AddAttribute(tp); } mc.AddField(f); } MyMethod construct = new MyMethod(); construct.OverwriteContent(@"//[Note] public [method name](Transform t, DataDrive_Service service) : base(t, service) { }"); construct.SetMethSign(null, "View_" + goName, null); mc.AddMethod(construct); MyMethod bindData = new MyMethod(); bindData.OverwriteContent(@"//[Note] public override void BindModel() { base.BindModel(); }"); mc.AddMethod(bindData); string path = Application.dataPath + createPath; if (!Directory.Exists(path)) { Debug.LogError(string.Format("文件夹不存在!路径:{0}", path)); return; } path = path + "View_" + goName + ".cs"; File.WriteAllText(path, mc.ToString()); Debug.Log(string.Format("生成成功!路径:{0}", path)); }
private void buttonClear_Click(object sender, RoutedEventArgs e) { MyField.ClearField(); ships = new Ships(beginShips); Group1.IsEnabled = true; groupBox.IsEnabled = true; buttonStartGame.IsEnabled = false; if (MyField.ClickOnBox == null) { MyField.ClickOnBox += MyField_ClickOnBox; } }
public System.Collections.Generic.IDictionary <string, MyField> ToDic() { Dictionary <string, MyField> dic = new Dictionary <string, MyField>(); dic["IDx"] = new MyField(this.IDx, typeof(System.Int32), true); dic["Title"] = new MyField(this.Title, typeof(System.String)); dic["Indate"] = new MyField(this.Indate, typeof(System.DateTime)); dic["Content"] = new MyField(this.Content, typeof(System.String)); dic["img1"] = new MyField(this.img1, typeof(System.String)); dic["img2"] = new MyField(this.img2, typeof(System.String)); dic["IsTop"] = new MyField(this.IsTop, typeof(System.Int32)); dic["Price"] = new MyField(this.Price, typeof(System.Decimal)); return(dic); }
private void buttonNewGame_Click(object sender, RoutedEventArgs e) { groupBox.IsEnabled = true; groupBox1.IsEnabled = true; Group1.IsEnabled = true; buttonStartGame.IsEnabled = false; buttonNewGame.IsEnabled = false; buttonClear.IsEnabled = true; buttonAutoPlacement.IsEnabled = true; MyField.ClearField(); EnemyField.ClearField(); EnemyField.ClickOnBox -= EnemyField_ClickBox; MyField.ClickOnBox += MyField_ClickOnBox; }
public PlayPage(OnlineGame onlineGame) { WindowConfig.PlayPageCon = this; WindowConfig.OnlineGame = onlineGame; WindowConfig.IsLoaded = onlineGame.GameConfig.GameStatus == GameStatus.Loaded; OnlineGame = onlineGame; WindowConfig.GameState = WindowConfig.State.Online; InitializeComponent(); WindowConfig.GetCurrentAudioImg(AudioImg); MyField.PlaceHitted(); EnemyField.PlaceHitted(); PauseItem.IsEnabled = OnlineGame.PlayerRole == PlayerRole.Server; SaveGameItem.IsEnabled = OnlineGame.PlayerRole == PlayerRole.Server; WindowConfig.SetStartColor(); IsPaused = false; //ImageBehavior.SetAnimatedSource(TimerImage, new BitmapImage(new Uri("/Resources/timer.gif", UriKind.Relative)) { CreateOptions = BitmapCreateOptions.IgnoreImageCache }); //ImageBehavior.SetAnimateInDesignMode(TimerImage, true); GameSpeed gs = WindowConfig.GameState == WindowConfig.State.Online ? OnlineGame.GameConfig.GameSpeed : Game.GameConfig.GameSpeed; switch (gs) { case GameSpeed.Fast: timer.Interval = new TimeSpan(0, 0, 0, 1, 250); break; case GameSpeed.Medium: timer.Interval = new TimeSpan(0, 0, 0, 2, 500); break; case GameSpeed.Slow: timer.Interval = new TimeSpan(0, 0, 0, 5); break; case GameSpeed.Turtle: timer.Interval = new TimeSpan(0, 0, 0, 12, 500); break; } // timer.Interval = new TimeSpan(0, 0, 1); timer.Tick += Tick; // timer.Start(); InitTimer(); Timer.Start(); timer.Start(); }
//---------------------------------------------------------------------------------------------------- /// <summary> /// ステージを変更 /// </summary> /// <param name="stageNum">ステージ番号</param> /// <returns>成功か</returns> public bool ChangeStage(int stageNum) { //現在のフィールドの削除 if (m_currentField) { Destroy(m_currentField.gameObject); } //ステージ番号 switch (stageNum) { case 0: m_currentField = Instantiate(myField1.gameObject, transform).GetComponent <MyField>(); break; case 1: m_currentField = Instantiate(myField2.gameObject, transform).GetComponent <MyField>(); break; case 2: m_currentField = Instantiate(myField3.gameObject, transform).GetComponent <MyField>(); break; case 3: m_currentField = Instantiate(myField4.gameObject, transform).GetComponent <MyField>(); break; default: return(false); } //ステージの敵設定 foreach (Transform enemy in m_currentField.WeakEnemiesCollection) { enemy.GetComponent <MyWeakEnemy>().AiManagerScript = myGame.CharacterScript.AiManagerScript; } //ステージの反転設定 if (myGame.CameraScript.IsInvertedDrawing != m_currentField.IsInversionField) { myGame.CameraScript.InvertDrawing(m_currentField.IsInversionField); } return(true); }
public System.Collections.Generic.IDictionary <string, MyField> ToDic() { Dictionary <string, MyField> dic = new Dictionary <string, MyField>(); dic["ClassId"] = new MyField(this.ClassId, typeof(System.String)); dic["Click"] = new MyField(this.Click, typeof(System.Int32)); dic["Content"] = new MyField(this.Content, typeof(System.String)); dic["Description"] = new MyField(this.Description, typeof(System.String)); dic["Idx"] = new MyField(this.Idx, typeof(System.Int32), true); dic["Img1"] = new MyField(this.Img1, typeof(System.String)); dic["Img2"] = new MyField(this.Img2, typeof(System.String)); dic["Img3"] = new MyField(this.Img3, typeof(System.String)); dic["Img4"] = new MyField(this.Img4, typeof(System.String)); dic["Img5"] = new MyField(this.Img5, typeof(System.String)); dic["Img6"] = new MyField(this.Img6, typeof(System.String)); dic["Img7"] = new MyField(this.Img7, typeof(System.String)); dic["Img8"] = new MyField(this.Img8, typeof(System.String)); dic["InDate"] = new MyField(this.InDate, typeof(System.DateTime)); dic["Istop"] = new MyField(this.Istop, typeof(System.Int32)); dic["Kwd"] = new MyField(this.Kwd, typeof(System.String)); dic["Title"] = new MyField(this.Title, typeof(System.String)); dic["UpdateTime"] = new MyField(this.UpdateTime, typeof(System.DateTime)); return(dic); }
public Outer() { MyField = new MyField(); }
//创建类_Client private static void ProductClass_NoMessage(List <string> strList, string IclassName, string gate) { var className = ""; var gateClassName = ""; var result = ""; string gateFile = ""; if (gate.Contains('.')) { var gateArr = gate.Split('.'); className = /*IclassName + gateArr[1] + "_" + */ strList[0]; gateClassName = IclassName + gateArr[1]; gateFile = "D:/TestClass/" + gateClassName + ".cs"; if (!File.Exists(gateFile)) { MyClass gateClass = new MyClass(gateClassName); gateClass.AddNameSpace("System"); result = gateClass.ToString(); } else { result = File.ReadAllText(gateFile).ToString(); } } else { className = IclassName + strList[0]; gateClassName = gate; gateFile = "D:/TestClass/" + IclassName + gateClassName + ".cs"; } //if(strList.Count) //c.AddNameSpace("System"); //添加field if (strList.Count > 1) { MyClass c = new MyClass(className); for (int i = 1; i < strList.Count; i++) { //先判断类型 var f = new MyField(); string field; if (i == 1) { field = string.Format("public {0};", strList[i]); } else { field = string.Format("public {0};", strList[i]); } f.SetContent(field); c.AddField(f); } var code = c.ToString(); if (gate.Contains('.')) { result = result.Insert(result.LastIndexOf('}'), code); } else { //Debug.Log(className); result = code; } } //result = result.Insert(result.LastIndexOf('}'),code); var dir = Path.GetDirectoryName(path + "/RouteClass/"); if (Directory.Exists(dir) == false) { Directory.CreateDirectory(dir); } var files = path + "/RouteClass/" + className + ".cs"; if (File.Exists(files)) { File.Delete(files); } //ProductMethodClass(c, gate, strList,IclassName); ProductMethodClass_Now(className, gate, strList, IclassName); File.WriteAllText(gateFile, result); }
public IndexableFieldTypeAnonymousClass(MyField outerInstance) { this.outerInstance = outerInstance; }
private static void ProductClass_Message(List <Array> listArr, List <string> listStr, string IclassName, string gate) { var classNameArr = listArr[0]; var className = classNameArr.GetValue(classNameArr.Length - 1); string gateClassName = ""; string result = ""; string gateFile = ""; if (gate.Contains('.')) { var gateArr = gate.Split('.'); //className = /*IclassName + gateArr[1] + "_" + */className; gateClassName = IclassName + gateArr[1]; gateFile = "D:/TestClass/" + gateClassName + ".cs"; if (!File.Exists(gateFile)) { MyClass gateClass = new MyClass(gateClassName); gateClass.AddNameSpace("System"); result = gateClass.ToString(); } else { result = File.ReadAllText(gateFile).ToString(); gateFile = "D:/TestClass/" + gateClassName + ".cs"; } } else { //className = IclassName + className; gateClassName = gate; gateFile = "D:/TestClass/" + IclassName + gateClassName + ".cs"; } MyClass c = new MyClass(className.ToString()); var subClassName = ""; for (int i = 1; i < listArr.Count; i++) { var arr = listArr[i]; subClassName = arr.GetValue(0).ToString(); MyClass subClass = new MyClass(subClassName); for (int n = 1; n < arr.Length; n++) { var f = new MyField(); //if(n == 1) //{ // field = string.Format("public {0};", arr.GetValue(n)); //} //else //{ // field = string.Format("public {0};", arr.GetValue(n)); //} string field = string.Format("public {0};", arr.GetValue(n)); f.SetContent(field); subClass.AddField(f); } c.AddClass(subClass); } //添加field if (listStr.Count > 1) { for (int i = 0; i < listStr.Count; i++) { //先判断类型 var f = new MyField(); string field = ""; var arrField = listStr[i].Split(' '); if (arrField[0] == subClassName) { var str = listStr[i].Insert(listStr[i].LastIndexOf(' '), "[]"); field = string.Format("public {0};", str); } else { field = string.Format("public {0};", listStr[i]); } //if (i == 0) //{ // field = string.Format("public {0};", listStr[i]); //} //else //{ // field = string.Format("public {0};", listStr[i]); //} f.SetContent(field); c.AddField(f); } } var code = c.ToString(); if (gate.Contains('.')) { result = result.Insert(result.LastIndexOf('}'), code); } else { result = code; } var files = path + "/RouteClass/Response_" + c.Name + ".cs"; if (File.Exists(files)) { File.Delete(files); } File.WriteAllText(gateFile, result); //AssetDatabase.Refresh(); //ProductMethodClass_All(c, gate, listStr, IclassName); ProductMethodClass_Now(className.ToString(), gate, listStr, IclassName); }
public void ReceiveMsg(object sender, GameData Data) { //parse message /* * first check if id is the same, if id is not set set it * dann if its attack request return message about succesfuly * */ if (Data.GameId == GameId) { bool labelupdaterequired = false; switch (Data.Type) { case GameMessage.Attack: { GameData respond = new GameData(GameMessage.AttackRespond); respond.GameId = GameId; //check and send respond back Field.Cell CheckingCell = MyField.getCell(Data.AttackingCell.X, Data.AttackingCell.Y); if (CheckingCell.State == CellState.Occupied) { MyDeckCounter[CheckingCell.Shipid].DeckRemains -= 1; if (MyDeckCounter[CheckingCell.Shipid].DeckRemains == 0) { switch (MyDeckCounter[CheckingCell.Shipid].Type) { case ShipType.FourDeck: MyCounters[0]--; break; case ShipType.ThreeDeck: MyCounters[1]--; break; case ShipType.TwoDeck: MyCounters[2]--; break; case ShipType.OneDeck: MyCounters[3]--; break; } MyDeckCounter.Remove(CheckingCell.Shipid); labelupdaterequired = true; } MyField.setCellState(Data.AttackingCell.X, Data.AttackingCell.Y, CellState.Hit); respond.shiptype = CheckingCell.Type; respond.AttackResult = true; respond.shipId = CheckingCell.Shipid; respond.AttackingCell = Data.AttackingCell; SendMessage(this, respond); OnDataUpdate(this, new DataUpdateEventArguments(true, Data.AttackingCell, labelupdaterequired)); if (labelupdaterequired) { if (MyDeckCounter.Count == 0) { OnGameFinished(this, false); } } } else if (CheckingCell.State == CellState.Free) { MyField.setCellState(Data.AttackingCell.X, Data.AttackingCell.Y, CellState.Missed); respond.AttackResult = false; respond.AttackingCell = Data.AttackingCell; SendMessage(this, respond); OnDataUpdate(this, new DataUpdateEventArguments(true, Data.AttackingCell, false)); CurrentMove = true; } //if the there is no ships, invoke endgame ChangeMove(this, new EventArgs()); } break; case GameMessage.AttackRespond: { //add data to local list, invoke gamefinish if there is no ships left //invoke update data, change mode if (Data.GameId == GameId) { if (Data.AttackResult) { if (EnemyDeckCounter.ContainsKey(Data.shipId)) { CurrentMove = true; EnemyDeckCounter[Data.shipId].DeckRemains--; if (EnemyDeckCounter[Data.shipId].DeckRemains == 0) { labelupdaterequired = true; EnemyCounters[(byte)EnemyDeckCounter[Data.shipId].Type]--; EnemyDeckCounter.Remove(Data.shipId); } EnemyField.setCellState(Data.AttackingCell.X, Data.AttackingCell.Y, CellState.Hit); OnDataUpdate(this, new DataUpdateEventArguments(false, Data.AttackingCell, labelupdaterequired)); //if all enemycounters == 0 dann we win if (EnemyCounters[0] == 0 && EnemyCounters[1] == 0 && EnemyCounters[2] == 0 && EnemyCounters[3] == 0) { OnGameFinished(this, true); } } else { EnemyDeckCounter.Add(Data.shipId, new ship(Data.shiptype)); ReceiveMsg(this, Data); } } else { CurrentMove = false; EnemyField.setCellState(Data.AttackingCell.X, Data.AttackingCell.Y, CellState.Missed); OnDataUpdate(this, new DataUpdateEventArguments(false, Data.AttackingCell, labelupdaterequired)); } } ChangeMove(this, new EventArgs()); } break; case GameMessage.EndGame: { //finish game with win msg //invoke game finished OnGameFinished(this, true); } break; } } else { if (GameId == "00000-1") { GameId = Data.GameId; ReceiveMsg(sender, Data); } } }
private void buttonAutoPlacement_Click(object sender, RoutedEventArgs e) { MyField.AutoPlacementShips(ships); buttonStartGame.IsEnabled = true; MyField.ClickOnBox -= MyField_ClickOnBox; }
public IndexableFieldTypeAnonymousInnerClassHelper(MyField outerInstance) { this.outerInstance = outerInstance; }
public MyClass() { myField = new MyField(); }