private void ActOnMessage() { Regex regex = new Regex("([A-Z]+)(?::\\s?((?:\\d+(?:,\\s?)?)+))?"); if (regex.IsMatch(Message)) { Match match = regex.Match(Message); string operation = match.Groups[1].Value; Regex divider = new Regex(",\\s?"); string[] args = divider.Split(match.Groups[2].Value); if (operation.ToUpper().Equals("EXPANDALL")) { if (Int32.TryParse(args[0], out int x) && Int32.TryParse(args[1], out int y)) { GetBoard().ExpandEmpty(x, y, true); } } else if (operation.ToUpper().Equals("BOOM")) { EndGame(); } else if (operation.ToUpper().Equals("BADFLAG")) { if (FlagCount > 0) { FlagCount--; MineCountField.Text = FlagCount.ToString(); } } else if (operation.ToUpper().Equals("GOODFLAG")) { if (FlagCount > 0) { MineCount--; FlagCount--; MineCountField.Text = FlagCount.ToString(); EndGame(); } } else if (operation.ToUpper().Equals("REFRESH")) { GetBoard().RefreshContents(); } } }
public override void GenerateBoard(Panel panel) { GetBoard().SetPanel(panel); IGenerator gen = _factory.CreateGenerator("NativeGenerator"); int size = 0; switch (GetDifficulty()) { case Difficulty.Beginner: size = 8; MineCount = 10; break; case Difficulty.Intermediate: size = 16; MineCount = 40; break; case Difficulty.Expert: size = 24; MineCount = 99; break; } // Create and filter the board GetBoard().MakeBoard(size); char[,] board = gen.GenerateBoard(size, MineCount); ICriteria boardFilter = new SizeChecker(board, GetDifficulty()); boardFilter = new MinesChecker(boardFilter); boardFilter = new NumberChecker(boardFilter); board = boardFilter.Verify(); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { Square square; switch (board[i, j]) { case 'X': square = new Mine(i, j); break; case '0': square = new EmptySquare(i, j); break; default: square = new NumberSquare(i, j, board[i, j] - '0'); break; } GetBoard().AddSquare(square); AddSquareToGame(square); //square.Button.Top += panel.Top; //square.Button.Left += panel.Left; panel.Controls.Add(square.Button); square.Subscribe(this); } } // Start the game FlagCount = MineCount; MineCountField.Text = FlagCount.ToString(); GameTimer = new GameTimer(TimerField); GameTimer.Start(); }
public static System.Collections.Generic.List <FlagCount> GetFlags_old(double dimMin) { System.Collections.Generic.List <FlagCount> ls = new System.Collections.Generic.List <FlagCount>(); //CoreDb.LinqHelper.GetGetter<FlagCount>(""); //CoreDb.LinqHelper.GetSetter<FlagCount>(""); //CoreDb.LinqHelper.GetGetters<FlagCount>(); //CoreDb.LinqHelper.GetSetters<FlagCount>(); string sql = @" -- DECLARE @dimMin float -- SET @dimMin = 30.0 ;WITH CTE AS ( SELECT flag ,country ,country_id ,width ,height ,b64 ,@dimMin/width AS rW ,@dimMin/height AS rH , CASE WHEN @dimMin/width > @dimMin/height THEN @dimMin/width ELSE @dimMin/height END AS rMAX , CASE WHEN @dimMin/width > @dimMin/height THEN @dimMin/height ELSE @dimMin/width END AS rMIN --,geoip_locations_temp.continent_name --,geoip_locations_temp.country_iso_code ,geoip_locations_temp.country_name FROM flags LEFT JOIN geoip.geoip_locations_temp ON geoip_locations_temp.country_iso_code = FLAGS.flag ) SELECT flag ,country ,country_id ,width ,height --,CEILING(width * rMIN) AS wRedim --,CEILING(height * rMIN) AS hRedim ,CAST(ROUND(width * rMIN, 0) AS integer) AS wRedim ,CAST(ROUND(height * rMIN, 0) AS integer) AS hRedim ,b64 --,ABS(CHECKSUM(NEWID())) % (10+1 -0) + 0 AS rn ,ABS(CHECKSUM(NEWID())) % (150+1 -2) + 2 AS flagCount ,country_name FROM CTE WHERE flag IN ('NL', 'CH', 'AD', 'FR', 'IT', 'NP') ORDER BY flag "; using (System.Data.Common.DbConnection con = GetConnection()) { if (con.State != System.Data.ConnectionState.Open) { con.Open(); } using (System.Data.Common.DbCommand cmd = con.CreateCommand()) { cmd.CommandText = sql; // dimMin System.Data.Common.DbParameter width = cmd.CreateParameter(); width.ParameterName = "@dimMin"; width.Value = dimMin; width.DbType = System.Data.DbType.Double; cmd.Parameters.Add(width); using (System.Data.Common.DbDataReader idr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection | System.Data.CommandBehavior.SequentialAccess)) { int fieldCount = idr.FieldCount; string[] fields = new string[fieldCount]; // CoreDb.Getter_t<FlagCount>[] getters = new CoreDb.Getter_t<FlagCount>[fieldCount]; CoreDb.Setter_t <FlagCount>[] setters = new CoreDb.Setter_t <FlagCount> [fieldCount]; for (int i = 0; i < fieldCount; ++i) { fields[i] = idr.GetName(i); // getters[i] = CoreDb.LinqHelper.GetGetter<FlagCount>(fields[i]); setters[i] = CoreDb.LinqHelper.GetSetter <FlagCount>(fields[i]); } // Next i while (idr.Read()) { FlagCount tThisValue = System.Activator.CreateInstance <FlagCount>(); for (int i = 0; i < fieldCount; ++i) { if (setters[i] != null) { object value = idr.GetValue(i); setters[i](tThisValue, value); } // End if (setters[i] != null) } // Next i ls.Add(tThisValue); } // Whend } // End Using idr } // End Using cmd if (con.State != System.Data.ConnectionState.Closed) { con.Close(); } } // End Using con return(ls); }
private void ChangeLabelCount() { LabelCount.Text = FlagCount.ToString() + " / " + Mines.ToString(); }