Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I don't know if what I programmed worth anything, I've never programmed something like that, I just need to handle a player movement on a map, I thought a tile map will work, but I don't know anymore.

Description of logic of end result

I have a board game I want to program, the map has 3 levels.

Each level is a square (outer square, inner, and middle square).

On a player move phase (I have phases and turns implemented).

He rolls a dice (random func from 1 to 6 implemented).

And he can move forward or backwards how much he rolled (let's say he rolled 3).

End description of logic of end result

Below here is what I tried to do.

I can get the player map pos, the map is a 2d array (like a tilemap), I've also created a "location" array to represent each location. (bellow is an example not actual code).

var map = [
             [0,1,3,5]
            ,[11,31,4,5,]
            ,[12,31,4,5,]
          ];

var locations = [];
locations[0]={name:"trailer park",desc:"bla",pos_on_map:[0,0]};
locations[1]={name:"mall",desc:"bla",pos_on_map:[1,0]};

Say I created a move method on the game handle object how do I let the player select to move 3 squares backwards or forward(he can select to move 1 or 2 if he wants). and what if it means going from 0 to 11 or 12 or from 11 to 3.

How do I loop through such options? It's from one array "row" to another on the 2d array.

Now I have:

if(game_manger.turn_phase >2){game_manger.manu="game_manu"}
//loop trogh all input options output
var loop_tims = game_manger.move_amount;
var c_player = game_manger_p.current_player();
var p_loc = c_player.loc;
var c_p_level = c_player.map_level;
var board_len = my_map[c_p_level].length ;

for(var i =0; i < loop_tims;i++)
{

    if(i < board_len)//only existing locations
    {

        var loc = i+1 + p_loc;//map location num
        jout(loc+")locatio name");
    }
}

It's not very well implemented... not even the map data part, I don't think a 2d array like this will work I need something to separate it to levels but still let me output it like a tile map.

Also there is no info anywhere on the web about how to program a board game or a turn based game.

share|improve this question
    
why vote down? im really at a dead end and cant find any info on the subject. –  rolen123 Jul 13 '13 at 14:45
    
I think your question is kind of vague. At first it seems you want a solution for finding possible movement locations, and how to wrap an array, then you talk about how you're unsure if you even want to use the array and how there's no info on how to make a board game. It sounds like you're undecided where you want to go. If you found a solution for finding movement locations, would you then think the 2D array would work? I think you need to figure out your data structures and be sure you want to use them before you move on with the project. –  Byte56 Jul 13 '13 at 14:54
    
You should post your solution as an answer (you'll be able to accept it a few hours later) rather than editing your question to contain it. –  Josh Petrie Jul 14 '13 at 0:12
add comment

2 Answers

The problem you have is pretty fundamental and open ended, there isn't one solution to your problem. I'm trying to understand the issue here. You have two arrays: The map array is the 2D array which describes your map and the other locations just holds where significant locations are.

Though maybe some psuedo code could help you:

1. Get the players current position
2. Get the status of the position the player wishes to move to
3. Look at the contents of the position to make sure it's ok
4. If the position is OK to move too set the value of the array 
   at the given position to indicate the player is there
5. Remove the player status from his current position in the array
6. Update the current position of the player with the moved to position

Does this help?

share|improve this answer
    
ill use something like that when the player chooses where to go but how do i show him where he should go? i thoght of using somthing like that:brasshats.com/screen1.gif somthing that wil hilight where the player can go to. –  rolen123 Jul 13 '13 at 15:26
    
Well that's what I meant with the openendiness of your question, that's specific based on your implementation and the graphics library your using. I can't really answer that question for you. –  Bryan Abrams Jul 13 '13 at 15:57
    
yore right it is kinda open ended i need a solution ,i wrote what i need,if you have any resources or somthing that would be helpful. ill use the small code you wrote for the move method eventually. i dont think what library i use matter because you can program a board game with ascii. –  rolen123 Jul 13 '13 at 16:22
    
Just keep doing what you're doing, you're on the right track. What people do is they represent the data in the computer like you. They process data in a way they decide and later after doing calculations like for moving the player, they map that data to a graphical representation, like an image. –  Bryan Abrams Jul 13 '13 at 22:42
    
its a ok i solved it with the power of google! but thanks for trying to help me. –  rolen123 Jul 13 '13 at 22:47
add comment

solved:

didnt test it for bugs but its based on Manhattan distance algoritem thing.

as it seems my location chose menu was in an intimate (information) relationship with player class so i moved the method and they got it on too so i had to separate this method it was too unrefractiony unorganised and not very useful. so location manu will only call sometimes.

what dose it do is take the distance of movement and chack its maximum and minmum movment both left and right and up and down and then loops on all of those values,checks if posible pos |x-i+y-j| is not bigger then distance :

x=500 y=500 dist=5,i=495 j=495,|x:500-i:495|+|y:500-j:495|=10<5=false (you cant move 5 left and 5 up its a little bigger then 5 the distance).

but if true put it in can_move_array ,and after you fill it do the type of action,output to show the player input to verify he chose a right move action. afterwerds ill add more condition like type of location because my board has levels,and i dont want players moving into a next level square.

someone should write a tut about it not enough resources for that kind of fun games.

maybe write an engine...

player_p.move_info = function(distanse,type,map,y_input)
 {
var can_move_array = [];
var move_amount = distanse;//game_manger.move_amount;
var x = this.loc[0];
var y = this.loc[1];

//map level and length
var p_level = this.map_level;
var board_len = my_map[p_level].length ;

//move from, its curent position less move amount so you can move backwords too.
var min_x= x - move_amount;
var min_y= y - move_amount;

//maximum amount can move
var max_x = x + move_amount;
var max_y = y + move_amount;
//for x
for(i = min_x; i<=max_x; i++ )
{
    //for y
    for(j = min_y; j<=max_x; j++ )
    {
         if (Math.abs(x-i) + Math.abs(y-j) <= distance) 
         {
            can_move_array.push() ={x:i,y:j, location:map[i][j]};//overkill...but i need the map location num and the map cordenates.
         }

    }
}


if(type == "output")
{
    this.move_output(can_move_array);//loops can move an hilights it
    return;
}
if(type == "input")
{
    this.move_input(can_move_array,y_input);//looks stupid but chacks if input is in  can move array.if not ...return
    return;
}

its only conceptual and ill need to fix it .but you can use the general idea.if not leave a comment ill help.

share|improve this answer
1  
For Hexgrids, there is a basic engine here: hexgridutilities.codeplex.com; open source MIT license. –  Pieter Geerkens Jul 14 '13 at 1:21
    
ill check into it(wasnt thinking of hex but why not) –  rolen123 Jul 14 '13 at 9:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.