public void ChangePanel(Direction direction) { newX = x; newY = y; switch (direction) { case Direction.Up: newY -= 1; break; case Direction.Down: newY += 1; break; case Direction.Left: newX -= 1; break; case Direction.Right: newX += 1; break; } if (newX < 0 || newY < 0 || newX >= _panels.GetLength(1) || newY >= _panels.GetLength(0)) { return; } _transitionLine = 0; _transitionDirection = direction; _isTransitioning = true; }
public void NewGame() { currentGameRules = new GameRules(); //resetting game-state parameters activePawn = null; isWhiteTurn = false; isCaptureAvailable = false; isMultiCapture = false; //populating board with pawns moveList.Clear(); foreach (Target t in targetList) { t.Dispose(); } targetList.Clear(); if (boardPanels != null) { //made that way so panels from board wouldn't flicker when new game is created //create new board with new pawns List <Pawn> newPawns = new List <Pawn>(); Panel[,] newPanels = InitializeBoard(); InitializePawns(newPanels, newPawns); foreach (Pawn p in newPawns) { p.ResetPawnGraphics(); } for (int i = 0; i < boardPanels.GetLength(0); i++) { for (int j = 0; j < boardPanels.GetLength(1); j++) { boardPanels[i, j].Dispose(); } } for (int i = 0; i < pawnList.Count; i++) { pawnList[i].Dispose(); } pawnList.Clear(); boardPanels = newPanels; pawnList = newPawns; } else { this.boardPanels = InitializeBoard(); InitializePawns(boardPanels, pawnList); foreach (Pawn p in pawnList) { p.ResetPawnGraphics(); } } InitializeTurn(); }
public void TestBoardSize() { //This procedure ensures the board is an 8 by 8 grid Panel[,] board = gen.GenerateBoard(); if (!(board.GetLength(0) == 8 && board.GetLength(1) == 8)) { Assert.Fail(); } }
private void Clear(Panel[,] panel) { for (int i = 0; i < panel.GetLength(0); i++) { for (int j = 0; j < panel.GetLength(1); j++) { panel[i, j].BackgroundImage = null; } } }
public void CreateBoard(Label original) { for (int row = 0; row < grid.GetLength(0); row++) { for (int col = 0; col < grid.GetLength(1); col++) { grid[row, col] = new Panel(Clone(original, row + "-" + col, new Point(30 * col + 5, 30 * row + 5))); //create the panels } } }
private void initColorPanelRow(int row) { for (int i = 0; i < colorPanels.GetLength(1); i++) { colorPanels[row, i] = new Panel(); colorPanels[row, i].Width = panelWidth; colorPanels[row, i].Height = panelHeight; colorPanels[row, i].Left = i * panelWidth; colorPanels[row, i].Top = row * panelHeight; colorPanels[row, i].BackColor = Color.Black; pnlContainer.Controls.Add(colorPanels[row, i]); } }
void SetColours() { for (int i = 0; i < BoardState.GetLength(0); i++) { for (int x = 0; x < BoardState.GetLength(1); x++) { BoardState[i, x].BackColor = Grey; } } for (int i = 0; i < SideAnswerSquares.GetLength(0); i++) { SideAnswerSquares[i].BackColor = Grey; } }
void InitializeGame() { seed = Environment.TickCount; rnd = new Random(seed); rnd = new Random(seed + rnd.Next(0, 100)); it_list = new List <Item>(); its_number = new List <int>(); for (int i = 0; i < 4; i++) { its_number.Add(ItemReset()); } p1_it_count = 0; //パネルセット初期化 panel_data1 = new Panel[3, 4]; panel_data2 = new Panel[3, 4]; for (int i = 0; i < panel_data1.GetLength(0); i++) { for (int j = 0; j < panel_data1.GetLength(1); j++) { panel_data1[i, j] = new Panel(p_list[rnd.Next(0, 4)], rnd.Next(0, 4)); } } for (int i = 0; i < panel_data2.GetLength(0); i++) { for (int j = 0; j < panel_data2.GetLength(1); j++) { panel_data2[i, j] = new Panel(p_list[rnd.Next(0, 4)], rnd.Next(0, 4)); } } c_list = new List <Cursor>(); c_list.Add(new Cursor("Player1", cs, playerImage[0], scoreImage, wk, ar, Vector2.Zero, panel_data1, new Vector2(h_margin, v_margin), new Keys[6] { Keys.W, Keys.D, Keys.S, Keys.A, Keys.Q, Keys.E }, oc, 1, cr_se1, pz_se, it_se, fd_se)); c_list.Add(new Cursor("Player2", cs, playerImage[1], scoreImage, wk, ar, Vector2.Zero, panel_data2, new Vector2(window_width - h_margin - pn_size * panel_data2.GetLength(0), v_margin), new Keys[6] { Keys.NumPad8, Keys.NumPad6, Keys.NumPad5, Keys.NumPad4, Keys.NumPad7, Keys.NumPad9 }, sq, 3, cr_se2, pz_se, it_se, fd_se)); start = false; end = false; inter = 0; MediaPlayer.IsRepeating = true; clm = false; co_nm = Color.White; freezeCount = FREEZEWAIT; }
private int[] FindObjIndexesByPanel(Panel panel) { for (int i = 0; i < _field.GetLength(0); i++) { for (int k = 0; k < _field.GetLength(1); k++) { if (_field[i, k] == panel) { return(new Int32[2] { i, k }); } } } return(null); }
public SlidePuzzleControl(int rows, int columns) { InitializeComponent(); Tiles = new Panel[rows, columns]; int[] indeces = new int[rows * columns - 1]; for (int i = 0; i < indeces.Length; i++) { indeces[i] = i + 1; } Random random = new(); for (int i = 0; i < indeces.Length; i++) { int b = random.Next(indeces.Length); int temp = indeces[i]; indeces[i] = indeces[b]; indeces[b] = temp; } int index = 0; for (int row = 0; row < Tiles.GetLength(0); row++) { for (int column = 0; column < Tiles.GetLength(1); column++) { if (row is 0 && column is 0) { continue; } Panel panel = new(); Label label = new(); label.Text = indeces[index++].ToString(); panel.BackColor = GetRandomColor(); bool isDark = panel.BackColor.R + panel.BackColor.G + panel.BackColor.B / 3 < 255 / 2; panel.ForeColor = isDark ? Color.White : Color.Black; panel.Click += Tile_Click; panel.Controls.Add(label); Tiles[row, column] = panel; Controls.Add(panel); } } CustomLayout(); }
//______________________________________Zeichnen der Panels________________________ private void initPanelSchwarzWeiss() { for (int i = 0; i < panelSchwarzWeiss.GetLength(0); i++) { for (int j = 0; j < panelSchwarzWeiss.GetLength(1); j++) { panelSchwarzWeiss[i, j] = new Panel(); panelSchwarzWeiss[i, j].Width = RESULTSQUARE; panelSchwarzWeiss[i, j].Height = RESULTSQUARE; panelSchwarzWeiss[i, j].Left = panelVersuche[i, 4].Location.X + RESULTSQUARE + 10 + (j * 25) + 50; //TODO: dieErgebnisse[i, j].Left = farbwahlbox.Location.X + (farbwahlbox.Width - (i*RESULTSQUARE) - 10); panelSchwarzWeiss[i, j].Top = panelVersuche[i, 4].Location.Y + ((panelVersuche[i, j].Height - RESULTSQUARE) / 2); panelSchwarzWeiss[i, j].BackColor = Color.LightGray; panelSchwarzWeiss[i, j].Parent = this; panelSchwarzWeiss[i, j].BringToFront(); } } }
Panel[,] ShuffledPanels() { Panel[,] dstPanels = panels; int len_x = dstPanels.GetLength(0); int len_y = dstPanels.GetLength(1); int pLength = len_x * len_y; for (int i = 0; i < pLength; i++) { int r = Random.Range(0, pLength); int[] srcIndex = OneDimensionToTwo(r); int[] dstIndex = OneDimensionToTwo(i); Panel temp = dstPanels [dstIndex [0], dstIndex [1]]; dstPanels [dstIndex [0], dstIndex [1]] = dstPanels [srcIndex [0], srcIndex [1]]; dstPanels [srcIndex [0], srcIndex [1]] = temp; } return(dstPanels); }
private void initColorPanels() { colorPanels = new Panel[panelXCount, panelYCount]; pnlContainer.Width = panelXCount * panelWidth; pnlContainer.Height = panelYCount * panelHeight; pnlContainer.Controls.Clear(); for (int i = 0; i < colorPanels.GetLength(0); i++) { initColorPanelRow(i); } }
/// <summary> /// Zeichnen der Panele, Groupboxen für die versuche /// </summary> private void initPanelVersuche() { for (int i = 0; i < panelVersuche.GetLength(0); i++) //Spalten { for (int j = 0; j < panelVersuche.GetLength(1); j++) //Zeilen { panelVersuche[i, j] = new Panel(); panelVersuche[i, j].Width = VERSUCHSQUARE; panelVersuche[i, j].Height = VERSUCHSQUARE; panelVersuche[i, j].Left = (j * 52) + 20; panelVersuche[i, j].Top = this.Height - 200 - (i * 47); panelVersuche[i, j].BackColor = Color.LightGray; panelVersuche[i, j].Parent = this; panelVersuche[i, j].BringToFront(); panelVersuche[i, j].Click += versuch_Click; } } /////////////////////////////////////Grouboxen///////////////////////////////// for (int i = 0; i < panelVersuche.GetLength(0); i++) { versuchsbox = new GroupBox(); versuchsbox.Text = "Versuch " + (i + 1); versuchsbox.Font = new Font("Calibri", 10, FontStyle.Italic); versuchsbox.ForeColor = Color.White; versuchsbox.Location = new Point(10, panelVersuche[i, 1].Location.Y - 16); versuchsbox.Width = 270; versuchsbox.Height = 55; this.Controls.Add(versuchsbox); versuchsbox.BackColor = Color.Transparent; } }
public void onDraw() { int s; if (cr_dr_f == 1) { s = 11; } else { s = 2; } Game1.spriteBatch.Draw(wk, new Rectangle((int)pn_pos.X - s, (int)pn_pos.Y - 10, Game1.pn_size * p_data.GetLength(0) + 12, Game1.pn_size * p_data.GetLength(1) + 20), Color.White); Game1.spriteBatch.Draw(Game1.p_list[4].im, new Rectangle((int)pn_pos.X, (int)pn_pos.Y, Game1.pn_size * p_data.GetLength(0), Game1.pn_size * p_data.GetLength(1)), null, Color.White * fd); Rectangle re = new Rectangle(0, 0, Game1.pn_size, Game1.pn_size); for (int i = 0; i < p_data.GetLength(0); i++)//パネル描画 { for (int j = 0; j < p_data.GetLength(1); j++) { if (i == (int)(nm_mv1.X / Game1.pn_size) && j == (int)(nm_mv1.Y / Game1.pn_size) && ch_cn != -1) { re.X = (int)(pn_pos.X + nm_mv1.X) + Game1.pn_size / 2; re.Y = (int)(pn_pos.Y + nm_mv1.Y) + Game1.pn_size / 2; } else if (i == (int)(nm_mv2.X / Game1.pn_size) && j == (int)(nm_mv2.Y / Game1.pn_size) && ch_cn != -1) { re.X = (int)(pn_pos.X + nm_mv2.X) + Game1.pn_size / 2; re.Y = (int)(pn_pos.Y + nm_mv2.Y) + Game1.pn_size / 2; } else { re.X = (int)pn_pos.X + Game1.pn_size / 2 + i * Game1.pn_size; re.Y = (int)pn_pos.Y + Game1.pn_size / 2 + j * Game1.pn_size; } Game1.spriteBatch.Draw(p_data[i, j].im, re, null, new Color(vsanm[i, j], vsanm[i, j], vsanm[i, j], 255 * fd), (float)(Math.PI * p_data[i, j].dr / 2), new Vector2(p_data[i, j].im.Width / 2, p_data[i, j].im.Height / 2), SpriteEffects.None, 0f); } } Game1.spriteBatch.Draw(im, new Rectangle((int)(pos.X + vel.X + pn_pos.X) - 5, (int)(pos.Y + vel.Y + pn_pos.Y) - 5, Game1.pn_size + 10, Game1.pn_size + 10), Color.White);//カーソル描画 if (slc && ch_cn == -1) { for (int i = 0; i < 4; i++) { if (mable[i]) { Game1.spriteBatch.Draw(ar_im, new Rectangle((int)(pos.X + pn_pos.X) + Game1.pn_size / 2, (int)(pos.Y + pn_pos.Y) + Game1.pn_size / 2, Game1.pn_size, Game1.pn_size), null, Color.White, (float)(Math.PI * i / 2), new Vector2(ar_im.Width / 2, ar_im.Height * 1.5f), SpriteEffects.None, 0f); } } } for (int i = 0; i < cr_data.Count; i++) { cr_data[i].onDraw(); } Game1.spriteBatch.Draw(scoreImage, new Rectangle((int)pn_pos.X + 20, (int)pn_pos.Y - 100, 120, 40), Color.White); Game1.spriteBatch.DrawString(Game1.spriteFont1, sc.ToString(), pn_pos + new Vector2(250, -100), Color.SkyBlue); Game1.spriteBatch.DrawString(Game1.spriteFont1, t[0].ToString(), pn_pos + new Vector2(0, -150), Color.SkyBlue); Game1.spriteBatch.DrawString(Game1.spriteFont1, t[1].ToString(), pn_pos + new Vector2(50, -150), Color.SkyBlue); Game1.spriteBatch.Draw(nameImage, new Rectangle((int)pn_pos.X + 20, (int)pn_pos.Y - 50, 180, 40), Color.White); }
public Cursor(string name, Texture2D image, Texture2D nameImage, Texture2D scoreImage, Texture2D waku_image, Texture2D arrow_image, Vector2 position, Panel[,] panel_data, Vector2 panel_pos, Keys[] key_set, Texture2D[] creature_image, int creature_direction, SoundEffect move_se, SoundEffect change_se, SoundEffect item_se, SoundEffect fade_se) { nm = name; wk = waku_image; im = image; this.nameImage = nameImage; this.scoreImage = scoreImage; ar_im = arrow_image; pos = position; vel = Vector2.Zero; sp = DEFAULT_SPEED; spSub = sp; mv_count = sp + 1; inter = 10; se_count = 0; p_data = panel_data; vsflag = new bool[p_data.GetLength(0), p_data.GetLength(1)]; vsanm = new float[p_data.GetLength(0), p_data.GetLength(1)]; for (int i = 0; i < vsflag.GetLength(0) * vsflag.GetLength(1); i++) { vsflag[i % vsflag.GetLength(0), i / vsflag.GetLength(0)] = false; vsanm[i % vsflag.GetLength(0), i / vsflag.GetLength(0)] = 1.00f; } pn_pos = panel_pos; k_set = key_set; dire = Vector2.Zero; slc = false; mable = new bool[4] { false, true, true, false }; cr_im = creature_image; cr_mable = new bool[4] { false, false, false, false }; cr_dr_f = creature_direction; glx = 0; int vcrx = 0; switch (cr_dr_f) { case 1: vcrx = -Game1.pn_size; glx = Game1.pn_size * panel_data.GetLength(0); number = 0; break; case 3: vcrx = Game1.pn_size * panel_data.GetLength(0); glx = -Game1.pn_size; number = 1; break; } cr_pos_f = new Vector2(vcrx, Game1.rnd.Next(0, panel_data.GetLength(1)) * Game1.pn_size); prc = false; mv_se = move_se; ch_se = change_se; it_se = item_se; fd_se = fade_se; cr_data = new List <Creature>(); cr_data.Add(new Creature(cr_im, cr_pos_f, pn_pos, glx, cr_dr_f, spSub, 2, p_data, it_se, fd_se, isSpUp, isSpDown)); sc = 0; rt = 1f; fd = 1f; gnr = true; ch_sp = 8; ch_cn = -1; t = new int[2] { 0, 0 }; it_process = true; }
public void initialize(bool k = true) { if (k) { if (gnr) { fd -= 0.1f; if (fd <= 0f) { gnr = false; } } else { if (fd <= 0f) { p_data = new Panel[3, 4]; for (int i = 0; i < p_data.GetLength(0); i++) { for (int j = 0; j < p_data.GetLength(1); j++) { p_data[i, j] = new Panel(Game1.p_list[Game1.rnd.Next(0, 4)], Game1.rnd.Next(0, 4)); vsflag[i, j] = false; vsanm[i, j] = 1.00f; } } Item_Handle(true, 2); Item_Handle(false, 2); rt = 1f; fd = 0.1f; } else { fd += 0.1f; if (fd >= 1f) { prc = false; gnr = true; cr_pos_f.Y = Game1.rnd.Next(0, p_data.GetLength(1)) * Game1.pn_size; cr_data.Add(new Creature(cr_im, cr_pos_f, pn_pos, glx, cr_dr_f, spSub, 2, p_data, it_se, fd_se, isSpUp, isSpDown)); } } } } else { p_data = new Panel[3, 4]; for (int i = 0; i < p_data.GetLength(0); i++) { for (int j = 0; j < p_data.GetLength(1); j++) { p_data[i, j] = new Panel(Game1.p_list[Game1.rnd.Next(0, 4)], Game1.rnd.Next(0, 4)); vsflag[i, j] = false; vsanm[i, j] = 1.00f; } } cr_pos_f.Y = Game1.rnd.Next(0, p_data.GetLength(1)) * Game1.pn_size; cr_data.Add(new Creature(cr_im, cr_pos_f, pn_pos, glx, cr_dr_f, spSub, 2, p_data, it_se, fd_se, isSpUp, isSpDown)); prc = false; gnr = true; } }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { // Random patrooling action int row = 0; int col = 0; int prevRow = -1; int prevCol = -1; Random rnd = new Random(); while (true) { if (prevRow >= 0 && prevCol >= 0) { mapPanels[prevRow, prevCol].BackgroundImage = Image.FromFile(mapLocations[prevRow, prevCol]); } cor1 = prevRow; cor2 = prevCol; mapPanels[row, col].BackgroundImage = Image.FromFile("C:\\Users\\i.Gerov\\source\\repos\\Emergency Center\\Emergency Center\\Images\\police.png"); prevRow = row; prevCol = col; if (backgroundWorker1.CancellationPending) { cor1 = -1; cor2 = -1; mapPanels[row, col].BackgroundImage = Image.FromFile(mapLocations[row, col]); e.Cancel = true; return; } // check for crash if ((row == cor3 && col == cor4)) { cor1 = -1; cor2 = -1; mapPanels[row, col].BackgroundImage = Image.FromFile(mapLocations[row, col]); if (buttonOne.Text == "Stop") { buttonOne.PerformClick(); } if (buttonTwo.Text == "Stop") { buttonTwo.PerformClick(); } reader.Speak("Vehicles have crashed"); e.Cancel = true; MessageBox.Show("CRASH!"); return; } // generate random direction int dir = rnd.Next(0, 4); if (dir == 0) { if (col + 1 < mapPanels.GetLength(1)) { if (mapPanels[row, col + 1].BackColor == clr1) { col++; } else { continue; } } else { continue; } } else if (dir == 1) { if (row + 1 < mapPanels.GetLength(0)) { if (mapPanels[row + 1, col].BackColor == clr1) { row++; } else { continue; } } else { continue; } } else if (dir == 2) { if (col - 1 >= 0) { if (mapPanels[row, col - 1].BackColor == clr1) { col--; } else { continue; } } else { continue; } } else if (dir == 3) { if (row - 1 >= 0) { if (mapPanels[row - 1, col].BackColor == clr1) { row--; } else { continue; } } else { continue; } } //Thread.Sleep(300); Thread.Sleep(500); } }
private void InitializeForm(object sender, EventArgs e) { System.GC.Collect(); panels = new Panel[NB_ROWS, NB_COLUMNS]; selectedPanels = new bool[NB_ROWS, NB_COLUMNS]; this.Controls.Clear(); MainMenu mainStrip = new MainMenu(); MenuItem superGameOption = new MenuItem(); MenuItem subGameNewOption = new MenuItem(); MenuItem subGameLoadOption = new MenuItem(); MenuItem subGameAboutOption = new MenuItem(); superGameOption.Text = "Game"; subGameNewOption.Text = "New Game"; subGameLoadOption.Text = "Load Bingo Data"; subGameAboutOption.Text = "About"; subGameNewOption.Click += new EventHandler(onNewGameMenuClicked); subGameLoadOption.Click += new EventHandler(onLoadDataMenuClicked); subGameAboutOption.Click += new EventHandler(onAboutMenuClicked); superGameOption.MenuItems.Add(subGameNewOption); superGameOption.MenuItems.Add(subGameLoadOption); superGameOption.MenuItems.Add(subGameAboutOption); mainStrip.MenuItems.Add(superGameOption); this.Menu = mainStrip; PictureBox logo = new PictureBox(); logo.Image = Properties.Resources.logo; logo.SizeMode = PictureBoxSizeMode.StretchImage; logo.Location = new Point((ClientSize.Width / 2) - (logo.Size.Width / 2), HEADER / 10); this.Controls.Add(logo); this.Icon = Properties.Resources.icon; List <string> strings = FileReader.ReadFile(gameDataPath); if (strings != null) { string freeSpace = strings[0]; strings.Remove(strings[0]); Shuffle(strings); for (int i = 0; i < panels.GetLength(0); i++) { for (int j = 0; j < panels.GetLength(1); j++) { Panel newPanel = new Panel(); newPanel.Width = this.Width / NB_COLUMNS - 3; newPanel.Height = (this.Height - HEADER) / NB_ROWS; newPanel.Margin = new Padding(0, 0, 0, 0); newPanel.Name = i + ";" + j; newPanel.Location = new Point(j * newPanel.Width, i * newPanel.Height + HEADER / 2); Label newLabel = new Label(); newLabel.AutoSize = false; newLabel.TextAlign = ContentAlignment.MiddleCenter; newLabel.Dock = DockStyle.Fill; newLabel.Click += new EventHandler(OnLabelClicked); newLabel.Name = i + ";" + j; if (newPanel.Name == NB_ROWS / 2 + ";" + NB_COLUMNS / 2) { newLabel.Text = freeSpace; ManageClickOnLabel(newLabel); } else { newLabel.Text = strings[0]; strings.Remove(strings[0]); } panels[i, j] = newPanel; newPanel.Controls.Add(newLabel); this.Controls.Add(newPanel); } } } else { Label newLabel = new Label(); newLabel.AutoSize = false; newLabel.TextAlign = ContentAlignment.MiddleCenter; newLabel.Dock = DockStyle.Fill; newLabel.Text = "A bingo card could not be loaded. Check your Data directory for missing or broken files."; this.Controls.Add(newLabel); } }