My players are labeled avatar, and they are a string with 2 elements.
Player[] avatar = new Player[2];
My Player Turning code:
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
for (int j = 0; j < 2; j++)
if (avatar[j].TurnSpent == false)
{
PlayerTurn(j);
avatar[j].TurnSpent = true;
}
foreach (Player a in avatar)
a.TurnSpent = false;
base.Update(gameTime);
}
My playerTurn Method:
public void PlayerTurn( int j)
{
KeyboardState cur = Keyboard.GetState();
if(avatar[j].TurnSpent == false)
{
if (cur.IsKeyDown(Keys.Space) && !old.IsKeyDown(Keys.Space) && (avatar[j].Position < 49))
{
// handle space down
int tempPos = 0;
int i = d.Roll();
avatar[j].Move(i);
message = "Player 1 rolled a " + i;
tempPos = avatar[j].Position;
avatar[j].Move(adjustment[space_types[avatar[j].Position]]);
if (space_types[tempPos] == 1)
space_types[tempPos] = 2;
avatar[j].Roll();
}
else if (avatar[j].Position == 49)
{
}
old = cur;
}
}
My PlayerClass:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace JohnGame
{
public class Player
{
private int position;
private int rollCount;
private bool turnSpent;
public bool TurnSpent
{
get { return turnSpent; }
set { turnSpent = value; }
}
public int Position
{
get { return position; }
set { position = value; }
}
public int RollCount
{
get { return rollCount; }
set { rollCount = value; }
}
public Player()
{
position = 0;
RollCount = 0;
turnSpent = false;
}
private void SetPosition(int pos)
{
if (pos >= 49)
pos = 49;
if (pos <= 0)
pos = 0;
position = pos;
}
public void Move(int i)
{
SetPosition(position + i);
}
public void Roll()
{
RollCount++;
}
}
}
Thanks,
John


Sign In
Create Account

Back to top









