How are you supposed to start it? Because I am completely lost and need help Thi
ID: 3881626 • Letter: H
Question
How are you supposed to start it? Because I am completely lost and need help
Explanation / Answer
colorgame.cs
using System;
class Game{
private char[] array = new char[11];
Game(){
for(int i=0;i<11;i++)
array[i] = ' ';
}
void Display(){
for(int x=0;x<11;x++){
Console.Write(array[x]);
}
}
bool full(){
for(int x=0;x<11;x++){
if (array[x] == ' ')
return false;
}
return true;
}
void move(char player, int pos){
array[pos-1] = player;
}
int score(char player){
int count = 0;
int score = 0;
for (int i=0;i<11;i++){
if(array[i] == player)
count++;
else{
if(count == 2)
score += 4;
else
if(count == 3)
score += 6;
else
if(count == 4)
score += 8;
count = 0;
}
}
return score;
}
}
public class Program{
static void main(string[] args){
Game game = new Game();
int position = 0;
while(game.full() == false){
game.Display();
Console.Write("Red Player- Enter your move: ");
position = Convert.ToInt32(Console.ReadLine());
game.move('R',position);
if(game.full() == false){
game.Display();
Console.Write("Blue Player- Enter your move: ");
position = Convert.ToInt32(Console.ReadLine());
game.move('B', position);
}
}
game.Display();
Console.WriteLine("Red Player- Your score is {0}",game.score('R'));
Console.WriteLine("Blue Player- Your score is {0}",game.score('B'));
Console.WriteLine();
Console.Write("Press any key to continue.....");
Console.ReadKey();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.