Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com pacman c#

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 03-09-2011, 03:38 PM PM User | #1 jannemoon New to the CF scene   Join Date: Mar 2011 Posts: 1 Thanks: 0 Thanked 0 Times in 0 Posts pacman c# Me and a friend have to make pacman in csharp for school. And we're stuck. We got some kind of code for the collision of pacman, although it's not the thing we want, because with this code pacman has to start in the left corner. So if anyone wants to help us with this, he would be greatful. Code: ```int a = 1; int b = 1; private void frmMain_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Right) { position = 1; if (b + 1 <= _Level1.GetLength(0)) { if (_Level1[a, b + 1] == 0) { pacman.MoveRight(); b++; } } } if (e.KeyCode == Keys.Left) { position = 2; if (b - 1 >= 0) { if (_Level1[a, b - 1] == 0) { pacman.MoveLeft(); b--; } } } if (e.KeyCode == Keys.Up) { position = 3; if (a - 1 >= 0) { if (_Level1[a - 1, b] == 0) { pacman.MoveUp(); a--; } } } if (e.KeyCode == Keys.Down) { position = 4; if (a + 1 <= _Level1.GetLength(0)) { if (_Level1[a + 1, b] == 0) { pacman.MoveDown(); a++; } } } }``` _Level1 is the name of our array, which is 28x28. In our array a '0' stands for a walkable tile. We were thinking about getting the value of the array and then checking if it is a walkable tile or not, but we don't have any clue how to do it. Another problem we have with letting our monsters walk randomly without getting through the walls. We got the right code, atleast we think we have, because it works when we apply it to 1 monster. If we try to use the code on 4 monsters they start walking through the walls. And again, with this code the monsters have to start in the top left corner. Code: ```private int _monsterMove1, _monsterMove2, _monsterMove3, _monsterMove4; int c = 1; int d = 1; private bool noLeft = false; private bool noRight = false; private bool noUp = false; private bool noDown = false; private void monsterMove() { Random monsterMove1 = new Random(); _monsterMove1 = monsterMove1.Next(1, 5); Random monsterMove2 = new Random(); _monsterMove2 = monsterMove2.Next(6, 10); Random monsterMove3 = new Random(); _monsterMove3 = monsterMove3.Next(11, 15); Random monsterMove4 = new Random(); _monsterMove4 = monsterMove4.Next(16, 20); } private void monsterBlock() { monsterMove(); if (noRight) { if (_monsterMove1 == 1) { _monsterMove1 = 2; noRight = false; } if (_monsterMove2 == 6) { _monsterMove2 = 7; noRight = false; } if (_monsterMove3 == 11) { _monsterMove3 = 12; noRight = false; } if (_monsterMove4 == 16) { _monsterMove4 = 17; noRight = false; } } else { if (noLeft) { if (_monsterMove1 == 2) { _monsterMove1 = 3; noLeft = false; } if (_monsterMove2 == 7) { _monsterMove2 = 8; noLeft = false; } if (_monsterMove3 == 12) { _monsterMove3 = 13; noLeft = false; } if (_monsterMove4 == 17) { _monsterMove4 = 18; noLeft = false; } } else { if (noUp) { if (_monsterMove1 == 3) { _monsterMove1 = 4; noUp = false; } if (_monsterMove2 == 8) { _monsterMove2 = 9; noUp = false; } if (_monsterMove3 == 13) { _monsterMove3 = 14; noUp = false; } if (_monsterMove4 == 18) { _monsterMove4 = 19; noUp = false; } } else { if (noDown) { if (_monsterMove1 == 4) { _monsterMove1 = 1; noDown = false; } if (_monsterMove2 == 9) { _monsterMove2 = 6; noDown = false; } if (_monsterMove3 == 14) { _monsterMove3 = 11; noDown = false; } if (_monsterMove4 == 19) { _monsterMove4 = 16; noDown = false; } } } } } StepRight(); StepLeft(); StepDown(); StepUp(); } private void StepRight() { if (_monsterMove1 == 1 && _Level1[c, d - 1] == 0) { monster1.MoveRight(); d--; } if (_monsterMove2 == 6 && _Level1[c, d + 1] == 0) { monster2.MoveRight(); d++; } if (_monsterMove3 == 11 && _Level1[c, d + 1] == 0) { monster3.MoveRight(); d++; } if (_monsterMove4 == 16 && _Level1[c, d + 1] == 0) { monster4.MoveRight(); d++; } } private void StepLeft() { if (_monsterMove1 == 2 && _Level1[c, d - 1] == 0) { monster1.MoveLeft(); d--; } if (_monsterMove2 == 7 && _Level1[c, d - 1] == 0) { monster2.MoveLeft(); d--; } if (_monsterMove3 == 12 && _Level1[c, d - 1] == 0) { monster3.MoveLeft(); d--; } if (_monsterMove4 == 17 && _Level1[c, d - 1] == 0) { monster4.MoveLeft(); d--; } } private void StepDown() { if (_monsterMove1 == 3 && _Level1[c + 1, d] == 0) { monster1.MoveDown(); c++; } if (_monsterMove2 == 8 && _Level1[c + 1, d] == 0) { monster2.MoveDown(); c++; } if (_monsterMove3 == 13 && _Level1[c + 1, d] == 0) { monster3.MoveDown(); c++; } if (_monsterMove4 == 18 && _Level1[c + 1, d] == 0) { monster4.MoveDown(); c++; } } private void StepUp() { if (_monsterMove1 == 4 && _Level1[c - 1, d] == 0) { monster1.MoveUp(); c--; } if (_monsterMove2 == 9 && _Level1[c - 1, d] == 0) { monster2.MoveUp(); c--; } if (_monsterMove3 == 14 && _Level1[c - 1, d] == 0) { monster3.MoveUp(); c--; } if (_monsterMove4 == 19 && _Level1[c - 1, d] == 0) { monster4.MoveUp(); c--; } }``` Thanks in advance.

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 07:14 AM.