Hey, I am trying to make a backgammon game, My teacher asked me to do somestuff in my project and i dont really know how to do it, Can someone help me with that please?
I am trying to do it and its not working for me, Please can someone help me with that?
My Teacher Says "There is a place where we wrote to check if he was allowed to move
Then write a function that checks the can move at all: and returns can or can not. Once you find one place that can move, then you will return the truth and should not continue to check
If there is a player out there, then check for each cube if allowed to put it in place that it brings it.
If all its parts are in place of the end (and then can pull out) then check that can move (because the legality there is a little different)
If there is no player out there, then for any place that has players check for each cube if you can move"
My C# Code
using System;
namespace ConsoleApp43
{
class Program
{
static string playerName1, playerName2;
static int whatToMove;
static int countToMove;
static int turn;
static int[] bord = new int[26];
static int[] dice = new int[4];
static Random rnd = new Random();
static int outRed;
static int outBlue;
static void PrintPlayers()
{
int jump = 0;
for (int i = 0; i < 13; i++)
{
Console.SetCursorPosition(i * 5 + jump + 3, 2);
if (bord[i] != 0)
{
if (bord[i] > 0)
Console.ForegroundColor = ConsoleColor.Blue;
else
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(Math.Abs(bord[i]) + " ");
}
Console.SetCursorPosition(i * 5 + jump + 3, 12);
if (bord[25 - i] != 0)
{
if (bord[25 - i] > 0)
Console.ForegroundColor = ConsoleColor.Blue;
else
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(Math.Abs(bord[25 - i]) + " ");
}
if (i == 6)
jump = 5;
}
if (outBlue > 0)
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.SetCursorPosition(38, 2);
Console.Write(outBlue);
}
if (outRed > 0)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.SetCursorPosition(38, 12);
Console.Write(outRed);
}
Console.ForegroundColor = ConsoleColor.White;
}
public static void PrintScreen()
{
Console.SetCursorPosition(1, 1);
for (int i = 1; i <= 71; i++)
Console.Write("═");
Console.SetCursorPosition(1, 13);
for (int i = 1; i <= 71; i++)
Console.Write("═");
for (int i = 2; i <= 12; i++)
{
Console.SetCursorPosition(1, i);
Console.Write("║");
Console.SetCursorPosition(6, i);
Console.Write("║");
Console.SetCursorPosition(36, i);
Console.Write("║");
Console.SetCursorPosition(41, i);
Console.Write("║");
Console.SetCursorPosition(71, i);
Console.Write("║");
}
for (int i = 0; i < 14; i++)
{
Console.SetCursorPosition(1 + i * 5, 2);
Console.Write("║");
Console.SetCursorPosition(1 + i * 5, 12);
Console.Write("║");
}
int jump = 0;
for (int i = 1; i < 13; i++)
{
Console.SetCursorPosition(jump + 3 + i * 5, 0);
Console.Write(i);
Console.SetCursorPosition(jump + 3 + i * 5, 14);
Console.Write(25 - i);
if (i == 6)
jump = 5;
}
Console.SetCursorPosition(38, 0);
Console.Write(99);
Console.SetCursorPosition(38, 14);
Console.Write(99);
}
static void PrintDice(int x, int y, int dice)
{
Console.SetCursorPosition(x, y);
Console.Write("╔═══╗");
Console.SetCursorPosition(x, y + 1);
Console.Write("║");
Console.SetCursorPosition(x + 2, y + 1);
Console.Write(dice);
Console.SetCursorPosition(x + 4, y + 1);
Console.Write("║");
Console.SetCursorPosition(x, y + 2);
Console.Write("╚═══╝");
}
static void DeleteDice() {
for (int i = 0; i < 3; i++)
{
Console.SetCursorPosition(14, 6 + i);
Console.Write(" ");
Console.SetCursorPosition(49, 6 + i);
Console.Write(" ");
}
}
public static void PrintDice()
{
dice[0] = rnd.Next(1, 7);
dice[1] = rnd.Next(1, 7);
DeleteDice();
if (dice[0] == dice[1])
{
PrintDice(14, 6, dice[0]);
PrintDice(24, 6, dice[0]);
PrintDice(49, 6, dice[0]);
PrintDice(59, 6, dice[0]);
dice[2] = dice[0];
dice[3] = dice[0];
}
else
{
PrintDice(17, 6, dice[0]);
PrintDice(55, 6, dice[1]);
dice[2] = 0;
dice[3] = 0;
}
}
public static bool checkDice(int countToMove, bool toPrint = false)
{
for (int i = 0; i < dice.Length; i++)
if (dice[i] == countToMove)
{
int whereToMove = bord[whatToMove + (countToMove * turn)];
if (whereToMove == 0 || whereToMove == Math.Abs(whereToMove) * turn || whereToMove == turn * -1)
return true;
else
{
if (toPrint == true)
Console.WriteLine("You cannot move there");
return false;
}
}
if (toPrint == true)
Console.WriteLine("No dice like that");
return false;
}
public static bool checkMove(int whatToMove)
{
if (whatToMove == 99)
{
if (turn == 1 && outBlue > 0)
return true;
else
{
if (turn == -1 && outRed > 0)
return true;
else
return false;
}
}
if (turn == 1 && bord[whatToMove] > 0)
return true;
else
if (turn == -1 && bord[whatToMove] < 0)
return true;
return false;
}
public static void PrintPlayerTurn()
{
if (turn == 1)
{
Console.SetCursorPosition(0, 15);
Console.WriteLine("Its your turn: " + playerName1);
}
else
{
Console.WriteLine("Its your turn: " + playerName2);
}
}
public static void MoveMe(int whatToMove, int countToMove)
{
}
static void Main(string[] args)
{
playerName1 = "Roie";
playerName2 = "Avichay";
for (int i = 0; i < 26; i++)
bord[i] = 0;
bord[1] = 2;
bord[12] = 5;
bord[17] = 3;
bord[19] = 5;
bord[24] = -2;
bord[13] = -5;
bord[8] = -3;
bord[6] = -5;
outBlue = 0;
outRed = 0;
turn = 1;
PrintScreen();
PrintPlayers();
PrintDice();
PrintPlayerTurn();
Console.SetCursorPosition(0, 16);
do
{
Console.Write("What do you want to move? ");
try
{
whatToMove = int.Parse(Console.ReadLine());
}
catch (Exception e)
{
whatToMove = 0;
}
} while (((whatToMove > 0 && whatToMove < 26) || whatToMove == 99) && checkMove(whatToMove) == false);
do
{
Console.Write("how much do you want to move? ");
countToMove = int.Parse(Console.ReadLine());
} while (checkDice(countToMove, true) == false);
Console.SetCursorPosition(0, 20);
}
}
}
What I have tried:
I have tried to make it and its not worked for me...
The project looks like that right now :
Screenshot 1 — imgbb.com[
^]