ID:144421
 
Code:
mob
Login()
world<<"[src.name] has logged in"
loc = locate(/turf/start)
icon = 'tank.dmi'
..()
start_battle()

var
letter[]
A
B
C
D
player
count = 0
turn
move = "move"
mob
proc
start_battle()
var/mob/M
for(M in view())
M.count++
if(M.count==0)
M<<"You cannot play against yourself"
return 0
if(M.count==1)
M<<"You are now player one"
M.turn=1
M.move = "done"
if(M.count==2)
M<<"You are now player two"
M.turn=2
M.move = "done"
if(M.count==3)
M<<"You are now player three"
M.turn=3
M.move = "done"
if(M.count==4)
M<<"You are now player four"
M.turn=4
M.move = "done"
if(M.turn==1)
M<<"It is now your turn"
M.move=5


turf
start
turf
ground
icon = 'dirt.dmi'
mob
Move()
if(move=="done")
src<<"It it currently not your turn"
else if(move=="move") ..()
else if(move<=0)
src<<"You are out of moves, click *end turn* to end your turn."
switch(alert(src,"End turn?","END","Yes","No"))
if("Yes")
var/mob/M
M.turn="over"
for(M in view())
if(M.turn==1)
M<<"It is now your turn"
world<<"It is now [M]'s turn"
M.move=5
if(M.turn==2)
M<<"It is now your turn"
world<<"It is now [M]'s turn"
M.move=5
else
src.move--
src<<"You have [src.move] move\s left."
..()
mob
test_dummy
icon = 'tank.dmi'
New()
walk_around()
proc
walk_around()
for()
sleep(2)
walk_rand(src)


Problem description:

My turn system doesn't work properly, i'm trying to figure out a way to define player 1 2 3 and 4.That way, I can easily call on them at anytime. This is the closest I can get. Is there an easier way to define the players as letters or something so I can call on them easier? Ex:
view() << "It is now [A]'s turn!"
A.turn = 1
new/mob/proc/end_turn(A)
A.move = 5
//anyways, I hope you get the point.



It's a much better idea to use a datum to control battles, and it's probably the only correct way to doing it, especially when there are going to be 5 players in a battle. If you don't know how to use datums, you can take a look at Lummox JR's DreamTutor on datums.

What you basically want to do is to create an instance of the battle datum when you get into combat. The battle datum will then hold all variables and procs that control the battle (who is in the battle, figuring out whose turn it is, ending turns, etc)

Some skeleton code would look similar to this:

mob/player
var
battle/game // variable to create game

verb/start_game()
var/list/players
// TODO: Get a list of players the game starter will be playing against

src.game = new /battle (src, players) // create an instance of the game, and let the game start and end itself

proc/action_regarding_game() // generic action a player may want to do
if(src.game && src in game.players) // check if the player is first playing a game, and if they are a valid player
if(src.game.getTurn() == src) // check if the player's turn is up
// your action here
else
src << "It's not your turn!"


battle // datum to control battles
var
mob/player/creator // who runs the current battle
turn // number telling whose turn it is
list/players = list() // list of people in the battle

New(mob/M, list/P)
src.creator = M
src.players = P
for(var/mob/player/A in src.players)
A.game = src
src.StartGame()


proc
getTurn() // returns the current turn
return players[src.turn]

StartGame()
src.turn = 1
src.players << "[src.creator]'s game has started!"
src.StartTurn()

StartTurn()
src.getTurn() << "It is now your turn."

NextTurn()
src.turn ++
if(src.turn > length(src.players))
src.turn = 1
src.StartTurn()

// ...


Generally, battle datums are structured this way if players are taking turns.
In response to Unknown Person
Hmm, very confusing.

That guide you showed me doesn't make any sence.

Isn't the blue book supposed to teach all? I feel just as lost as I was before reading the blue book as I am now. It's not a good feeling.