CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   A Tricky Question for JavaScript (http://www.codingforums.com/showthread.php?t=273397)

Aurak 09-17-2012 11:20 PM

A Tricky Question for JavaScript
 
I am a university student, currently working on my assessment piece for this semester for my application development class, and for it, we need to develop and make a working app for a mobile device. Before I go too much further, we have to use a program called Appcelerator Titanium Studio for the coding, and it uses JavaScript to do the coding.

While I won't be asking anyone for code to use in my app,, my project partner and I do acknowledge we are going to need help, as a large part of the core of our app involves things outside of the scope of what our class teaches. Our project is a simple 5 level static map Rogue-like game. What I am asking is what would be the easiest and most reliable techniques to implement the following types of systems?
  • 2 dimensional map
  • Movement
  • Combat
  • Equipment/Inventory/Character management
  • Connecting the graphics to everything
  • Movement/combat of the enemies

We are incorporating very basic graphics, with none of the images being animated during movement or combat. At this point in time, we are only really looking to make it all 'work reliably', so we don't mind if the code isn't 'that well done', as this is a complex task, and is not going to be made commercially available (at least until we have learned more and can make this exactly how we want).

What we have thought so far is to use a 2 dimensional array for the map, with each space storing a value that denotes whether it is a floor, wall, void (outside the level map), or whatever, and movement checks the direction the player wishes to go for this value and then moves them if it is possible.

Again, I am not looking for code but just advice on how to best approach this. Short snippets of code to demonstrate an example is fine, but I don't want you guys to do my assessment for me.

VIPStephan 09-18-2012 12:34 AM

And this has to be done in JavaScript? I thought mobile applications are programs written in real programming languages?

felgall 09-18-2012 03:50 AM

Quote:

Originally Posted by VIPStephan (Post 1270775)
And this has to be done in JavaScript? I thought mobile applications are programs written in real programming languages?


JavaScript IS a real programming language. There is nothing that other languages can do that cannot be done equally well by JavaScript provided that it is available to run on the particular environment.

As a suggestion for where to start in buiding such a complex app using JavaScript - I suggest breaking the project up into a number of separate objects that will interact with each other in the final app and to build and test each of the objects separately prior to linking them together.

Aurak 09-18-2012 07:47 AM

It does, because we are required to use Titanium Studio for doing the coding, and that is the language it uses. You code in JS, and it then does something or other that makes it work with which ever mobile system you tell it to work on. I would prefer to just extend my Java lessons and code straight for Android using it's native language, but one of the requirements of the assessment is to use this idiot program that is 'available for Windows' but so far I have not encountered anyone who uses it with Windows and does not have it crash constantly (if they can even get to a point they can code without it freezing or crashing).

As to breaking it into smaller sections, we are part way there. We aren't sure how far down we can/should break it up, other than into combat, movement, inventory management, character management, and how to do the maps/levels.

felgall 09-18-2012 10:17 PM

Quote:

Originally Posted by Aurak (Post 1270852)
We aren't sure how far down we can/should break it up, other than into combat, movement, inventory management, character management, and how to do the maps/levels.

Just keep breaking it down into smaller pieces until the way to code each piece becomes simple and obvious.

Old Pedant 09-18-2012 11:46 PM

I'm truly curious how this could be used to create a (presumably? "combat" and "enemies" sounds like it) multi-player game, given that JS doesn't have any way to do user-to-user communications.

I suppose this magic Titanium Studio might have a server-side component that would enable that, somehow, but if so this seems like a pretty ambitious project for a one-semester class.

Hmmm...google is your friend...
http://www.appcelerator.com/platform/titanium-studio
Quote:

Titanium Studio is an all inclusive powerful Eclipse-based integrated development environment (IDE), that simplifies the mobile development process. Use Titanium Studio to rapidly build, test, package and publish mobile, desktop and web applications. Take advantage of new functionality like advanced code assisting, ACS integration, module management, Git integration, an enhanced publishing workflow and a full-featured editor. Manage Titanium projects, test your mobile apps in the simulator or on device, automate app packaging deploy to a public or private App Store and much more … all from within the new Titanium Studio.
I don't see anything in there that claims to support client-to-client communications, but maybe the devil is in the details.

Aurak 09-19-2012 03:58 AM

It's not a multiplayer game, I probably should have made that clearer, so sorry for any confusion. Rogue-likes are traditionally a single player dungeon crawler. NetHack is a good example of a traditional Rogue-like, and comes with both the command prompt ('real' Rogue-likes don't use graphics, just ASCII characters) and a gui.

As to it being ambitious, yes, we are aware of that. Our 'main' programming class assessment is to make a GUI based sudoku and calkuro game (no choice there, we were told that's what we are doing), with a long list of what to implement. This is on a similar scale to that I believe, just in a more interesting (to my project partner and I) way. To try and prevent us getting too far ahead of ourselves, we said at the start it would be capped at 5 levels, static maps (so no random map generation, like the 'real' Rogue-likes had), and just simple versions of the other major things in that style of game.

The combat/movement of enemies is simply for loosely AI style opponents. They will have set amounts of health and damage, and would only need to move them towards the player.

When it comes to breaking the different pieces down, combat would be the most complex I think. Choosing the direction to attack, doing the damage (if there is an enemy in range), checking the enemy's health, and the death of the enemy if applicable Then the reciprocal for the enemy/enemies attacking the player.

Movement would be, based on how I am thinking of doing it with a 2 dimensional array, would be that it checks either the column or the row that the player is trying to move to. Each of the entries in the array holds a value (eg 1 for floor, 2 for wall, 3 for void/inaccessible space). If the check returns anything other than 1, it would not move them to that space. If it returned 1, it would then move them, and change the variable storing their current position to reflect the change.

Character creation is relatively simple, choose a name, choose a class (only difference between them is the ranged classes can attack up to 3 spaces away, otherwise identical).

Inventory/character management is a little more complex. Items that can be equipped would be just touch to equip or unequip if it is worn. Usable things like health potions would be touch to use, then subtract 1 count from the number in the inventory. Of course, there is also how things get into the inventory, specific game events that trigger the count for an item to increase.

Connecting the graphics to everything will be another tricky part I think. To date, neither of us have any experience connecting graphics into anything with coding aside from a web design class last semester and we are just starting to deal with graphics on moving objects in our application development class.

The assessment is broken into 3 stages, and while we are only at the 2nd stage (interface creation), we are trying to get as much of a head start on the final stage as we can due to the complexity of it all.

Old Pedant 09-19-2012 04:40 AM

If you only need static images (that is, the characters can't wave their arms or actually look like they are throwing something), it's not too tough. You just use the z-index to position the characters in front of the static map (or, for that matter, make the map image be a background image).

I would certainly NOT say this is on the same order of complexity as creating a sudoku game. It's at least an order of magnitude more complex. Reaching toward two orders of magnitude.

Let me put it this way: I think I could create a sudoku game in a day, fairly easily. I think it would take me at least a week and likely two to do what you are describing here. Assuming I wanted to make a game that was worth playing, at least.

Glad to know it's not multi-player. At least now it sounds like it's possible to do in a semester. (I do recognize that you can't spend the entire semester doing JUST this. When would you have time to party? <grin/>)

Aurak 09-19-2012 04:45 AM

I don't party so there's half a semester gained on it's own haha.

The problems I'm having with Java (another matter that doesn't need to be gone into here) make this seem a lot easier. It's just finding the starting point and the right way to go about it. As I mentioned in the first post, efficiency isn't really high on our list, only that it be reliable and relatively easy to implement.

If we were to go with the map being a background image instead of doing it as a 2 dimensional array, how would we go about that? I was thinking the array simply because I've spent the last few weeks dealing with those so they are fresh in my mind. I would have to split the image into sections somehow, either literally making them individual pieces, or figuratively and be able to specify co-ordinates for the center of each tile.

Oh and the sudoku game involves making a GUI, saving games, providing different complexity of puzzles, storing statistics for different players, as well as implementing calkuro, a mathmatics based game that uses the rules of sudoku. I just refer to it as a sudoku game for short because it's faster, and I'm not yet to the stage of implementing calkuro into it.

Old Pedant 09-19-2012 06:22 AM

You can still use the 2D array id. I assume you will have a different image for each "kind" of square on the board, no?

So you simply create a <table> with <tr> rows and <td> colummns, such that each <td> is the mapping of one element of your 2D array. And you make the background image of each <td> correspond to the type of square per the specs in your 2D array.

Example:
Code:

<style type="text/css">
table#playfield td {
    width: 80px; height: 80px;
}
</style>

<table id="playfield"></table>

<script type="text/javascript">
var fieldtypes = [
    "blank", /* 0 */
    "grass", /* 1 */
    "mountain", /* 2 */
    "swamp" /* 3 */
];
var gamefield =
  [ 
      [ 1, 1, 0, 1 ],
      [ 1, 3, 3, 2 ],
      [ 1, 3, 0, 2 ],
      [ 3, 3, 2, 2 ]
  ];

var tbl = document.getElementById("playfield");
for ( var r = 0; r < gamefield.length; ++r )
{
    var row = gamefield[r];
    var trow = tbl.insertRow();
    for ( var c = 0; c < row.length; ++c )
    {
        var cell = row[c];
        var image = fieldtypes[cell] + ".png";
        var tcell = trow.insertCell( );
        tcell.backgroundImage = "url('/images/" + image + "')";
    }
}
</script>

See? As simple as that.

Old Pedant 09-19-2012 06:25 AM

Slightly better than just using the numbers to designate the map would be to use meaningful names. Would be easier to envision the board.

Code:


<script type="text/javascript">
var fieldtypes = [
    "blank", /* 0 */
    "grass", /* 1 */
    "mountain", /* 2 */
    "swamp" /* 3 */
];
var blank = 0, grass = 1, mount = 2, swamp = 3;

var gamefield =
  [ 
      [ grass, grass, blank, grass ],
      [ grass, swamp, swamp, mount ],
      [ grass, swamp, blank, mount ],
      [ swamp, swamp, mount, mount ]
  ];


Old Pedant 09-19-2012 06:29 AM

Quote:

Oh and the sudoku game involves making a GUI, saving games, providing different complexity of puzzles, storing statistics for different players,...
Okay, I give up. How do you store statistics for different players without storing them on a server? You mean just storing local (same machine) scores?

Even so, how do you save games and scores? Are you guaranteed that all the devices used will have local storage?

Old Pedant 09-19-2012 06:31 AM

Have to admit I've never figured out how to predict the difficulty of solving of a computer-generated sudoku puzzle. I mean you can take a stab at it, based on the count of given numbers on the board, but that isn't a good measure of how complex it will be for a human to solve.

Aurak 09-19-2012 06:36 AM

Thanks. That will help quite a lot. I'll let you know how we go with it once we get onto that part. We hope to have our interface done by the middle of next week (we both have a couple of other assessments we are working on too, otherwise we would be cramming every waking moment we weren't at uni into this), and then we will be moving on to the 'engine', the behind the scenes coding like this.

Our lecturer has already said he is going to be grading tasks based on their complexity, and right now, we look to be able to make the most mistakes before we fail. His comment regarding grading and our work was that he only needs to be able to get past character creation and into a map for us to pass, and if he can get to the end of the 5th level without it crashing, we will have a minimum of a distinction. That being said, he has also said we are going to be under the most pressure to pull off our app.

Aurak 09-19-2012 06:38 AM

Quote:

Originally Posted by Old Pedant (Post 1271225)
Have to admit I've never figured out how to predict the difficulty of solving of a computer-generated sudoku puzzle. I mean you can take a stab at it, based on the count of given numbers on the board, but that isn't a good measure of how complex it will be for a human to solve.

Puzzles are created by people, stored in a text file in a specific format, such as:

0 0 0 5 0 0 8 3 1
0 5 3 0 0 8 7 0 0
7 0 0 0 4 2 0 6 0
0 0 9 0 3 0 0 7 8
0 0 2 4 0 6 1 0 0
6 3 0 0 9 0 2 0 0
0 1 0 7 6 0 0 0 9
0 0 4 9 0 0 5 8 0
2 9 7 0 0 3 0 0 0

The 0's are the 'empty' spaces. The program can generate solutions (part of the supplied code that we must use, and are not allowed modify). We just have to create the code around that, that actually makes the game work. The statistics are supposed to be saved locally in a .txt file. There are a few other things we have to do, but I'm not that far into the task yet, I've just finished making it load the puzzle in and am now working on getting the different options to work (enter number, remove a number, get a hint, get the solution).


All times are GMT +1. The time now is 07:01 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.