public int AggresiveMove(int playerID, GameMatrix gm) { int pWinCheck = PrimaryWinMove(playerID, gm); if (pWinCheck != 0) { return(pWinCheck); } int pBlockCheck = PrimaryBlockMove(playerID, gm); if (pBlockCheck != 0) { return(pBlockCheck); } int best = 0; int bestmove = 0; for (int iii = 1; iii < 10; iii++) { if (gm.MoveLegal(iii)) { int value = gm.calculateAttackScore(iii, playerID); if (value >= best) { bestmove = iii; best = value; } } } return(bestmove); }
public PlayController() : base(ControllerNames.Play) { Rectangle[,] regions = new Rectangle[8, 8]; gc = GameConfigs.GetInstance(); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { regions[i, j] = new Rectangle(gc.GetRealPoint(j + 1, i + 1), new Point(gc.RegionWidth, gc.RegionHeight)); } } gameMatrix = new GameMatrix(regions, 8, 8); gameModel = new GameModel(gameMatrix); gameMatrix.OnItemKilled += () => { bonusPointsModel.Points += 1; }; gameTimerModel = new GameTimerModel(); bonusPointsModel = new BonusPointsModel(); gameModel.Timer = gameTimerModel; gameModel.BonusPoints = bonusPointsModel; renderer = new PlayRenderer(gameModel); gameTimerModel.Start(); }
private static void FillGameMatrix() { removable_wall_possibles.Clear(); for (int i = 0; i <= GameMatrix.GetUpperBound(0); i++) { for (int j = 0; j <= GameMatrix.GetUpperBound(1); j++) { //falak behlyezése if (i % 2 == 1 && j % 2 == 1) { GameMatrix[i, j] = (int)Enums.FieldTypes.wall; } else { GameMatrix[i, j] = (int)Enums.FieldTypes.basic; //kirobbantható falak helyei lehetnek if (!( (i == 0 && j == 0) || i == 1 && j == 0 || (i == 0 && j == 1) || (i == GameMatrix.GetUpperBound(0) && j == GameMatrix.GetUpperBound(1)) || (i == GameMatrix.GetUpperBound(0) && j == GameMatrix.GetUpperBound(1) - 1) || (i == GameMatrix.GetUpperBound(0) - 1 && j == GameMatrix.GetUpperBound(1)) )) { Position p = new Position(); p.X = i; p.Y = j; removable_wall_possibles.Add(p); } } } } }
public void Update(int dt) { if (GameOver) { return; } BonusPoints.Update(dt); Timer.Update(dt); if (Timer.State == DynamicState.END) { GameOver = true; return; } bool isBusy = false; bool hasInvisible = false; foreach (var go in GameMatrix) { go.Update(dt); isBusy |= go.IsBusy(); hasInvisible |= !go.Visible; } if (!isBusy) { if (hasInvisible) { GameMatrix.Next(MatrixState.KILL); } else { GameMatrix.Next(); if (clientSwapModel != null && GameMatrix.State == MatrixState.NONE) { switch (clientSwapModel.Direction) { case SwapDirection.HORIZONTAL: GameMatrix.SwapH(clientSwapModel.GameObject1, clientSwapModel.GameObject2); break; case SwapDirection.VERTICAL: GameMatrix.SwapV(clientSwapModel.GameObject1, clientSwapModel.GameObject2); break; } } if (clientSwapModel != null) { clientSwapModel = null; } } } CanClientInput = !isBusy && GameMatrix.State == MatrixState.NONE; }
public Game(int cellSize) { gameMatrix = GameMatrices.gameMatrixWithDots; GameMatrixSize[0] = GameMatrix.GetLength(0); GameMatrixSize[1] = GameMatrix.GetLength(1); Human = new Human(this.GameMatrixSize, cellSize, this, new int[] { 23, 14 }, Directions.Left, 1); blinky = new Red(this.GameMatrixSize, cellSize, this, new int[] { 5, 6 }, Directions.Down, 1); pinky = new Pink(this.GameMatrixSize, cellSize, this, new int[] { 29, 1 }, Directions.Right, 1); inky = new Blue(this.GameMatrixSize, cellSize, this, new int[] { 29, 26 }, Directions.Up, 1); clyde = new Orange(this.GameMatrixSize, cellSize, this, new int[] { 5, 26 }, Directions.Left, 1); Players = new Player[] { Human, blinky, pinky, inky, clyde }; foreach (Player ght in Players) { if (ght is AI) { Human.HumanPositionChanged += ((AI)ght).OnHumanPositionChanged; } } blinky.RedPositionChanged += inky.OnRedPositionChanged; this.cellSize = cellSize; dotsCount = CountDots(); frameTimer = new DispatcherTimer(); frameTimer.Interval = TimeSpan.FromMilliseconds(interval); frameTimer.Tick += Timer_Tick; frameTimer.Start(); gameTimer = new Timer(); gameTimer.Interval = gameTimerIntervals[gameTimerCounter]; gameTimer.Elapsed += GameTimer_Elapsed; gameTimer.Start(); stopwatch.Start(); scaredTimer = new DispatcherTimer(); scaredTimer.Tick += ScaredTimer_Tick; }
public void ResetGame() { isGameOver = false; GameData.ListCells.Clear(); GameData = new GameMatrix(settings.xAxis, settings.yAxis, settings.mines); GameData.InitialSetup(rand); updateGameboard(); }
public static void GameMatrixItemAdd(int x, int y, Enums.FieldTypes fieldTypes) { if (x > GameMatrix.GetUpperBound(0) || y > GameMatrix.GetUpperBound(1)) { return; } GameMatrix[x, y] = (int)fieldTypes; }
// Start is called before the first frame update void Start() { winner = 0; wm = GetComponent <WinManager>(); ai = GetComponent <AIPlaceManager>(); setPlayers(MenuManager.AIPlayers); players = shuffle(player1, player2, player3); gm = new GameMatrix(); }
public void ProcessAllRules_DefaultRules_ShouldBeValid() { var processRules = ProcessRules.DefaultRules(); var gameMatrix = new GameMatrix(6, 6).Activate(new[] { new Point(2, 3) }); Assert.That(gameMatrix[2, 3].IsOn, "Initialized Correctly"); processRules.ProcessAllRules(gameMatrix); Assert.That(gameMatrix[2, 3].IsOn, Is.False, "It dies was removed"); }
public void ProcessAllRules_AnyLiveCellWithFewerThanTwoLiveNeighboursDies_IsDead() { var processRules = new ProcessRules(new Rule().Live().CellWithFewerThan(2).Neighbours().Dies()); var gameMatrix = new GameMatrix(6, 6).Activate(new [] { new Point(2, 3) }); Assert.That(gameMatrix[2, 3].IsOn, "Initialized Correctly"); processRules.ProcessAllRules(gameMatrix); Assert.That(gameMatrix[2, 3].IsOn, Is.False, "It dies was removed"); }
static void Main(string[] args) { int x, y, r; string e; Console.WriteLine("BubbleBreaker Console:"); Console.WriteLine("======================"); Console.Write("Anzahl Zeilen? "); e = Console.ReadLine(); x = int.Parse(e); Console.Write("Anzahl Spalten? "); e = Console.ReadLine(); y = int.Parse(e); GameMatrix SpielLogik = new GameMatrix(x, y); SpielLogik.ResetMatrix(); Console.WriteLine(MatrixAusgeben(SpielLogik)); // Main Loop while (SpielLogik.EsGibtGleicheNachbarnUndMatrixIstNichtLeer()) { Console.Write("Element auswählen (#zeile,#spalte): "); e = Console.ReadLine(); // Ich mache keine checks ob die Eingabe korrekt ist, ich gehe davon aus, dass korrekte Eingaben erfolgen string[] pStringArray = e.Split(',', ':', '/', '.', ';', ' '); if (pStringArray.Length != 2) { continue; // Falscheingaben abfangen } x = int.Parse(pStringArray[0]); // x Adresse y = int.Parse(pStringArray[1]); // y Adresse if (x < 0 || x >= SpielLogik.Zeilen) { continue; // Falscheingaben abfangen } if (y < 0 || y >= SpielLogik.Spalten) { continue; // Falscheingaben abfangen } r = SpielLogik.FindeGleicheNachbarn(x, y); Console.WriteLine(string.Format("Gefundene gleichfarbige Bubble: {0}", r)); SpielLogik.EnferneAusgewaehlteBubbles(); Console.WriteLine(); Console.WriteLine(MatrixAusgeben(SpielLogik)); } Console.WriteLine(); Console.WriteLine("Spiel ist zu ende! Kein weiterer Zug möglich!"); Console.ReadLine(); }
public void ClientSwapH(AGameObject go1, AGameObject go2) { GameMatrix.SwapH(go1, go2); clientSwapModel = new SwapModel { GameObject1 = go1, GameObject2 = go2, Direction = SwapDirection.HORIZONTAL }; }
public void ClientSwapV(AGameObject go1, AGameObject go2) { GameMatrix.SwapV(go1, go2); clientSwapModel = new SwapModel { GameObject1 = go1, GameObject2 = go2, Direction = SwapDirection.VERTICAL }; }
/// <summary> /// Neues Spiel starten (Erzeugen neues Spiel und Gfx Objekt, Initialisieren, Erstmalige Anzeige) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click(object sender, RoutedEventArgs e) { StartMsg.Visibility = Visibility.Collapsed; SpielLogik = new GameMatrix(10, 10); SpielGfx = new GfxInterface(MyCanvas, SpielLogik); SpielLogik.ResetMatrix(); SpielGfx.BubblesAnzeigen(); PunktzahlAnzeigen(); MyCanvas.PointerPressed += MyCanvas_PointerPressed; MyCanvas.PointerMoved += MyCanvas_PointerMoved; }
public int HandleAIMove(int playerID, GameMatrix gm, int AIinfo) { if (AIinfo == 1) { return(AggresiveMove(playerID, gm)); } else { return(RandomMove(playerID, gm)); } }
public void ProcessAllRules_AnyDeadCellWithExactlyThreeLiveNeighbours_BecomesLiveCell() { var processRules = new ProcessRules(new Rule().Dead().CellWithExactly(3).Neighbours().Lives()); var activate = new[] { new Point(2, 2), new Point(3, 3), new Point(2, 4) }; var gameMatrix = new GameMatrix(6, 6).Activate(activate); var processAllRules = processRules.ProcessAllRules(gameMatrix); var shouldBeActive = new[] { new Point(2, 2), new Point(2, 3), new Point(2, 4), new Point(3, 3) }; Assert.That(processAllRules.Count, Is.EqualTo(1), "Changes"); Assert.That(gameMatrix.GetCells(shouldBeActive).IsAllAlive(), "All Points are alive"); }
public void ProcessAllRules_AnyLiveCellWithTwoLiveNeighbours_ShouldLiveOn() { var processRules = new ProcessRules( new Rule().Live().CellWithTwoOrThree().Neighbours().Lives()); var activate = new[] { new Point(2, 2), new Point(2, 3), new Point(3, 2), new Point(3, 3) }; var gameMatrix = new GameMatrix(6, 6).Activate(activate); var processAllRules = processRules.ProcessAllRules(gameMatrix); var shouldBeActive = new[] { new Point(2, 2), new Point(2, 3), new Point(3, 2), new Point(3, 3) }; Assert.That(processAllRules.Count, Is.EqualTo(4), "Changes"); Assert.That(gameMatrix.GetCells(shouldBeActive).IsAllAlive(), "All Points are alive"); }
private void ResetMatrix() { if (gameMatrix != null) { List <GameObject> cubesFromPrevRound = gameMatrix.GetLeftOversCubes(); cubesFromPrevRound.AddRange(gameMatrix.GetOverStacked()); for (int i = cubesFromPrevRound.Count - 1; i >= 0; i--) { Destroy(cubesFromPrevRound[i]); } } gameMatrix = new GameMatrix(matrixDimensions); }
private int PrimaryWinMove(int playerID, GameMatrix gm) { for (int iii = 1; iii < 10; iii++) { if (gm.MoveLegal(iii)) { if (gm.MoveWinner(iii, playerID) == playerID) { return(iii); } } } return(0); }
protected override void ProduceAtCase(int indexR, int indexC, GameMatrix mat) { if (gnd.IsAccessible(indexR, indexC)) { GameObject obj = res.GetObject(indexR, indexC); if (obj != null) { if (!string.Equals(obj.tag, "none") && obj.GetComponent <Radioactive>() == null) { obj.AddComponent <Radioactive> (); } } } }
public static bool CheckField(int left, int top, List <Enums.FieldTypes> fieldTypes) { if (left > GameMatrix.GetUpperBound(0) || top > GameMatrix.GetUpperBound(1) || left < 0 || top < 0) { return(false); } foreach (Enums.FieldTypes item in fieldTypes) { if (GameMatrix[left, top] == (int)item) { return(true); } } return(false); }
/// <summary> /// Konstruktor Initialisiert die Verweise auf benötigte Objekte der Oberfläche und der Spiel Logik /// </summary> /// <param name="canvas">Objekt für die Zeichenfläche</param> /// <param name="matrix">Spiel Logik Objekt</param> public GfxInterface(Canvas canvas, GameMatrix matrix) { _canvas = canvas; _matrix = matrix; _farben[BubbleFarbe.Rot] = new SolidColorBrush(Colors.Red); _farben[BubbleFarbe.Gruen] = new SolidColorBrush(Colors.Green); _farben[BubbleFarbe.Blau] = new SolidColorBrush(Colors.Blue); _farben[BubbleFarbe.Violett] = new SolidColorBrush(Colors.Purple); ZellMass = PlatzProZelle(); _letzterFokus.X = -1.0; _letzterFokus.Y = -1.0; _fokus = ErzeugeFokusObjekt(); _fokusAn = false; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.activity_main); //Grid initialization gridGame = FindViewById <GridView>(Resource.Id.gridGame); //Imageview Initialization imgResetGame = FindViewById <ImageView>(Resource.Id.imgResetGame); imgflagCell = FindViewById <ImageView>(Resource.Id.imgflag); //Object with game settings settings = SetupGame.LoadGameSetup("easy"); //Max number of colums for the grid, equivalent to the horizontal spots gridGame.NumColumns = settings.xAxis; availableFlags = settings.mines; //All Game Data GameData = new GameMatrix(settings.xAxis, settings.yAxis, settings.mines); GameData.InitialSetup(rand); //List is sent to the Custom Adapter objCell = new deviget_minesweeper.ClassAdapters.CustomCellAdapter(GameData.ListCells, (AppCompatActivity)this); objCell.actionMenuSelected += ObjCell_actionMenuSelected; imgResetGame.Click += ImgResetGame_Click; imgflagCell.Click += ImgflagCell_Click; //Data populate to the GridView gridGame.Adapter = objCell; objCell.NotifyDataSetChanged(); }
/// <summary> /// Ausgabe der Matrix, trennung Präsentationslogic von spiel Logic !!! /// </summary> /// <param name="matrix"></param> /// <returns></returns> static string MatrixAusgeben(GameMatrix matrix) { string result = ""; string crlf = Environment.NewLine; string xAchse = " |"; for (int i = 0; i < matrix.Spalten; i++) { xAchse += string.Format(" {0,2} |", i); } xAchse += crlf; string xDiv = " "; foreach (char e in xAchse) { xDiv += "-"; } xDiv += crlf; string Zeile = ""; string punkte = string.Format("Punktzahl: {0}", matrix.Score) + crlf + crlf; result += punkte; result += xAchse; result += xDiv; for (int i = 0; i < matrix.Zeilen; i++) // Zeilen { Zeile = string.Format(" {0,2} |", i); for (int j = 0; j < matrix.Spalten; j++) { Zeile += string.Format(" {0} |", matrix.ZelleDerAdresse(i, j).FarbRepraesentation()); } Zeile += string.Format(" {0,2}", i); Zeile += crlf; result += Zeile; result += xDiv; } result += xAchse; return(result); }
public static List <Position> GetWallPositions() { List <Position> positions = new List <Position>(); for (int i = 0; i <= GameMatrix.GetUpperBound(0); i++) { for (int j = 0; j <= GameMatrix.GetUpperBound(1); j++) { if (GameMatrix[i, j] == (int)Enums.FieldTypes.wall) { Position p = new Position(); p.X = i * field_width + (field_width / 2); p.Y = j * field_height + (field_height / 2); positions.Add(p); } } } return(positions); }
public MainWindow() { InitializeComponent(); _gameMatrix = new GameMatrix(40, 40); _rules = ProcessRules.DefaultRules(); _timer = new Timer { Interval = TimeSpan.FromSeconds(.5).TotalMilliseconds, }; _timer.Elapsed += UpdateBoard; _gameMatrix.Activate(_gameMatrix.RandomPoints().Take((_gameMatrix.Height * _gameMatrix.Width) / 2).ToArray()); Loaded += OnLoaded; const byte i = 241; _colorOff = new SolidColorBrush(new Color { A = 255, R = i, B = i, G = i }); _colorOn = new SolidColorBrush(Colors.Gray); }
protected virtual void ProduceAtCase(int indexR, int indexC, GameMatrix mat) { if (gnd.IsAccessible(indexR, indexC)) { GameObject obj = mat.GetObject(indexR, indexC); if (obj != null) { if (string.Equals(obj.tag, prefabProduced.tag)) { // La ressource sur le terrain est la meme que la ressource produite par le terrain, donc on stack la nouvelle ressource sur celle deja presente obj.GetComponent <QuantityUnit> ().StackUnit(); } else if (string.Equals(obj.tag, "none")) { // On a une ressource nulle sur le terrain. On la remplace par une ressource produite. obj = InstantiateGameObject(coo.indexR, coo.indexC, prefabProduced); } // sinon, la ressource presente est differente donc on ne la remplace pas/ on ne la stack pas } } }
// Update is called once per frame public int RandomMove(int playerID, GameMatrix gm) { int pWinCheck = PrimaryWinMove(playerID, gm); if (pWinCheck != 0) { return(pWinCheck); } int pBlockCheck = PrimaryBlockMove(playerID, gm); if (pBlockCheck != 0) { return(pBlockCheck); } int value = (int)(Random.value * 10); value = value % 9; value = value + 1; return(value); }
private int PrimaryBlockMove(int playerID, GameMatrix gm) { int nextPlayer; if (playerID == 3) { nextPlayer = 1; } else { nextPlayer = playerID + 1; } for (int iii = 1; iii < 10; iii++) { if (gm.MoveLegal(iii)) { if (gm.MoveWinner(iii, nextPlayer) == nextPlayer) { return(iii); } } } return(0); }
public CheckersGameBoard(eBoardSize i_BoardSize) { r_BoardSize = i_BoardSize; r_BoardMatrix = new GameMatrix((int)r_BoardSize, (int)r_BoardSize); InitializePiecesOnBoard(); }