There are several examples of how to do this on: http://roguebasin.roguelikedevelopment.org/index.php?title=Field_of_Vision
You can use this code to check if a wall is in a units line of sight.
Unit u = ...;
Vec2 direction = new Vec2(1, 0); // whatever direction the unit is facing, 1,0 = along the X axis
Vec2 searchPosition = u.position().clone();
for(int i = 0; i < u.searchDistance /* how far should we cast a ray*/; i++) {
if(map[searchPosition.x][searchPosition.y] == 0) {
return true;
}
searchPosition.add(direction);
}
return false;
If a wall is in the way this code will return true, if not it will return the opposite. With a few modifications you can make it check for another unit.