public bool update(BGField field) { if (field.GetValueByPosition(left, top) != 3) { return(true); } field.SetValueAtPosition(left, top, 0); if (dir == 1) { top--; } if (dir == 2) { top++; } if (dir == 3) { left--; } if (dir == 4) { left++; } if (top == 20 || top == -1 || left == 10 || left == -1) { return(true); } field.SetValueAtPosition(left, top, 3); return(false); }
private void Fire(BGField field, List <Arrow> Arrows) { int count = 0; for (int i = 0; i < Arrows.Count; i++) { if (Arrows[i].getType()) { count++; } } if (type && count == TankGame.Level) { return; } if (olddir == 1 && top - 2 != -1) { Arrows.Add(new Arrow(left, top - 2, olddir, field, type)); } if (olddir == 2 && top + 2 != 20) { Arrows.Add(new Arrow(left, top + 2, olddir, field, type)); } if (olddir == 3 && left - 2 != -1) { Arrows.Add(new Arrow(left - 2, top, olddir, field, type)); } if (olddir == 4 && left + 2 != 10) { Arrows.Add(new Arrow(left + 2, top, olddir, field, type)); } }
private void Draw(BGField field, int dir_, int value) { field.SetValueAtPosition(left, top, value); field.SetValueAtPosition(left + 1, top, value); field.SetValueAtPosition(left - 1, top, value); field.SetValueAtPosition(left, top + 1, value); field.SetValueAtPosition(left, top - 1, value); switch (dir_) { case 1: field.SetValueAtPosition(left - 1, top + 1, value); field.SetValueAtPosition(left + 1, top + 1, value); //if (type) field.SetValueAtPosition(left, top + 1, value); break; case 2: field.SetValueAtPosition(left - 1, top - 1, value); field.SetValueAtPosition(left + 1, top - 1, value); //if (type) field.SetValueAtPosition(left, top + 1, value); break; case 3: field.SetValueAtPosition(left + 1, top - 1, value); field.SetValueAtPosition(left + 1, top + 1, value); //if (type) field.SetValueAtPosition(left, top + 1, value); break; case 4: field.SetValueAtPosition(left - 1, top - 1, value); field.SetValueAtPosition(left - 1, top + 1, value); //if (type) field.SetValueAtPosition(left, top + 1, value); break; } }
public void update(BGField field) { if (buffer.Count <= 0) { ReCreateBuf(); } PrintWall(field); }
public Arrow(int left_, int top_, int dir_, BGField field, bool type_ = false) { left = left_; top = top_; dir = dir_; type = type_; field.SetValueAtPosition(left, top, 3); }
private void PrintWall(BGField field) { int left = buffer[buffer.Count - 1], top = 0; buffer.RemoveAt(buffer.Count - 1); while (field.GetValueByPosition(left, top) == 2) { top++; } field.SetValueAtPosition(left, top, 2); }
public void delete(BGField field) { field.SetValueAtPosition(left, top, 0); field.SetValueAtPosition(left, top + 1, 0); field.SetValueAtPosition(left, top - 1, 0); field.SetValueAtPosition(left + 1, top, 0); field.SetValueAtPosition(left + 1, top + 1, 0); field.SetValueAtPosition(left + 1, top - 1, 0); field.SetValueAtPosition(left - 1, top, 0); field.SetValueAtPosition(left - 1, top + 1, 0); field.SetValueAtPosition(left - 1, top - 1, 0); }
public void Move(int dir, BGField field, List <Arrow> Arrows) { Print(field, 0); if (dir == 1 && left != 0) { left--; } if (dir == 2 && left != 9) { left++; } Print(field, 1); }
static public bool IsCreateble(BGField field, int left, int top) { for (int i = left; i < left + 5; i++) { for (int j = top; j < top + 5; j++) { if (field.GetValueByPosition(i, j) != 0) { return(false); } } } return(true); }
public bool IsCorrupted(BGField field) { if (field.GetValueByPosition(left, top) == 3) { return(true); } if (field.GetValueByPosition(left, top + 1) == 3) { return(true); } if (field.GetValueByPosition(left, top - 1) == 3) { return(true); } if (field.GetValueByPosition(left + 1, top) == 3) { return(true); } if (field.GetValueByPosition(left + 1, top + 1) == 3) { return(true); } if (field.GetValueByPosition(left + 1, top - 1) == 3) { return(true); } if (field.GetValueByPosition(left - 1, top) == 3) { return(true); } if (field.GetValueByPosition(left - 1, top + 1) == 3) { return(true); } if (field.GetValueByPosition(left - 1, top - 1) == 3) { return(true); } //for(int i = top - 1;i<=top+1;i++) //{ // for(int j = left - 1;j<=left+1;j++) // { // if (field.GetValueByPosition(left, top) == 3) // return true; // } //} return(false); }
public bool update(BGField field, ConsoleKey key, List <Arrow> Arrows) { if (IsCorrupted(field)) { return(true); } if (dir != olddir && dir != 5 && dir != 0) { olddir = dir; } if (ConsoleKey.NoName == key) { dir = 0; } if (ConsoleKey.UpArrow == key) { dir = 1; } if (ConsoleKey.DownArrow == key) { dir = 2; } if (ConsoleKey.LeftArrow == key) { dir = 3; } if (ConsoleKey.RightArrow == key) { dir = 4; } if (ConsoleKey.Spacebar == key) { dir = 5; } if (dir == 5) { Fire(field, Arrows); } if (dir != 0) { Move(field); } return(false); }
private void Move(BGField field) { Draw(field, olddir, 0); if (dir == olddir) { if (dir == 1 && top - 1 != 0) { if (top - 1 >= 1 && field.GetValueByPosition(left, top - 2) != 1 && field.GetValueByPosition(left + 1, top - 2) != 1 && field.GetValueByPosition(left - 1, top - 2) != 1) { top--; } } if (dir == 2 && top + 1 != 19) { if (top + 1 <= 18 && field.GetValueByPosition(left, top + 2) != 1 && field.GetValueByPosition(left + 1, top + 2) != 1 && field.GetValueByPosition(left - 1, top + 2) != 1) { top++; } } if (dir == 3 && left - 1 != 0) { if (left - 1 >= 1 && field.GetValueByPosition(left - 2, top) != 1 && field.GetValueByPosition(left - 2, top + 1) != 1 && field.GetValueByPosition(left - 2, top - 1) != 1) { left--; } } if (dir == 4 && left + 1 != 9) { if (left + 1 <= 18 && field.GetValueByPosition(left + 2, top) != 1 && field.GetValueByPosition(left + 2, top + 1) != 1 && field.GetValueByPosition(left + 2, top - 1) != 1) { left++; } } Draw(field, dir, 1); } if (dir == 5) { Draw(field, olddir, 1); return; } Draw(field, dir, 1); }
public bool update(ConsoleKey key, BGField field, List <Arrow> Arrows) { int direction = 0; if (key == ConsoleKey.LeftArrow) { direction = 1; } if (key == ConsoleKey.RightArrow) { direction = 2; } if (direction == 1 && field.GetValueByPosition(left, top - 1) == 2) { return(true); } Move(direction, field, Arrows); return(false); }
public bool update(BGField field) { if (top == 0) { field.SetValueAtPosition(left, top, 0); return(true); } if (field.GetValueByPosition(left, top - 1) == 2) { field.SetValueAtPosition(left, top - 1, 0); field.SetValueAtPosition(left, top, 0); return(true); } else { field.SetValueAtPosition(left, top, 0); top--; field.SetValueAtPosition(left, top, 1); return(false); } }
private void Print(BGField field, int value) { if (left == 0) { field.SetValueAtPosition(left, top, value); field.SetValueAtPosition(left, top - 1, value); field.SetValueAtPosition(left + 1, top, value); } if (left == 9) { field.SetValueAtPosition(left, top, value); field.SetValueAtPosition(left, top - 1, value); field.SetValueAtPosition(left - 1, top, value); } if (left > 0 && left < 9) { field.SetValueAtPosition(left, top, value); field.SetValueAtPosition(left, top - 1, value); field.SetValueAtPosition(left + 1, top, value); field.SetValueAtPosition(left - 1, top, value); } }